# # Copyright (C) 2025 Amlogic, Inc. All rights reserved. # #!/bin/bash set -e BL22= RTOS1= RTOS2= OUT_FILE="blob-rtos.bin" FIP_BUILD_FOLDER="fip/_tmp/" function align_4k() { local file=$1 local raw_size= local file_size= local rem_val= raw_size=`stat -c %s ${file}` file_size=`expr ${raw_size} + 4095` rem_val=`expr ${file_size} % 4096` file_size=`expr ${file_size} - ${rem_val}` #echo ==== align file ${file} from ${raw_size} to ${file_size} ==== dd if=/dev/zero of=${file}_tmp.bin bs=1 count=${file_size} &> /dev/null dd if=${file} of=${file}_tmp.bin bs=1 count=${file_size} conv=notrunc &> /dev/null mv ${file}_tmp.bin ${file} } function amfc_compress() { local file=$1 amfc_zstd_hdr=amfc_zstd_hdr.bin ./fip/tools/aml_zstd ${file} -19 -o ${file}.tmp bin_org_size=`stat -c %s ${file}` bin_zstd_size=`stat -c %s ${file}.tmp` printf "%s" "@ZST" > $amfc_zstd_hdr printf "%02x%02x%02x%02x" $[(bin_org_size) & 0xff] \ $[((bin_org_size) >> 8) & 0xff] $[((bin_org_size) >> 16) & 0xff] \ $[((bin_org_size) >> 24) & 0xff] | xxd -r -ps >> $amfc_zstd_hdr printf "%02x%02x%02x%02x" $[(bin_zstd_size) & 0xff] \ $[((bin_zstd_size) >> 8) & 0xff] $[((bin_zstd_size) >> 16) & 0xff] \ $[((bin_zstd_size) >> 24) & 0xff] | xxd -r -ps >> $amfc_zstd_hdr cat $amfc_zstd_hdr ${file}.tmp > ${file}.zstd rm $amfc_zstd_hdr ${file}.tmp -f } function package_binary() { local fw_size= local rem_val= local bin1=$1 local bin2=$2 local out_bin=$3 # align bin1 size up to 4KB and padding bin2 at the end of bin1 fw_size=`stat -c %s ${bin1}` fw_size=`expr ${fw_size} + 4095` rem_val=`expr ${fw_size} % 4096` fw_size=`expr ${fw_size} - ${rem_val}` dd if=/dev/zero of=${bin1}_tmp.bin bs=1 count=${fw_size} &> /dev/null dd if=${bin1} of=${bin1}_tmp.bin bs=1 count=${fw_size} conv=notrunc &> /dev/null cat ${bin2} >> ${bin1}_tmp.bin mv ${bin1}_tmp.bin ${out_bin} echo ==== package ${bin1} ${bin2} to ${out_bin} ==== } function usage() { cat << EOF Usage: ${CUR_SOC}_create_rtos.sh --help create boot blobs for ${CUR_SOC}, input payload will be compressed before create bootblob ${CUR_SOC}_create_rtos.sh --bl22 [bl22.bin] --rtos1 [rtos1.bin] --rtos2 [rtos2.bin] --out rtos.bin EOF exit 1 } function parser() { local i=0 local argv=() for arg in "$@" ; do argv[$i]="$arg" i=$((i + 1)) done i=0 while [ $i -lt $# ]; do arg="${argv[$i]}" i=$((i + 1)) # must place here case "$arg" in --h|--help) usage exit ;; --bl22) BL22="${argv[$i]}" i=$((i + 1)) continue ;; --rtos1) RTOS1="${argv[$i]}" i=$((i + 1)) continue ;; --rtos2) RTOS2="${argv[$i]}" i=$((i + 1)) continue ;; --out) OUT_FILE="${argv[$i]}" i=$((i + 1)) continue ;; *) echo "unsupported args: ${arg}" usage exit ;; esac done } # steps: # 1, compress for rtos1/rtos2 # 2, align compressed file size to 4K # 3, call acpu image tools to generate blobs # 4, package blobs to final output function create_blob() { local bl22_file_size local rtos1_file_size local rtos2_file_size # process bl22 cp -rf ${BL22} ${FIP_BUILD_FOLDER}/bl22.bin align_4k ${FIP_BUILD_FOLDER}/bl22.bin bl22_file_size=`stat -c %s ${FIP_BUILD_FOLDER}/bl22.bin` echo bl22 size: ${bl22_file_size} if [ ${bl22_file_size} -gt 28672 ] || [ ${bl22_file_size} -lt 4096 ]; then echo bl22 size ${bl22_file_size} wrong exit -1 fi # process rtos1 cp -rf ${RTOS1} ${FIP_BUILD_FOLDER}/rtos1.bin amfc_compress ${FIP_BUILD_FOLDER}/rtos1.bin align_4k ${FIP_BUILD_FOLDER}/rtos1.bin.zstd rtos1_file_size=`stat -c %s ${FIP_BUILD_FOLDER}/rtos1.bin.zstd` echo rtos1 size: ${rtos1_file_size} if [ ${rtos1_file_size} -gt 5242880 ] || [ ${rtos1_file_size} -lt 16384 ]; then echo rtos1 size ${rtos1_file_size} wrong exit -1 fi # process rtos2 cp -rf ${RTOS2} ${FIP_BUILD_FOLDER}/rtos2.bin rtos2_file_size=`stat -c %s ${FIP_BUILD_FOLDER}/rtos2.bin` if [ ${rtos2_file_size} -eq 0 ]; then dd if=/dev/zero of=${FIP_BUILD_FOLDER}/rtos2.bin.zstd bs=4 count=1 &> /dev/null else amfc_compress ${FIP_BUILD_FOLDER}/rtos2.bin fi align_4k ${FIP_BUILD_FOLDER}/rtos2.bin.zstd rtos2_file_size=`stat -c %s ${FIP_BUILD_FOLDER}/rtos2.bin.zstd` echo rtos2 size: ${rtos2_file_size} if [ ${rtos2_file_size} -gt 20971520 ] || [ ${rtos2_file_size} -lt 65536 ]; then if [ ${rtos2_file_size} -ne 4096 ]; then echo rtos2 size ${rtos2_file_size} wrong exit -1 fi fi fip/c5/binary-tool/acpu-imagetool create-boot-blobs --scs-family=c5 \ --infile-bl2-2-payload=${FIP_BUILD_FOLDER}/bl22.bin \ --size-payload-bl2-2=${bl22_file_size} \ --infile-rtos-1-payload=${FIP_BUILD_FOLDER}/rtos1.bin.zstd \ --size-payload-rtos-1=${rtos1_file_size} \ --infile-rtos-2-payload=${FIP_BUILD_FOLDER}/rtos2.bin.zstd \ --size-payload-rtos-2=${rtos2_file_size} \ --outfile-blob-bl2-rtos=${FIP_BUILD_FOLDER}/rtos-blob-final.bin cp ${FIP_BUILD_FOLDER}/rtos-blob-final.bin ${OUT_FILE} # clean up #rm -rf ${BL22}.temp_size #rm -rf ${BL22}.tmp #rm -rf ${BL22}-rtos1.bin #rm -rf ${BL22}-blob.bin #rm -rf ${RTOS1}.tmp #rm -rf ${RTOS1}.zstd #rm -rf ${RTOS1}-blob.bin #rm -rf ${RTOS2}.tmp #rm -rf ${RTOS2}.zstd #rm -rf ${RTOS2}-blob.bin } parser $@ if [ -z ${BL22} ]; then echo "ERROR: NO bl22" usage exit -1 fi if [ -z ${RTOS1} ]; then echo "ERROR:NO rtos1" usage exit -1 fi if [ -z ${RTOS2} ]; then echo "ERROR:NO rtos2" usage exit -1 fi create_blob ${BL22} ${RTOS1} ${RTOS2} ${OUT_FILE}