Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # include uboot pre-build macros |
| 4 | #declare CONFIG_FILE=("${buildtree}/.config") |
| 5 | #declare AUTOCFG_FILE=("${buildtree}/include/autoconf.mk") |
| 6 | |
| 7 | function 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_NANE="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 | echo "------------------------------------------------------" |
| 41 | echo "DDRFW_TYPE: ${DDRFW_TYPE}" |
| 42 | echo "------------------------------------------------------" |
| 43 | } |
| 44 | |
| 45 | function mk_bl2ex() { |
| 46 | output=$1 |
| 47 | payload=$2 |
| 48 | ddr_type=$3 |
| 49 | |
| 50 | if [ ! -f ${output}/bl2.bin ] || \ |
| 51 | [ ! -f ${output}/bl2e.bin ] || \ |
| 52 | [ ! -f ${output}/bl2x.bin ]; then |
| 53 | echo "Error: ${output}/bl2/e/x.bin does not all exist... abort" |
| 54 | ls -la ${output} |
| 55 | exit -1 |
| 56 | fi |
| 57 | |
| 58 | echo "=================================================================" |
| 59 | echo "image packing with acpu-imagetool for bl2 bl2e bl2x" |
| 60 | |
| 61 | dd if=/dev/zero of=${payload}/bl2.bin bs=127904 count=1 |
| 62 | dd if=${output}/bl2.bin of=${payload}/bl2.bin conv=notrunc |
| 63 | |
| 64 | dd if=/dev/zero of=${payload}/bl2e.bin bs=65536 count=1 |
| 65 | dd if=${output}/bl2e.bin of=${payload}/bl2e.bin conv=notrunc |
| 66 | |
| 67 | dd if=/dev/zero of=${payload}/bl2x.bin bs=65536 count=1 |
| 68 | dd if=${output}/bl2x.bin of=${payload}/bl2x.bin conv=notrunc |
| 69 | |
| 70 | |
| 71 | echo "====================================================" |
| 72 | echo "------ process for Synopsys ddr fw ------" |
| 73 | INPUT_DDRFW=./${FIP_FOLDER}${CUR_SOC} |
| 74 | |
| 75 | if [ "$ddr_type" == "ddr4" ]; then |
| 76 | dd if=${INPUT_DDRFW}/ddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 77 | dd if=${INPUT_DDRFW}/ddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 78 | elif [ "$ddr_type" == "ddr3" ]; then |
| 79 | dd if=${INPUT_DDRFW}/ddr3_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 80 | dd if=/dev/zero of=${payload}/ddrfw_2d.bin bs=36864 count=1 |
| 81 | elif [ "$ddr_type" == "lpddr4" ]; then |
| 82 | dd if=${INPUT_DDRFW}/lpddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 83 | dd if=${INPUT_DDRFW}/lpddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 84 | elif [ "$ddr_type" == "lpddr3" ]; then |
| 85 | dd if=${INPUT_DDRFW}/lpddr3_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 86 | dd if=/dev/zero of=${payload}/ddrfw_2d.bin bs=36864 count=1 |
| 87 | else |
| 88 | echo "un-recognized ddr_type: ${ddr_type}" |
| 89 | echo "---- use default ddr4 ----" |
| 90 | dd if=${INPUT_DDRFW}/ddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 91 | dd if=${INPUT_DDRFW}/ddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 92 | fi |
| 93 | |
| 94 | piei_size=`stat -c %s ${INPUT_DDRFW}/piei.fw` |
| 95 | if [ $piei_size -gt 12384 ]; then |
| 96 | dd if=${INPUT_DDRFW}/piei.fw of=${payload}/ddrfw_piei.bin skip=96 bs=1 count=12288 |
| 97 | else |
| 98 | dd if=/dev/zero of=${payload}/ddrfw_piei.bin bs=12288 count=1 |
| 99 | dd if=${INPUT_DDRFW}/piei.fw of=${payload}/ddrfw_piei.bin skip=96 bs=1 conv=notrunc |
| 100 | fi |
| 101 | |
| 102 | cat ${payload}/ddrfw_1d.bin ${payload}/ddrfw_2d.bin \ |
| 103 | ${payload}/ddrfw_piei.bin > ${payload}/ddrfw_data.bin |
| 104 | |
| 105 | if [ ! -f ${payload}/ddrfw_data.bin ]; then |
| 106 | echo "ddrfw_data payload does not exist in ${payload} !" |
| 107 | exit -1 |
| 108 | fi |
| 109 | ddrfw_data_size=`stat -c %s ${payload}/ddrfw_data.bin` |
| 110 | if [ $ddrfw_data_size -ne 86016 ]; then |
| 111 | echo "ddr_fwdata size is not equal to 84K, $ddrfw_data_size" |
| 112 | exit -1 |
| 113 | fi |
| 114 | |
| 115 | |
| 116 | echo "====================================================" |
| 117 | echo "------ process for device and chip params ------" |
| 118 | INPUT_PARAMS=${output} |
| 119 | |
| 120 | if [ ! -f ${INPUT_PARAMS}/device_acs.bin ]; then |
| 121 | echo "dev acs params not exist !" |
| 122 | exit -1 |
| 123 | fi |
| 124 | |
| 125 | if [ ! -f ${INPUT_PARAMS}/chip_acs.bin ]; then |
| 126 | echo "chip acs params not exist !" |
| 127 | exit -1 |
| 128 | fi |
| 129 | chip_acs_size=`stat -c %s ${INPUT_PARAMS}/chip_acs.bin` |
| 130 | dev_acs_size=`stat -c %s ${INPUT_PARAMS}/device_acs.bin` |
| 131 | |
| 132 | if [ $chip_acs_size -gt 4096 ]; then |
| 133 | echo "chip acs size exceed limit 4096, $chip_acs_size" |
| 134 | exit -1 |
| 135 | else |
| 136 | dd if=/dev/zero of=${payload}/chip_acs.bin bs=4096 count=1 |
| 137 | dd if=${INPUT_PARAMS}/chip_acs.bin of=${payload}/chip_acs.bin conv=notrunc |
| 138 | fi |
| 139 | |
| 140 | if [ $dev_acs_size -gt 28672 ]; then |
| 141 | echo "chip acs size exceed limit 28672, $dev_acs_size" |
| 142 | exit -1 |
| 143 | else |
| 144 | dd if=/dev/zero of=${payload}/device_acs.bin bs=28672 count=1 |
| 145 | dd if=${INPUT_PARAMS}/device_acs.bin of=${payload}/device_acs.bin conv=notrunc |
| 146 | fi |
| 147 | |
| 148 | ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-boot-blobs \ |
| 149 | --infile-bl2-payload=${payload}/bl2.bin \ |
| 150 | --infile-bl2e-payload=${payload}/bl2e.bin \ |
| 151 | --infile-bl2x-payload=${payload}/bl2x.bin \ |
| 152 | --infile-dvinit-params=${payload}/device_acs.bin \ |
| 153 | --infile-csinit-params=${payload}/chip_acs.bin \ |
| 154 | --infile-ddr-fwdata=${payload}/ddrfw_data.bin \ |
| 155 | --outfile-bb1st=${output}/bb1st.bin \ |
| 156 | --outfile-blob-bl2e=${output}/blob-bl2e.bin \ |
| 157 | --outfile-blob-bl2x=${output}/blob-bl2x.bin |
| 158 | |
| 159 | if [ ! -f ${output}/bb1st.bin ] || \ |
| 160 | [ ! -f ${output}/blob-bl2e.bin ] || \ |
| 161 | [ ! -f ${output}/blob-bl2x.bin ]; then |
| 162 | echo "Error: ${output}/ bootblobs do not all exist... abort" |
| 163 | ls -la ${output}/ |
| 164 | exit -1 |
| 165 | fi |
| 166 | echo "done to genenrate bb1st.bin folder" |
| 167 | } |
| 168 | |
| 169 | function mk_devfip() { |
| 170 | output=$1 |
| 171 | payload=$2 |
| 172 | |
| 173 | # fix size for BL30 128KB --> 64KB |
| 174 | if [ -f ${output}/bl30.bin ]; then |
| 175 | blx_size=`stat -c %s ${output}/bl30.bin` |
| 176 | if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then |
| 177 | echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}" |
| 178 | exit -1 |
| 179 | fi |
| 180 | else |
| 181 | echo "Warning: null bl30" |
| 182 | dd if=/dev/random of=${output}/bl30.bin bs=4096 count=1 |
| 183 | #dd if=bl30/bin/sc2/bl30.bin of=${output}/bl30.bin |
| 184 | fi |
| 185 | dd if=/dev/zero of=${payload}/bl30.bin bs=${BL30_BIN_SIZE} count=1 |
| 186 | dd if=${output}/bl30.bin of=${payload}/bl30.bin conv=notrunc |
| 187 | |
| 188 | # fix size for BL40 96KB |
| 189 | if [ -f ${output}/bl40.bin ]; then |
| 190 | blx_szie=`stat -c %s ${output}/bl40.bin` |
| 191 | if [ $blx_size -gt 98304 ]; then |
| 192 | echo "Error: bl40 size exceed limit 98304" |
| 193 | exit -1 |
| 194 | fi |
| 195 | else |
| 196 | echo "Warning: null bl40" |
| 197 | #dd if=/dev/random of=${output}/bl40.bin bs=4096 count=1 |
| 198 | dd if=/dev/zero of=${output}/bl40.bin bs=4096 count=1 |
| 199 | fi |
| 200 | dd if=/dev/zero of=${payload}/bl40.bin bs=98304 count=1 |
| 201 | dd if=${output}/bl40.bin of=${payload}/bl40.bin conv=notrunc |
| 202 | |
| 203 | |
| 204 | # fix size for BL31 256KB |
| 205 | if [ ! -f ${output}/bl31.bin ]; then |
| 206 | echo "Error: ${output}/bl31.bin does not exist... abort" |
| 207 | exit -1 |
| 208 | fi |
| 209 | blx_size=`stat -c %s ${output}/bl31.bin` |
| 210 | echo "BL31 size: ${blx_size}" |
| 211 | if [ $blx_size -gt 262144 ]; then |
| 212 | echo "Error: bl31 size exceed limit 262144" |
| 213 | exit -1 |
| 214 | fi |
| 215 | dd if=/dev/zero of=${payload}/bl31.bin bs=262144 count=1 |
| 216 | dd if=${output}/bl31.bin of=${payload}/bl31.bin conv=notrunc |
| 217 | |
| 218 | |
| 219 | # fix size for BL32 512KB |
| 220 | if [ -f ${output}/bl32.bin ]; then |
| 221 | blx_size=`stat -c %s ${output}/bl32.bin` |
| 222 | if [ $blx_size -gt 524288 ]; then |
| 223 | echo "Error: bl32 size exceed limit 524288" |
| 224 | exit -1 |
| 225 | fi |
| 226 | else |
| 227 | echo "Warning: null bl32" |
| 228 | dd if=/dev/random of=${output}/bl32.bin bs=4096 count=1 |
| 229 | #dd if=bl32/bin/sc2/bl32.bin of=${output}/bl32.bin |
| 230 | fi |
| 231 | dd if=/dev/zero of=${payload}/bl32.bin bs=524288 count=1 |
| 232 | dd if=${output}/bl32.bin of=${payload}/bl32.bin conv=notrunc |
| 233 | |
| 234 | |
| 235 | # fix size for BL33 1024KB + 512 KB |
| 236 | if [ ! -f ${output}/bl33.bin ]; then |
| 237 | echo "Error: ${output}/bl33.bin does not exist... abort" |
| 238 | exit -1 |
| 239 | fi |
| 240 | blx_size=`stat -c %s ${output}/bl33.bin` |
| 241 | if [ $blx_size -gt 1572864 ]; then |
| 242 | echo "Error: bl33 size exceed limit 0x180000" |
| 243 | exit -1 |
| 244 | fi |
| 245 | dd if=/dev/zero of=${payload}/bl33.bin bs=1572864 count=1 |
| 246 | dd if=${output}/bl33.bin of=${payload}/bl33.bin conv=notrunc |
| 247 | |
| 248 | |
| 249 | ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-device-fip \ |
| 250 | --infile-bl30-payload=${payload}/bl30.bin \ |
| 251 | --infile-bl40-payload=${payload}/bl40.bin \ |
| 252 | --infile-bl31-payload=${payload}/bl31.bin \ |
| 253 | --infile-bl32-payload=${payload}/bl32.bin \ |
| 254 | --infile-bl33-payload=${payload}/bl33.bin \ |
| 255 | --outfile-device-fip=${output}/device-fip.bin |
| 256 | |
| 257 | if [ ! -f ${output}/device-fip.bin ]; then |
| 258 | echo "Error: ${output}/device-fip.bin does not exist... abort" |
| 259 | exit -1 |
| 260 | fi |
| 261 | echo "done to genenrate device-fip.bin" |
| 262 | } |
| 263 | |
| 264 | function mk_uboot() { |
| 265 | output_images=$1 |
| 266 | input_payloads=$2 |
| 267 | postfix=$3 |
| 268 | |
| 269 | device_fip="${input_payloads}/device-fip.bin${postfix}" |
| 270 | bb1st="${input_payloads}/bb1st.bin${postfix}" |
| 271 | bl2e="${input_payloads}/blob-bl2e.bin${postfix}" |
| 272 | bl2x="${input_payloads}/blob-bl2x.bin${postfix}" |
| 273 | |
| 274 | if [ ! -f ${device_fip} ] || \ |
| 275 | [ ! -f ${bb1st} ] || \ |
| 276 | [ ! -f ${bl2e} ] || \ |
| 277 | [ ! -f ${bl2x} ]; then |
| 278 | echo "Error: ${input_payloads}/ bootblob does not all exist... abort" |
| 279 | ls -la ${input_payloads}/ |
| 280 | exit -1 |
| 281 | fi |
| 282 | |
| 283 | file_info_cfg="${output_images}/aml-payload.cfg" |
| 284 | file_info_cfg_temp=${temp_cfg}.temp |
| 285 | |
| 286 | bootloader="${output_images}/u-boot.bin${postfix}" |
| 287 | sdcard_image="${output_images}/u-boot.bin.sd.bin${postfix}" |
| 288 | |
| 289 | #fake ddr fip 256KB |
| 290 | ddr_fip="${input_payloads}/ddr-fip.bin" |
| 291 | if [ ! -f ${ddr_fip} ]; then |
| 292 | dd if=/dev/zero of=${ddr_fip} bs=1024 count=256 status=none |
| 293 | fi |
| 294 | |
| 295 | #cat those together with 4K upper aligned for sdcard |
| 296 | align_base=4096 |
| 297 | total_size=0 |
| 298 | for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do |
| 299 | size=`stat -c "%s" ${file}` |
| 300 | upper=$[(size+align_base-1)/align_base*align_base] |
| 301 | total_size=$[total_size+upper] |
| 302 | echo ${file} ${size} ${upper} |
| 303 | done |
| 304 | |
| 305 | echo ${total_size} |
| 306 | rm -f ${bootloader} |
| 307 | dd if=/dev/zero of=${bootloader} bs=${total_size} count=1 status=none |
| 308 | |
| 309 | sector=512 |
| 310 | seek=0 |
| 311 | seek_sector=0 |
| 312 | dateStamp=SC2-`date +%Y%m%d%H%M%S` |
| 313 | |
| 314 | echo @AMLBOOT > ${file_info_cfg_temp} |
| 315 | dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=8 conv=notrunc &> /dev/null |
| 316 | nItemNum=5 |
| 317 | nSizeHDR=$[64+nItemNum*16] |
| 318 | printf "01 %02x %02x %02x 00 00 00 00" $[(nItemNum)&0xFF] $[(nSizeHDR)&0xFF] $[((nSizeHDR)>>8)&0xFF] \ |
| 319 | | xxd -r -ps > ${file_info_cfg_temp} |
| 320 | cat ${file_info_cfg_temp} >> ${file_info_cfg} |
| 321 | |
| 322 | echo ${dateStamp} > ${file_info_cfg_temp} |
| 323 | dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=16 oflag=append conv=notrunc &> /dev/null |
| 324 | |
| 325 | index=0 |
| 326 | arrPayload=("BBST" "BL2E" "BL2X" "DDRF" "DEVF"); |
| 327 | nPayloadOffset=0 |
| 328 | nPayloadSize=0 |
| 329 | for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do |
| 330 | size=`stat -c "%s" ${file}` |
| 331 | size_sector=$[(size+align_base-1)/align_base*align_base] |
| 332 | nPayloadSize=$[size_sector] |
| 333 | size_sector=$[size_sector/sector] |
| 334 | seek_sector=$[seek/sector+seek_sector] |
| 335 | #nPayloadOffset=$[sector*(seek_sector+1)] |
| 336 | nPayloadOffset=$[sector*(seek_sector)] |
| 337 | echo ${file} ${seek_sector} ${size_sector} |
| 338 | dd if=${file} of=${bootloader} bs=${sector} seek=${seek_sector} conv=notrunc status=none |
| 339 | |
| 340 | echo ${arrPayload[$index]} > ${file_info_cfg_temp}.x |
| 341 | index=$((index+1)) |
| 342 | dd if=${file_info_cfg_temp}.x of=${file_info_cfg_temp} bs=1 count=4 &> /dev/null |
| 343 | rm -f ${file_info_cfg_temp}.x |
| 344 | printf "%02x %02x %02x %02x %02x %02x %02x %02x 00 00 00 00" $[(nPayloadOffset)&0xFF] $[((nPayloadOffset)>>8)&0xFF] $[((nPayloadOffset)>>16)&0xFF] $[((nPayloadOffset)>>24)&0xFF] \ |
| 345 | $[(nPayloadSize)&0xFF] $[((nPayloadSize)>>8)&0xFF] $[((nPayloadSize)>>16)&0xFF] $[((nPayloadSize)>>24)&0xFF] | xxd -r -ps >> ${file_info_cfg_temp} |
| 346 | dd if=${file_info_cfg_temp} of=${file_info_cfg} oflag=append conv=notrunc &> /dev/null |
| 347 | rm -f ${file_info_cfg_temp} |
| 348 | seek=$[(size+align_base-1)/align_base*align_base] |
| 349 | done |
| 350 | |
| 351 | openssl dgst -sha256 -binary ${file_info_cfg} > ${file_info_cfg}.sha256 |
| 352 | cat ${file_info_cfg} >> ${file_info_cfg}.sha256 |
| 353 | #cat ${file_info_cfg}.sha256 >> ${file_info_cfg} |
| 354 | rm -f ${file_info_cfg} |
| 355 | mv -f ${file_info_cfg}.sha256 ${file_info_cfg} |
| 356 | |
| 357 | dd if=${file_info_cfg} of=${bootloader} bs=512 seek=508 conv=notrunc status=none |
| 358 | |
| 359 | echo "Image SDCARD" |
| 360 | total_size=$[total_size+512] |
| 361 | rm -f ${sdcard_image} |
| 362 | dd if=/dev/zero of=${sdcard_image} bs=${total_size} count=1 status=none |
| 363 | dd if=${file_info_cfg} of=${sdcard_image} conv=notrunc status=none |
| 364 | dd if=${bootloader} of=${sdcard_image} bs=512 seek=1 conv=notrunc status=none |
| 365 | |
| 366 | rm -f ${file_info_cfg} |
| 367 | } |
| 368 | |
| 369 | function cleanup() { |
| 370 | cp ${FIP_BUILD_FOLDER}u-boot.bin* ${BUILD_FOLDER} |
| 371 | # cp bootblobs for PXP |
| 372 | cp ${FIP_BUILD_FOLDER}device-fip.bin ${BUILD_FOLDER} -f |
| 373 | cp ${FIP_BUILD_FOLDER}bb1st.bin ${BUILD_FOLDER} -f |
| 374 | cp ${FIP_BUILD_FOLDER}blob-bl* ${BUILD_FOLDER} -f |
| 375 | echo "output file are generated in ${BUILD_FOLDER} folder" |
| 376 | #rm -f ${BUILD_PATH}/test-* |
| 377 | #rm -rf ${BUILD_PAYLOAD} |
| 378 | rm -f ${BUILD_PATH}/bl*.enc ${BUILD_PATH}/bl2*.sig |
| 379 | } |
| 380 | |
| 381 | function encrypt_step() { |
| 382 | dbg "encrypt: $@" |
| 383 | |
| 384 | } |
| 385 | |
| 386 | function encrypt() { |
| 387 | #u-boot.bin generate |
| 388 | |
| 389 | return |
| 390 | } |
| 391 | |
| 392 | function build_fip() { |
| 393 | |
| 394 | # acs_tool process ddr timing and configurable parameters |
| 395 | #python ${FIP_FOLDER}/acs_tool.pyc ${BUILD_PATH}/${AML_BL2_NAME} ${BUILD_PATH}/bl2_acs.bin ${BUILD_PATH}/acs.bin 0 |
| 396 | |
| 397 | # fix bl2/bl2e/bl2x |
| 398 | if [ -d ${BUILD_PAYLOAD} ]; then |
| 399 | rm -rf ${BUILD_PAYLOAD} |
| 400 | fi |
| 401 | mkdir -p ${BUILD_PAYLOAD}/ |
| 402 | |
| 403 | # make boot blobs |
| 404 | mk_bl2ex ${BUILD_PATH} ${BUILD_PAYLOAD} ${DDRFW_TYPE} |
| 405 | |
| 406 | # make devicefip |
| 407 | mk_devfip ${BUILD_PATH} ${BUILD_PAYLOAD} |
| 408 | |
| 409 | |
| 410 | # build final bootloader |
| 411 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} |
| 412 | |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | function process_blx() { |
| 417 | |
| 418 | |
| 419 | # process loop |
| 420 | for loop in ${!BLX_NAME[@]}; do |
| 421 | if [ "NULL" != "${BLX_RAWBIN_NAME[$loop]}" ] && \ |
| 422 | [ -n "${BLX_RAWBIN_NAME[$loop]}" ] && \ |
| 423 | [ -f ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} ]; then |
| 424 | if [ ${BLX_NAME[$loop]} == "bl2" ]; then |
| 425 | option_args="--chip_acs ${BUILD_PATH}/chip_acs.bin --ddr_type ${DDRFW_TYPE}" |
| 426 | fi |
| 427 | ./${FIP_FOLDER}${CUR_SOC}/bin/sign-blx.sh --blxname ${BLX_NAME[$loop]} --input ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} --output ${BUILD_PATH} ${option_args} |
| 428 | fi |
| 429 | if [ "NULL" != "${BLX_BIN_SIZE[$loop]}" ] && \ |
| 430 | [ "NULL" != "${BLX_BIN_NAME[$loop]}" ] && \ |
| 431 | [ -n "${BLX_BIN_NAME[$loop]}" ] && \ |
| 432 | [ -f ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} ]; then |
| 433 | blx_size=`stat -c %s ${BUILD_PATH}/${BLX_BIN_NAME[$loop]}` |
| 434 | if [ $blx_size -ne ${BLX_BIN_SIZE[$loop]} ]; then |
| 435 | echo "Error: ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} size not match" |
| 436 | exit -1 |
| 437 | fi |
| 438 | fi |
| 439 | done |
| 440 | |
| 441 | if [ ! -f ${BUILD_PATH}/device_acs.bin ]; then |
| 442 | echo "dev acs params not exist !" |
| 443 | exit -1 |
| 444 | fi |
| 445 | |
| 446 | dev_acs_size=`stat -c %s ${BUILD_PATH}/device_acs.bin` |
| 447 | |
| 448 | if [ $dev_acs_size -gt ${DEV_ACS_BIN_SIZE} ]; then |
| 449 | echo "chip acs size exceed limit ${DEV_ACS_BIN_SIZE}, $dev_acs_size" |
| 450 | exit -1 |
| 451 | else |
| 452 | dd if=/dev/zero of=${BUILD_PATH}/dvinit-params.bin bs=${DEV_ACS_BIN_SIZE} count=1 |
| 453 | dd if=${BUILD_PATH}/device_acs.bin of=${BUILD_PATH}/dvinit-params.bin conv=notrunc |
| 454 | fi |
| 455 | |
| 456 | ./${FIP_FOLDER}${CUR_SOC}/bin/add-dvinit-params.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} |
| 457 | |
| 458 | # fix size for BL30 128KB |
| 459 | if [ -f ${BUILD_PATH}/bl30.bin ]; then |
| 460 | #blx_size=`du -b ${BUILD_PATH}/bl30.bin | awk '{print int(${BUILD_PATH}/bl30.bin)}'` |
| 461 | blx_size=`stat -c %s ${BUILD_PATH}/bl30.bin` |
| 462 | if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then |
| 463 | echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}" |
| 464 | exit -1 |
| 465 | fi |
| 466 | else |
| 467 | echo "Warning: local bl30" |
| 468 | #dd if=/dev/random of=${BUILD_PATH}/bl30.bin bs=4096 count=1 |
| 469 | dd if=bl30/bin/sc2/bl30.bin of=${BUILD_PATH}/bl30.bin |
| 470 | fi |
| 471 | dd if=/dev/zero of=${BUILD_PATH}/bl30-payload.bin bs=${BL30_BIN_SIZE} count=1 |
| 472 | dd if=${BUILD_PATH}/bl30.bin of=${BUILD_PATH}/bl30-payload.bin conv=notrunc |
| 473 | |
| 474 | # fix size for BL33 1024KB |
| 475 | if [ ! -f ${BUILD_PATH}/bl33.bin ]; then |
| 476 | echo "Error: ${BUILD_PATH}/bl33.bin does not exist... abort" |
| 477 | exit -1 |
| 478 | fi |
| 479 | #blx_size=`du -b ${BUILD_PATH}/bl33.bin | awk '{print int(${BUILD_PATH}/bl33.bin)}'` |
| 480 | blx_size=`stat -c %s ${BUILD_PATH}/bl33.bin` |
| 481 | if [ $blx_size -gt ${BL33_BIN_SIZE} ]; then |
| 482 | echo "Error: bl33 size exceed limit ${BL33_BIN_SIZE}" |
| 483 | exit -1 |
| 484 | fi |
| 485 | dd if=/dev/zero of=${BUILD_PATH}/bl33-payload.bin bs=${BL33_BIN_SIZE} count=1 |
| 486 | dd if=${BUILD_PATH}/bl33.bin of=${BUILD_PATH}/bl33-payload.bin conv=notrunc |
| 487 | |
| 488 | cp ./${FIP_FOLDER}${CUR_SOC}/templates/blob-bl40.bin.signed ${BUILD_PATH} |
| 489 | #./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} |
| 490 | |
| 491 | return |
| 492 | } |
| 493 | |
| 494 | function build_signed() { |
| 495 | |
| 496 | process_blx $@ |
| 497 | |
| 498 | ./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} |
| 499 | postfix=.signed |
| 500 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} |
| 501 | |
| 502 | if [ "y" == "${CONFIG_AML_SIGNED_UBOOT}" ]; then |
| 503 | if [ ! -d "${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys" ]; then |
| 504 | ./${FIP_FOLDER}${CUR_SOC}/bin/download-keys.sh device ${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys/ |
| 505 | fi |
| 506 | |
| 507 | fw_arb_cfg=${UBOOT_SRC_FOLDER}/${BOARD_DIR}/fw_arb.cfg |
| 508 | if [ -s "${fw_arb_cfg}" ]; then |
| 509 | source ${fw_arb_cfg} |
| 510 | export DEVICE_SCS_SEGID=${DEVICE_SCS_SEGID} |
| 511 | export DEVICE_VENDOR_SEGID=${DEVICE_VENDOR_SEGID} |
| 512 | export DEVICE_SCS_VERS=${DEVICE_SCS_VERS} |
| 513 | export DEVICE_TEE_VERS=${DEVICE_TEE_VERS} |
| 514 | export DEVICE_REE_VERS=${DEVICE_REE_VERS} |
| 515 | fi |
| 516 | export DEVICE_SCS_KEY_TOP=$(pwd)/${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys |
| 517 | export DEVICE_BUILD_PATH=$(pwd)/${BUILD_PATH} |
| 518 | if [ "y" == "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then |
| 519 | export DEVICE_ROOTRSA_INDEX=1 |
| 520 | elif [ -n "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then |
| 521 | export DEVICE_ROOTRSA_INDEX=${CONFIG_DEVICE_ROOTRSA_INDEX} |
| 522 | fi |
| 523 | make -C ./${FIP_FOLDER}${CUR_SOC} dv-sign |
| 524 | postfix=.device.signed |
| 525 | |
| 526 | # build final bootloader |
| 527 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} |
| 528 | fi |
| 529 | |
| 530 | return |
| 531 | } |
| 532 | |
| 533 | function copy_other_soc() { |
| 534 | cp ${BL33_BUILD_FOLDER}${BOARD_DIR}/firmware/acs.bin ${BUILD_PATH}/device_acs.bin -f |
| 535 | |
Honglin Zhang | 1f30916 | 2020-09-29 05:30:31 -0400 | [diff] [blame^] | 536 | if [ ! -f ${BUILD_PATH}/chip_acs.bin ]; then |
| 537 | cp ./${FIP_FOLDER}${CUR_SOC}/chip_acs.bin ${BUILD_PATH}/chip_acs.bin -f |
| 538 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 539 | # device acs params parse for ddr timing |
| 540 | #./${FIP_FOLDER}parse ${BUILD_PATH}/device_acs.bin |
| 541 | } |
| 542 | |
| 543 | function package() { |
| 544 | # BUILD_PATH without "/" |
| 545 | x=$((${#BUILD_PATH}-1)) |
| 546 | if [ "\\" == "${BUILD_PATH:$x:1}" ] || [ "/" == "${BUILD_PATH:$x:1}" ]; then |
| 547 | BUILD_PATH=${BUILD_PATH:0:$x} |
| 548 | fi |
| 549 | |
| 550 | init_vari $@ |
| 551 | # Enable Clear Image Packing for PXP |
| 552 | build_fip $@ |
| 553 | # Bypass Sign Process for PXP |
| 554 | #build_signed $@ |
| 555 | #copy_file |
| 556 | cleanup |
| 557 | echo "Bootloader build done!" |
| 558 | } |