blob: 404ad0a3bac39fdebabdc121527ef86788059b20 [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
developer7273f5f2022-12-12 17:18:16 +080018MTK_MANIFEST_FEED=${BUILD_DIR}/../mtk-openwrt-feeds
developer20d67712022-03-02 14:09:32 +080019
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}'`
developer068e1a42022-08-29 17:24:20 +080029if [ -z ${OPENWRT_VER} ]; then
30 OPENWRT_VER=`cat ${BUILD_DIR}/feeds.conf.default | grep "src-git-full packages" | awk -F ";openwrt" '{print $2}'`
31fi
32
developer20d67712022-03-02 14:09:32 +080033cp ${BUILD_DIR}/feeds.conf.default ${BUILD_DIR}/feeds.conf.default_ori
34
35clean() {
36 echo "clean start!"
37 echo "It will take some time ......"
38 make distclean
39 rm -rf ${INSTALL_DIR}
40 echo "clean done!"
41}
42
43do_patch(){
44 files=`find $1 -name "*.patch" | sort`
45 for file in $files
46 do
47 patch -f -p1 -i ${file} || exit 1
48 done
49}
50
51prepare() {
52 echo "Preparing...."
53 #FIXME : workaround HOST PC build issue
54 #cd package/mtk/applications/luci-app-mtk/;git checkout Makefile;cd -
55 #mv package/mtk package/mtk_soc/ ./
56 #rm -rf tmp/ feeds/ target/ package/ scripts/ tools/ include/ toolchain/ rules.mk
57 #git checkout target/ package/ scripts/ tools/ include/ toolchain/ rules.mk
58 #mv ./mtk ./mtk_soc/ package/
59 cp ${BUILD_DIR}/autobuild/feeds.conf.default${OPENWRT_VER} ${BUILD_DIR}/feeds.conf.default
60
61 #update feed
62 ${BUILD_DIR}/scripts/feeds update -a
63
64 #check if manifest mtk_feed exist,if yes,overwrite and update it in feeds/
65 if [ -d ${MTK_MANIFEST_FEED} ]; then
66 rm -rf ${MTK_FEED_DIR}
67 ln -s ${MTK_MANIFEST_FEED} ${MTK_FEED_DIR}
68 ${BUILD_DIR}/scripts/feeds update -a
69 fi
70
71 #do mtk_feed prepare_sdk.sh
72 cp ${MTK_FEED_DIR}/prepare_sdk.sh ${BUILD_DIR}
73
74 #if $1 exist(mt76), keep origin openwrt patches and remove mtk local eth driver
75 if [ -z ${1} ]; then
76 ${BUILD_DIR}/prepare_sdk.sh ${MTK_FEED_DIR} || exit 1
77 else
78 ${BUILD_DIR}/prepare_sdk.sh ${MTK_FEED_DIR} ${1} || exit 1
79 rm -rf ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/
80 fi
81 #install feed
82 ${BUILD_DIR}/scripts/feeds install -a
83 ${BUILD_DIR}/scripts/feeds install -a luci
84
85 #do mtk_soc openwrt patch
86 do_patch ${BUILD_DIR}/autobuild/openwrt_patches${OPENWRT_VER}/mtk_soc || exit 1
87}
88
89add_proprietary_kernel_files() {
90 #cp mtk proprietary ko_module source to mtk target
91 #and also need to be done in release mtk target
developer20d67712022-03-02 14:09:32 +080092
developer9b3248d2022-07-06 00:44:05 +080093 # mean it is old process for possible build issue and should delete it gradually in the furture.
94 if [ ! -d ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless/wifi_utility ]; then
95 mkdir -p ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless
96 cp -rf ${BUILD_DIR}/../ko_module/gateway/proprietary_driver/drivers/wifi_utility/ ${BUILD_DIR}/target/linux/mediatek/files-5.4/drivers/net/wireless
97 fi
developer20d67712022-03-02 14:09:32 +080098
99 cp -fpR ${BUILD_DIR}/autobuild/target/ ${BUILD_DIR}
100}
101
102prepare_mtwifi() {
103 #remove officail OpenWRT wifi script
104 #wifi-profile pkg will install wifi_jedi instead
105 rm -rf ${BUILD_DIR}/package/base-files/files/sbin/wifi
106
107 add_proprietary_kernel_files
108
109 #do mtk_wifi openwrt patch
110 do_patch ${BUILD_DIR}/autobuild/openwrt_patches${OPENWRT_VER}/mtk_wifi || exit 1
111}
112
developer9b3248d2022-07-06 00:44:05 +0800113prepare_flowoffload() {
developer3fb2e8c2022-07-08 11:35:22 +0800114 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0004-2102-netfilter-remove-nf_flow_table_hw.patch
115
developer9b3248d2022-07-06 00:44:05 +0800116 #rm patches for flowblock
117 rm -rf ./target/linux/generic/pending-5.4/64*.patch
118 rm -rf ./target/linux/generic/hack-5.4/647-netfilter-flow-acct.patch
119 rm -rf ./target/linux/generic/hack-5.4/650-netfilter-add-xt_OFFLOAD-target.patch
120 rm -rf ./target/linux/mediatek/patches-5.4/1002-mtkhnat-add-support-for-virtual-interface-acceleration.patch
121
122 #hack mt7986 config5.4
123 echo "CONFIG_BRIDGE_NETFILTER=y" >> ./target/linux/mediatek/mt7986/config-5.4
124 echo "CONFIG_NETFILTER_FAMILY_BRIDGE=y" >> ./target/linux/mediatek/mt7986/config-5.4
125 echo "CONFIG_SKB_EXTENSIONS=y" >> ./target/linux/mediatek/mt7986/config-5.4
126
127 #hack mt7622 config5.4
128 echo "CONFIG_BRIDGE_NETFILTER=y" >> ./target/linux/mediatek/mt7622/config-5.4
129 echo "CONFIG_NETFILTER_FAMILY_BRIDGE=y" >> ./target/linux/mediatek/mt7622/config-5.4
130 echo "CONFIG_SKB_EXTENSIONS=y" >> ./target/linux/mediatek/mt7622/config-5.4
131}
132
developere2cc0fa2022-03-29 17:31:03 +0800133prepare_mac80211() {
developer7b9aeab2022-06-13 11:31:33 +0800134 rm -rf ${BUILD_DIR}/package/network/services/hostapd
135 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/services/hostapd ${BUILD_DIR}/package/network/services
136
137 rm -rf ${BUILD_DIR}/package/libs/libnl-tiny
138 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/libs/libnl-tiny ${BUILD_DIR}/package/libs
139
140 rm -rf ${BUILD_DIR}/package/network/utils/iw
developerbd32d6d2022-06-14 13:19:41 +0800141 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iw ${BUILD_DIR}/package/network/utils
developer7b9aeab2022-06-13 11:31:33 +0800142
143 rm -rf ${BUILD_DIR}/package/network/utils/iwinfo
144 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/network/utils/iwinfo ${BUILD_DIR}/package/network/utils
145
146 rm -rf ${BUILD_DIR}/package/kernel/mac80211
developer7273f5f2022-12-12 17:18:16 +0800147 if [ $1 = "1" ]; then
148 echo "=========================MAC80211 v6.1==================="
149 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mac80211 ${BUILD_DIR}/package/kernel
150 rm -rf ${MTK_FEED_DIR}/autobuild_mac80211_release/package/kernel/mac80211
151 mv ${MTK_FEED_DIR}/autobuild_mac80211_release/package/kernel/mac80211_dev ${MTK_FEED_DIR}/autobuild_mac80211_release/package/kernel/mac80211
152 else
153 echo "=========================MAC80211 v5.15=================="
154 tar xvf ${MTK_FEED_DIR}/autobuild_mac80211_release/package/kernel/mac80211/mac80211_v5.15.81_077622a1.tar.gz -C ${BUILD_DIR}/package/kernel/
155 fi
developer7b9aeab2022-06-13 11:31:33 +0800156 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mac80211 ${BUILD_DIR}/package/kernel
157
158 rm -rf ${BUILD_DIR}/package/firmware/wireless-regdb
developerbd32d6d2022-06-14 13:19:41 +0800159 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/firmware/wireless-regdb ${BUILD_DIR}/package/firmware
developer7b9aeab2022-06-13 11:31:33 +0800160
161 cp -fpR ${BUILD_DIR}/./../mac80211_package/package/kernel/mt76 ${BUILD_DIR}/package/kernel
developer7273f5f2022-12-12 17:18:16 +0800162 rm -rf ${BUILD_DIR}/package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch
developer27f88012022-09-01 11:15:04 +0800163 rm -rf ${BUILD_DIR}/package/kernel/mt76/patches/101-fix-encap-offload-ethernet-type-check.patch
developer9b3248d2022-07-06 00:44:05 +0800164 #hack mt7986 hostapd config
165 echo "CONFIG_MBO=y" >> ./package/network/services/hostapd/files/hostapd-full.config
166 echo "CONFIG_WPS_UPNP=y" >> ./package/network/services/hostapd/files/hostapd-full.config
167 echo "CONFIG_DPP=y" >> ./package/network/services/hostapd/files/hostapd-full.config
168 echo "CONFIG_DPP2=y" >> ./package/network/services/hostapd/files/hostapd-full.config
169 echo "CONFIG_DPP3=y" >> ./package/network/services/hostapd/files/hostapd-full.config
170 echo "CONFIG_DPP=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
171 echo "CONFIG_DPP2=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
172 echo "CONFIG_DPP3=y" >> ./package/network/services/hostapd/files/wpa_supplicant-full.config
173
developere2cc0fa2022-03-29 17:31:03 +0800174 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
175 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0002-master-hostapd-makefile-for-utils.patch
176 patch -f -p1 -i ${MTK_FEED_DIR}/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch
177 cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/package/ ${BUILD_DIR}
developer73b93122022-04-19 23:16:58 +0800178 cp -rfa ${MTK_FEED_DIR}/autobuild_mac80211_release/target/ ${BUILD_DIR}
developere2cc0fa2022-03-29 17:31:03 +0800179}
180
developer20d67712022-03-02 14:09:32 +0800181copy_main_Config() {
182 echo cp -rfa autobuild/$1/.config ./.config
183 cp -rfa autobuild/$1/.config ./.config
184}
185
186install_output_Image() {
187 mkdir -p ${INSTALL_DIR}/$1
188
189 files=`find bin/targets/$3/*${2}* -name "*.bin" -o -name "*.img"`
190 file_count=0
191
192 for file in $files
193 do
194 tmp=${file%.*}
195 cp -rf $file ${INSTALL_DIR}/$1/${tmp##*/}-${BUILD_TIME}.${file##*.}
196 ((file_count++))
197 done
198
199 if [ ${file_count} = 0 ]; then
200 if [ ${build_flag} -eq 0 ]; then
201 let build_flag+=1
202 echo " Restart to debug-build with "make V=s -j1", starting......"
203 build $1 -j1 || [ "$LOCAL" != "1" ]
204 else
205 echo " **********Failed to build $1, bin missing.**********"
206 fi
207 else
208 echo "Install image OK!!!"
209 echo "Build $1 successfully!"
210 fi
211}
212
213install_output_Config() {
214 echo cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config
215 cp -rfa autobuild/$1/.config ${INSTALL_DIR}/$1/openwrt.config
216 [ -f tmp/kernel.config ] && cp tmp/kernel.config ${INSTALL_DIR}/$1/kernel.config
217}
218
219install_output_KernelDebugFile() {
220 KernelDebugFile=bin/targets/$3/mt${2}*/kernel-debug.tar.bz2
221 if [ -f ${KernelDebugFile} ]; then
222 echo cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2
223 cp -rfa ${KernelDebugFile} ${INSTALL_DIR}/$1/kernel-debug.tar.bz2
224 fi
225}
226
227install_output_RootfsDebugFile() {
228 STAGING_DIR_ROOT=$(make -f "autobuild/get_stagingdir_root.mk" get-staging-dir-root)
229 if [ -d ${STAGING_DIR_ROOT} ]; then
230 STAGING_DIR_ROOT_PREFIX=$(dirname ${STAGING_DIR_ROOT})
231 STAGING_DIR_ROOT_NAME=$(basename ${STAGING_DIR_ROOT})
232 echo "tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C \"$STAGING_DIR_ROOT_PREFIX\" \"$STAGING_DIR_ROOT_NAME\""
233 tar -jcf ${INSTALL_DIR}/$1/rootfs-debug.tar.bz2 -C "$STAGING_DIR_ROOT_PREFIX" "$STAGING_DIR_ROOT_NAME"
234 fi
235}
236
237install_output_feeds_buildinfo() {
238 feeds_buildinfo=$(find bin/targets/$3/*${2}*/ -name "feeds.buildinfo")
239 echo "feeds_buildinfo=$feeds_buildinfo"
240 if [ -f ${feeds_buildinfo} ]; then
241 cp -rf $feeds_buildinfo ${INSTALL_DIR}/$1/feeds.buildinfo
242 else
243 echo "feeds.buildinfo is not found!!!"
244 fi
245}
246
247install_release() {
248 temp=${1#*mt}
249 chip_name=${temp:0:4}
250 temp1=`grep "CONFIG_TARGET_ramips=y" autobuild/$1/.config`
251
252 if [ "${temp1}" == "CONFIG_TARGET_ramips=y" ]; then
253 arch_name="ramips"
254 else
255 arch_name="mediatek"
256 fi
257
258 #install output image
259 install_output_Image $1 ${chip_name} ${arch_name}
260
261 #install output config
262 install_output_Config $1
263
264 #install output Kernel-Debug-File
265 install_output_KernelDebugFile $1 ${chip_name} ${arch_name}
266
267 #tar unstripped rootfs for debug symbols
268 install_output_RootfsDebugFile $1
269
270 #install output feeds buildinfo
271 install_output_feeds_buildinfo $1 ${chip_name} ${arch_name}
272}
273
274prepare_final() {
275 #cp customized autobuild SDK patches
276 cp -fpR ${BUILD_DIR}/autobuild/$1/target/ ${BUILD_DIR}
277 cp -fpR ${BUILD_DIR}/autobuild/$1/package/ ${BUILD_DIR}
developer7273f5f2022-12-12 17:18:16 +0800278 cp -fpR ${BUILD_DIR}/autobuild/$1/tools/ ${BUILD_DIR}
developer20d67712022-03-02 14:09:32 +0800279
280
281 #cp special subtarget patches
282 case $1 in
283 mt7986*)
284 cp -rf ${BUILD_DIR}/autobuild/mt7986-AX6000/target/linux/mediatek/patches-5.4/*.* ${BUILD_DIR}/target/linux/mediatek/patches-5.4
285 ;;
286 *)
287 ;;
288 esac
289
290 #rm old legacy patch, ex old nfi nand driver
291 case $1 in
292 mt7986*|\
293 mt7981*)
294 rm -rf ${BUILD_DIR}/target/linux/mediatek/patches-5.4/0303-mtd-spinand-disable-on-die-ECC.patch
295 ;;
296 *)
297 ;;
298 esac
299
300 cd ${BUILD_DIR}
301 [ -f autobuild/$1/.config ] || {
302 echo "unable to locate autobuild/$1/.config !"
303 return
304 }
305
306 rm -rf ./tmp
307 #copy main test config(.config)
308 copy_main_Config $1
309
310 echo make defconfig
311 make defconfig
312}
313
314build() {
315 echo "###############################################################################"
316 echo "# $1"
317 echo "###############################################################################"
318 echo "build $1"
319
320 cd ${BUILD_DIR}
321
developer9b3248d2022-07-06 00:44:05 +0800322 #make
323
324 echo "make V=s -j $(($(nproc) + 1)) download world"
325 make V=s -j $(($(nproc) + 1)) download world || exit 1
326
327 #tar unstripped rootfs for debug symbols
328 install_release $1
329}
330
331build_log() {
332 echo "###############################################################################"
333 echo "# $1"
334 echo "###############################################################################"
335 echo "build $1"
336
337 cd ${BUILD_DIR}
338
339 #make
340
341 echo "make V=s -j $(($(nproc) + 1)) download world"
342 make V=s -j $(($(nproc) + 1)) download world || make V=s -j1 || exit 1
developer20d67712022-03-02 14:09:32 +0800343
344 #tar unstripped rootfs for debug symbols
345 install_release $1
346}