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" |
dongqing.li | e538ef8 | 2022-08-24 15:11:31 +0800 | [diff] [blame] | 12 | AML_KEY_BLOB_NAME="aml-user-key.sig" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 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 |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 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 |
Bo Lv | a3a9ac0 | 2021-09-26 09:35:44 +0800 | [diff] [blame] | 53 | if [ -n "${CONFIG_FORMER_SIGN}" ]; then |
| 54 | CHIPSET_VARIANT="no_variant" |
| 55 | else |
| 56 | CHIPSET_VARIANT="general" |
| 57 | fi |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 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 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 65 | echo "------------------------------------------------------" |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 66 | echo "DDRFW_TYPE: ${DDRFW_TYPE} CHIPSET_NAME: ${CHIPSET_NAME} CHIPSET_VARIANT: ${CHIPSET_VARIANT} AMLOGIC_KEY_TYPE: ${AMLOGIC_KEY_TYPE}" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 67 | echo "------------------------------------------------------" |
| 68 | } |
| 69 | |
| 70 | function mk_bl2ex() { |
| 71 | output=$1 |
| 72 | payload=$2 |
| 73 | ddr_type=$3 |
| 74 | |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 75 | if [ ! -f ${output}/bl2.bin.sto ] || \ |
| 76 | [ ! -f ${output}/bl2.bin.usb ] || \ |
| 77 | [ ! -f ${output}/bl2e.bin.sto ] || \ |
| 78 | [ ! -f ${output}/bl2e.bin.usb ] || \ |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 79 | [ ! -f ${output}/bl2x.bin ]; then |
| 80 | echo "Error: ${output}/bl2/e/x.bin does not all exist... abort" |
| 81 | ls -la ${output} |
| 82 | exit -1 |
| 83 | fi |
| 84 | |
| 85 | echo "=================================================================" |
| 86 | echo "image packing with acpu-imagetool for bl2 bl2e bl2x" |
| 87 | |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 88 | dd if=/dev/zero of=${payload}/bl2.bin.sto bs=127904 count=1 |
| 89 | dd if=${output}/bl2.bin.sto of=${payload}/bl2.bin.sto conv=notrunc |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 90 | |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 91 | dd if=/dev/zero of=${payload}/bl2.bin.usb bs=127904 count=1 |
| 92 | dd if=${output}/bl2.bin.usb of=${payload}/bl2.bin.usb conv=notrunc |
| 93 | |
| 94 | dd if=/dev/zero of=${payload}/bl2e.bin.sto bs=65536 count=1 |
| 95 | dd if=${output}/bl2e.bin.sto of=${payload}/bl2e.bin.sto conv=notrunc |
| 96 | |
| 97 | dd if=/dev/zero of=${payload}/bl2e.bin.usb bs=65536 count=1 |
| 98 | dd if=${output}/bl2e.bin.usb of=${payload}/bl2e.bin.usb conv=notrunc |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 99 | |
| 100 | dd if=/dev/zero of=${payload}/bl2x.bin bs=65536 count=1 |
| 101 | dd if=${output}/bl2x.bin of=${payload}/bl2x.bin conv=notrunc |
| 102 | |
| 103 | |
| 104 | echo "====================================================" |
| 105 | echo "------ process for Synopsys ddr fw ------" |
| 106 | INPUT_DDRFW=./${FIP_FOLDER}${CUR_SOC} |
| 107 | |
| 108 | if [ "$ddr_type" == "ddr4" ]; then |
| 109 | dd if=${INPUT_DDRFW}/ddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 110 | dd if=${INPUT_DDRFW}/ddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 111 | elif [ "$ddr_type" == "ddr3" ]; then |
| 112 | dd if=${INPUT_DDRFW}/ddr3_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 113 | dd if=/dev/zero of=${payload}/ddrfw_2d.bin bs=36864 count=1 |
| 114 | elif [ "$ddr_type" == "lpddr4" ]; then |
| 115 | dd if=${INPUT_DDRFW}/lpddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 116 | dd if=${INPUT_DDRFW}/lpddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 117 | elif [ "$ddr_type" == "lpddr3" ]; then |
| 118 | dd if=${INPUT_DDRFW}/lpddr3_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 119 | dd if=/dev/zero of=${payload}/ddrfw_2d.bin bs=36864 count=1 |
| 120 | else |
| 121 | echo "un-recognized ddr_type: ${ddr_type}" |
| 122 | echo "---- use default ddr4 ----" |
| 123 | dd if=${INPUT_DDRFW}/ddr4_1d.fw of=${payload}/ddrfw_1d.bin skip=96 bs=1 count=36864 |
| 124 | dd if=${INPUT_DDRFW}/ddr4_2d.fw of=${payload}/ddrfw_2d.bin skip=96 bs=1 count=36864 |
| 125 | fi |
| 126 | |
| 127 | piei_size=`stat -c %s ${INPUT_DDRFW}/piei.fw` |
| 128 | if [ $piei_size -gt 12384 ]; then |
| 129 | dd if=${INPUT_DDRFW}/piei.fw of=${payload}/ddrfw_piei.bin skip=96 bs=1 count=12288 |
| 130 | else |
| 131 | dd if=/dev/zero of=${payload}/ddrfw_piei.bin bs=12288 count=1 |
| 132 | dd if=${INPUT_DDRFW}/piei.fw of=${payload}/ddrfw_piei.bin skip=96 bs=1 conv=notrunc |
| 133 | fi |
| 134 | |
| 135 | cat ${payload}/ddrfw_1d.bin ${payload}/ddrfw_2d.bin \ |
| 136 | ${payload}/ddrfw_piei.bin > ${payload}/ddrfw_data.bin |
| 137 | |
| 138 | if [ ! -f ${payload}/ddrfw_data.bin ]; then |
| 139 | echo "ddrfw_data payload does not exist in ${payload} !" |
| 140 | exit -1 |
| 141 | fi |
| 142 | ddrfw_data_size=`stat -c %s ${payload}/ddrfw_data.bin` |
| 143 | if [ $ddrfw_data_size -ne 86016 ]; then |
| 144 | echo "ddr_fwdata size is not equal to 84K, $ddrfw_data_size" |
| 145 | exit -1 |
| 146 | fi |
| 147 | |
| 148 | |
| 149 | echo "====================================================" |
| 150 | echo "------ process for device and chip params ------" |
| 151 | INPUT_PARAMS=${output} |
| 152 | |
| 153 | if [ ! -f ${INPUT_PARAMS}/device_acs.bin ]; then |
| 154 | echo "dev acs params not exist !" |
| 155 | exit -1 |
| 156 | fi |
| 157 | |
| 158 | if [ ! -f ${INPUT_PARAMS}/chip_acs.bin ]; then |
| 159 | echo "chip acs params not exist !" |
| 160 | exit -1 |
| 161 | fi |
| 162 | chip_acs_size=`stat -c %s ${INPUT_PARAMS}/chip_acs.bin` |
| 163 | dev_acs_size=`stat -c %s ${INPUT_PARAMS}/device_acs.bin` |
| 164 | |
| 165 | if [ $chip_acs_size -gt 4096 ]; then |
| 166 | echo "chip acs size exceed limit 4096, $chip_acs_size" |
| 167 | exit -1 |
| 168 | else |
| 169 | dd if=/dev/zero of=${payload}/chip_acs.bin bs=4096 count=1 |
| 170 | dd if=${INPUT_PARAMS}/chip_acs.bin of=${payload}/chip_acs.bin conv=notrunc |
| 171 | fi |
| 172 | |
| 173 | if [ $dev_acs_size -gt 28672 ]; then |
| 174 | echo "chip acs size exceed limit 28672, $dev_acs_size" |
| 175 | exit -1 |
| 176 | else |
| 177 | dd if=/dev/zero of=${payload}/device_acs.bin bs=28672 count=1 |
| 178 | dd if=${INPUT_PARAMS}/device_acs.bin of=${payload}/device_acs.bin conv=notrunc |
| 179 | fi |
| 180 | |
| 181 | ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-boot-blobs \ |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 182 | --infile-bl2-payload=${payload}/bl2.bin.sto \ |
| 183 | --infile-bl2e-payload=${payload}/bl2e.bin.sto \ |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 184 | --infile-bl2x-payload=${payload}/bl2x.bin \ |
| 185 | --infile-dvinit-params=${payload}/device_acs.bin \ |
| 186 | --infile-csinit-params=${payload}/chip_acs.bin \ |
| 187 | --infile-ddr-fwdata=${payload}/ddrfw_data.bin \ |
Huaihong Lei | a40d4ba | 2023-04-14 15:13:15 +0800 | [diff] [blame] | 188 | --scs-family=sc2 \ |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 189 | --outfile-bb1st=${output}/bb1st.sto.bin \ |
| 190 | --outfile-blob-bl2e=${output}/blob-bl2e.sto.bin \ |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 191 | --outfile-blob-bl2x=${output}/blob-bl2x.bin |
| 192 | |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 193 | ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-boot-blobs \ |
| 194 | --infile-bl2-payload=${payload}/bl2.bin.usb \ |
| 195 | --infile-bl2e-payload=${payload}/bl2e.bin.usb \ |
| 196 | --infile-bl2x-payload=${payload}/bl2x.bin \ |
| 197 | --infile-dvinit-params=${payload}/device_acs.bin \ |
| 198 | --infile-csinit-params=${payload}/chip_acs.bin \ |
| 199 | --infile-ddr-fwdata=${payload}/ddrfw_data.bin \ |
Huaihong Lei | a40d4ba | 2023-04-14 15:13:15 +0800 | [diff] [blame] | 200 | --scs-family=sc2 \ |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 201 | --outfile-bb1st=${output}/bb1st.usb.bin \ |
| 202 | --outfile-blob-bl2e=${output}/blob-bl2e.usb.bin \ |
| 203 | --outfile-blob-bl2x=${output}/blob-bl2x.bin |
| 204 | |
| 205 | if [ ! -f ${output}/bb1st.sto.bin ] || \ |
| 206 | [ ! -f ${output}/bb1st.usb.bin ] || \ |
| 207 | [ ! -f ${output}/blob-bl2e.sto.bin ] || \ |
| 208 | [ ! -f ${output}/blob-bl2e.usb.bin ] || \ |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 209 | [ ! -f ${output}/blob-bl2x.bin ]; then |
| 210 | echo "Error: ${output}/ bootblobs do not all exist... abort" |
| 211 | ls -la ${output}/ |
| 212 | exit -1 |
| 213 | fi |
dongqing.li | e538ef8 | 2022-08-24 15:11:31 +0800 | [diff] [blame] | 214 | echo "done to generate bb1st.bin folder" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | function mk_devfip() { |
| 218 | output=$1 |
| 219 | payload=$2 |
| 220 | |
| 221 | # fix size for BL30 128KB --> 64KB |
| 222 | if [ -f ${output}/bl30.bin ]; then |
| 223 | blx_size=`stat -c %s ${output}/bl30.bin` |
| 224 | if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then |
| 225 | echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}" |
| 226 | exit -1 |
| 227 | fi |
| 228 | else |
| 229 | echo "Warning: null bl30" |
| 230 | dd if=/dev/random of=${output}/bl30.bin bs=4096 count=1 |
| 231 | #dd if=bl30/bin/sc2/bl30.bin of=${output}/bl30.bin |
| 232 | fi |
| 233 | dd if=/dev/zero of=${payload}/bl30.bin bs=${BL30_BIN_SIZE} count=1 |
| 234 | dd if=${output}/bl30.bin of=${payload}/bl30.bin conv=notrunc |
| 235 | |
| 236 | # fix size for BL40 96KB |
| 237 | if [ -f ${output}/bl40.bin ]; then |
dongqing.li | e538ef8 | 2022-08-24 15:11:31 +0800 | [diff] [blame] | 238 | blx_size=`stat -c %s ${output}/bl40.bin` |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 239 | if [ $blx_size -gt 98304 ]; then |
| 240 | echo "Error: bl40 size exceed limit 98304" |
| 241 | exit -1 |
| 242 | fi |
| 243 | else |
| 244 | echo "Warning: null bl40" |
| 245 | #dd if=/dev/random of=${output}/bl40.bin bs=4096 count=1 |
| 246 | dd if=/dev/zero of=${output}/bl40.bin bs=4096 count=1 |
| 247 | fi |
| 248 | dd if=/dev/zero of=${payload}/bl40.bin bs=98304 count=1 |
| 249 | dd if=${output}/bl40.bin of=${payload}/bl40.bin conv=notrunc |
| 250 | |
| 251 | |
| 252 | # fix size for BL31 256KB |
| 253 | if [ ! -f ${output}/bl31.bin ]; then |
| 254 | echo "Error: ${output}/bl31.bin does not exist... abort" |
| 255 | exit -1 |
| 256 | fi |
| 257 | blx_size=`stat -c %s ${output}/bl31.bin` |
| 258 | echo "BL31 size: ${blx_size}" |
| 259 | if [ $blx_size -gt 262144 ]; then |
| 260 | echo "Error: bl31 size exceed limit 262144" |
| 261 | exit -1 |
| 262 | fi |
| 263 | dd if=/dev/zero of=${payload}/bl31.bin bs=262144 count=1 |
| 264 | dd if=${output}/bl31.bin of=${payload}/bl31.bin conv=notrunc |
| 265 | |
| 266 | |
| 267 | # fix size for BL32 512KB |
| 268 | if [ -f ${output}/bl32.bin ]; then |
| 269 | blx_size=`stat -c %s ${output}/bl32.bin` |
| 270 | if [ $blx_size -gt 524288 ]; then |
| 271 | echo "Error: bl32 size exceed limit 524288" |
| 272 | exit -1 |
| 273 | fi |
| 274 | else |
| 275 | echo "Warning: null bl32" |
| 276 | dd if=/dev/random of=${output}/bl32.bin bs=4096 count=1 |
| 277 | #dd if=bl32/bin/sc2/bl32.bin of=${output}/bl32.bin |
| 278 | fi |
| 279 | dd if=/dev/zero of=${payload}/bl32.bin bs=524288 count=1 |
| 280 | dd if=${output}/bl32.bin of=${payload}/bl32.bin conv=notrunc |
| 281 | |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 282 | if [ "y" == "${CONFIG_AML_BL33_COMPRESS_ENABLE}" ]; then |
| 283 | mv -f ${output}/bl33.bin ${output}/bl33.bin.org |
| 284 | encrypt_step --bl3sig --input ${output}/bl33.bin.org --output ${output}/bl33.bin.org.lz4 --compress lz4 --level v3 --type bl33 |
| 285 | #get LZ4 format bl33 image from bl33.bin.enc with offset 0x720 |
| 286 | dd if=${output}/bl33.bin.org.lz4 of=${output}/bl33.bin bs=1 skip=1824 >& /dev/null |
| 287 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 288 | # fix size for BL33 1024KB + 512 KB |
| 289 | if [ ! -f ${output}/bl33.bin ]; then |
| 290 | echo "Error: ${output}/bl33.bin does not exist... abort" |
| 291 | exit -1 |
| 292 | fi |
| 293 | blx_size=`stat -c %s ${output}/bl33.bin` |
| 294 | if [ $blx_size -gt 1572864 ]; then |
| 295 | echo "Error: bl33 size exceed limit 0x180000" |
| 296 | exit -1 |
| 297 | fi |
| 298 | dd if=/dev/zero of=${payload}/bl33.bin bs=1572864 count=1 |
| 299 | dd if=${output}/bl33.bin of=${payload}/bl33.bin conv=notrunc |
| 300 | |
| 301 | |
| 302 | ./${FIP_FOLDER}${CUR_SOC}/binary-tool/acpu-imagetool create-device-fip \ |
| 303 | --infile-bl30-payload=${payload}/bl30.bin \ |
| 304 | --infile-bl40-payload=${payload}/bl40.bin \ |
| 305 | --infile-bl31-payload=${payload}/bl31.bin \ |
| 306 | --infile-bl32-payload=${payload}/bl32.bin \ |
| 307 | --infile-bl33-payload=${payload}/bl33.bin \ |
| 308 | --outfile-device-fip=${output}/device-fip.bin |
| 309 | |
| 310 | if [ ! -f ${output}/device-fip.bin ]; then |
| 311 | echo "Error: ${output}/device-fip.bin does not exist... abort" |
| 312 | exit -1 |
| 313 | fi |
dongqing.li | e538ef8 | 2022-08-24 15:11:31 +0800 | [diff] [blame] | 314 | echo "done to generate device-fip.bin" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Tao Zeng | c3c70b5 | 2021-01-06 17:29:40 +0800 | [diff] [blame] | 317 | # due to size limit of BL2, only one type of DDR firmware is |
| 318 | # built into bl2 code package. For support other ddr types, we |
| 319 | # need bind them to ddr_fip.bin and let bl2 fw to try it. |
| 320 | # |
| 321 | # Note: No piei fw in following arry because it have build into |
| 322 | # bl2 |
| 323 | # Total ddr-fip.bin size: 256KB, 4KB for header, 252(36*7)KB for fw |
| 324 | # so max 7 ddr fw support |
| 325 | declare -a DDR_FW_NAME=("aml_ddr.fw" \ |
| 326 | "ddr4_1d.fw" \ |
| 327 | "ddr4_2d.fw" \ |
| 328 | "lpddr4_1d.fw" \ |
| 329 | "lpddr4_2d.fw") |
| 330 | declare -a DDR_FW_MAGIC=("AML0" \ |
| 331 | "d444" \ |
| 332 | "d422" \ |
| 333 | "dl44" \ |
| 334 | "dl42") |
| 335 | function mk_ddr_fip() |
| 336 | { |
| 337 | local outpath=$1 |
| 338 | local out_hdr=$1/ddr-hdr.bin |
| 339 | local out_fip=$1/ddr-fip.bin |
| 340 | local offset=4096 # start offset inside ddr-fip.bin |
| 341 | local fw_size= |
| 342 | local rem_val= |
| 343 | local fw_cnt=0 |
| 344 | local hdr_size=64 |
| 345 | local input_dir=./${FIP_FOLDER}${CUR_SOC} |
| 346 | |
| 347 | # first: make a empty ddr-fip.bin and ddr-fip-hdr.bin |
| 348 | rm -rf ${out_hdr} |
| 349 | rm -rf ${out_fip} |
| 350 | touch ${out_fip} |
| 351 | touch ${out_hdr} |
| 352 | |
| 353 | # count firmware number we need package |
| 354 | for i in ${!DDR_FW_NAME[@]}; do |
| 355 | if [[ "${DDR_FW_NAME[${i}]}" == "${DDRFW_TYPE}"* ]]; then |
| 356 | echo "==== skip ${DDR_FW_NAME[${i}]} ====" |
| 357 | continue |
| 358 | fi |
| 359 | fw_cnt=`expr ${fw_cnt} + 1` |
| 360 | done |
| 361 | |
| 362 | # build header for ddr-hdr.bin |
| 363 | # dwMagic |
| 364 | printf "%s" "@DFM" >> ${out_hdr} |
| 365 | # nCount of firmware |
| 366 | printf "%02x%02x" $[(fw_cnt) & 0xff] $[((fw_cnt) >> 8) & 0xff] | xxd -r -ps >> ${out_hdr} |
| 367 | # padding nVersion/szReserved to 0 |
| 368 | printf "\0\0\0\0\0\0\0\0\0\0" >> ${out_hdr} |
| 369 | |
| 370 | # build ddr-fip.bin and ddr-hdr.bin |
| 371 | for i in ${!DDR_FW_NAME[@]}; do |
| 372 | if [[ "${DDR_FW_NAME[${i}]}" == "${DDRFW_TYPE}"* ]]; then |
| 373 | continue |
| 374 | fi |
| 375 | |
| 376 | # ============= package ddr-fip.bin ============= |
| 377 | # get size of fw and align up to 4KB for |
| 378 | # some strage device such as nand |
| 379 | fw_size=`stat -c %s ${input_dir}/${DDR_FW_NAME[${i}]}` |
| 380 | fw_size=`expr ${fw_size} + 4095` |
| 381 | rem_val=`expr ${fw_size} % 4096` |
| 382 | fw_size=`expr ${fw_size} - ${rem_val}` |
| 383 | |
| 384 | # 1. make sure we only copy 36KB, 32KB IMEM + 4KB DMEM |
| 385 | # 2. make a empty bin with fw_size |
| 386 | # 3. copy from fw to empty bin |
dongqing.li | e538ef8 | 2022-08-24 15:11:31 +0800 | [diff] [blame] | 387 | # 4. padding this bin to final output |
Tao Zeng | c3c70b5 | 2021-01-06 17:29:40 +0800 | [diff] [blame] | 388 | if [ ${fw_size} -gt "36864" ]; then |
| 389 | fw_size="36864" |
| 390 | fi |
| 391 | dd if=/dev/zero of=${outpath}/_tmp.bin bs=1 count=${fw_size} &> /dev/null |
| 392 | dd if=${input_dir}/${DDR_FW_NAME[${i}]} of=${outpath}/_tmp.bin skip=96 bs=1 count=${fw_size} conv=notrunc &> /dev/null |
| 393 | cat ${outpath}/_tmp.bin >> ${out_fip} |
| 394 | |
| 395 | # ============= make ddr-hdr.bin ============= |
| 396 | # dwMagic |
| 397 | printf "%s" "@DFM" >> ${out_hdr} |
| 398 | # nVersion, fix to 0 |
| 399 | printf "\0\0" >> ${out_hdr} |
| 400 | # nSize, fix to 64 bytes |
| 401 | printf "%02x%02x" $[(hdr_size) & 0xff] $[((hdr_size) >> 8) & 0xff] | xxd -r -ps >> ${out_hdr} |
| 402 | # nIMGOffset |
| 403 | printf "%02x%02x%02x%02x" $[(offset) & 0xff] $[((offset) >> 8) & 0xff] \ |
| 404 | $[((offset) >> 16) & 0xff] $[((offset) >> 24) & 0xff] | xxd -r -ps >> ${out_hdr} |
| 405 | # nIMGSize |
| 406 | printf "%02x%02x%02x%02x" $[(fw_size) & 0xff] $[((fw_size) >> 8) & 0xff] \ |
| 407 | $[((fw_size) >> 16) & 0xff] $[((fw_size) >> 24) & 0xff] | xxd -r -ps >> ${out_hdr} |
| 408 | # fw_ver, fix to 0 |
| 409 | printf "\0\0\0\0" >> ${out_hdr} |
| 410 | # fw_magic |
| 411 | printf "%s" ${DDR_FW_MAGIC[${i}]} >> ${out_hdr} |
| 412 | # szRerved2 |
| 413 | printf "\0\0\0\0\0\0\0\0" >> ${out_hdr} |
| 414 | # szIMGSHA2 |
| 415 | openssl dgst -sha256 -binary ${outpath}/_tmp.bin >> ${out_hdr} |
| 416 | |
| 417 | offset=`expr ${offset} + ${fw_size}` |
| 418 | done; |
| 419 | rm ${outpath}/_tmp.bin |
| 420 | |
| 421 | # generate ddr-fip.bin |
| 422 | fw_size=`stat -c "%s" ${out_fip}` |
| 423 | if [ ${fw_size} -gt "258048" ]; then |
| 424 | echo "==== size of ${out_fip}:${fw_size}, over limit ====" |
| 425 | exit -1 |
| 426 | else |
| 427 | dd if=/dev/zero of=${out_fip}.tmp bs=1024 count=252 status=none |
| 428 | dd if=${out_fip} of=${out_fip}.tmp bs=1 count=${fw_size} conv=notrunc |
| 429 | fi |
| 430 | |
| 431 | # bind to final ddr-fip.bin |
| 432 | fw_size=`stat -c "%s" ${out_hdr}` |
| 433 | if [ ${fw_size} -gt "4096" ]; then |
| 434 | echo "==== size of ${ot_hdr}:${fw_size}, over limit ====" |
| 435 | exit -1 |
| 436 | else |
| 437 | dd if=/dev/zero of=${out_hdr}.tmp bs=1 count=4096 status=none |
| 438 | dd if=${out_hdr} of=${out_hdr}.tmp bs=1 count=${fw_size} conv=notrunc |
| 439 | fi |
| 440 | cat ${out_hdr}.tmp > ${out_fip} |
| 441 | cat ${out_fip}.tmp >> ${out_fip} |
| 442 | rm -rf ${out_fip}.tmp |
| 443 | rm -rf ${out_hdr}.tmp |
| 444 | } |
| 445 | |
| 446 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 447 | function mk_uboot() { |
| 448 | output_images=$1 |
| 449 | input_payloads=$2 |
| 450 | postfix=$3 |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 451 | storage_type_suffix=$4 |
| 452 | chipset_variant_suffix=$5 |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 453 | |
| 454 | device_fip="${input_payloads}/device-fip.bin${postfix}" |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 455 | bb1st="${input_payloads}/bb1st${storage_type_suffix}${chipset_variant_suffix}.bin${postfix}" |
| 456 | bl2e="${input_payloads}/blob-bl2e${storage_type_suffix}${chipset_variant_suffix}.bin${postfix}" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 457 | bl2x="${input_payloads}/blob-bl2x.bin${postfix}" |
| 458 | |
| 459 | if [ ! -f ${device_fip} ] || \ |
| 460 | [ ! -f ${bb1st} ] || \ |
| 461 | [ ! -f ${bl2e} ] || \ |
| 462 | [ ! -f ${bl2x} ]; then |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 463 | echo fip:${device_fip} |
| 464 | echo bb1st:${bb1st} |
| 465 | echo bl2e:${bl2e} |
| 466 | echo bl2x:${bl2x} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 467 | echo "Error: ${input_payloads}/ bootblob does not all exist... abort" |
| 468 | ls -la ${input_payloads}/ |
| 469 | exit -1 |
| 470 | fi |
| 471 | |
| 472 | file_info_cfg="${output_images}/aml-payload.cfg" |
| 473 | file_info_cfg_temp=${temp_cfg}.temp |
| 474 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 475 | bootloader="${output_images}/u-boot.bin${storage_type_suffix}${postfix}" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 476 | sdcard_image="${output_images}/u-boot.bin.sd.bin${postfix}" |
| 477 | |
| 478 | #fake ddr fip 256KB |
| 479 | ddr_fip="${input_payloads}/ddr-fip.bin" |
| 480 | if [ ! -f ${ddr_fip} ]; then |
Tao Zeng | c3c70b5 | 2021-01-06 17:29:40 +0800 | [diff] [blame] | 481 | echo "==== use empty ddr-fip ====" |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 482 | dd if=/dev/zero of=${ddr_fip} bs=1024 count=256 status=none |
| 483 | fi |
| 484 | |
| 485 | #cat those together with 4K upper aligned for sdcard |
| 486 | align_base=4096 |
| 487 | total_size=0 |
| 488 | for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do |
| 489 | size=`stat -c "%s" ${file}` |
| 490 | upper=$[(size+align_base-1)/align_base*align_base] |
| 491 | total_size=$[total_size+upper] |
| 492 | echo ${file} ${size} ${upper} |
| 493 | done |
| 494 | |
| 495 | echo ${total_size} |
| 496 | rm -f ${bootloader} |
| 497 | dd if=/dev/zero of=${bootloader} bs=${total_size} count=1 status=none |
| 498 | |
| 499 | sector=512 |
| 500 | seek=0 |
| 501 | seek_sector=0 |
| 502 | dateStamp=SC2-`date +%Y%m%d%H%M%S` |
| 503 | |
| 504 | echo @AMLBOOT > ${file_info_cfg_temp} |
| 505 | dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=8 conv=notrunc &> /dev/null |
| 506 | nItemNum=5 |
| 507 | nSizeHDR=$[64+nItemNum*16] |
| 508 | printf "01 %02x %02x %02x 00 00 00 00" $[(nItemNum)&0xFF] $[(nSizeHDR)&0xFF] $[((nSizeHDR)>>8)&0xFF] \ |
| 509 | | xxd -r -ps > ${file_info_cfg_temp} |
| 510 | cat ${file_info_cfg_temp} >> ${file_info_cfg} |
| 511 | |
| 512 | echo ${dateStamp} > ${file_info_cfg_temp} |
| 513 | dd if=${file_info_cfg_temp} of=${file_info_cfg} bs=1 count=16 oflag=append conv=notrunc &> /dev/null |
| 514 | |
| 515 | index=0 |
| 516 | arrPayload=("BBST" "BL2E" "BL2X" "DDRF" "DEVF"); |
| 517 | nPayloadOffset=0 |
| 518 | nPayloadSize=0 |
| 519 | for file in ${bb1st} ${bl2e} ${bl2x} ${ddr_fip} ${device_fip}; do |
| 520 | size=`stat -c "%s" ${file}` |
| 521 | size_sector=$[(size+align_base-1)/align_base*align_base] |
| 522 | nPayloadSize=$[size_sector] |
| 523 | size_sector=$[size_sector/sector] |
| 524 | seek_sector=$[seek/sector+seek_sector] |
| 525 | #nPayloadOffset=$[sector*(seek_sector+1)] |
| 526 | nPayloadOffset=$[sector*(seek_sector)] |
| 527 | echo ${file} ${seek_sector} ${size_sector} |
| 528 | dd if=${file} of=${bootloader} bs=${sector} seek=${seek_sector} conv=notrunc status=none |
| 529 | |
| 530 | echo ${arrPayload[$index]} > ${file_info_cfg_temp}.x |
| 531 | index=$((index+1)) |
| 532 | dd if=${file_info_cfg_temp}.x of=${file_info_cfg_temp} bs=1 count=4 &> /dev/null |
| 533 | rm -f ${file_info_cfg_temp}.x |
| 534 | printf "%02x %02x %02x %02x %02x %02x %02x %02x 00 00 00 00" $[(nPayloadOffset)&0xFF] $[((nPayloadOffset)>>8)&0xFF] $[((nPayloadOffset)>>16)&0xFF] $[((nPayloadOffset)>>24)&0xFF] \ |
| 535 | $[(nPayloadSize)&0xFF] $[((nPayloadSize)>>8)&0xFF] $[((nPayloadSize)>>16)&0xFF] $[((nPayloadSize)>>24)&0xFF] | xxd -r -ps >> ${file_info_cfg_temp} |
| 536 | dd if=${file_info_cfg_temp} of=${file_info_cfg} oflag=append conv=notrunc &> /dev/null |
| 537 | rm -f ${file_info_cfg_temp} |
| 538 | seek=$[(size+align_base-1)/align_base*align_base] |
| 539 | done |
| 540 | |
| 541 | openssl dgst -sha256 -binary ${file_info_cfg} > ${file_info_cfg}.sha256 |
| 542 | cat ${file_info_cfg} >> ${file_info_cfg}.sha256 |
| 543 | #cat ${file_info_cfg}.sha256 >> ${file_info_cfg} |
| 544 | rm -f ${file_info_cfg} |
| 545 | mv -f ${file_info_cfg}.sha256 ${file_info_cfg} |
| 546 | |
| 547 | dd if=${file_info_cfg} of=${bootloader} bs=512 seek=508 conv=notrunc status=none |
| 548 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 549 | if [ ${storage_type_suffix} == ".sto" ]; then |
| 550 | echo "Image SDCARD" |
| 551 | total_size=$[total_size+512] |
| 552 | rm -f ${sdcard_image} |
| 553 | dd if=/dev/zero of=${sdcard_image} bs=${total_size} count=1 status=none |
| 554 | dd if=${file_info_cfg} of=${sdcard_image} conv=notrunc status=none |
| 555 | dd if=${bootloader} of=${sdcard_image} bs=512 seek=1 conv=notrunc status=none |
| 556 | |
| 557 | mv ${bootloader} ${output_images}/u-boot.bin${postfix} |
| 558 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 559 | |
| 560 | rm -f ${file_info_cfg} |
| 561 | } |
| 562 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 563 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 564 | function cleanup() { |
| 565 | cp ${FIP_BUILD_FOLDER}u-boot.bin* ${BUILD_FOLDER} |
| 566 | # cp bootblobs for PXP |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 567 | #cp ${FIP_BUILD_FOLDER}device-fip.bin ${BUILD_FOLDER} -f |
| 568 | #cp ${FIP_BUILD_FOLDER}bb1st.bin ${BUILD_FOLDER} -f |
| 569 | #cp ${FIP_BUILD_FOLDER}blob-bl* ${BUILD_FOLDER} -f |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 570 | echo "output file are generated in ${BUILD_FOLDER} folder" |
| 571 | #rm -f ${BUILD_PATH}/test-* |
| 572 | #rm -rf ${BUILD_PAYLOAD} |
| 573 | rm -f ${BUILD_PATH}/bl*.enc ${BUILD_PATH}/bl2*.sig |
| 574 | } |
| 575 | |
| 576 | function encrypt_step() { |
| 577 | dbg "encrypt: $@" |
benlong.zhou | fc5f353 | 2021-04-29 10:43:28 +0800 | [diff] [blame] | 578 | local ret=0 |
| 579 | ./${FIP_FOLDER}${CUR_SOC}/aml_encrypt_${CUR_SOC} $@ |
| 580 | ret=$? |
| 581 | if [ 0 != $ret ]; then |
| 582 | echo "Err! aml_encrypt_${CUR_SOC} return $ret" |
| 583 | exit $ret |
| 584 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | function encrypt() { |
| 588 | #u-boot.bin generate |
| 589 | |
| 590 | return |
| 591 | } |
| 592 | |
| 593 | function build_fip() { |
| 594 | |
| 595 | # acs_tool process ddr timing and configurable parameters |
| 596 | #python ${FIP_FOLDER}/acs_tool.pyc ${BUILD_PATH}/${AML_BL2_NAME} ${BUILD_PATH}/bl2_acs.bin ${BUILD_PATH}/acs.bin 0 |
| 597 | |
| 598 | # fix bl2/bl2e/bl2x |
| 599 | if [ -d ${BUILD_PAYLOAD} ]; then |
| 600 | rm -rf ${BUILD_PAYLOAD} |
| 601 | fi |
| 602 | mkdir -p ${BUILD_PAYLOAD}/ |
| 603 | |
| 604 | # make boot blobs |
| 605 | mk_bl2ex ${BUILD_PATH} ${BUILD_PAYLOAD} ${DDRFW_TYPE} |
| 606 | |
| 607 | # make devicefip |
| 608 | mk_devfip ${BUILD_PATH} ${BUILD_PAYLOAD} |
| 609 | |
| 610 | |
| 611 | # build final bootloader |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 612 | #mk_uboot ${BUILD_PATH} ${BUILD_PATH} |
| 613 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} "" .sto ${CHIPSET_VARIANT_SUFFIX} |
| 614 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} "" .usb ${CHIPSET_VARIANT_SUFFIX} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 615 | |
| 616 | return |
| 617 | } |
| 618 | |
| 619 | function process_blx() { |
| 620 | |
| 621 | |
| 622 | # process loop |
| 623 | for loop in ${!BLX_NAME[@]}; do |
| 624 | if [ "NULL" != "${BLX_RAWBIN_NAME[$loop]}" ] && \ |
| 625 | [ -n "${BLX_RAWBIN_NAME[$loop]}" ] && \ |
| 626 | [ -f ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} ]; then |
Bo Lv | a3a9ac0 | 2021-09-26 09:35:44 +0800 | [diff] [blame] | 627 | if [ -n "${CONFIG_FORMER_SIGN}" ]; then |
| 628 | ./${FIP_FOLDER}${CUR_SOC}/bin/sign-blx.sh --blxname ${BLX_NAME[$loop]} --input ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \ |
| 629 | --output ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chipset_name ${CHIPSET_NAME} --chipset_variant ${CHIPSET_VARIANT} \ |
| 630 | --key_type ${AMLOGIC_KEY_TYPE} --soc ${CUR_SOC} --chip_acs ${BUILD_PATH}/chip_acs.bin --ddr_type ${DDRFW_TYPE} |
| 631 | else |
| 632 | if [ -n "${CONFIG_JENKINS_SIGN}" ]; then |
| 633 | /usr/bin/python3 ./sign.py --type ${BLX_NAME[$loop]} --in ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \ |
| 634 | --out ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chip ${CHIPSET_NAME} --chipVariant ${CHIPSET_VARIANT} \ |
Bo Lv | b37b900 | 2021-11-24 19:47:13 +0800 | [diff] [blame] | 635 | --keyType ${AMLOGIC_KEY_TYPE} --chipAcsFile ${BUILD_PATH}/chip_acs.bin --ddrType ${DDRFW_TYPE} |
Bo Lv | a3a9ac0 | 2021-09-26 09:35:44 +0800 | [diff] [blame] | 636 | else |
| 637 | /usr/bin/python3 ./${FIP_FOLDER}/jenkins_sign.py --type ${BLX_NAME[$loop]} --in ${BUILD_PATH}/${BLX_RAWBIN_NAME[$loop]} \ |
| 638 | --out ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} --chip ${CHIPSET_NAME} --chipVariant ${CHIPSET_VARIANT} --keyType ${AMLOGIC_KEY_TYPE} \ |
| 639 | --chipAcsFile ${BUILD_PATH}/chip_acs.bin --ddrType ${DDRFW_TYPE} |
| 640 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 641 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 642 | fi |
| 643 | if [ "NULL" != "${BLX_BIN_SIZE[$loop]}" ] && \ |
| 644 | [ "NULL" != "${BLX_BIN_NAME[$loop]}" ] && \ |
| 645 | [ -n "${BLX_BIN_NAME[$loop]}" ] && \ |
| 646 | [ -f ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} ]; then |
| 647 | blx_size=`stat -c %s ${BUILD_PATH}/${BLX_BIN_NAME[$loop]}` |
| 648 | if [ $blx_size -ne ${BLX_BIN_SIZE[$loop]} ]; then |
| 649 | echo "Error: ${BUILD_PATH}/${BLX_BIN_NAME[$loop]} size not match" |
| 650 | exit -1 |
| 651 | fi |
| 652 | fi |
| 653 | done |
| 654 | |
| 655 | if [ ! -f ${BUILD_PATH}/device_acs.bin ]; then |
| 656 | echo "dev acs params not exist !" |
| 657 | exit -1 |
| 658 | fi |
| 659 | |
| 660 | dev_acs_size=`stat -c %s ${BUILD_PATH}/device_acs.bin` |
| 661 | |
| 662 | if [ $dev_acs_size -gt ${DEV_ACS_BIN_SIZE} ]; then |
| 663 | echo "chip acs size exceed limit ${DEV_ACS_BIN_SIZE}, $dev_acs_size" |
| 664 | exit -1 |
| 665 | else |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 666 | dd if=/dev/zero of=${BUILD_PATH}/dvinit-params.bin bs=${DEV_ACS_BIN_SIZE} count=1 &> /dev/null |
| 667 | dd if=${BUILD_PATH}/device_acs.bin of=${BUILD_PATH}/dvinit-params.bin conv=notrunc &> /dev/null |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 668 | fi |
| 669 | |
Huaihong Lei | a40d4ba | 2023-04-14 15:13:15 +0800 | [diff] [blame] | 670 | ./${FIP_FOLDER}${CUR_SOC}/bin/add-dvinit-params.sh ${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/dvinit-params.bin ${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${CUR_SOC} |
| 671 | ./${FIP_FOLDER}${CUR_SOC}/bin/add-dvinit-params.sh ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/dvinit-params.bin ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed ${CUR_SOC} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 672 | |
| 673 | # fix size for BL30 128KB |
| 674 | if [ -f ${BUILD_PATH}/bl30.bin ]; then |
| 675 | #blx_size=`du -b ${BUILD_PATH}/bl30.bin | awk '{print int(${BUILD_PATH}/bl30.bin)}'` |
| 676 | blx_size=`stat -c %s ${BUILD_PATH}/bl30.bin` |
| 677 | if [ $blx_size -gt ${BL30_BIN_SIZE} ]; then |
| 678 | echo "Error: bl30 size exceed limit ${BL30_BIN_SIZE}" |
| 679 | exit -1 |
| 680 | fi |
| 681 | else |
| 682 | echo "Warning: local bl30" |
| 683 | #dd if=/dev/random of=${BUILD_PATH}/bl30.bin bs=4096 count=1 |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 684 | dd if=bl30/bin/sc2/bl30.bin of=${BUILD_PATH}/bl30.bin &> /dev/null |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 685 | fi |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 686 | dd if=/dev/zero of=${BUILD_PATH}/bl30-payload.bin bs=${BL30_BIN_SIZE} count=1 &> /dev/null |
| 687 | dd if=${BUILD_PATH}/bl30.bin of=${BUILD_PATH}/bl30-payload.bin conv=notrunc &> /dev/null |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 688 | |
benlong.zhou | fc5f353 | 2021-04-29 10:43:28 +0800 | [diff] [blame] | 689 | if [ "y" == "${CONFIG_AML_BL33_COMPRESS_ENABLE}" ]; then |
| 690 | mv -f ${BUILD_PATH}/bl33.bin ${BUILD_PATH}/bl33.bin.org |
| 691 | encrypt_step --bl3sig --input ${BUILD_PATH}/bl33.bin.org --output ${BUILD_PATH}/bl33.bin.org.lz4 --compress lz4 --level v3 --type bl33 |
| 692 | #get LZ4 format bl33 image from bl33.bin.enc with offset 0x720 |
| 693 | dd if=${BUILD_PATH}/bl33.bin.org.lz4 of=${BUILD_PATH}/bl33.bin bs=1 skip=1824 >& /dev/null |
| 694 | fi |
| 695 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 696 | # fix size for BL33 1024KB |
| 697 | if [ ! -f ${BUILD_PATH}/bl33.bin ]; then |
| 698 | echo "Error: ${BUILD_PATH}/bl33.bin does not exist... abort" |
| 699 | exit -1 |
| 700 | fi |
| 701 | #blx_size=`du -b ${BUILD_PATH}/bl33.bin | awk '{print int(${BUILD_PATH}/bl33.bin)}'` |
| 702 | blx_size=`stat -c %s ${BUILD_PATH}/bl33.bin` |
| 703 | if [ $blx_size -gt ${BL33_BIN_SIZE} ]; then |
| 704 | echo "Error: bl33 size exceed limit ${BL33_BIN_SIZE}" |
| 705 | exit -1 |
| 706 | fi |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 707 | dd if=/dev/zero of=${BUILD_PATH}/bl33-payload.bin bs=${BL33_BIN_SIZE} count=1 &> /dev/null |
| 708 | dd if=${BUILD_PATH}/bl33.bin of=${BUILD_PATH}/bl33-payload.bin conv=notrunc &> /dev/null |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 709 | |
benlong.zhou | fc5f353 | 2021-04-29 10:43:28 +0800 | [diff] [blame] | 710 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 711 | if [ ! -f ${BUILD_PATH}/blob-bl40.bin.signed ]; then |
| 712 | echo "Warning: local bl40" |
| 713 | cp bl40/bin/${CUR_SOC}/${BLX_BIN_SUB_CHIP}/blob-bl40.bin.signed ${BUILD_PATH} |
| 714 | fi |
| 715 | if [ ! -f ${BUILD_PATH}/device-fip-header.bin ]; then |
| 716 | echo "Warning: local device fip header templates" |
| 717 | cp ${CHIPSET_TEMPLATES_PATH}/${CUR_SOC}/${BLX_BIN_SUB_CHIP}/device-fip-header.bin ${BUILD_PATH} |
| 718 | fi |
| 719 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 720 | #./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} |
| 721 | |
| 722 | return |
| 723 | } |
| 724 | |
| 725 | function build_signed() { |
| 726 | |
| 727 | process_blx $@ |
| 728 | |
Tao Zeng | c3c70b5 | 2021-01-06 17:29:40 +0800 | [diff] [blame] | 729 | # package ddr-fip.bin |
Meng yu | 7246c8c | 2022-02-15 09:49:22 +0000 | [diff] [blame] | 730 | if [[ "y" == ${CONFIG_DDR_FULL_FW} ]]; then |
Tao Zeng | c3c70b5 | 2021-01-06 17:29:40 +0800 | [diff] [blame] | 731 | mk_ddr_fip ${BUILD_PATH} |
| 732 | fi |
| 733 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 734 | ./${FIP_FOLDER}${CUR_SOC}/bin/gen-bl.sh ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} ${BUILD_PATH} ${CHIPSET_VARIANT_SUFFIX} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 735 | postfix=.signed |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 736 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .sto ${CHIPSET_VARIANT_SUFFIX} |
| 737 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .usb ${CHIPSET_VARIANT_SUFFIX} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 738 | |
Zhongfu Luo | dcc44a1 | 2020-12-16 15:14:28 +0800 | [diff] [blame] | 739 | list_pack="${BUILD_PATH}/bb1st.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/bb1st.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed" |
| 740 | list_pack="$list_pack ${BUILD_PATH}/blob-bl2e.sto${CHIPSET_VARIANT_SUFFIX}.bin.signed ${BUILD_PATH}/blob-bl2e.usb${CHIPSET_VARIANT_SUFFIX}.bin.signed" |
| 741 | 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" |
| 742 | list_pack="$list_pack ${BUILD_PATH}/bl30-payload.bin ${BUILD_PATH}/bl33-payload.bin ${BUILD_PATH}/dvinit-params.bin" |
| 743 | if [ -f ${BUILD_PATH}/ddr-fip.bin ]; then |
| 744 | list_pack="$list_pack ${BUILD_PATH}/ddr-fip.bin" |
| 745 | fi |
| 746 | u_pack=${BUILD_FOLDER}/"$(basename ${BOARD_DIR})"-u-boot.aml.zip |
| 747 | zip -j $u_pack ${list_pack} >& /dev/null |
| 748 | |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 749 | if [ "y" == "${CONFIG_AML_SIGNED_UBOOT}" ]; then |
| 750 | if [ ! -d "${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys" ]; then |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 751 | ./${FIP_FOLDER}${CUR_SOC}/bin/download-keys.sh ${AMLOGIC_KEY_TYPE} ${CUR_SOC} device ${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys/ |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 752 | fi |
| 753 | |
| 754 | fw_arb_cfg=${UBOOT_SRC_FOLDER}/${BOARD_DIR}/fw_arb.cfg |
| 755 | if [ -s "${fw_arb_cfg}" ]; then |
| 756 | source ${fw_arb_cfg} |
| 757 | export DEVICE_SCS_SEGID=${DEVICE_SCS_SEGID} |
| 758 | export DEVICE_VENDOR_SEGID=${DEVICE_VENDOR_SEGID} |
| 759 | export DEVICE_SCS_VERS=${DEVICE_SCS_VERS} |
| 760 | export DEVICE_TEE_VERS=${DEVICE_TEE_VERS} |
| 761 | export DEVICE_REE_VERS=${DEVICE_REE_VERS} |
| 762 | fi |
| 763 | export DEVICE_SCS_KEY_TOP=$(pwd)/${UBOOT_SRC_FOLDER}/${BOARD_DIR}/device-keys |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 764 | export DEVICE_INPUT_PATH=$(pwd)/${BUILD_PATH} |
| 765 | export DEVICE_OUTPUT_PATH=$(pwd)/${BUILD_PATH} |
| 766 | export PROJECT=${CHIPSET_NAME} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 767 | if [ "y" == "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then |
| 768 | export DEVICE_ROOTRSA_INDEX=1 |
| 769 | elif [ -n "${CONFIG_DEVICE_ROOTRSA_INDEX}" ]; then |
| 770 | export DEVICE_ROOTRSA_INDEX=${CONFIG_DEVICE_ROOTRSA_INDEX} |
| 771 | fi |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 772 | export DEVICE_VARIANT_SUFFIX=${CHIPSET_VARIANT_SUFFIX} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 773 | |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 774 | export DEVICE_STORAGE_SUFFIX=.sto |
| 775 | make -C ./${FIP_FOLDER}${CUR_SOC} dv-boot-blobs |
| 776 | export DEVICE_STORAGE_SUFFIX=.usb |
| 777 | make -C ./${FIP_FOLDER}${CUR_SOC} dv-boot-blobs |
| 778 | |
| 779 | make -C ./${FIP_FOLDER}${CUR_SOC} dv-device-fip |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 780 | # build final bootloader |
Zhongfu Luo | 3a6e534 | 2020-12-27 13:11:54 +0800 | [diff] [blame] | 781 | postfix=.device.signed |
| 782 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .sto ${CHIPSET_VARIANT_SUFFIX} |
| 783 | mk_uboot ${BUILD_PATH} ${BUILD_PATH} ${postfix} .usb ${CHIPSET_VARIANT_SUFFIX} |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 784 | fi |
| 785 | |
| 786 | return |
| 787 | } |
| 788 | |
| 789 | function copy_other_soc() { |
| 790 | cp ${BL33_BUILD_FOLDER}${BOARD_DIR}/firmware/acs.bin ${BUILD_PATH}/device_acs.bin -f |
| 791 | |
Honglin Zhang | 1f30916 | 2020-09-29 05:30:31 -0400 | [diff] [blame] | 792 | if [ ! -f ${BUILD_PATH}/chip_acs.bin ]; then |
| 793 | cp ./${FIP_FOLDER}${CUR_SOC}/chip_acs.bin ${BUILD_PATH}/chip_acs.bin -f |
| 794 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 795 | # device acs params parse for ddr timing |
| 796 | #./${FIP_FOLDER}parse ${BUILD_PATH}/device_acs.bin |
| 797 | } |
| 798 | |
| 799 | function package() { |
| 800 | # BUILD_PATH without "/" |
| 801 | x=$((${#BUILD_PATH}-1)) |
| 802 | if [ "\\" == "${BUILD_PATH:$x:1}" ] || [ "/" == "${BUILD_PATH:$x:1}" ]; then |
| 803 | BUILD_PATH=${BUILD_PATH:0:$x} |
| 804 | fi |
| 805 | |
| 806 | init_vari $@ |
| 807 | # Enable Clear Image Packing for PXP |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 808 | if [ -n "${CONFIG_BUILD_UNSIGN}" ]; then |
| 809 | build_fip $@ |
| 810 | else |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 811 | # Bypass Sign Process for PXP |
Zhongfu Luo | 43f1a8a | 2022-03-16 19:13:07 +0800 | [diff] [blame] | 812 | build_signed $@ |
| 813 | fi |
Honglin Zhang | 6b455ce | 2020-09-07 22:59:54 -0400 | [diff] [blame] | 814 | #copy_file |
| 815 | cleanup |
| 816 | echo "Bootloader build done!" |
| 817 | } |