blob: 0e7ac8e00525dd16d16050b58484a5204c4560c3 [file] [log] [blame]
wenbo.wangbd036162023-10-27 10:41:34 +08001#!/bin/bash
2
3# include uboot pre-build macros
4#declare CONFIG_FILE=("${buildtree}/.config")
5#declare AUTOCFG_FILE=("${buildtree}/include/autoconf.mk")
6
7function init_vari() {
8 #source ${CONFIG_FILE} &> /dev/null # ignore warning/error
9 #source ${AUTOCFG_FILE} &> /dev/null # ignore warning/error
10
11 AML_BL2_NAME="bl2.bin"
12 AML_KEY_BLOB_NAME="aml-user-key.sig"
13
14 if [ "y" == "${CONFIG_AML_SECURE_BOOT_V3}" ]; then
15 V3_PROCESS_FLAG="--level v3"
16 fi
17
18 if [ "y" == "${CONFIG_AML_CRYPTO_AES}" ]; then
19 BOOT_SIG_FLAG="--aeskey enable"
20 EFUSE_GEN_FLAG="--aeskey enable"
21 fi
22
23 if [ "y" == "${CONFIG_AML_EFUSE_GEN_AES_ONLY}" ]; then
24 EFUSE_GEN_FLAG="--aeskey only"
25 fi
26
27 if [ "y" == "${CONFIG_AML_BL33_COMPRESS_ENABLE}" ]; then
28 BL33_COMPRESS_FLAG="--compress lz4"
29 fi
30
31 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
32 BL3X_SUFFIX="img"
33 fi
34
35 if [ -n "${CONFIG_DDRFW_TYPE}" ]; then
36 DDRFW_TYPE="${CONFIG_DDRFW_TYPE}"
37 else
38 DDRFW_TYPE="ddr4"
39 fi
40
41 if [ -n "${BLX_BIN_SUB_CHIP}" ]; then
42 CHIPSET_NAME=`echo ${BLX_BIN_SUB_CHIP} | tr 'A-Z' 'a-z'`
43 fi
44
45 # script can use chipset varient to override config varient
46 if [ -n "${SCRIPT_ARG_CHIPSET_VARIANT}" ]; then
47 CHIPSET_VARIANT="${SCRIPT_ARG_CHIPSET_VARIANT}"
48 CHIPSET_VARIANT_SUFFIX=".${CHIPSET_VARIANT}"
49 elif [ -n "${CONFIG_CHIPSET_VARIANT}" ]; then
50 CHIPSET_VARIANT="${CONFIG_CHIPSET_VARIANT}"
51 CHIPSET_VARIANT_SUFFIX=".${CHIPSET_VARIANT}"
52 else
53 if [ -n "${CONFIG_FORMER_SIGN}" ]; then
54 CHIPSET_VARIANT="no_variant"
55 else
56 CHIPSET_VARIANT="general"
57 fi
58 CHIPSET_VARIANT_SUFFIX=""
59 fi
60
61 if [ -n "${CONFIG_AMLOGIC_KEY_TYPE}" ]; then
62 AMLOGIC_KEY_TYPE="${CONFIG_AMLOGIC_KEY_TYPE}"
63 fi
64
wenbo.wangc7934642024-07-24 11:16:47 +080065 if [ ! -n "${BL2E_PAYLOAD_SIZE}" ]; then
66 BL2E_PAYLOAD_SIZE=${CONFIG_BL2E_PAYLOAD_SIZE}
67 export BL2E_PAYLOAD_SIZE
68 fi
69
wenbo.wangbd036162023-10-27 10:41:34 +080070 echo "------------------------------------------------------"
Lawrence Mok61ffc792024-06-12 01:07:23 +000071 echo "DDRFW_TYPE: ${DDRFW_TYPE} CHIPSET_NAME: ${CHIPSET_NAME} CHIPSET_VARIANT: ${CHIPSET_VARIANT} AMLOGIC_KEY_TYPE: ${AMLOGIC_KEY_TYPE} SIGNING_SCHEME=$DV_SIGNING_SCHEME.$CS_SIGNING_SCHEME"
wenbo.wangc7934642024-07-24 11:16:47 +080072 echo "BL2E_PAYLOAD_SIZE: ${BL2E_PAYLOAD_SIZE}"
wenbo.wangbd036162023-10-27 10:41:34 +080073 echo "------------------------------------------------------"
74}
75
76function mk_bl2ex() {
77 output=$1
78 payload=$2
79 ddr_type=$3
80
81 if [ ! -f ${output}/bl2.bin.sto ] || \
82 [ ! -f ${output}/bl2.bin.usb ] || \
83 [ ! -f ${output}/bl2e.bin.sto ] || \
84 [ ! -f ${output}/bl2e.bin.usb ] || \
85 [ ! -f ${output}/bl2x.bin ]; then
86 echo "Error: ${output}/bl2/e/x.bin does not all exist... abort"
87 ls -la ${output}
88 exit -1
89 fi
90
91 echo "================================================================="
92 echo "image packing with acpu-imagetool for bl2 bl2e bl2x"
93
wenbo.wang2139a582024-02-28 16:36:35 +080094 dd if=/dev/zero of=${payload}/bl2.bin.sto bs=202592 count=1
wenbo.wangbd036162023-10-27 10:41:34 +080095 dd if=${output}/bl2.bin.sto of=${payload}/bl2.bin.sto conv=notrunc
96
wenbo.wang2139a582024-02-28 16:36:35 +080097 dd if=/dev/zero of=${payload}/bl2.bin.usb bs=202592 count=1
wenbo.wangbd036162023-10-27 10:41:34 +080098 dd if=${output}/bl2.bin.usb of=${payload}/bl2.bin.usb conv=notrunc
99
wenbo.wang2139a582024-02-28 16:36:35 +0800100 dd if=/dev/zero of=${payload}/bl2e.bin.sto bs=98304 count=1
wenbo.wangbd036162023-10-27 10:41:34 +0800101 dd if=${output}/bl2e.bin.sto of=${payload}/bl2e.bin.sto conv=notrunc
102
wenbo.wang2139a582024-02-28 16:36:35 +0800103 dd if=/dev/zero of=${payload}/bl2e.bin.usb bs=98304 count=1
wenbo.wangbd036162023-10-27 10:41:34 +0800104 dd if=${output}/bl2e.bin.usb of=${payload}/bl2e.bin.usb conv=notrunc
105
wenbo.wang2139a582024-02-28 16:36:35 +0800106 dd if=/dev/zero of=${payload}/bl2x.bin bs=98304 count=1
wenbo.wangbd036162023-10-27 10:41:34 +0800107 dd if=${output}/bl2x.bin of=${payload}/bl2x.bin conv=notrunc
108
wenbo.wangbd036162023-10-27 10:41:34 +0800109 echo "===================================================="
110 echo "------ process for device and chip params ------"
111 INPUT_PARAMS=${output}
112
113 if [ ! -f ${INPUT_PARAMS}/device_acs.bin ]; then
114 echo "dev acs params not exist !"
115 exit -1
116 fi
117
118 if [ ! -f ${INPUT_PARAMS}/chip_acs.bin ]; then
119 echo "chip acs params not exist !"
120 exit -1
121 fi
122 chip_acs_size=`stat -c %s ${INPUT_PARAMS}/chip_acs.bin`
123 dev_acs_size=`stat -c %s ${INPUT_PARAMS}/device_acs.bin`
wenbo.wangbd036162023-10-27 10:41:34 +0800124 if [ $chip_acs_size -gt 2048 ]; then
125 echo "chip acs size exceed limit 2048, $chip_acs_size"
126 exit -1
127 else
128 dd if=/dev/zero of=${payload}/chip_acs.bin bs=2048 count=1
129 dd if=${INPUT_PARAMS}/chip_acs.bin of=${payload}/chip_acs.bin conv=notrunc
130 fi
131
wenbo.wang2139a582024-02-28 16:36:35 +0800132 if [ $dev_acs_size -gt 7168 ]; then
133 echo "dev acs size exceed limit 7168, $dev_acs_size"
wenbo.wangbd036162023-10-27 10:41:34 +0800134 exit -1
135 else
wenbo.wang2139a582024-02-28 16:36:35 +0800136 dd if=/dev/zero of=${payload}/device_acs.bin bs=7168 count=1
wenbo.wangbd036162023-10-27 10:41:34 +0800137 dd if=${INPUT_PARAMS}/device_acs.bin of=${payload}/device_acs.bin conv=notrunc
138 fi
139
140 ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-boot-blobs \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000141 --chipset-authen-algorithm=rsa,none \
142 --device-authen-algorithm=rsa,none \
wenbo.wangbd036162023-10-27 10:41:34 +0800143 --infile-bl2-payload=${payload}/bl2.bin.sto \
144 --infile-bl2e-payload=${payload}/bl2e.bin.sto \
145 --infile-bl2x-payload=${payload}/bl2x.bin \
146 --infile-dvinit-params=${payload}/device_acs.bin \
147 --infile-csinit-params=${payload}/chip_acs.bin \
wenbo.wang2139a582024-02-28 16:36:35 +0800148 --scs-family=s7d \
wenbo.wangbd036162023-10-27 10:41:34 +0800149 --outfile-bb1st=${output}/bb1st.sto.bin \
150 --outfile-blob-bl2e=${output}/blob-bl2e.sto.bin \
151 --outfile-blob-bl2x=${output}/blob-bl2x.bin
152
153 ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-boot-blobs \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000154 --chipset-authen-algorithm=rsa,none \
155 --device-authen-algorithm=rsa,none \
wenbo.wangbd036162023-10-27 10:41:34 +0800156 --infile-bl2-payload=${payload}/bl2.bin.usb \
157 --infile-bl2e-payload=${payload}/bl2e.bin.usb \
158 --infile-bl2x-payload=${payload}/bl2x.bin \
159 --infile-dvinit-params=${payload}/device_acs.bin \
160 --infile-csinit-params=${payload}/chip_acs.bin \
wenbo.wang2139a582024-02-28 16:36:35 +0800161 --scs-family=s7d \
wenbo.wangbd036162023-10-27 10:41:34 +0800162 --outfile-bb1st=${output}/bb1st.usb.bin \
163 --outfile-blob-bl2e=${output}/blob-bl2e.usb.bin \
164 --outfile-blob-bl2x=${output}/blob-bl2x.bin
165
166
167 if [ ! -f ${output}/bb1st.sto.bin ] || \
168 [ ! -f ${output}/bb1st.usb.bin ] || \
169 [ ! -f ${output}/blob-bl2e.sto.bin ] || \
170 [ ! -f ${output}/blob-bl2e.usb.bin ] || \
171 [ ! -f ${output}/blob-bl2x.bin ]; then
172 echo "Error: ${output}/ bootblobs do not all exist... abort"
173 ls -la ${output}/
174 exit -1
175 fi
176 echo "done to generate bb1st.bin folder"
177}
178
wenbo.wang5af83a12024-04-10 15:59:28 +0800179function amfc_compress() {
180 local path=$1
181 local comp_lv=$2
182 amfc_zstd_hdr=$1/amfc_zstd_hdr.bin
183 ./fip/tools/zstd $1/bl33.bin.org -$comp_lv -o $1/bl33.bin.zstd
184 bin_org_size=`stat -c %s $1/bl33.bin.org`
185 bin_zstd_size=`stat -c %s $1/bl33.bin.zstd`
wenbo.wangd9fa53b2024-11-26 20:03:09 +0800186 printf "%s" "ZSTD" > $amfc_zstd_hdr
wenbo.wang5af83a12024-04-10 15:59:28 +0800187
188 printf "%02x%02x%02x%02x" $[(bin_org_size) & 0xff] \
189 $[((bin_org_size) >> 8) & 0xff] $[((bin_org_size) >> 16) & 0xff] \
190 $[((bin_org_size) >> 24) & 0xff] | xxd -r -ps >> $amfc_zstd_hdr
191
192 printf "%02x%02x%02x%02x" $[(bin_zstd_size) & 0xff] \
193 $[((bin_zstd_size) >> 8) & 0xff] $[((bin_zstd_size) >> 16) & 0xff] \
194 $[((bin_zstd_size) >> 24) & 0xff] | xxd -r -ps >> $amfc_zstd_hdr
195
196 cat $amfc_zstd_hdr $1/bl33.bin.zstd > $1/bl33.bin
197 rm $amfc_zstd_hdr -f
198}
199
wenbo.wangbd036162023-10-27 10:41:34 +0800200function mk_devfip() {
201 output=$1
202 payload=$2
203
204 # fix size for BL30 128KB --> 64KB
205 if [ -f ${output}/bl30.bin ]; then
206 blx_size=`stat -c %s ${output}/bl30.bin`
207 if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then
208 echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}"
209 exit -1
210 fi
211 else
212 echo "Warning: null bl30"
213 dd if=/dev/random of=${output}/bl30.bin bs=4096 count=1
214 #dd if=bl30/bin/sc2/bl30.bin of=${output}/bl30.bin
215 fi
216 dd if=/dev/zero of=${payload}/bl30.bin bs=${BL30_BIN_SIZE} count=1
217 dd if=${output}/bl30.bin of=${payload}/bl30.bin conv=notrunc
218
219 # fix size for BL40 96KB
220 if [ -f ${output}/bl40.bin ]; then
221 blx_size=`stat -c %s ${output}/bl40.bin`
222 if [ $blx_size -gt 98304 ]; then
223 echo "Error: bl40 size exceed limit 98304"
224 exit -1
225 fi
226 else
227 echo "Warning: null bl40"
228 #dd if=/dev/random of=${output}/bl40.bin bs=4096 count=1
229 dd if=/dev/zero of=${output}/bl40.bin bs=4096 count=1
230 fi
231 dd if=/dev/zero of=${payload}/bl40.bin bs=98304 count=1
232 dd if=${output}/bl40.bin of=${payload}/bl40.bin conv=notrunc
233
234
235 # fix size for BL31 256KB
236 if [ ! -f ${output}/bl31.bin ]; then
237 echo "Error: ${output}/bl31.bin does not exist... abort"
238 exit -1
239 fi
240 blx_size=`stat -c %s ${output}/bl31.bin`
241 echo "BL31 size: ${blx_size}"
242 if [ $blx_size -gt 262144 ]; then
243 echo "Error: bl31 size exceed limit 262144"
244 exit -1
245 fi
246 dd if=/dev/zero of=${payload}/bl31.bin bs=262144 count=1
247 dd if=${output}/bl31.bin of=${payload}/bl31.bin conv=notrunc
248
249
250 # fix size for BL32 512KB
251 if [ -f ${output}/bl32.bin ]; then
rui guo73e690a2024-03-28 10:24:12 +0800252 echo "compress bl32.bin"
253 mv -f ${output}/bl32.bin ${output}/bl32.bin.org
254 encrypt_step --bl3sig --input ${output}/bl32.bin.org --output ${output}/bl32.bin.org.lz4 --compress lz4 --level v3 --type bl32
255 dd if=${output}/bl32.bin.org.lz4 of=${output}/bl32.bin bs=1 skip=1824 >& /dev/null
256
wenbo.wangbd036162023-10-27 10:41:34 +0800257 blx_size=`stat -c %s ${output}/bl32.bin`
258 if [ $blx_size -gt 524288 ]; then
259 echo "Error: bl32 size exceed limit 524288"
260 exit -1
261 fi
262 else
263 echo "Warning: null bl32"
264 dd if=/dev/random of=${output}/bl32.bin bs=4096 count=1
265 #dd if=bl32/bin/sc2/bl32.bin of=${output}/bl32.bin
266 fi
267 dd if=/dev/zero of=${payload}/bl32.bin bs=524288 count=1
268 dd if=${output}/bl32.bin of=${payload}/bl32.bin conv=notrunc
wenbo.wangbd036162023-10-27 10:41:34 +0800269 if [ "y" == "${CONFIG_AML_BL33_COMPRESS_ENABLE}" ]; then
270 mv -f ${output}/bl33.bin ${output}/bl33.bin.org
wenbo.wang5af83a12024-04-10 15:59:28 +0800271 amfc_compress ${output} 9
272#encrypt_step --bl3sig --input ${output}/bl33.bin.org --output ${output}/bl33.bin.org.lz4 --compress lz4 --level v3 --type bl33
wenbo.wangbd036162023-10-27 10:41:34 +0800273 #get LZ4 format bl33 image from bl33.bin.enc with offset 0x720
wenbo.wang5af83a12024-04-10 15:59:28 +0800274#dd if=${output}/bl33.bin.org.lz4 of=${output}/bl33.bin bs=1 skip=1824 >& /dev/null
wenbo.wangbd036162023-10-27 10:41:34 +0800275 fi
276 # fix size for BL33 1024KB + 512 KB
277 if [ ! -f ${output}/bl33.bin ]; then
278 echo "Error: ${output}/bl33.bin does not exist... abort"
279 exit -1
280 fi
281 blx_size=`stat -c %s ${output}/bl33.bin`
282 if [ $blx_size -gt 1572864 ]; then
283 echo "Error: bl33 size exceed limit 0x180000"
284 exit -1
285 fi
286 dd if=/dev/zero of=${payload}/bl33.bin bs=1572864 count=1
287 dd if=${output}/bl33.bin of=${payload}/bl33.bin conv=notrunc
288
wenbo.wangbd036162023-10-27 10:41:34 +0800289 ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-device-fip \
290 --infile-bl30-payload=${payload}/bl30.bin \
291 --infile-bl40-payload=${payload}/bl40.bin \
292 --infile-bl31-payload=${payload}/bl31.bin \
293 --infile-bl32-payload=${payload}/bl32.bin \
294 --infile-bl33-payload=${payload}/bl33.bin \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000295 --outfile-device-fip=${output}/device-fip.bin \
296 --header-layout=mini \
297 --chipset-authen-algorithm=rsa,none \
298 --device-authen-algorithm=rsa,none
wenbo.wangbd036162023-10-27 10:41:34 +0800299
300 if [ ! -f ${output}/device-fip.bin ]; then
301 echo "Error: ${output}/device-fip.bin does not exist... abort"
302 exit -1
303 fi
304 echo "done to generate device-fip.bin"
305}
306
307# due to size limit of BL2, only one type of DDR firmware is
308# built into bl2 code package. For support other ddr types, we
309# need bind them to ddr_fip.bin and let bl2 fw to try it.
310#
311# Note: No piei fw in following arry because it have build into
312# bl2
313# Total ddr-fip.bin size: 256KB, 4KB for header, 252(36*7)KB for fw
314# so max 7 ddr fw support
315declare -a DDR_FW_NAME=("aml_ddr.fw" \
316 "ddr4_1d.fw" \
317 "ddr4_2d.fw" \
318 "lpddr4_1d.fw" \
319 "lpddr4_2d.fw")
320declare -a DDR_FW_MAGIC=("AML0" \
321 "d444" \
322 "d422" \
323 "dl44" \
324 "dl42")
325function mk_ddr_fip()
326{
327 local outpath=$1
328 local out_hdr=$1/ddr-hdr.bin
329 local out_fip=$1/ddr-fip.bin
330 local offset=4096 # start offset inside ddr-fip.bin
331 local fw_size=
332 local rem_val=
333 local fw_cnt=0
334 local hdr_size=64
335 local input_dir=./${FIP_FOLDER}${CUR_SOC}
336
337 # first: make a empty ddr-fip.bin and ddr-fip-hdr.bin
338 rm -rf ${out_hdr}
339 rm -rf ${out_fip}
340 touch ${out_fip}
341 touch ${out_hdr}
342
343 # count firmware number we need package
344 for i in ${!DDR_FW_NAME[@]}; do
345 if [[ "${DDR_FW_NAME[${i}]}" == "${DDRFW_TYPE}"* ]]; then
346 echo "==== skip ${DDR_FW_NAME[${i}]} ===="
347 continue
348 fi
349 fw_cnt=`expr ${fw_cnt} + 1`
350 done
351
352 # build header for ddr-hdr.bin
353 # dwMagic
354 printf "%s" "@DFM" >> ${out_hdr}
355 # nCount of firmware
356 printf "%02x%02x" $[(fw_cnt) & 0xff] $[((fw_cnt) >> 8) & 0xff] | xxd -r -ps >> ${out_hdr}
357 # padding nVersion/szReserved to 0
358 printf "\0\0\0\0\0\0\0\0\0\0" >> ${out_hdr}
359
360 # build ddr-fip.bin and ddr-hdr.bin
361 for i in ${!DDR_FW_NAME[@]}; do
362 if [[ "${DDR_FW_NAME[${i}]}" == "${DDRFW_TYPE}"* ]]; then
363 continue
364 fi
365
366 # ============= package ddr-fip.bin =============
367 # get size of fw and align up to 4KB for
368 # some strage device such as nand
369 fw_size=`stat -c %s ${input_dir}/${DDR_FW_NAME[${i}]}`
370 fw_size=`expr ${fw_size} + 4095`
371 rem_val=`expr ${fw_size} % 4096`
372 fw_size=`expr ${fw_size} - ${rem_val}`
373
374 # 1. make sure we only copy 36KB, 32KB IMEM + 4KB DMEM
375 # 2. make a empty bin with fw_size
376 # 3. copy from fw to empty bin
377 # 4. padding this bin to final output
378 if [ ${fw_size} -gt "36864" ]; then
379 fw_size="36864"
380 fi
381 dd if=/dev/zero of=${outpath}/_tmp.bin bs=1 count=${fw_size} &> /dev/null
382 dd if=${input_dir}/${DDR_FW_NAME[${i}]} of=${outpath}/_tmp.bin skip=96 bs=1 count=${fw_size} conv=notrunc &> /dev/null
383 cat ${outpath}/_tmp.bin >> ${out_fip}
384
385 # ============= make ddr-hdr.bin =============
386 # dwMagic
387 printf "%s" "@DFM" >> ${out_hdr}
388 # nVersion, fix to 0
389 printf "\0\0" >> ${out_hdr}
390 # nSize, fix to 64 bytes
391 printf "%02x%02x" $[(hdr_size) & 0xff] $[((hdr_size) >> 8) & 0xff] | xxd -r -ps >> ${out_hdr}
392 # nIMGOffset
393 printf "%02x%02x%02x%02x" $[(offset) & 0xff] $[((offset) >> 8) & 0xff] \
394 $[((offset) >> 16) & 0xff] $[((offset) >> 24) & 0xff] | xxd -r -ps >> ${out_hdr}
395 # nIMGSize
396 printf "%02x%02x%02x%02x" $[(fw_size) & 0xff] $[((fw_size) >> 8) & 0xff] \
397 $[((fw_size) >> 16) & 0xff] $[((fw_size) >> 24) & 0xff] | xxd -r -ps >> ${out_hdr}
398 # fw_ver, fix to 0
399 printf "\0\0\0\0" >> ${out_hdr}
400 # fw_magic
401 printf "%s" ${DDR_FW_MAGIC[${i}]} >> ${out_hdr}
402 # szRerved2
403 printf "\0\0\0\0\0\0\0\0" >> ${out_hdr}
404 # szIMGSHA2
405 openssl dgst -sha256 -binary ${outpath}/_tmp.bin >> ${out_hdr}
406
407 offset=`expr ${offset} + ${fw_size}`
408 done;
409 rm ${outpath}/_tmp.bin
410
411 # generate ddr-fip.bin
412 fw_size=`stat -c "%s" ${out_fip}`
413 if [ ${fw_size} -gt "258048" ]; then
414 echo "==== size of ${out_fip}:${fw_size}, over limit ===="
415 exit -1
416 else
417 dd if=/dev/zero of=${out_fip}.tmp bs=1024 count=252 status=none
418 dd if=${out_fip} of=${out_fip}.tmp bs=1 count=${fw_size} conv=notrunc
419 fi
420
421 # bind to final ddr-fip.bin
422 fw_size=`stat -c "%s" ${out_hdr}`
423 if [ ${fw_size} -gt "4096" ]; then
424 echo "==== size of ${ot_hdr}:${fw_size}, over limit ===="
425 exit -1
426 else
427 dd if=/dev/zero of=${out_hdr}.tmp bs=1 count=4096 status=none
428 dd if=${out_hdr} of=${out_hdr}.tmp bs=1 count=${fw_size} conv=notrunc
429 fi
430 cat ${out_hdr}.tmp > ${out_fip}
431 cat ${out_fip}.tmp >> ${out_fip}
432 rm -rf ${out_fip}.tmp
433 rm -rf ${out_hdr}.tmp
434}
435
436
437function mk_uboot() {
438 output_images=$1
439 input_payloads=$2
440 postfix=$3
441 storage_type_suffix=$4
442 chipset_variant_suffix=$5
443
444 device_fip="${input_payloads}/device-fip.bin${postfix}"
445 bb1st="${input_payloads}/bb1st${storage_type_suffix}${chipset_variant_suffix}.bin${postfix}"
446 bl2e="${input_payloads}/blob-bl2e${storage_type_suffix}${chipset_variant_suffix}.bin${postfix}"
447 bl2x="${input_payloads}/blob-bl2x.bin${postfix}"
448
449 if [ ! -f ${device_fip} ] || \
450 [ ! -f ${bb1st} ] || \
451 [ ! -f ${bl2e} ] || \
452 [ ! -f ${bl2x} ]; then
453 echo fip:${device_fip}
454 echo bb1st:${bb1st}
455 echo bl2e:${bl2e}
456 echo bl2x:${bl2x}
457 echo "Error: ${input_payloads}/ bootblob does not all exist... abort"
458 ls -la ${input_payloads}/
459 exit -1
460 fi
461
wenbo.wang78380a02024-06-03 11:22:41 +0800462 attach_blob_hdr ${bb1st}
Hongjun Yuan2643a822024-10-08 17:48:20 -0700463 if [ "$CONFIG_DYNAMIC_SZ" == "y" ] ; then
wenbo.wange74cf382024-08-01 10:56:11 +0800464 local bl2e_sz=`stat -c "%s" ${bl2e}`
465 local bl2x_sz=`stat -c "%s" ${bl2x}`
466 if [ "$CONFIG_BL2E_96K" == "y" ] && [ "$bl2e_sz" -lt "116912" ]; then
467 dd if=/dev/zero of=${bl2e}.max bs=1 count=116912 &> /dev/null
468 dd if=${bl2e} of=${bl2e}.max conv=notrunc &> /dev/null
wenbo.wang5590a262024-08-02 11:10:08 +0800469 bl2e=${bl2e}.max
wenbo.wange74cf382024-08-01 10:56:11 +0800470 elif [ "$CONFIG_BL2E_128K" == "y" ] && [ "$bl2e_sz" -lt "149680" ]; then
471 dd if=/dev/zero of=${bl2e}.max bs=1 count=149680 &> /dev/null
472 dd if=${bl2e} of=${bl2e}.max conv=notrunc &> /dev/null
wenbo.wang5590a262024-08-02 11:10:08 +0800473 bl2e=${bl2e}.max
wenbo.wange74cf382024-08-01 10:56:11 +0800474 elif [ "$CONFIG_BL2E_256K" == "y" ] && [ "$bl2e_sz" -lt "280752" ]; then
475 dd if=/dev/zero of=${bl2e}.max bs=1 count=280752 &> /dev/null
476 dd if=${bl2e} of=${bl2e}.max conv=notrunc &> /dev/null
wenbo.wang5590a262024-08-02 11:10:08 +0800477 bl2e=${bl2e}.max
wenbo.wange74cf382024-08-01 10:56:11 +0800478 elif [ "$CONFIG_BL2E_1024K" == "y" ] && [ "$bl2e_sz" -lt "1067184" ]; then
479 dd if=/dev/zero of=${bl2e}.max bs=1 count=1067184 &> /dev/null
480 dd if=${bl2e} of=${bl2e}.max conv=notrunc &> /dev/null
wenbo.wang5590a262024-08-02 11:10:08 +0800481 bl2e=${bl2e}.max
wenbo.wange74cf382024-08-01 10:56:11 +0800482 fi
wenbo.wang78380a02024-06-03 11:22:41 +0800483
wenbo.wange74cf382024-08-01 10:56:11 +0800484 if [ "$bl2x_sz" -lt "108720" ]; then
485 dd if=/dev/zero of=${bl2x}.max bs=1 count=108720 &> /dev/null
486 dd if=${bl2x} of=${bl2x}.max conv=notrunc &> /dev/null
wenbo.wang5590a262024-08-02 11:10:08 +0800487 bl2x=${bl2x}.max
wenbo.wange74cf382024-08-01 10:56:11 +0800488 fi
wenbo.wangc7934642024-07-24 11:16:47 +0800489 fi
wenbo.wangbd036162023-10-27 10:41:34 +0800490 file_info_cfg="${output_images}/aml-payload.cfg"
491 file_info_cfg_temp=${temp_cfg}.temp
492
493 bootloader="${output_images}/u-boot.bin${storage_type_suffix}${postfix}"
xiane58635922025-03-06 11:12:27 +0900494 #sdcard_image="${output_images}/u-boot.bin.sd.bin${postfix}"
wenbo.wangbd036162023-10-27 10:41:34 +0800495
496 #fake ddr fip 256KB
497 ddr_fip="${input_payloads}/ddr-fip.bin"
498 if [ ! -f ${ddr_fip} ]; then
499 echo "==== use empty ddr-fip ===="
500 dd if=/dev/zero of=${ddr_fip} bs=1024 count=256 status=none
501 fi
502
503 #cat those together with 4K upper aligned for sdcard
504 align_base=4096
505 total_size=0
506 for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do
507 size=`stat -c "%s" ${file}`
508 upper=$[(size+align_base-1)/align_base*align_base]
509 total_size=$[total_size+upper]
510 echo ${file} ${size} ${upper}
511 done
512
513 echo ${total_size}
514 rm -f ${bootloader}
515 dd if=/dev/zero of=${bootloader} bs=${total_size} count=1 status=none
516
517 sector=512
518 seek=0
wenbo.wang78380a02024-06-03 11:22:41 +0800519 seek_sector=0
Sam Wu6dac7242024-04-02 10:58:54 +0800520 dateStamp=S7D-${CHIPSET_NAME}-`date +%y%m%d%H%M%S`
wenbo.wangbd036162023-10-27 10:41:34 +0800521
522 echo @AMLBOOT > ${file_info_cfg_temp}
523 dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=8 conv=notrunc &> /dev/null
524 nItemNum=5
525 nSizeHDR=$[64+nItemNum*16]
526 printf "02 %02x %02x %02x" $[(nItemNum)&0xFF] $[(nSizeHDR)&0xFF] $[((nSizeHDR)>>8)&0xFF] \
527 | xxd -r -ps > ${file_info_cfg_temp}
528 cat ${file_info_cfg_temp} >> ${file_info_cfg}
529
530 echo ${dateStamp} > ${file_info_cfg_temp}
531 dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=20 oflag=append conv=notrunc &> /dev/null
532
533 index=0
534 arrPayload=("BBST" "BL2E" "BL2X" "DDRF" "DEVF");
535 nPayloadOffset=0
536 nPayloadSize=0
537 for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do
538 size=`stat -c "%s" ${file}`
539 size_sector=$[(size+align_base-1)/align_base*align_base]
540 nPayloadSize=$[size_sector]
541 size_sector=$[size_sector/sector]
542 seek_sector=$[seek/sector+seek_sector]
543 #nPayloadOffset=$[sector*(seek_sector+1)]
544 nPayloadOffset=$[sector*(seek_sector)]
wenbo.wangd1d96692024-10-16 16:26:47 +0800545 echo ${file} ${seek_sector} ${size_sector} $[sector*(seek_sector)]
wenbo.wangbd036162023-10-27 10:41:34 +0800546 dd if=${file} of=${bootloader} bs=${sector} seek=${seek_sector} conv=notrunc status=none
547
548 echo ${arrPayload[$index]} > ${file_info_cfg_temp}.x
549 index=$((index+1))
550 dd if=${file_info_cfg_temp}.x of=${file_info_cfg_temp} bs=1 count=4 &> /dev/null
551 rm -f ${file_info_cfg_temp}.x
552 printf "%02x %02x %02x %02x %02x %02x %02x %02x 00 00 00 00" $[(nPayloadOffset)&0xFF] $[((nPayloadOffset)>>8)&0xFF] $[((nPayloadOffset)>>16)&0xFF] $[((nPayloadOffset)>>24)&0xFF] \
553 $[(nPayloadSize)&0xFF] $[((nPayloadSize)>>8)&0xFF] $[((nPayloadSize)>>16)&0xFF] $[((nPayloadSize)>>24)&0xFF] | xxd -r -ps >> ${file_info_cfg_temp}
554 dd if=${file_info_cfg_temp} of=${file_info_cfg} oflag=append conv=notrunc &> /dev/null
555 rm -f ${file_info_cfg_temp}
556 seek=$[(size+align_base-1)/align_base*align_base]
557 done
558
559 openssl dgst -sha256 -binary ${file_info_cfg} > ${file_info_cfg}.sha256
560 cat ${file_info_cfg} >> ${file_info_cfg}.sha256
561 #cat ${file_info_cfg}.sha256 >> ${file_info_cfg}
562 rm -f ${file_info_cfg}
563 mv -f ${file_info_cfg}.sha256 ${file_info_cfg}
564
wenbo.wang78380a02024-06-03 11:22:41 +0800565 dd if=${file_info_cfg} of=${bootloader} bs=512 seek=540 conv=notrunc status=none
566 dd if=${MAIN_FOLDER}/fip/${CUR_SOC}/bin/hdr_revA of=${bootloader} bs=512 seek=543 conv=notrunc status=none
wenbo.wang06f2b6b2024-03-19 19:50:29 +0800567
wenbo.wangbd036162023-10-27 10:41:34 +0800568 if [ ${storage_type_suffix} == ".sto" ]; then
xiane58635922025-03-06 11:12:27 +0900569 #echo "Image SDCARD"
570 #total_size=$[total_size+512]
571 #rm -f ${sdcard_image}
572 #dd if=/dev/zero of=${sdcard_image} bs=${total_size} count=1 status=none
573 #dd if=${file_info_cfg} of=${sdcard_image} conv=notrunc status=none
574 #dd if=${bootloader} of=${sdcard_image} bs=512 seek=1 conv=notrunc status=none
wenbo.wangbd036162023-10-27 10:41:34 +0800575 mv ${bootloader} ${output_images}/u-boot.bin${postfix}
576 fi
577
578 rm -f ${file_info_cfg}
579}
580
581
582function cleanup() {
583 cp ${FIP_BUILD_FOLDER}u-boot.bin* ${BUILD_FOLDER}
584 # cp bootblobs for PXP
585 #cp ${FIP_BUILD_FOLDER}device-fip.bin ${BUILD_FOLDER} -f
586 #cp ${FIP_BUILD_FOLDER}bb1st.bin ${BUILD_FOLDER} -f
587 #cp ${FIP_BUILD_FOLDER}blob-bl* ${BUILD_FOLDER} -f
588 echo "output file are generated in ${BUILD_FOLDER} folder"
589 #rm -f ${BUILD_PATH}/test-*
590 #rm -rf ${BUILD_PAYLOAD}
591 rm -f ${BUILD_PATH}/bl*.enc ${BUILD_PATH}/bl2*.sig
592}
593
594function encrypt_step() {
595 dbg "encrypt: $@"
596 local ret=0
597 ./${FIP_FOLDER}${CUR_SOC}/aml_encrypt_${CUR_SOC} $@
598 ret=$?
599 if [ 0 != $ret ]; then
600 echo "Err! aml_encrypt_${CUR_SOC} return $ret"
601 exit $ret
602 fi
603}
604
605function encrypt() {
606 #u-boot.bin generate
607
608 return
609}
610
611function build_fip() {
612
613 # acs_tool process ddr timing and configurable parameters
614 #python ${FIP_FOLDER}/acs_tool.pyc ${BUILD_PATH}/${AML_BL2_NAME} ${BUILD_PATH}/bl2_acs.bin ${BUILD_PATH}/acs.bin 0
615
616 # fix bl2/bl2e/bl2x
617 if [ -d ${BUILD_PAYLOAD} ]; then
618 rm -rf ${BUILD_PAYLOAD}
619 fi
620 mkdir -p ${BUILD_PAYLOAD}/
621
622 # make boot blobs
623 mk_bl2ex ${BUILD_PATH} ${BUILD_PAYLOAD} ${DDRFW_TYPE}
624
625 # make devicefip
626 mk_devfip ${BUILD_PATH} ${BUILD_PAYLOAD}
627
628
629 # build final bootloader
630 #mk_uboot ${BUILD_PATH} ${BUILD_PATH}
631 mk_uboot ${BUILD_PATH} ${BUILD_PATH} "" .sto ${CHIPSET_VARIANT_SUFFIX}
xiane58635922025-03-06 11:12:27 +0900632 #mk_uboot ${BUILD_PATH} ${BUILD_PATH} "" .usb ${CHIPSET_VARIANT_SUFFIX}
wenbo.wangbd036162023-10-27 10:41:34 +0800633
634 return
635}
636
Lawrence Mok61ffc792024-06-12 01:07:23 +0000637function rename_blx_remove_sig_scheme() {
638 # Remove dv/cs sig scheme extension because some places don't use BLX_BIN_NAME
639 for loop in ${!BLX_NAME[@]}; do
640 f="${BUILD_PATH}/${BLX_BIN_NAME[$loop]}"
641 cleaned="${f%.${DV_SIGNING_SCHEME}.${CS_SIGNING_SCHEME}}"
642 if [ -f "$f" ] && [ "$f" != "$cleaned" ]; then
643 mv "$f" "$cleaned" -f
644 fi
645 done
646}
647
wenbo.wangd1d96692024-10-16 16:26:47 +0800648
wenbo.wangbd036162023-10-27 10:41:34 +0800649declare CHIPACS_SIZE="8192"
650declare DDRFW_SIZE="212992"
651function process_blx() {
652
wenbo.wangbd036162023-10-27 10:41:34 +0800653 # process loop
654 for loop in ${!BLX_NAME[@]}; do
655 if [ "NULL" != "${BLX_RAWBIN_NAME[$loop]}" ] && \
656 [ -n "${BLX_RAWBIN_NAME[$loop]}" ] && \
657 [ -f ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} ]; then
658 if [ -n "${CONFIG_FORMER_SIGN}" ]; then
659 if [ ${BLX_NAME[$loop]} == "bl2" ]; then
660 ./${FIP_FOLDER}${CUR_SOC}/bin/gen-merge-bin.sh --input0 ${BUILD_PATH}/chip_acs.bin --size0 ${CHIPACS_SIZE} \
661 --input1 ${BUILD_PATH}/ddrfw_data.bin --size1 ${DDRFW_SIZE} --output ${BUILD_PATH}/chip_acs.bin
662 fi
Lawrence Mokb7aee662024-06-12 00:31:11 +0000663 if [ ${BLX_NAME[$loop]} == "bl32" ]; then
664 echo "compress bl32.bin"
665 local bl32=${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]}
666 mv -f "$bl32" "$bl32.org"
667
668 encrypt_step --bl3sig --input "$bl32.org" --output "$bl32.org.lz4" --compress lz4 --level v3 --type bl32
669 dd if="$bl32.org.lz4" of="$bl32" bs=1 skip=1824 >& /dev/null
670 blx_size=`stat -c %s $bl32`
671 if [ $blx_size -gt 524288 ]; then
672 echo "Error: bl32 size exceed limit 524288"
673 exit -1
674 fi
675 fi
wenbo.wangbd036162023-10-27 10:41:34 +0800676 ./${FIP_FOLDER}${CUR_SOC}/bin/sign-blx.sh --blxname ${BLX_NAME[$loop]} --input ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \
677 --output ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chipset_name ${CHIPSET_NAME} --chipset_variant ${CHIPSET_VARIANT} \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000678 --key_type ${AMLOGIC_KEY_TYPE} --soc ${CUR_SOC} --chip_acs ${BUILD_PATH}/chip_acs.bin --ddr_type ${DDRFW_TYPE} \
wenbo.wangc7934642024-07-24 11:16:47 +0800679 --dv-sig-scheme $DV_SIGNING_SCHEME --cs-sig-scheme $CS_SIGNING_SCHEME --extra_args "bl2e_size=${BL2E_PAYLOAD_SIZE}"
wenbo.wangbd036162023-10-27 10:41:34 +0800680 else
681 if [ -n "${CONFIG_JENKINS_SIGN}" ]; then
682 if [ ${BLX_NAME[$loop]} == "bl2" ]; then
683 ./${FIP_FOLDER}${CUR_SOC}/bin/gen-merge-bin.sh --input0 ${BUILD_PATH}/chip_acs.bin --size0 ${CHIPACS_SIZE} \
684 --input1 ${BUILD_PATH}/ddrfw_data.bin --size1 ${DDRFW_SIZE} --output ${BUILD_PATH}/chip_acs.bin
685 fi
686 /usr/bin/python3 ./sign.py --type ${BLX_NAME[$loop]} --in ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \
687 --out ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chip ${CHIPSET_NAME} --chipVariant ${CHIPSET_VARIANT} \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000688 --keyType ${AMLOGIC_KEY_TYPE} --chipAcsFile ${BUILD_PATH}/chip_acs.bin --ddrType ${DDRFW_TYPE} \
wenbo.wangc7934642024-07-24 11:16:47 +0800689 --dvSigScheme $DV_SIGNING_SCHEME --csSigScheme $CS_SIGNING_SCHEME --extraArgs "bl2e_size=${BL2E_PAYLOAD_SIZE}"
wenbo.wangbd036162023-10-27 10:41:34 +0800690 else
691 if [ ${BLX_NAME[$loop]} == "bl2" ]; then
692 ./${FIP_FOLDER}${CUR_SOC}/bin/gen-merge-bin.sh --input0 ${BUILD_PATH}/chip_acs.bin --size0 ${CHIPACS_SIZE} \
693 --input1 ${BUILD_PATH}/ddrfw_data.bin --size1 ${DDRFW_SIZE} --output ${BUILD_PATH}/chip_acs.bin
694 fi
695 /usr/bin/python3 ./${FIP_FOLDER}/jenkins_sign.py --type ${BLX_NAME[$loop]} --in ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \
696 --out ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chip ${CHIPSET_NAME} --chipVariant ${CHIPSET_VARIANT} --keyType ${AMLOGIC_KEY_TYPE} \
Lawrence Mok61ffc792024-06-12 01:07:23 +0000697 --chipAcsFile ${BUILD_PATH}/chip_acs.bin --ddrType ${DDRFW_TYPE} \
wenbo.wangc7934642024-07-24 11:16:47 +0800698 --dvSigScheme $DV_SIGNING_SCHEME --csSigScheme $CS_SIGNING_SCHEME --extraArgs "bl2e_size=${BL2E_PAYLOAD_SIZE}"
wenbo.wangbd036162023-10-27 10:41:34 +0800699 fi
700 fi
701 fi
wenbo.wangbd036162023-10-27 10:41:34 +0800702 done
703
Bo Lv52f663b2024-06-26 10:54:02 +0800704 if [ ! -f ${BUILD_PATH}/blob-bl40.bin.signed ]; then
705 echo "Warning: local bl40"
706 cp bl40/bin/${CUR_SOC}/${BLX_BIN_SUB_CHIP}/blob-bl40.bin.signed.${DV_SIGNING_SCHEME}.${CS_SIGNING_SCHEME} ${BUILD_PATH}
707 fi
708
709
Lawrence Mok61ffc792024-06-12 01:07:23 +0000710 # Remove sig scheme because some parts of the script doesn't use BLX_BIN_NAME
711 rename_blx_remove_sig_scheme
712
wenbo.wangbd036162023-10-27 10:41:34 +0800713 if [ ! -f ${BUILD_PATH}/device_acs.bin ]; then
714 echo "dev acs params not exist !"
715 exit -1
716 fi
717
718 dev_acs_size=`stat -c %s ${BUILD_PATH}/device_acs.bin`
719
720 if [ $dev_acs_size -gt ${DEV_ACS_BIN_SIZE} ]; then
721 echo "chip acs size exceed limit ${DEV_ACS_BIN_SIZE}, $dev_acs_size"
722 exit -1
723 else
724 dd if=/dev/zero of=${BUILD_PATH}/dvinit-params.bin bs=${DEV_ACS_BIN_SIZE} count=1 &> /dev/null
725 dd if=${BUILD_PATH}/device_acs.bin of=${BUILD_PATH}/dvinit-params.bin conv=notrunc &> /dev/null
726 fi
727
wenbo.wangd1d96692024-10-16 16:26:47 +0800728 ./${FIP_FOLDER}${CUR_SOC}/bin/add-dvinit-params.sh ${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/blob-bl2e.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/dvinit-params.bin ${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${CUR_SOC}
729 ./${FIP_FOLDER}${CUR_SOC}/bin/add-dvinit-params.sh ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/blob-bl2e.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/dvinit-params.bin ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed ${CUR_SOC}
wenbo.wangbd036162023-10-27 10:41:34 +0800730
731 # fix size for BL30 128KB
732 if [ -f ${BUILD_PATH}/bl30.bin ]; then
733 #blx_size=`du -b ${BUILD_PATH}/bl30.bin | awk '{print int(${BUILD_PATH}/bl30.bin)}'`
734 blx_size=`stat -c %s ${BUILD_PATH}/bl30.bin`
735 if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then
736 echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}"
737 exit -1
738 fi
739 else
740 echo "Warning: local bl30"
741 #dd if=/dev/random of=${BUILD_PATH}/bl30.bin bs=4096 count=1
742 dd if=bl30/bin/sc2/bl30.bin of=${BUILD_PATH}/bl30.bin &> /dev/null
743 fi
744 dd if=/dev/zero of=${BUILD_PATH}/bl30-payload.bin bs=${BL30_BIN_SIZE} count=1 &> /dev/null
745 dd if=${BUILD_PATH}/bl30.bin of=${BUILD_PATH}/bl30-payload.bin conv=notrunc &> /dev/null
wenbo.wangbd036162023-10-27 10:41:34 +0800746 if [ "y" == "${CONFIG_AML_BL33_COMPRESS_ENABLE}" ]; then
747 mv -f ${BUILD_PATH}/bl33.bin ${BUILD_PATH}/bl33.bin.org
wenbo.wang5af83a12024-04-10 15:59:28 +0800748 amfc_compress ${BUILD_PATH} 9
749#encrypt_step --bl3sig --input ${BUILD_PATH}/bl33.bin.org --output ${BUILD_PATH}/bl33.bin.org.lz4 --compress lz4 --level v3 --type bl33
wenbo.wangbd036162023-10-27 10:41:34 +0800750 #get LZ4 format bl33 image from bl33.bin.enc with offset 0x720
wenbo.wang5af83a12024-04-10 15:59:28 +0800751# dd if=${BUILD_PATH}/bl33.bin.org.lz4 of=${BUILD_PATH}/bl33.bin bs=1 skip=1824 >& /dev/null
wenbo.wangbd036162023-10-27 10:41:34 +0800752 fi
753
754 # fix size for BL33 1024KB
755 if [ ! -f ${BUILD_PATH}/bl33.bin ]; then
756 echo "Error: ${BUILD_PATH}/bl33.bin does not exist... abort"
757 exit -1
758 fi
759 #blx_size=`du -b ${BUILD_PATH}/bl33.bin | awk '{print int(${BUILD_PATH}/bl33.bin)}'`
760 blx_size=`stat -c %s ${BUILD_PATH}/bl33.bin`
761 if [ $blx_size -gt ${BL33_BIN_SIZE} ]; then
762 echo "Error: bl33 size exceed limit ${BL33_BIN_SIZE}"
763 exit -1
764 fi
765 dd if=/dev/zero of=${BUILD_PATH}/bl33-payload.bin bs=${BL33_BIN_SIZE} count=1 &> /dev/null
766 dd if=${BUILD_PATH}/bl33.bin of=${BUILD_PATH}/bl33-payload.bin conv=notrunc &> /dev/null
767
Lawrence Mok61ffc792024-06-12 01:07:23 +0000768 template_ext=".${DV_SIGNING_SCHEME}.${CS_SIGNING_SCHEME}"
769 if [ ! -f ${BUILD_PATH}/device-fip-header.bin${template_ext} ]; then
wenbo.wangbd036162023-10-27 10:41:34 +0800770 echo "Warning: local device fip header templates"
Lawrence Mok61ffc792024-06-12 01:07:23 +0000771 cp ${CHIPSET_TEMPLATES_PATH}/${CUR_SOC}/${BLX_BIN_SUB_CHIP}/device-fip-header.bin${template_ext} ${BUILD_PATH}/
wenbo.wangbd036162023-10-27 10:41:34 +0800772 fi
773
774 #./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH}
775
776 return
777}
778
779function build_signed() {
780
781 process_blx $@
782
783 # package ddr-fip.bin
784 if [[ "y" == ${CONFIG_DDR_FULL_FW} ]]; then
785 mk_ddr_fip ${BUILD_PATH}
786 fi
787
788 ./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} ${CHIPSET_VARIANT_SUFFIX}
789 postfix=.signed
790 mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .sto ${CHIPSET_VARIANT_SUFFIX}
xiane58635922025-03-06 11:12:27 +0900791 #mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .usb ${CHIPSET_VARIANT_SUFFIX}
wenbo.wangbd036162023-10-27 10:41:34 +0800792
793 list_pack="${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed"
794 list_pack="$list_pack ${BUILD_PATH}/blob-bl2e.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/blob-bl2e.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed"
795 list_pack="$list_pack ${BUILD_PATH}/blob-bl2x.bin.signed ${BUILD_PATH}/blob-bl31.bin.signed ${BUILD_PATH}/blob-bl32.bin.signed ${BUILD_PATH}/blob-bl40.bin.signed"
Zhongfu Luo43e01c32024-07-09 19:44:14 +0800796 list_pack="$list_pack ${BUILD_PATH}/bl30-payload.bin ${BUILD_PATH}/bl33-payload.bin ${BUILD_PATH}/bl33.bin.org ${BUILD_PATH}/dvinit-params.bin"
wenbo.wangbd036162023-10-27 10:41:34 +0800797 if [ -f ${BUILD_PATH}/ddr-fip.bin ]; then
798 list_pack="$list_pack ${BUILD_PATH}/ddr-fip.bin"
799 fi
xiane58635922025-03-06 11:12:27 +0900800 #u_pack=${BUILD_FOLDER}/"$(basename ${BOARD_DIR})"-u-boot.aml.zip
801 #zip -j $u_pack ${list_pack} >& /dev/null
wenbo.wangbd036162023-10-27 10:41:34 +0800802
803 if [ "y" == "${CONFIG_AML_SIGNED_UBOOT}" ]; then
804 if [ ! -d "${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys" ]; then
805 ./${FIP_FOLDER}${CUR_SOC}/bin/download-keys.sh ${AMLOGIC_KEY_TYPE} ${CUR_SOC} device ${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys/
806 fi
807
wenbo.wangbd036162023-10-27 10:41:34 +0800808 if [ "y" == "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then
Zhongfu Luo43e01c32024-07-09 19:44:14 +0800809 DEVICE_ROOTRSA_INDEX=1
wenbo.wangbd036162023-10-27 10:41:34 +0800810 elif [ -n "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then
Zhongfu Luo43e01c32024-07-09 19:44:14 +0800811 DEVICE_ROOTRSA_INDEX=${CONFIG_DEVICE_ROOTRSA_INDEX}
812 else
813 DEVICE_ROOTRSA_INDEX=0
wenbo.wangbd036162023-10-27 10:41:34 +0800814 fi
wenbo.wangbd036162023-10-27 10:41:34 +0800815
Zhongfu Luo43e01c32024-07-09 19:44:14 +0800816 ./${FIP_FOLDER}${CUR_SOC}/bin/device-vendor-scs-signing.sh --key-dir ${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys/ --project ${CHIPSET_NAME} \
817 --sig-scheme ${DV_SIGNING_SCHEME} --input-dir ${BUILD_PATH} --rootkey-index ${DEVICE_ROOTRSA_INDEX} --chipset-variant ${CHIPSET_VARIANT} \
818 --arb-config ${UBOOT_SRC_FOLDER}/${BOARD_DIR}/fw_arb.cfg --out-dir ${BUILD_PATH}
wenbo.wangbd036162023-10-27 10:41:34 +0800819 fi
820
821 return
822}
823
824function copy_other_soc() {
825 cp ${BL33_BUILD_FOLDER}${BOARD_DIR}/firmware/acs.bin ${BUILD_PATH}/device_acs.bin -f
826
827 if [ ! -f ${BUILD_PATH}/chip_acs.bin ]; then
828 cp ./${FIP_FOLDER}${CUR_SOC}/chip_acs.bin ${BUILD_PATH}/chip_acs.bin -f
829 fi
830
831 # device acs params parse for ddr timing
832 #./${FIP_FOLDER}parse ${BUILD_PATH}/device_acs.bin
Lawrence Mok61ffc792024-06-12 01:07:23 +0000833
834 # Remove sig scheme because some parts of the script does not use BLX_BIN_NAME
835 rename_blx_remove_sig_scheme
wenbo.wangbd036162023-10-27 10:41:34 +0800836}
837
838function package() {
839 # BUILD_PATH without "/"
840 x=$((${#BUILD_PATH}-1))
841 if [ "\\" == "${BUILD_PATH:$x:1}" ] || [ "/" == "${BUILD_PATH:$x:1}" ]; then
842 BUILD_PATH=${BUILD_PATH:0:$x}
843 fi
844
845 init_vari $@
846 # Enable Clear Image Packing for PXP
847 if [ -n "${CONFIG_BUILD_UNSIGN}" ]; then
848 build_fip $@
849 else
850 # Bypass Sign Process for PXP
851 build_signed $@
852 fi
853 #copy_file
854 cleanup
wenbo.wang06f2b6b2024-03-19 19:50:29 +0800855
wenbo.wangbd036162023-10-27 10:41:34 +0800856 echo "Bootloader build done!"
857}
wenbo.wang06f2b6b2024-03-19 19:50:29 +0800858
wenbo.wang78380a02024-06-03 11:22:41 +0800859function attach_blob_hdr () {
860 local bb1st_folder=${MAIN_FOLDER}/$1
861 local bl2_size=`stat -c "%s" $bb1st_folder`
862
863 if [ "${bl2_size}" -le "${BL2_MAX_SIZE}" ]; then
864 dd if=/dev/zero of=${bb1st_folder}.max bs=1024 count=266 status=none
865 dd if=${bb1st_folder} of=${bb1st_folder}.max bs=1 count=${bl2_size} conv=notrunc
866 bb1st_folder=${bb1st_folder}.max
wenbo.wang06f2b6b2024-03-19 19:50:29 +0800867 fi
wenbo.wang78380a02024-06-03 11:22:41 +0800868
869 ${FIP_FOLDER}${CUR_SOC}/bin/attach_sbh.sh $bb1st_folder $bb1st_folder.hdr
870 bb1st_folder=$bb1st_folder.hdr
871
872 bb1st=${bb1st_folder}
wenbo.wang06f2b6b2024-03-19 19:50:29 +0800873}
874