blob: 1f023e48d2171a259b9642d148c48f77dac0f30f [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
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800112
xiaobo gue6c46862018-01-10 18:58:09 +0800113 # switch bl31 version
114 switch_bl31 ${CUR_SOC}
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800115
xiaobo gue6c46862018-01-10 18:58:09 +0800116 # get version of each blx
117 get_versions
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +0800118
xiaobo gue6c46862018-01-10 18:58:09 +0800119 # build loop
120 for loop in ${!BLX_NAME[@]}; do
121 dbg "BIN_PATH[${loop}]: ${BIN_PATH[loop]}"
122 if [ "null" == ${BIN_PATH[loop]} ]; then
123 get_blx_bin ${loop}
124 elif [ "source" == ${BIN_PATH[loop]} ]; then
125 dbg "Build blx source code..."
126 build_blx_src ${BLX_NAME[loop]} ${BLX_SRC_FOLDER[loop]} ${FIP_BUILD_FOLDER} ${CUR_SOC}
127 else
128 if [ ! -e ${BIN_PATH[loop]} ]; then
129 echo "Error: ${BIN_PATH[loop]} doesn't exist... abort"
130 exit -1
131 else
132 cp ${BIN_PATH[loop]} ${FIP_BUILD_FOLDER} -f
133 echo "Get ${BLX_NAME[$loop]} from ${BIN_PATH[loop]}... done"
134 fi
135 fi
136 done
137 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800138}
139
140copy_bootloader() {
xiaobo gue6c46862018-01-10 18:58:09 +0800141 mkdir -p ${BUILD_FOLDER}
Haixiang Baof008dc12019-05-23 18:47:15 +0800142 cp ${FIP_BUILD_FOLDER}u-boot.bin* ${BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800143 if [ "y" == "${CONFIG_AML_CRYPTO_IMG}" ]; then
144 cp ${FIP_BUILD_FOLDER}boot.img.encrypt ${BUILD_FOLDER}boot.img.encrypt
145 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800146}
147
148function update_bin_path() {
xiaobo gu8a3907e2019-05-22 11:46:49 +0800149 for loop in ${!BLX_NAME[@]}; do
150 if [ "${BLX_NAME[$loop]}" == "${BLX_NAME_GLB[$1]}" ]; then
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800151 dbg "Update BIN_PATH[$loop]=$2"
xiaobo gu8a3907e2019-05-22 11:46:49 +0800152 BIN_PATH[$loop]=$2
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800153 break
xiaobo gu8a3907e2019-05-22 11:46:49 +0800154 fi
155 done
156}
Xiaobo Gu059502e2017-01-12 21:20:39 +0800157
158function clean() {
xiaobo gue6c46862018-01-10 18:58:09 +0800159 echo "Clean up"
xiaobo gu0c2598b2019-06-28 11:22:17 +0800160 if [ -e ${BL33_PATH1} ]; then
161 cd ${MAIN_FOLDER}
162 cd ${BL33_PATH1}
163 make distclean
164 fi
165 if [ -e ${BL33_PATH2} ]; then
166 cd ${MAIN_FOLDER}
167 cd ${BL33_PATH2}
168 make distclean
169 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800170 cd ${MAIN_FOLDER}
171 rm ${FIP_BUILD_FOLDER} -rf
xiaobo gu3ce64072018-03-06 17:20:44 +0800172 rm ${BUILD_FOLDER}/* -rf
Haixiang Baof008dc12019-05-23 18:47:15 +0800173 mkdir -p ${BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800174 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800175}
176
177function build() {
xiaobo gue6c46862018-01-10 18:58:09 +0800178 # *************************************************
179 # IMPORTANT!!!!
180 # don't change sequence of following function call
181 # *************************************************
182 clean
183
184 # pre-build, get .config defines
185 pre_build_uboot $@
186
187 # variable init depends on uboot .config
188 init_variable_early $@
189
190 # must source under main function, all sub function can use these variables
191 # but if source in sub-function, only sub-function(or sub-sub..) can use them
192 source ${FIP_FOLDER}${CUR_SOC}/variable_soc.sh
193
Honglin Zhang694f5342019-12-09 14:54:40 +0800194 # compile fip tools for ddr_parse and map_tool
195 prepare_tools
196
xiaobo gue6c46862018-01-10 18:58:09 +0800197 # source soc package script
198 source ${FIP_FOLDER}${CUR_SOC}/build.sh
199
200 # update bin path, use bin.git or user defined or source code
201 bin_path_parser $@
xiaobo gude8a46a2018-03-05 21:41:54 +0800202 #bin_path_update $@
xiaobo gue6c46862018-01-10 18:58:09 +0800203
204 # build bl33/bl301..etc
Liang Ji51eee082019-05-20 14:01:24 +0800205 if [ ! $CONFIG_SYSTEM_AS_ROOT ]; then
Xindong Xu33eda2d2018-09-25 18:52:38 +0800206 CONFIG_SYSTEM_AS_ROOT=null
207 fi
Liang Ji51eee082019-05-20 14:01:24 +0800208 if [ ! $CONFIG_AVB2 ]; then
Xindong Xu33eda2d2018-09-25 18:52:38 +0800209 CONFIG_AVB2=null
210 fi
211 build_uboot ${CONFIG_SYSTEM_AS_ROOT} ${CONFIG_AVB2}
xiaobo gue6c46862018-01-10 18:58:09 +0800212
213 # source other configs after uboot compile
214 init_variable_late
215
216 # bl2/bl30/bl31..etc, build or copy from bin.git
217 build_blx $@
218
219 # cp bl33(uboot)
220 copy_bl33
221
222 # cp other firmwares(soc related)
223 copy_other_soc
224
Zhongfu Luo6c2587f2019-05-15 16:27:50 +0800225 # make build directory
226 mkdir -p ${BUILD_FOLDER}
227
xiaobo gue6c46862018-01-10 18:58:09 +0800228 # package final bootloader
229 package
230
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800231 if [ "y" != "${CONFIG_AML_SIGNED_UBOOT}" ]; then
232 # copy bootloader to main folder
233 copy_bootloader
234 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800235}
236
237function usage() {
238 cat << EOF
239 Usage:
240 $(basename $0) --help
241
xiaobo gue6c46862018-01-10 18:58:09 +0800242 Bootloader build script.
Xiaobo Gu059502e2017-01-12 21:20:39 +0800243
244 command list:
Xiaobo Gu059502e2017-01-12 21:20:39 +0800245 1. build default uboot:
246 ./$(basename $0) [config_name]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800247
xiaobo gue6c46862018-01-10 18:58:09 +0800248 2. build uboot with specified bl[x].bin
249 ./$(basename $0) [config_name] --bl[x] [path]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800250
xiaobo gue6c46862018-01-10 18:58:09 +0800251 3. build uboot with bl[x]/src source code
Xiaobo Gu059502e2017-01-12 21:20:39 +0800252 ./$(basename $0) [config_name] --update-bl[x]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800253
xiaobo gue6c46862018-01-10 18:58:09 +0800254 4. print config list
255 ./$(basename $0) --config
256
257 5. check compile status with filter(optional)
258 ./$(basename $0) --check-compile [filter]
259
xiaobo gu6368ebe2018-03-29 21:49:25 +0800260 6. update aml ddr fw by source code (for g12a and later use)
261 ./$(basename $0) [config_name] --update-bl2 --ddrfw
262
xiaobo gue6c46862018-01-10 18:58:09 +0800263
264 Example:
265 1) ./$(basename $0) gxb_p200_v1
266 build gxb_p200_v1 config
267
268 2) ./$(basename $0) gxb_p200_v1 --bl2 fip/bl2.bin --bl30 fip/bl30.bin
269 build gxb_p200_v1 with specified bl2.bin and bl30.bin
270
271 3) ./$(basename $0) gxb_p200_v1 --update-bl31 --update-bl2
272 build gxb_p200_v1 with bl31/bl2 source code
273
274 4) ./$(basename $0) --config
275 print config list
276
277 5) ./$(basename $0) --check-compile skt
278 check all skt board compile status
279
280 Remark:
281 bl[x].bin/img priority:
282 1. uboot will use binaries under bl[x]/bin/ folder by default, bl[x] version specified in .repo/manifest.xml
283 2. if you want use your own bl[x].bin, specify path by add "--bl[x] [path]" parameter
284 3. if you want use bl[x].bin by compile source code, please add "--update-bl[x]" parameter
285
Xiaobo Gu059502e2017-01-12 21:20:39 +0800286
287EOF
288 exit 1
289}
290
xiaobo gue6c46862018-01-10 18:58:09 +0800291function print_config() {
292 cat << EOF
293 Usable configs:
294`uboot_config_list`
295EOF
296 exit 1
297}
298
Xiaobo Gu059502e2017-01-12 21:20:39 +0800299function parser() {
xiaobo gue6c46862018-01-10 18:58:09 +0800300 local i=0
301 local argv=()
302 for arg in "$@" ; do
303 argv[$i]="$arg"
304 i=$((i + 1))
305 done
306 i=0
307 while [ $i -lt $# ]; do
308 arg="${argv[$i]}"
xiaobo gu3ce64072018-03-06 17:20:44 +0800309 i=$((i + 1)) # must place here
xiaobo gue6c46862018-01-10 18:58:09 +0800310 case "$arg" in
311 -h|--help|help)
312 usage
313 exit ;;
314 --config)
315 print_config
xiaobo gu3ce64072018-03-06 17:20:44 +0800316 return ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800317 --check-compile)
xiaobo gu66f95292018-01-11 13:38:13 +0800318 check_compile "${argv[@]:$((i))}"
xiaobo gue6c46862018-01-10 18:58:09 +0800319 exit ;;
320 clean|distclean|-distclean|--distclean)
321 clean
322 exit ;;
323 *)
324 esac
325 done
326}
327
xiaobo gude8a46a2018-03-05 21:41:54 +0800328function bin_path_update() {
329 # overwrite path in case some git repository doesn't exist
330 for loop in ${!BLX_BIN_FOLDER[@]}; do
331 if [ -ne ${BLX_BIN_FOLDER[$loop]} ]; then
332 dbg "BLX_BIN_FOLDER[$loop] doesn't exist, use src code"
333 update_bin_path $loop "source"
334 fi
335 done
336
337 for loop in ${!BLX_SRC_FOLDER[@]}; do
338 echo ""
339 done
340}
341
xiaobo gue6c46862018-01-10 18:58:09 +0800342function bin_path_parser() {
343 local i=0
344 local argv=()
345 for arg in "$@" ; do
346 argv[$i]="$arg"
347 i=$((i + 1))
348 done
349 i=0
xiaobo gu6368ebe2018-03-29 21:49:25 +0800350 # ddr fw define, co-work with bl2 build script
351 export CONFIG_DDR_FW
xiaobo gue6c46862018-01-10 18:58:09 +0800352 while [ $i -lt $# ]; do
353 arg="${argv[$i]}"
354 i=$((i + 1)) # must pleace here
355 case "$arg" in
356 --bl2)
357 update_bin_path 0 "${argv[@]:$((i))}"
358 continue ;;
359 --bl30)
360 update_bin_path 1 "${argv[@]:$((i))}"
361 continue ;;
362 --bl31)
363 update_bin_path 2 "${argv[@]:$((i))}"
364 continue ;;
365 --bl32)
366 update_bin_path 3 "${argv[@]:$((i))}"
367 continue ;;
Zhongfu Luo3e54c6f2020-02-15 21:30:50 +0800368 --bl40)
369 update_bin_path 4 "${argv[@]:$((i))}"
370 continue ;;
371 --sign-bl40)
372 update_bin_path 4 "${argv[@]:$((i))}"
373 CONFIG_SIGN_BL40=1
374 continue ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800375 --update-bl2)
376 update_bin_path 0 "source"
377 continue ;;
378 --update-bl30)
379 update_bin_path 1 "source"
380 continue ;;
381 --update-bl31)
382 update_bin_path 2 "source"
383 continue ;;
384 --update-bl32)
385 update_bin_path 3 "source"
386 continue ;;
xiaobo gu6368ebe2018-03-29 21:49:25 +0800387 --ddrfw)
388 CONFIG_DDR_FW=1
389 export CONFIG_DDR_FW
390 continue ;;
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800391 --cas)
392 cas="${argv[$i]}"
393 #limit the "--cas xxx" only works for g12a
394 if [ "${CUR_SOC}" == "g12a" ]; then
395 CONFIG_CAS=${cas}
396 fi
397 if [[ "${CONFIG_CAS}" == "irdeto" || \
398 "${CONFIG_CAS}" == "vmx" || \
399 "${CONFIG_CAS}" == "nagra" ]]; then
400 CONFIG_AML_SIGNED_UBOOT=y
401 export CONFIG_AML_SIGNED_UBOOT
402 fi
403 echo "CAS: ${cas},${CONFIG_CAS}"
404 export CONFIG_CAS
405 continue ;;
Xindong Xuad0d2832018-07-30 19:15:52 +0800406 --systemroot)
407 CONFIG_SYSTEM_AS_ROOT=systemroot
408 echo "export CONFIG_SYSTEM_AS_ROOT"
409 export CONFIG_SYSTEM_AS_ROOT=systemroot
410 continue ;;
Xindong Xu33eda2d2018-09-25 18:52:38 +0800411 --avb2)
412 CONFIG_AVB2=avb2
413 echo "export CONFIG_AVB2"
414 export CONFIG_AVB2=avb2
415 continue ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800416 *)
417 esac
418 done
Xiaobo Gu059502e2017-01-12 21:20:39 +0800419}
420
421function main() {
xiaobo gue6c46862018-01-10 18:58:09 +0800422 if [ -z $1 ]
423 then
424 usage
425 return
426 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800427
xiaobo gue6c46862018-01-10 18:58:09 +0800428 MAIN_FOLDER=`pwd`
429 parser $@
430 build $@
Xiaobo Gu059502e2017-01-12 21:20:39 +0800431}
432
433main $@ # parse all paras to function