blob: 1aa06d3427931d70bec4814dd91ac29715a7734a [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
45 source ${CONFIG_FILE} &> /dev/null # ignore warning/error
46 if [ "y" == "${CONFIG_SUPPORT_CUSOTMER_BOARD}" ]; then
47 BOARD_DIR="customer/board/${CONFIG_SYS_BOARD}"
48 else
49 BOARD_DIR="${CONFIG_BOARDDIR}"
50 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +080051}
52
53function build_blx_src() {
xiaobo gue6c46862018-01-10 18:58:09 +080054 # compile $name $src_folder $bin_folder $soc
55 local name=$1
56 local src_folder=$2
57 local bin_folder=$3
58 local soc=$4
59 #dbg "compile - name: ${name}, src_folder: ${src_folder}, bin_folder: ${bin_folder}, soc: ${soc}"
60 if [ $name == ${BLX_NAME[0]} ]; then
61 # bl2
62 build_bl2 $src_folder $bin_folder $soc
63 elif [ $name == ${BLX_NAME[1]} ]; then
64 # bl30
65 build_bl30 $src_folder $bin_folder $soc
66 elif [ $name == ${BLX_NAME[2]} ]; then
67 # bl31
68 # some soc use v1.3
69 check_bl31_ver $soc
70 if [ $? != 0 ]; then
71 echo "check bl31 ver: use v1.3"
72 build_bl31_v1_3 $src_folder $bin_folder $soc
73 else
74 echo "check bl31 ver: use v1.0"
75 build_bl31 $src_folder $bin_folder $soc
76 fi
77 elif [ $name == ${BLX_NAME[3]} ]; then
78 # bl32
79 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
80 build_bl32 $src_folder $bin_folder $soc
81 fi
82 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +080083}
84
85function build_blx() {
xiaobo gue6c46862018-01-10 18:58:09 +080086 # build each blx
87 mkdir -p ${FIP_BUILD_FOLDER}
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080088
xiaobo gue6c46862018-01-10 18:58:09 +080089 # switch bl31 version
90 switch_bl31 ${CUR_SOC}
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080091
xiaobo gue6c46862018-01-10 18:58:09 +080092 # get version of each blx
93 get_versions
Xiaobo Gu9dd3f3f2017-05-26 17:58:57 +080094
xiaobo gue6c46862018-01-10 18:58:09 +080095 # build loop
96 for loop in ${!BLX_NAME[@]}; do
97 dbg "BIN_PATH[${loop}]: ${BIN_PATH[loop]}"
98 if [ "null" == ${BIN_PATH[loop]} ]; then
99 get_blx_bin ${loop}
100 elif [ "source" == ${BIN_PATH[loop]} ]; then
101 dbg "Build blx source code..."
102 build_blx_src ${BLX_NAME[loop]} ${BLX_SRC_FOLDER[loop]} ${FIP_BUILD_FOLDER} ${CUR_SOC}
103 else
104 if [ ! -e ${BIN_PATH[loop]} ]; then
105 echo "Error: ${BIN_PATH[loop]} doesn't exist... abort"
106 exit -1
107 else
108 cp ${BIN_PATH[loop]} ${FIP_BUILD_FOLDER} -f
109 echo "Get ${BLX_NAME[$loop]} from ${BIN_PATH[loop]}... done"
110 fi
111 fi
112 done
113 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800114}
115
116copy_bootloader() {
xiaobo gue6c46862018-01-10 18:58:09 +0800117 mkdir -p ${BUILD_FOLDER}
118 cp ${FIP_BUILD_FOLDER}u-boot.bin ${BUILD_FOLDER}u-boot.bin
119 cp ${FIP_BUILD_FOLDER}u-boot.bin.encrypt ${BUILD_FOLDER}u-boot.bin.encrypt
120 cp ${FIP_BUILD_FOLDER}u-boot.bin.encrypt.efuse ${BUILD_FOLDER}u-boot.bin.encrypt.efuse
121 cp ${FIP_BUILD_FOLDER}u-boot.bin.encrypt.sd.bin ${BUILD_FOLDER}u-boot.bin.encrypt.sd.bin
122 cp ${FIP_BUILD_FOLDER}u-boot.bin.encrypt.usb.bl2 ${BUILD_FOLDER}u-boot.bin.encrypt.usb.bl2
123 cp ${FIP_BUILD_FOLDER}u-boot.bin.encrypt.usb.tpl ${BUILD_FOLDER}u-boot.bin.encrypt.usb.tpl
124 cp ${FIP_BUILD_FOLDER}u-boot.bin.sd.bin ${BUILD_FOLDER}u-boot.bin.sd.bin
125 cp ${FIP_BUILD_FOLDER}u-boot.bin.usb.bl2 ${BUILD_FOLDER}u-boot.bin.usb.bl2
126 cp ${FIP_BUILD_FOLDER}u-boot.bin.usb.tpl ${BUILD_FOLDER}u-boot.bin.usb.tpl
Xiaobo Gu059502e2017-01-12 21:20:39 +0800127
xiaobo gue6c46862018-01-10 18:58:09 +0800128 if [ "y" == "${CONFIG_AML_CRYPTO_IMG}" ]; then
129 cp ${FIP_BUILD_FOLDER}boot.img.encrypt ${BUILD_FOLDER}boot.img.encrypt
130 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800131}
132
133function update_bin_path() {
xiaobo gue6c46862018-01-10 18:58:09 +0800134 dbg "Update BIN_PATH[$1]=$2"
135 BIN_PATH[$1]=$2
136}
Xiaobo Gu059502e2017-01-12 21:20:39 +0800137
138function clean() {
xiaobo gue6c46862018-01-10 18:58:09 +0800139 echo "Clean up"
140 cd ${UBOOT_SRC_FOLDER}
141 make distclean
142 cd ${MAIN_FOLDER}
143 rm ${FIP_BUILD_FOLDER} -rf
xiaobo gu3ce64072018-03-06 17:20:44 +0800144 rm ${BUILD_FOLDER}/* -rf
xiaobo gue6c46862018-01-10 18:58:09 +0800145 return
Xiaobo Gu059502e2017-01-12 21:20:39 +0800146}
147
148function build() {
xiaobo gue6c46862018-01-10 18:58:09 +0800149 # *************************************************
150 # IMPORTANT!!!!
151 # don't change sequence of following function call
152 # *************************************************
153 clean
154
155 # pre-build, get .config defines
156 pre_build_uboot $@
157
158 # variable init depends on uboot .config
159 init_variable_early $@
160
161 # must source under main function, all sub function can use these variables
162 # but if source in sub-function, only sub-function(or sub-sub..) can use them
163 source ${FIP_FOLDER}${CUR_SOC}/variable_soc.sh
164
165 # source soc package script
166 source ${FIP_FOLDER}${CUR_SOC}/build.sh
167
168 # update bin path, use bin.git or user defined or source code
169 bin_path_parser $@
xiaobo gude8a46a2018-03-05 21:41:54 +0800170 #bin_path_update $@
xiaobo gue6c46862018-01-10 18:58:09 +0800171
172 # build bl33/bl301..etc
Xindong Xuad0d2832018-07-30 19:15:52 +0800173 build_uboot ${CONFIG_SYSTEM_AS_ROOT}
xiaobo gue6c46862018-01-10 18:58:09 +0800174
175 # source other configs after uboot compile
176 init_variable_late
177
178 # bl2/bl30/bl31..etc, build or copy from bin.git
179 build_blx $@
180
181 # cp bl33(uboot)
182 copy_bl33
183
184 # cp other firmwares(soc related)
185 copy_other_soc
186
187 # package final bootloader
188 package
189
190 # copy bootloader to main folder
191 copy_bootloader
Xiaobo Gu059502e2017-01-12 21:20:39 +0800192}
193
194function usage() {
195 cat << EOF
196 Usage:
197 $(basename $0) --help
198
xiaobo gue6c46862018-01-10 18:58:09 +0800199 Bootloader build script.
Xiaobo Gu059502e2017-01-12 21:20:39 +0800200
201 command list:
Xiaobo Gu059502e2017-01-12 21:20:39 +0800202 1. build default uboot:
203 ./$(basename $0) [config_name]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800204
xiaobo gue6c46862018-01-10 18:58:09 +0800205 2. build uboot with specified bl[x].bin
206 ./$(basename $0) [config_name] --bl[x] [path]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800207
xiaobo gue6c46862018-01-10 18:58:09 +0800208 3. build uboot with bl[x]/src source code
Xiaobo Gu059502e2017-01-12 21:20:39 +0800209 ./$(basename $0) [config_name] --update-bl[x]
Xiaobo Gu059502e2017-01-12 21:20:39 +0800210
xiaobo gue6c46862018-01-10 18:58:09 +0800211 4. print config list
212 ./$(basename $0) --config
213
214 5. check compile status with filter(optional)
215 ./$(basename $0) --check-compile [filter]
216
xiaobo gu6368ebe2018-03-29 21:49:25 +0800217 6. update aml ddr fw by source code (for g12a and later use)
218 ./$(basename $0) [config_name] --update-bl2 --ddrfw
219
xiaobo gue6c46862018-01-10 18:58:09 +0800220
221 Example:
222 1) ./$(basename $0) gxb_p200_v1
223 build gxb_p200_v1 config
224
225 2) ./$(basename $0) gxb_p200_v1 --bl2 fip/bl2.bin --bl30 fip/bl30.bin
226 build gxb_p200_v1 with specified bl2.bin and bl30.bin
227
228 3) ./$(basename $0) gxb_p200_v1 --update-bl31 --update-bl2
229 build gxb_p200_v1 with bl31/bl2 source code
230
231 4) ./$(basename $0) --config
232 print config list
233
234 5) ./$(basename $0) --check-compile skt
235 check all skt board compile status
236
237 Remark:
238 bl[x].bin/img priority:
239 1. uboot will use binaries under bl[x]/bin/ folder by default, bl[x] version specified in .repo/manifest.xml
240 2. if you want use your own bl[x].bin, specify path by add "--bl[x] [path]" parameter
241 3. if you want use bl[x].bin by compile source code, please add "--update-bl[x]" parameter
242
Xiaobo Gu059502e2017-01-12 21:20:39 +0800243
244EOF
245 exit 1
246}
247
xiaobo gue6c46862018-01-10 18:58:09 +0800248function print_config() {
249 cat << EOF
250 Usable configs:
251`uboot_config_list`
252EOF
253 exit 1
254}
255
Xiaobo Gu059502e2017-01-12 21:20:39 +0800256function parser() {
xiaobo gue6c46862018-01-10 18:58:09 +0800257 local i=0
258 local argv=()
259 for arg in "$@" ; do
260 argv[$i]="$arg"
261 i=$((i + 1))
262 done
263 i=0
264 while [ $i -lt $# ]; do
265 arg="${argv[$i]}"
xiaobo gu3ce64072018-03-06 17:20:44 +0800266 i=$((i + 1)) # must place here
xiaobo gue6c46862018-01-10 18:58:09 +0800267 case "$arg" in
268 -h|--help|help)
269 usage
270 exit ;;
271 --config)
272 print_config
xiaobo gu3ce64072018-03-06 17:20:44 +0800273 return ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800274 --check-compile)
xiaobo gu66f95292018-01-11 13:38:13 +0800275 check_compile "${argv[@]:$((i))}"
xiaobo gue6c46862018-01-10 18:58:09 +0800276 exit ;;
277 clean|distclean|-distclean|--distclean)
278 clean
279 exit ;;
280 *)
281 esac
282 done
283}
284
xiaobo gude8a46a2018-03-05 21:41:54 +0800285function bin_path_update() {
286 # overwrite path in case some git repository doesn't exist
287 for loop in ${!BLX_BIN_FOLDER[@]}; do
288 if [ -ne ${BLX_BIN_FOLDER[$loop]} ]; then
289 dbg "BLX_BIN_FOLDER[$loop] doesn't exist, use src code"
290 update_bin_path $loop "source"
291 fi
292 done
293
294 for loop in ${!BLX_SRC_FOLDER[@]}; do
295 echo ""
296 done
297}
298
xiaobo gue6c46862018-01-10 18:58:09 +0800299function bin_path_parser() {
300 local i=0
301 local argv=()
302 for arg in "$@" ; do
303 argv[$i]="$arg"
304 i=$((i + 1))
305 done
306 i=0
xiaobo gu6368ebe2018-03-29 21:49:25 +0800307 # ddr fw define, co-work with bl2 build script
308 export CONFIG_DDR_FW
xiaobo gue6c46862018-01-10 18:58:09 +0800309 while [ $i -lt $# ]; do
310 arg="${argv[$i]}"
311 i=$((i + 1)) # must pleace here
312 case "$arg" in
313 --bl2)
314 update_bin_path 0 "${argv[@]:$((i))}"
315 continue ;;
316 --bl30)
317 update_bin_path 1 "${argv[@]:$((i))}"
318 continue ;;
319 --bl31)
320 update_bin_path 2 "${argv[@]:$((i))}"
321 continue ;;
322 --bl32)
323 update_bin_path 3 "${argv[@]:$((i))}"
324 continue ;;
325 --update-bl2)
326 update_bin_path 0 "source"
327 continue ;;
328 --update-bl30)
329 update_bin_path 1 "source"
330 continue ;;
331 --update-bl31)
332 update_bin_path 2 "source"
333 continue ;;
334 --update-bl32)
335 update_bin_path 3 "source"
336 continue ;;
xiaobo gu6368ebe2018-03-29 21:49:25 +0800337 --ddrfw)
338 CONFIG_DDR_FW=1
339 export CONFIG_DDR_FW
340 continue ;;
Xindong Xuad0d2832018-07-30 19:15:52 +0800341 --systemroot)
342 CONFIG_SYSTEM_AS_ROOT=systemroot
343 echo "export CONFIG_SYSTEM_AS_ROOT"
344 export CONFIG_SYSTEM_AS_ROOT=systemroot
345 continue ;;
xiaobo gue6c46862018-01-10 18:58:09 +0800346 *)
347 esac
348 done
Xiaobo Gu059502e2017-01-12 21:20:39 +0800349}
350
351function main() {
xiaobo gue6c46862018-01-10 18:58:09 +0800352 if [ -z $1 ]
353 then
354 usage
355 return
356 fi
Xiaobo Gu059502e2017-01-12 21:20:39 +0800357
xiaobo gue6c46862018-01-10 18:58:09 +0800358 MAIN_FOLDER=`pwd`
359 parser $@
360 build $@
Xiaobo Gu059502e2017-01-12 21:20:39 +0800361}
362
363main $@ # parse all paras to function