blob: 56035077824cc0f606b216d840920d53e9de07a7 [file] [log] [blame]
developer20d67712022-03-02 14:09:32 +08001#!/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
9BUILD_TIME=`date +%Y%m%d%H%M%S`
10build_flag=0
11
12if [ -z ${BUILD_DIR} ]; then
13 LOCAL=1
14 BUILD_DIR=`pwd`
15fi
16
17MTK_FEED_DIR=${BUILD_DIR}/feeds/mtk_openwrt_feed
18MTK_MANIFEST_FEED=${BUILD_DIR}/../mtk-openwrt-feeds
19
20if [ -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
26fi
27
28OPENWRT_VER=`cat ${BUILD_DIR}/feeds.conf.default | grep "src-git packages" | awk -F ";openwrt" '{print $2}'`
29cp ${BUILD_DIR}/feeds.conf.default ${BUILD_DIR}/feeds.conf.default_ori
30
31clean() {
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
39do_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
47prepare() {
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
85add_proprietary_kernel_files() {
86 #cp mtk proprietary ko_module source to mtk target
87 #and also need to be done in release mtk target
developer20d67712022-03-02 14:09:32 +080088
developer9b3248d2022-07-06 00:44:05 +080089 # mean it is old process for possible build issue and should delete it gradually in the furture.
90 if [ ! -d ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless/wifi_utility ]; then
91 mkdir -p ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless
92 cp -rf ${BUILD_DIR}/../ko_module/gateway/proprietary_driver/drivers/wifi_utility/ ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless
93 fi
developer20d67712022-03-02 14:09:32 +080094
95 cp -fpR ${BUILD_DIR}/autobuild/target/ ${BUILD_DIR}
96}
97
98prepare_mtwifi() {
99 #remove officail OpenWRT wifi script
100 #wifi-profile pkg will install wifi_jedi instead
101 rm -rf ${BUILD_DIR}/package/base-files/files/sbin/wifi
102
103 add_proprietary_kernel_files
104
105 #do mtk_wifi openwrt patch
106 do_patch ${BUILD_DIR}/autobuild/openwrt_patches${OPENWRT_VER}/mtk_wifi || exit 1
107}
108
developer9b3248d2022-07-06 00:44:05 +0800109prepare_flowoffload() {
developer3fb2e8c2022-07-08 11:35:22 +0800110 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0004-2102-netfilter-remove-nf_flow_table_hw.patch
111
developer9b3248d2022-07-06 00:44:05 +0800112 #rm patches for flowblock
113 rm -rf ./target/linux/generic/pending-5.4/64*.patch
114 rm -rf ./target/linux/generic/hack-5.4/647-netfilter-flow-acct.patch
115 rm -rf ./target/linux/generic/hack-5.4/650-netfilter-add-xt_OFFLOAD-target.patch
116 rm -rf ./target/linux/mediatek/patches-5.4/1002-mtkhnat-add-support-for-virtual-interface-acceleration.patch
117
118 #hack mt7986 config5.4
119 echo "CONFIG_BRIDGE_NETFILTER=y" >> ./target/linux/mediatek/mt7986/config-5.4
120 echo "CONFIG_NETFILTER_FAMILY_BRIDGE=y" >> ./target/linux/mediatek/mt7986/config-5.4
121 echo "CONFIG_SKB_EXTENSIONS=y" >> ./target/linux/mediatek/mt7986/config-5.4
122
123 #hack mt7622 config5.4
124 echo "CONFIG_BRIDGE_NETFILTER=y" >> ./target/linux/mediatek/mt7622/config-5.4
125 echo "CONFIG_NETFILTER_FAMILY_BRIDGE=y" >> ./target/linux/mediatek/mt7622/config-5.4
126 echo "CONFIG_SKB_EXTENSIONS=y" >> ./target/linux/mediatek/mt7622/config-5.4
127}
128
developere2cc0fa2022-03-29 17:31:03 +0800129prepare_mac80211() {
developer7b9aeab2022-06-13 11:31:33 +0800130 rm -rf ${BUILD_DIR}/package/network/services/hostapd
131 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/services/hostapd ${BUILD_DIR}/package/network/services
132
133 rm -rf ${BUILD_DIR}/package/libs/libnl-tiny
134 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/libs/libnl-tiny ${BUILD_DIR}/package/libs
135
136 rm -rf ${BUILD_DIR}/package/network/utils/iw
developerbd32d6d2022-06-14 13:19:41 +0800137 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iw ${BUILD_DIR}/package/network/utils
developer7b9aeab2022-06-13 11:31:33 +0800138
139 rm -rf ${BUILD_DIR}/package/network/utils/iwinfo
140 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iwinfo ${BUILD_DIR}/package/network/utils
141
142 rm -rf ${BUILD_DIR}/package/kernel/mac80211
143 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mac80211 ${BUILD_DIR}/package/kernel
144
145 rm -rf ${BUILD_DIR}/package/firmware/wireless-regdb
developerbd32d6d2022-06-14 13:19:41 +0800146 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/firmware/wireless-regdb ${BUILD_DIR}/package/firmware
developer7b9aeab2022-06-13 11:31:33 +0800147
148 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mt76 ${BUILD_DIR}/package/kernel
149
developer9b3248d2022-07-06 00:44:05 +0800150 #hack mt7986 hostapd config
151 echo "CONFIG_MBO=y" >> ./package/network/services/hostapd/files/hostapd-full.config
152 echo "CONFIG_WPS_UPNP=y" >> ./package/network/services/hostapd/files/hostapd-full.config
153 echo "CONFIG_DPP=y" >> ./package/network/services/hostapd/files/hostapd-full.config
154 echo "CONFIG_DPP2=y" >> ./package/network/services/hostapd/files/hostapd-full.config
155 echo "CONFIG_DPP3=y" >> ./package/network/services/hostapd/files/hostapd-full.config
156 echo "CONFIG_DPP=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
157 echo "CONFIG_DPP2=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
158 echo "CONFIG_DPP3=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
159
developere2cc0fa2022-03-29 17:31:03 +0800160 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
161 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0002-master-hostapd-makefile-for-utils.patch
162 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch
163 cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/package/ ${BUILD_DIR}
developer73b93122022-04-19 23:16:58 +0800164 cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/target/ ${BUILD_DIR}
developere2cc0fa2022-03-29 17:31:03 +0800165}
166
developer20d67712022-03-02 14:09:32 +0800167copy_main_Config() {
168 echo cp -rfa autobuild/$1/.config ./.config
169 cp -rfa autobuild/$1/.config ./.config
170}
171
172install_output_Image() {
173 mkdir -p ${INSTALL_DIR}/$1
174
175 files=`find bin/targets/$3/*${2}* -name "*.bin" -o -name "*.img"`
176 file_count=0
177
178 for file in $files
179 do
180 tmp=${file%.*}
181 cp -rf $file ${INSTALL_DIR}/$1/${tmp##*/}-${BUILD_TIME}.${file##*.}
182 ((file_count++))
183 done
184
185 if [ ${file_count} = 0 ]; then
186 if [ ${build_flag} -eq 0 ]; then
187 let build_flag+=1
188 echo " Restart to debug-build with "make V=s -j1", starting......"
189 build $1 -j1 || [ "$LOCAL" != "1" ]
190 else
191 echo " **********Failed to build $1, bin missing.**********"
192 fi
193 else
194 echo "Install image OK!!!"
195 echo "Build $1 successfully!"
196 fi
197}
198
199install_output_Config() {
200 echo cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config
201 cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config
202 [ -f tmp/kernel.config ] && cp tmp/kernel.config ${INSTALL_DIR}/$1/kernel.config
203}
204
205install_output_KernelDebugFile() {
206 KernelDebugFile=bin/targets/$3/mt${2}*/kernel-debug.tar.bz2
207 if [ -f ${KernelDebugFile} ]; then
208 echo cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2
209 cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2
210 fi
211}
212
213install_output_RootfsDebugFile() {
214 STAGING_DIR_ROOT=$(make -f "autobuild/get_stagingdir_root.mk" get-staging-dir-root)
215 if [ -d ${STAGING_DIR_ROOT} ]; then
216 STAGING_DIR_ROOT_PREFIX=$(dirname ${STAGING_DIR_ROOT})
217 STAGING_DIR_ROOT_NAME=$(basename ${STAGING_DIR_ROOT})
218 echo "tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C \"$STAGING_DIR_ROOT_PREFIX\" \"$STAGING_DIR_ROOT_NAME\""
219 tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C "$STAGING_DIR_ROOT_PREFIX" "$STAGING_DIR_ROOT_NAME"
220 fi
221}
222
223install_output_feeds_buildinfo() {
224 feeds_buildinfo=$(find bin/targets/$3/*${2}*/ -name "feeds.buildinfo")
225 echo "feeds_buildinfo=$feeds_buildinfo"
226 if [ -f ${feeds_buildinfo} ]; then
227 cp -rf $feeds_buildinfo ${INSTALL_DIR}/$1/feeds.buildinfo
228 else
229 echo "feeds.buildinfo is not found!!!"
230 fi
231}
232
233install_release() {
234 temp=${1#*mt}
235 chip_name=${temp:0:4}
236 temp1=`grep "CONFIG_TARGET_ramips=y" autobuild/$1/.config`
237
238 if [ "${temp1}" == "CONFIG_TARGET_ramips=y" ]; then
239 arch_name="ramips"
240 else
241 arch_name="mediatek"
242 fi
243
244 #install output image
245 install_output_Image $1 ${chip_name} ${arch_name}
246
247 #install output config
248 install_output_Config $1
249
250 #install output Kernel-Debug-File
251 install_output_KernelDebugFile $1 ${chip_name} ${arch_name}
252
253 #tar unstripped rootfs for debug symbols
254 install_output_RootfsDebugFile $1
255
256 #install output feeds buildinfo
257 install_output_feeds_buildinfo $1 ${chip_name} ${arch_name}
258}
259
260prepare_final() {
261 #cp customized autobuild SDK patches
262 cp -fpR ${BUILD_DIR}/autobuild/$1/target/ ${BUILD_DIR}
263 cp -fpR ${BUILD_DIR}/autobuild/$1/package/ ${BUILD_DIR}
264
265
266 #cp special subtarget patches
267 case $1 in
268 mt7986*)
269 cp -rf ${BUILD_DIR}/autobuild/mt7986-AX6000/target/linux/mediatek/patches-5.4/*.* ${BUILD_DIR}/target/linux/mediatek/patches-5.4
270 ;;
271 *)
272 ;;
273 esac
274
275 #rm old legacy patch, ex old nfi nand driver
276 case $1 in
277 mt7986*|\
278 mt7981*)
279 rm -rf ${BUILD_DIR}/target/linux/mediatek/patches-5.4/0303-mtd-spinand-disable-on-die-ECC.patch
280 ;;
281 *)
282 ;;
283 esac
284
285 cd ${BUILD_DIR}
286 [ -f autobuild/$1/.config ] || {
287 echo "unable to locate autobuild/$1/.config !"
288 return
289 }
290
291 rm -rf ./tmp
292 #copy main test config(.config)
293 copy_main_Config $1
294
295 echo make defconfig
296 make defconfig
297}
298
299build() {
300 echo "###############################################################################"
301 echo "# $1"
302 echo "###############################################################################"
303 echo "build $1"
304
305 cd ${BUILD_DIR}
306
developer9b3248d2022-07-06 00:44:05 +0800307 #make
308
309 echo "make V=s -j $(($(nproc) + 1)) download world"
310 make V=s -j $(($(nproc) + 1)) download world || exit 1
311
312 #tar unstripped rootfs for debug symbols
313 install_release $1
314}
315
316build_log() {
317 echo "###############################################################################"
318 echo "# $1"
319 echo "###############################################################################"
320 echo "build $1"
321
322 cd ${BUILD_DIR}
323
324 #make
325
326 echo "make V=s -j $(($(nproc) + 1)) download world"
327 make V=s -j $(($(nproc) + 1)) download world || make V=s -j1 || exit 1
developer20d67712022-03-02 14:09:32 +0800328
329 #tar unstripped rootfs for debug symbols
330 install_release $1
331}