blob: 515abd6b0922f630ea784b71cf75b413b8eca562 [file] [log] [blame]
Xiaobo Gu059502e2017-01-12 21:20:39 +08001#!/bin/bash
2#
3# author: xiaobo.gu@amlogic.com
4# 2016.09.28
5# 2016.12.01-2016.12.20 Update for bootloader repo
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +08006# 2017.05.20-2017.05.26 Update for txlx and ATF1.3
Xiaobo Gu059502e2017-01-12 21:20:39 +08007
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +08008# include compile check script
9source fip/check_compile.sh
xiaobo gue6c46862018-01-10 18:58:09 +080010source fip/variables.sh
11source fip/lib.sh
12source fip/build_bl2.sh
13source fip/build_bl30.sh
14source fip/build_bl31.sh
15source fip/build_bl32.sh
16source fip/build_bl33.sh
17source fip/build_bl40.sh
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080018
Xiaobo Gu059502e2017-01-12 21:20:39 +080019
xiaobo gue6c46862018-01-10 18:58:09 +080020function init_variable_early() {
21 # source uboot pre-build configs
22 if [ ! -e ${SOURCE_FILE} ]; then
23 echo "${SOURCE_FILE} doesn't exist!"
24 cd ${MAIN_FOLDER}
25 exit -1
26 else
27 source ${SOURCE_FILE} &> /dev/null # ignore warning/error
28 fi
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080029
xiaobo gue6c46862018-01-10 18:58:09 +080030 CUR_SOC=${CONFIG_SYS_SOC}
Xiaobo Gu059502e2017-01-12 21:20:39 +080031
xiaobo gue6c46862018-01-10 18:58:09 +080032 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
33 BLX_NEEDFUL[3]="true"
34 fi
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080035
xiaobo gue6c46862018-01-10 18:58:09 +080036 # export variables
37 #export FIP_BUILD_FOLDER
38 #export CUR_SOC
Xiaobo Gu059502e2017-01-12 21:20:39 +080039
xiaobo gue6c46862018-01-10 18:58:09 +080040 export_variables
Xiaobo Gu059502e2017-01-12 21:20:39 +080041}
42
xiaobo gue6c46862018-01-10 18:58:09 +080043function init_variable_late() {
44 # after uboot build, source configs
xiaobo gua64f93c2018-07-31 21:27:43 +080045 local CONFIG_FILE_TMP="${MAIN_FOLDER}/autoconf"
46 local STR_INVALID="option"
47 if [ ! -e ${CONFIG_FILE} ]; then
48 echo "${CONFIG_FILE} doesn't exist!"
49 cd ${MAIN_FOLDER}
50 exit -1
51 else
52 # workaround for source file error
53 while read LINE
54 do
55 #echo $LINE
56 # ignore "*(option)*" lines
57 if [[ ${LINE} =~ ${STR_INVALID} ]]; then
58 echo "ignore: $LINE"
59 else
60 #echo "LINE: ${LINE}"
61 echo "$LINE" >> "${CONFIG_FILE_TMP}"
62 fi
63 done < ${CONFIG_FILE}
64 source "${CONFIG_FILE_TMP}" &> /dev/null
65 rm ${CONFIG_FILE_TMP}
66 fi
xiaobo gue6c46862018-01-10 18:58:09 +080067 if [ "y" == "${CONFIG_SUPPORT_CUSOTMER_BOARD}" ]; then
68 BOARD_DIR="customer/board/${CONFIG_SYS_BOARD}"
69 else
70 BOARD_DIR="${CONFIG_BOARDDIR}"
71 fi
xiaobo gua64f93c2018-07-31 21:27:43 +080072 export BOARD_DIR
Xiaobo Gu059502e2017-01-12 21:20:39 +080073}
74
75function build_blx_src() {
xiaobo gue6c46862018-01-10 18:58:09 +080076 # compile $name $src_folder $bin_folder $soc
77 local name=$1
78 local src_folder=$2
79 local bin_folder=$3
80 local soc=$4
81 #dbg "compile - name: ${name}, src_folder: ${src_folder}, bin_folder: ${bin_folder}, soc: ${soc}"
xiaobo gu8a3907e2019-05-22 11:46:49 +080082 if [ $name == ${BLX_NAME_GLB[0]} ]; then
xiaobo gue6c46862018-01-10 18:58:09 +080083 # bl2
84 build_bl2 $src_folder $bin_folder $soc
xiaobo gu8a3907e2019-05-22 11:46:49 +080085 elif [ $name == ${BLX_NAME_GLB[1]} ]; then
xiaobo gue6c46862018-01-10 18:58:09 +080086 # bl30
87 build_bl30 $src_folder $bin_folder $soc
xiaobo gu8a3907e2019-05-22 11:46:49 +080088 elif [ $name == ${BLX_NAME_GLB[2]} ]; then
xiaobo gue6c46862018-01-10 18:58:09 +080089 # bl31
90 # some soc use v1.3
91 check_bl31_ver $soc
92 if [ $? != 0 ]; then
93 echo "check bl31 ver: use v1.3"
94 build_bl31_v1_3 $src_folder $bin_folder $soc
95 else
96 echo "check bl31 ver: use v1.0"
97 build_bl31 $src_folder $bin_folder $soc
98 fi
xiaobo gu8a3907e2019-05-22 11:46:49 +080099 elif [ $name == ${BLX_NAME_GLB[3]} ]; then
xiaobo gue8bf44f2019-03-18 14:23:36 +0800100 # control flow for jenkins patchbuild
101 if [ "$BUILD_TYPE" != "AOSP" ]; then
102 # bl32
103 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
104 build_bl32 $src_folder $bin_folder $soc
105 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800106 fi
107 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800108}
109
110function build_blx() {
xiaobo gue6c46862018-01-10 18:58:09 +0800111 # build each blx
112 mkdir -p ${FIP_BUILD_FOLDER}
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800113
xiaobo gue6c46862018-01-10 18:58:09 +0800114 # switch bl31 version
115 switch_bl31 ${CUR_SOC}
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800116
xiaobo gue6c46862018-01-10 18:58:09 +0800117 # get version of each blx
118 get_versions
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800119
xiaobo gue6c46862018-01-10 18:58:09 +0800120 # build loop
121 for loop in ${!BLX_NAME[@]}; do
122 dbg "BIN_PATH[${loop}]: ${BIN_PATH[loop]}"
123 if [ "null" == ${BIN_PATH[loop]} ]; then
124 get_blx_bin ${loop}
125 elif [ "source" == ${BIN_PATH[loop]} ]; then
126 dbg "Build blx source code..."
127 build_blx_src ${BLX_NAME[loop]} ${BLX_SRC_FOLDER[loop]} ${FIP_BUILD_FOLDER} ${CUR_SOC}
128 else
129 if [ ! -e ${BIN_PATH[loop]} ]; then
130 echo "Error: ${BIN_PATH[loop]} doesn't exist... abort"
131 exit -1
132 else
133 cp ${BIN_PATH[loop]} ${FIP_BUILD_FOLDER} -f
134 echo "Get ${BLX_NAME[$loop]} from ${BIN_PATH[loop]}... done"
135 fi
136 fi
137 done
138 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800139}
140
141copy_bootloader() {
xiaobo gue6c46862018-01-10 18:58:09 +0800142 mkdir -p ${BUILD_FOLDER}
Haixiang Baof008dc12019-05-23 18:47:15 +0800143 cp ${FIP_BUILD_FOLDER}u-boot.bin* ${BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800144 if [ "y" == "${CONFIG_AML_CRYPTO_IMG}" ]; then
145 cp ${FIP_BUILD_FOLDER}boot.img.encrypt ${BUILD_FOLDER}boot.img.encrypt
146 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800147}
148
149function update_bin_path() {
xiaobo gu8a3907e2019-05-22 11:46:49 +0800150 for loop in ${!BLX_NAME[@]}; do
151 if [ "${BLX_NAME[$loop]}" == "${BLX_NAME_GLB[$1]}" ]; then
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800152 dbg "Update BIN_PATH[$loop]=$2"
xiaobo gu8a3907e2019-05-22 11:46:49 +0800153 BIN_PATH[$loop]=$2
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800154 break
xiaobo gu8a3907e2019-05-22 11:46:49 +0800155 fi
156 done
157}
Xiaobo Gu059502e2017-01-12 21:20:39 +0800158
159function clean() {
xiaobo gue6c46862018-01-10 18:58:09 +0800160 echo "Clean up"
xiaobo gu0c2598b2019-06-28 11:22:17 +0800161 if [ -e ${BL33_PATH1} ]; then
162 cd ${MAIN_FOLDER}
163 cd ${BL33_PATH1}
164 make distclean
165 fi
166 if [ -e ${BL33_PATH2} ]; then
167 cd ${MAIN_FOLDER}
168 cd ${BL33_PATH2}
169 make distclean
170 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800171 cd ${MAIN_FOLDER}
172 rm ${FIP_BUILD_FOLDER} -rf
xiaobo gu3ce64072018-03-06 17:20:44 +0800173 rm ${BUILD_FOLDER}/* -rf
Haixiang Baof008dc12019-05-23 18:47:15 +0800174 mkdir -p ${BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800175 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800176}
177
178function build() {
xiaobo gue6c46862018-01-10 18:58:09 +0800179 # *************************************************
180 # IMPORTANT!!!!
181 # don't change sequence of following function call
182 # *************************************************
183 clean
184
185 # pre-build, get .config defines
186 pre_build_uboot $@
187
188 # variable init depends on uboot .config
189 init_variable_early $@
190
191 # must source under main function, all sub function can use these variables
192 # but if source in sub-function, only sub-function(or sub-sub..) can use them
193 source ${FIP_FOLDER}${CUR_SOC}/variable_soc.sh
194
195 # source soc package script
196 source ${FIP_FOLDER}${CUR_SOC}/build.sh
197
198 # update bin path, use bin.git or user defined or source code
199 bin_path_parser $@
xiaobo gude8a46a2018-03-05 21:41:54 +0800200 #bin_path_update $@
xiaobo gue6c46862018-01-10 18:58:09 +0800201
202 # build bl33/bl301..etc
Liang Ji51eee082019-05-20 14:01:24 +0800203 if [ ! $CONFIG_SYSTEM_AS_ROOT ]; then
Xindong Xu33eda2d2018-09-25 18:52:38 +0800204 CONFIG_SYSTEM_AS_ROOT=null
205 fi
Liang Ji51eee082019-05-20 14:01:24 +0800206 if [ ! $CONFIG_AVB2 ]; then
Xindong Xu33eda2d2018-09-25 18:52:38 +0800207 CONFIG_AVB2=null
208 fi
209 build_uboot ${CONFIG_SYSTEM_AS_ROOT} ${CONFIG_AVB2}
xiaobo gue6c46862018-01-10 18:58:09 +0800210
211 # source other configs after uboot compile
212 init_variable_late
213
214 # bl2/bl30/bl31..etc, build or copy from bin.git
215 build_blx $@
216
217 # cp bl33(uboot)
218 copy_bl33
219
220 # cp other firmwares(soc related)
221 copy_other_soc
222
Zhongfu Luo6c2587f2019-05-15 16:27:50 +0800223 # make build directory
224 mkdir -p ${BUILD_FOLDER}
225
xiaobo gue6c46862018-01-10 18:58:09 +0800226 # package final bootloader
227 package
228
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800229 if [ "y" != "${CONFIG_AML_SIGNED_UBOOT}" ]; then
230 # copy bootloader to main folder
231 copy_bootloader
232 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800233}
234
235function usage() {
236 cat << EOF
237 Usage:
238 $(basename $0) --help
239
xiaobo gue6c46862018-01-10 18:58:09 +0800240 Bootloader build script.
Xiaobo Gu059502e2017-01-12 21:20:39 +0800241
242 command list:
Xiaobo Gu059502e2017-01-12 21:20:39 +0800243 1. build default uboot:
244 ./$(basename $0) [config_name]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800245
xiaobo gue6c46862018-01-10 18:58:09 +0800246 2. build uboot with specified bl[x].bin
247 ./$(basename $0) [config_name] --bl[x] [path]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800248
xiaobo gue6c46862018-01-10 18:58:09 +0800249 3. build uboot with bl[x]/src source code
Xiaobo Gu059502e2017-01-12 21:20:39 +0800250 ./$(basename $0) [config_name] --update-bl[x]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800251
xiaobo gue6c46862018-01-10 18:58:09 +0800252 4. print config list
253 ./$(basename $0) --config
254
255 5. check compile status with filter(optional)
256 ./$(basename $0) --check-compile [filter]
257
xiaobo gu6368ebe2018-03-29 21:49:25 +0800258 6. update aml ddr fw by source code (for g12a and later use)
259 ./$(basename $0) [config_name] --update-bl2 --ddrfw
260
xiaobo gue6c46862018-01-10 18:58:09 +0800261
262 Example:
263 1) ./$(basename $0) gxb_p200_v1
264 build gxb_p200_v1 config
265
266 2) ./$(basename $0) gxb_p200_v1 --bl2 fip/bl2.bin --bl30 fip/bl30.bin
267 build gxb_p200_v1 with specified bl2.bin and bl30.bin
268
269 3) ./$(basename $0) gxb_p200_v1 --update-bl31 --update-bl2
270 build gxb_p200_v1 with bl31/bl2 source code
271
272 4) ./$(basename $0) --config
273 print config list
274
275 5) ./$(basename $0) --check-compile skt
276 check all skt board compile status
277
278 Remark:
279 bl[x].bin/img priority:
280 1. uboot will use binaries under bl[x]/bin/ folder by default, bl[x] version specified in .repo/manifest.xml
281 2. if you want use your own bl[x].bin, specify path by add "--bl[x] [path]" parameter
282 3. if you want use bl[x].bin by compile source code, please add "--update-bl[x]" parameter
283
Xiaobo Gu059502e2017-01-12 21:20:39 +0800284
285EOF
286 exit 1
287}
288
xiaobo gue6c46862018-01-10 18:58:09 +0800289function print_config() {
290 cat << EOF
291 Usable configs:
292`uboot_config_list`
293EOF
294 exit 1
295}
296
Xiaobo Gu059502e2017-01-12 21:20:39 +0800297function parser() {
xiaobo gue6c46862018-01-10 18:58:09 +0800298 local i=0
299 local argv=()
300 for arg in "$@" ; do
301 argv[$i]="$arg"
302 i=$((i + 1))
303 done
304 i=0
305 while [ $i -lt $# ]; do
306 arg="${argv[$i]}"
xiaobo gu3ce64072018-03-06 17:20:44 +0800307 i=$((i + 1)) # must place here
xiaobo gue6c46862018-01-10 18:58:09 +0800308 case "$arg" in
309 -h|--help|help)
310 usage
311 exit ;;
312 --config)
313 print_config
xiaobo gu3ce64072018-03-06 17:20:44 +0800314 return ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800315 --check-compile)
xiaobo gu66f95292018-01-11 13:38:13 +0800316 check_compile "${argv[@]:$((i))}"
xiaobo gue6c46862018-01-10 18:58:09 +0800317 exit ;;
318 clean|distclean|-distclean|--distclean)
319 clean
320 exit ;;
321 *)
322 esac
323 done
324}
325
xiaobo gude8a46a2018-03-05 21:41:54 +0800326function bin_path_update() {
327 # overwrite path in case some git repository doesn't exist
328 for loop in ${!BLX_BIN_FOLDER[@]}; do
329 if [ -ne ${BLX_BIN_FOLDER[$loop]} ]; then
330 dbg "BLX_BIN_FOLDER[$loop] doesn't exist, use src code"
331 update_bin_path $loop "source"
332 fi
333 done
334
335 for loop in ${!BLX_SRC_FOLDER[@]}; do
336 echo ""
337 done
338}
339
xiaobo gue6c46862018-01-10 18:58:09 +0800340function bin_path_parser() {
341 local i=0
342 local argv=()
343 for arg in "$@" ; do
344 argv[$i]="$arg"
345 i=$((i + 1))
346 done
347 i=0
xiaobo gu6368ebe2018-03-29 21:49:25 +0800348 # ddr fw define, co-work with bl2 build script
349 export CONFIG_DDR_FW
xiaobo gue6c46862018-01-10 18:58:09 +0800350 while [ $i -lt $# ]; do
351 arg="${argv[$i]}"
352 i=$((i + 1)) # must pleace here
353 case "$arg" in
354 --bl2)
355 update_bin_path 0 "${argv[@]:$((i))}"
356 continue ;;
357 --bl30)
358 update_bin_path 1 "${argv[@]:$((i))}"
359 continue ;;
360 --bl31)
361 update_bin_path 2 "${argv[@]:$((i))}"
362 continue ;;
363 --bl32)
364 update_bin_path 3 "${argv[@]:$((i))}"
365 continue ;;
366 --update-bl2)
367 update_bin_path 0 "source"
368 continue ;;
369 --update-bl30)
370 update_bin_path 1 "source"
371 continue ;;
372 --update-bl31)
373 update_bin_path 2 "source"
374 continue ;;
375 --update-bl32)
376 update_bin_path 3 "source"
377 continue ;;
xiaobo gu6368ebe2018-03-29 21:49:25 +0800378 --ddrfw)
379 CONFIG_DDR_FW=1
380 export CONFIG_DDR_FW
381 continue ;;
Xindong Xuad0d2832018-07-30 19:15:52 +0800382 --systemroot)
383 CONFIG_SYSTEM_AS_ROOT=systemroot
384 echo "export CONFIG_SYSTEM_AS_ROOT"
385 export CONFIG_SYSTEM_AS_ROOT=systemroot
386 continue ;;
Xindong Xu33eda2d2018-09-25 18:52:38 +0800387 --avb2)
388 CONFIG_AVB2=avb2
389 echo "export CONFIG_AVB2"
390 export CONFIG_AVB2=avb2
391 continue ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800392 *)
393 esac
394 done
Xiaobo Gu059502e2017-01-12 21:20:39 +0800395}
396
397function main() {
xiaobo gue6c46862018-01-10 18:58:09 +0800398 if [ -z $1 ]
399 then
400 usage
401 return
402 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800403
xiaobo gue6c46862018-01-10 18:58:09 +0800404 MAIN_FOLDER=`pwd`
405 parser $@
406 build $@
Xiaobo Gu059502e2017-01-12 21:20:39 +0800407}
408
409main $@ # parse all paras to function