developer | 20d6771 | 2022-03-02 14:09:32 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # There are 2 env-variables set for you, you can use it in your script. |
| 4 | # ${BUILD_DIR} , working dir of this script, eg: openwrt/lede/ |
| 5 | # ${INSTALL_DIR}, where to install your build result, including: image, build log. |
| 6 | # |
| 7 | |
| 8 | #Global variable |
| 9 | BUILD_TIME=`date +%Y%m%d%H%M%S` |
| 10 | build_flag=0 |
| 11 | |
| 12 | if [ -z ${BUILD_DIR} ]; then |
| 13 | LOCAL=1 |
| 14 | BUILD_DIR=`pwd` |
| 15 | fi |
| 16 | |
| 17 | MTK_FEED_DIR=${BUILD_DIR}/feeds/mtk_openwrt_feed |
| 18 | MTK_MANIFEST_FEED=${BUILD_DIR}/../mtk-openwrt-feeds |
| 19 | |
| 20 | if [ -z ${INSTALL_DIR} ]; then |
| 21 | INSTALL_DIR=autobuild_release |
| 22 | mkdir -p ${INSTALL_DIR} |
| 23 | if [ ! -d target/linux ]; then |
| 24 | echo "You should call this scripts from openwrt's root directory." |
| 25 | fi |
| 26 | fi |
| 27 | |
| 28 | OPENWRT_VER=`cat ${BUILD_DIR}/feeds.conf.default | grep "src-git packages" | awk -F ";openwrt" '{print $2}'` |
| 29 | cp ${BUILD_DIR}/feeds.conf.default ${BUILD_DIR}/feeds.conf.default_ori |
| 30 | |
| 31 | clean() { |
| 32 | echo "clean start!" |
| 33 | echo "It will take some time ......" |
| 34 | make distclean |
| 35 | rm -rf ${INSTALL_DIR} |
| 36 | echo "clean done!" |
| 37 | } |
| 38 | |
| 39 | do_patch(){ |
| 40 | files=`find $1 -name "*.patch" | sort` |
| 41 | for file in $files |
| 42 | do |
| 43 | patch -f -p1 -i ${file} || exit 1 |
| 44 | done |
| 45 | } |
| 46 | |
| 47 | prepare() { |
| 48 | echo "Preparing...." |
| 49 | #FIXME : workaround HOST PC build issue |
| 50 | #cd package/mtk/applications/luci-app-mtk/;git checkout Makefile;cd - |
| 51 | #mv package/mtk package/mtk_soc/ ./ |
| 52 | #rm -rf tmp/ feeds/ target/ package/ scripts/ tools/ include/ toolchain/ rules.mk |
| 53 | #git checkout target/ package/ scripts/ tools/ include/ toolchain/ rules.mk |
| 54 | #mv ./mtk ./mtk_soc/ package/ |
| 55 | cp ${BUILD_DIR}/autobuild/feeds.conf.default${OPENWRT_VER} ${BUILD_DIR}/feeds.conf.default |
| 56 | |
| 57 | #update feed |
| 58 | ${BUILD_DIR}/scripts/feeds update -a |
| 59 | |
| 60 | #check if manifest mtk_feed exist,if yes,overwrite and update it in feeds/ |
| 61 | if [ -d ${MTK_MANIFEST_FEED} ]; then |
| 62 | rm -rf ${MTK_FEED_DIR} |
| 63 | ln -s ${MTK_MANIFEST_FEED} ${MTK_FEED_DIR} |
| 64 | ${BUILD_DIR}/scripts/feeds update -a |
| 65 | fi |
| 66 | |
| 67 | #do mtk_feed prepare_sdk.sh |
| 68 | cp ${MTK_FEED_DIR}/prepare_sdk.sh ${BUILD_DIR} |
| 69 | |
| 70 | #if $1 exist(mt76), keep origin openwrt patches and remove mtk local eth driver |
| 71 | if [ -z ${1} ]; then |
| 72 | ${BUILD_DIR}/prepare_sdk.sh ${MTK_FEED_DIR} || exit 1 |
| 73 | else |
| 74 | ${BUILD_DIR}/prepare_sdk.sh ${MTK_FEED_DIR} ${1} || exit 1 |
| 75 | rm -rf ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/ |
| 76 | fi |
| 77 | #install feed |
| 78 | ${BUILD_DIR}/scripts/feeds install -a |
| 79 | ${BUILD_DIR}/scripts/feeds install -a luci |
| 80 | |
| 81 | #do mtk_soc openwrt patch |
| 82 | do_patch ${BUILD_DIR}/autobuild/openwrt_patches${OPENWRT_VER}/mtk_soc || exit 1 |
| 83 | } |
| 84 | |
| 85 | add_proprietary_kernel_files() { |
| 86 | #cp mtk proprietary ko_module source to mtk target |
| 87 | #and also need to be done in release mtk target |
| 88 | mkdir -p ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless |
| 89 | cp -rf ${BUILD_DIR}/../ko_module/gateway/proprietary_driver/drivers/wifi_utility/ ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless |
| 90 | |
| 91 | mkdir -p ${BUILD_DIR}/target/linux/mediatek/files-5.4/include/uapi/linux/ |
| 92 | cp -rf ${BUILD_DIR}/../kernel/wapp_uapi_includes ${BUILD_DIR}/target/linux/mediatek/files-5.4/include/uapi/linux/wapp |
| 93 | |
| 94 | cp -fpR ${BUILD_DIR}/autobuild/target/ ${BUILD_DIR} |
| 95 | } |
| 96 | |
| 97 | prepare_mtwifi() { |
| 98 | #remove officail OpenWRT wifi script |
| 99 | #wifi-profile pkg will install wifi_jedi instead |
| 100 | rm -rf ${BUILD_DIR}/package/base-files/files/sbin/wifi |
| 101 | |
| 102 | add_proprietary_kernel_files |
| 103 | |
| 104 | #do mtk_wifi openwrt patch |
| 105 | do_patch ${BUILD_DIR}/autobuild/openwrt_patches${OPENWRT_VER}/mtk_wifi || exit 1 |
| 106 | } |
| 107 | |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 108 | prepare_mac80211() { |
developer | 7b9aeab | 2022-06-13 11:31:33 +0800 | [diff] [blame] | 109 | rm -rf ${BUILD_DIR}/package/network/services/hostapd |
| 110 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/services/hostapd ${BUILD_DIR}/package/network/services |
| 111 | |
| 112 | rm -rf ${BUILD_DIR}/package/libs/libnl-tiny |
| 113 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/libs/libnl-tiny ${BUILD_DIR}/package/libs |
| 114 | |
| 115 | rm -rf ${BUILD_DIR}/package/network/utils/iw |
developer | bd32d6d | 2022-06-14 13:19:41 +0800 | [diff] [blame] | 116 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iw ${BUILD_DIR}/package/network/utils |
developer | 7b9aeab | 2022-06-13 11:31:33 +0800 | [diff] [blame] | 117 | |
| 118 | rm -rf ${BUILD_DIR}/package/network/utils/iwinfo |
| 119 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iwinfo ${BUILD_DIR}/package/network/utils |
| 120 | |
| 121 | rm -rf ${BUILD_DIR}/package/kernel/mac80211 |
| 122 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mac80211 ${BUILD_DIR}/package/kernel |
| 123 | |
| 124 | rm -rf ${BUILD_DIR}/package/firmware/wireless-regdb |
developer | bd32d6d | 2022-06-14 13:19:41 +0800 | [diff] [blame] | 125 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/firmware/wireless-regdb ${BUILD_DIR}/package/firmware |
developer | 7b9aeab | 2022-06-13 11:31:33 +0800 | [diff] [blame] | 126 | |
| 127 | cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mt76 ${BUILD_DIR}/package/kernel |
| 128 | |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 129 | patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch |
| 130 | patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0002-master-hostapd-makefile-for-utils.patch |
| 131 | patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch |
| 132 | cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/package/ ${BUILD_DIR} |
developer | 73b9312 | 2022-04-19 23:16:58 +0800 | [diff] [blame] | 133 | cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/target/ ${BUILD_DIR} |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 134 | } |
| 135 | |
developer | 20d6771 | 2022-03-02 14:09:32 +0800 | [diff] [blame] | 136 | copy_main_Config() { |
| 137 | echo cp -rfa autobuild/$1/.config ./.config |
| 138 | cp -rfa autobuild/$1/.config ./.config |
| 139 | } |
| 140 | |
| 141 | install_output_Image() { |
| 142 | mkdir -p ${INSTALL_DIR}/$1 |
| 143 | |
| 144 | files=`find bin/targets/$3/*${2}* -name "*.bin" -o -name "*.img"` |
| 145 | file_count=0 |
| 146 | |
| 147 | for file in $files |
| 148 | do |
| 149 | tmp=${file%.*} |
| 150 | cp -rf $file ${INSTALL_DIR}/$1/${tmp##*/}-${BUILD_TIME}.${file##*.} |
| 151 | ((file_count++)) |
| 152 | done |
| 153 | |
| 154 | if [ ${file_count} = 0 ]; then |
| 155 | if [ ${build_flag} -eq 0 ]; then |
| 156 | let build_flag+=1 |
| 157 | echo " Restart to debug-build with "make V=s -j1", starting......" |
| 158 | build $1 -j1 || [ "$LOCAL" != "1" ] |
| 159 | else |
| 160 | echo " **********Failed to build $1, bin missing.**********" |
| 161 | fi |
| 162 | else |
| 163 | echo "Install image OK!!!" |
| 164 | echo "Build $1 successfully!" |
| 165 | fi |
| 166 | } |
| 167 | |
| 168 | install_output_Config() { |
| 169 | echo cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config |
| 170 | cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config |
| 171 | [ -f tmp/kernel.config ] && cp tmp/kernel.config ${INSTALL_DIR}/$1/kernel.config |
| 172 | } |
| 173 | |
| 174 | install_output_KernelDebugFile() { |
| 175 | KernelDebugFile=bin/targets/$3/mt${2}*/kernel-debug.tar.bz2 |
| 176 | if [ -f ${KernelDebugFile} ]; then |
| 177 | echo cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2 |
| 178 | cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2 |
| 179 | fi |
| 180 | } |
| 181 | |
| 182 | install_output_RootfsDebugFile() { |
| 183 | STAGING_DIR_ROOT=$(make -f "autobuild/get_stagingdir_root.mk" get-staging-dir-root) |
| 184 | if [ -d ${STAGING_DIR_ROOT} ]; then |
| 185 | STAGING_DIR_ROOT_PREFIX=$(dirname ${STAGING_DIR_ROOT}) |
| 186 | STAGING_DIR_ROOT_NAME=$(basename ${STAGING_DIR_ROOT}) |
| 187 | echo "tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C \"$STAGING_DIR_ROOT_PREFIX\" \"$STAGING_DIR_ROOT_NAME\"" |
| 188 | tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C "$STAGING_DIR_ROOT_PREFIX" "$STAGING_DIR_ROOT_NAME" |
| 189 | fi |
| 190 | } |
| 191 | |
| 192 | install_output_feeds_buildinfo() { |
| 193 | feeds_buildinfo=$(find bin/targets/$3/*${2}*/ -name "feeds.buildinfo") |
| 194 | echo "feeds_buildinfo=$feeds_buildinfo" |
| 195 | if [ -f ${feeds_buildinfo} ]; then |
| 196 | cp -rf $feeds_buildinfo ${INSTALL_DIR}/$1/feeds.buildinfo |
| 197 | else |
| 198 | echo "feeds.buildinfo is not found!!!" |
| 199 | fi |
| 200 | } |
| 201 | |
| 202 | install_release() { |
| 203 | temp=${1#*mt} |
| 204 | chip_name=${temp:0:4} |
| 205 | temp1=`grep "CONFIG_TARGET_ramips=y" autobuild/$1/.config` |
| 206 | |
| 207 | if [ "${temp1}" == "CONFIG_TARGET_ramips=y" ]; then |
| 208 | arch_name="ramips" |
| 209 | else |
| 210 | arch_name="mediatek" |
| 211 | fi |
| 212 | |
| 213 | #install output image |
| 214 | install_output_Image $1 ${chip_name} ${arch_name} |
| 215 | |
| 216 | #install output config |
| 217 | install_output_Config $1 |
| 218 | |
| 219 | #install output Kernel-Debug-File |
| 220 | install_output_KernelDebugFile $1 ${chip_name} ${arch_name} |
| 221 | |
| 222 | #tar unstripped rootfs for debug symbols |
| 223 | install_output_RootfsDebugFile $1 |
| 224 | |
| 225 | #install output feeds buildinfo |
| 226 | install_output_feeds_buildinfo $1 ${chip_name} ${arch_name} |
| 227 | } |
| 228 | |
| 229 | prepare_final() { |
| 230 | #cp customized autobuild SDK patches |
| 231 | cp -fpR ${BUILD_DIR}/autobuild/$1/target/ ${BUILD_DIR} |
| 232 | cp -fpR ${BUILD_DIR}/autobuild/$1/package/ ${BUILD_DIR} |
| 233 | |
| 234 | |
| 235 | #cp special subtarget patches |
| 236 | case $1 in |
| 237 | mt7986*) |
| 238 | cp -rf ${BUILD_DIR}/autobuild/mt7986-AX6000/target/linux/mediatek/patches-5.4/*.* ${BUILD_DIR}/target/linux/mediatek/patches-5.4 |
| 239 | ;; |
| 240 | *) |
| 241 | ;; |
| 242 | esac |
| 243 | |
| 244 | #rm old legacy patch, ex old nfi nand driver |
| 245 | case $1 in |
| 246 | mt7986*|\ |
| 247 | mt7981*) |
| 248 | rm -rf ${BUILD_DIR}/target/linux/mediatek/patches-5.4/0303-mtd-spinand-disable-on-die-ECC.patch |
| 249 | ;; |
| 250 | *) |
| 251 | ;; |
| 252 | esac |
| 253 | |
| 254 | cd ${BUILD_DIR} |
| 255 | [ -f autobuild/$1/.config ] || { |
| 256 | echo "unable to locate autobuild/$1/.config !" |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | rm -rf ./tmp |
| 261 | #copy main test config(.config) |
| 262 | copy_main_Config $1 |
| 263 | |
| 264 | echo make defconfig |
| 265 | make defconfig |
| 266 | } |
| 267 | |
| 268 | build() { |
| 269 | echo "###############################################################################" |
| 270 | echo "# $1" |
| 271 | echo "###############################################################################" |
| 272 | echo "build $1" |
| 273 | |
| 274 | cd ${BUILD_DIR} |
| 275 | |
| 276 | #make |
| 277 | echo make V=s $2 |
| 278 | make V=s $2 || exit 1 |
| 279 | |
| 280 | #tar unstripped rootfs for debug symbols |
| 281 | install_release $1 |
| 282 | } |