# # Copyright (C) 2025 Amlogic, Inc. All rights reserved. # #!/bin/bash EXEC_BASEDIR=$(dirname $(readlink -f $0)) BASEDIR_TOP=$(readlink -f ${EXEC_BASEDIR}/..) # # Settings # #BASEDIR_BUILD="${BASEDIR_TOP}/output" BASEDIR_BUILD="${BASEDIR_TOP}/`date +%Y%m%d%H%M%S%N`" postfix=.signed declare -a BLX_BIN_SIZE=("119712" "2048" "262144" "524288") declare CHIPACS_SIZE=${BLX_BIN_SIZE[3]} declare DDRFW_SIZE=${BLX_BIN_SIZE[4]} function split_ddrfw_from_chipacs() { local input=$1 local output1=$2 local output2=$3 local size=`expr ${CHIPACS_SIZE} + ${DDRFW_SIZE}` local input_size=`stat -c %s ${input}` if [ $input_size -ne ${size} ]; then echo "$input is not chipacs and ddrfw merge !!!" return fi dd if=${input} of=${output1}.tmp bs=1 count=${CHIPACS_SIZE} dd if=${input} of=${output2}.tmp skip=${CHIPACS_SIZE} bs=1 count=${DDRFW_SIZE} cat ${output1}.tmp > ${output1} cat ${output2}.tmp > ${output2} rm -rf ${output1}.tmp ${output2}.tmp return } function sign_blx() { local argv=("$@") local i=0 # Parse args while [ $i -lt $# ]; do arg="${argv[$i]}" #echo "i=$i argv[$i]=${argv[$i]}" i=$((i + 1)) case "$arg" in --blxname) blxname="${argv[$i]}" ;; --input) input="${argv[$i]}" ;; --output) output="${argv[$i]}" ;; --ddr_type) ddr_type="${argv[$i]}" ;; --chip_acs) chip_acs="${argv[$i]}" ;; --chipset_name) chipset_name="${argv[$i]}" ;; --chipset_variant) chipset_variant="${argv[$i]}" ;; --key_type) key_type="${argv[$i]}" ;; --soc) soc="${argv[$i]}" ;; --build_type) build_type="${argv[$i]}" ;; *) echo "Unknown option $arg"; exit 1 ;; esac i=$((i + 1)) done if [ -z ${input} ] || [ ! -f ${input} ]; then echo "input ${input} invalid" exit 1 fi if [ -z ${output} ]; then echo "output ${output} invalid" exit 1 fi if [ -z ${blxname} ]; then echo "blxname ${blxname} invalid" exit 1 fi if [ ${blxname} == "bl2c" ]; then blxname="bl2" fi if [ -z ${chipset_name} ]; then chipset_name="n611x1" fi # select bl2 sign template FEAT_BL2_TEMPLATE_TYPE= chipset_variant_suffix="" export FEAT_BL2_TEMPLATE_TYPE if [ -z ${key_type} ]; then key_type="dev-keys" fi if [ -z ${soc} ]; then soc="c4" fi if [ -z ${build_type} ]; then build_type=normal fi mkdir ${BASEDIR_BUILD} if [ ${blxname} == "bl2" ]; then dd if=/dev/zero of=${BASEDIR_BUILD}/bl2-payload.bin bs=${BLX_BIN_SIZE[0]} count=1 &> /dev/null dd if=/dev/zero of=${BASEDIR_BUILD}/csinit-params.bin bs=${BLX_BIN_SIZE[1]} count=1 &> /dev/null #dd if=/dev/zero of=${BASEDIR_BUILD}/ddr-fwdata.bin bs=${BLX_BIN_SIZE[4]} count=1 &> /dev/null elif [ ${blxname} == "bl31" ]; then dd if=/dev/zero of=${BASEDIR_BUILD}/${blxname}-payload.bin bs=${BLX_BIN_SIZE[2]} count=1 &> /dev/null elif [ ${blxname} == "bl32" ]; then dd if=/dev/zero of=${BASEDIR_BUILD}/${blxname}-payload.bin bs=${BLX_BIN_SIZE[3]} count=1 &> /dev/null else echo invalid blxname [$blxname] exit 1 fi ${EXEC_BASEDIR}/download-keys.sh ${key_type} ${soc} chipset ddrfw_split_flag=0 if [ ${blxname} == "bl2" ] && [ ${build_type} == "normal" ]; then if [ -z ${chip_acs} ] || [ ! -f ${chip_acs} ]; then echo "chip_acs ${chip_acs} invalid" exit 1 fi dd if=${chip_acs} of=${BASEDIR_BUILD}/csinit-params.bin conv=notrunc &> /dev/null dd if=${input} of=${BASEDIR_BUILD}/${blxname}-payload.bin conv=notrunc &> /dev/null ${EXEC_BASEDIR}/gen-boot-blobs.sh ${BASEDIR_BUILD} ${BASEDIR_BUILD} ${chipset_name} ${key_type} ${soc} ${chipset_variant} elif [ ${blxname} == "bl2" ] && [ ${build_type} == "bl2-only" ]; then dd if=${input} of=${BASEDIR_BUILD}/${blxname}-payload.bin conv=notrunc &> /dev/null ${EXEC_BASEDIR}/gen-boot-blob-bl2-only.sh ${BASEDIR_BUILD} ${BASEDIR_BUILD} ${chipset_name} ${key_type} ${soc} ${chipset_variant} elif [ ${blxname} == "bl2" ] && [ ${build_type} == "bl2-final" ]; then if [ -z ${chip_acs} ] || [ ! -f ${chip_acs} ]; then echo "chip_acs ${chip_acs} invalid" exit 1 fi dd if=${chip_acs} of=${BASEDIR_BUILD}/csinit-params.bin conv=notrunc &> /dev/null dd if=${input} of=${BASEDIR_BUILD}/bb1st${FEAT_BL2_TEMPLATE_TYPE}${chipset_variant_suffix}.bin.bl2-only conv=notrunc &> /dev/null ${EXEC_BASEDIR}/gen-boot-blob-bl2-final.sh ${BASEDIR_BUILD} ${BASEDIR_BUILD} ${chipset_name} ${key_type} ${soc} ${chipset_variant} elif [ ${blxname} == "bl31" ] || [ ${blxname} == "bl32" ]; then echo Error. bl31 and bl32 signing moved. fi if [ ${blxname} == "bl2" ]; then if [ ${build_type} == "bl2-only" ]; then cp ${BASEDIR_BUILD}/bb1st${FEAT_BL2_TEMPLATE_TYPE}${chipset_variant_suffix}.bin.bl2-only $output else cp ${BASEDIR_BUILD}/bb1st${FEAT_BL2_TEMPLATE_TYPE}${chipset_variant_suffix}.bin${postfix} $output fi else cp ${BASEDIR_BUILD}/blob-bl3-tee.bin${postfix} $output fi } rm -rf ${BASEDIR_BUILD} sign_blx $@ rm -rf ${BASEDIR_BUILD}