make/fit: optimise for fit

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I59067a208f3599f13acf995172ec720c1f141d18
This commit is contained in:
Joseph Chen 2020-04-13 20:45:19 +08:00
parent b074ddcefe
commit 8f53a15c01
2 changed files with 121 additions and 74 deletions

102
make.sh
View File

@ -97,6 +97,7 @@ PLATFORM_SHA=
PLATFORM_UBOOT_IMG_SIZE=
PLATFORM_TRUST_IMG_SIZE=
PACK_FORMAT="rk"
NOPACK="n"
#########################################################################################################
function help()
@ -146,7 +147,7 @@ function prepare()
{
case $BOARD in
# Parse from exit .config
''|elf*|loader*|spl*|itb|debug*|trust|uboot|map|sym|env|EXT_DTB=*|fit*)
''|elf*|loader*|spl*|itb|debug*|trust|uboot|map|sym|env|EXT_DTB=*|fit*|nopack)
if [ ! -f .config ]; then
echo
echo "ERROR: No .config"
@ -165,7 +166,7 @@ function prepare()
;;
#Subcmd
''|elf*|loader*|spl*|itb|debug*|trust*|uboot|map|sym|env|EXT_DTB=*|fit*)
''|elf*|loader*|spl*|itb|debug*|trust*|uboot|map|sym|env|EXT_DTB=*|fit*|nopack)
;;
*)
@ -318,6 +319,10 @@ function sub_commands()
OPTION=${SUBCMD}
;;
nopack)
NOPACK="y"
;;
*)
# Search function and code position of address
RELOC_OFF=${FUNCADDR#*-}
@ -452,6 +457,10 @@ function fixup_platform_configure()
function pack_uboot_image()
{
if [ "$PACK_FORMAT" != "rk" ]; then
return
fi
# Check file size
head_kb=2
uboot_kb=`ls -l u-boot.bin | awk '{print $5}'`
@ -469,15 +478,12 @@ function pack_uboot_image()
fi
# Pack
if [ "$PACK_FORMAT" = "rk" ]; then
uboot_load_addr=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" include/autoconf.mk|tr -d '\r'`
if [ -z $uboot_load_addr ]; then
echo "ERROR: No CONFIG_SYS_TEXT_BASE for u-boot";
exit 1
fi
${RKTOOLS}/loaderimage --pack --uboot u-boot.bin uboot.img ${uboot_load_addr} ${PLATFORM_UBOOT_IMG_SIZE}
uboot_load_addr=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" include/autoconf.mk|tr -d '\r'`
if [ -z $uboot_load_addr ]; then
echo "ERROR: No CONFIG_SYS_TEXT_BASE for u-boot";
exit 1
fi
${RKTOOLS}/loaderimage --pack --uboot u-boot.bin uboot.img ${uboot_load_addr} ${PLATFORM_UBOOT_IMG_SIZE}
ls u-boot.img u-boot-dtb.img >/dev/null 2>&1 && rm u-boot.img u-boot-dtb.img -rf
echo "pack uboot okay! Input: u-boot.bin"
}
@ -576,6 +582,10 @@ function pack_spl_loader_image()
function pack_loader_image()
{
if [ "$PACK_FORMAT" != "rk" ]; then
return
fi
if [ "$FILE" != "" ]; then
ini=$FILE;
else
@ -594,13 +604,9 @@ function pack_loader_image()
image=`sed -n "/PATH=/p" $ini | tr -d '\r' | cut -d '=' -f 2`
cp ${RKBIN}/${image} ./
else
if [ "$PACK_FORMAT" = "rk" ]; then
cd ${RKBIN}
${RKTOOLS}/boot_merger $ini
cd - && mv ${RKBIN}/*_loader_*.bin ./
else
./make.sh spl-s
fi
cd ${RKBIN}
${RKTOOLS}/boot_merger $ini
cd - && mv ${RKBIN}/*_loader_*.bin ./
fi
file=`ls *loader*.bin`
@ -626,21 +632,15 @@ function pack_arm32_trust_image()
tee_load_addr=$((dram_base+tee_offset))
tee_load_addr=$(echo "obase=16;${tee_load_addr}"|bc) # Convert Dec to Hex
if [ "$PACK_FORMAT" = "rk" ]; then
if [ $tosta_image ]; then
${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${tosta_image} ${tee_output} ${tee_load_addr} ${PLATFORM_TRUST_IMG_SIZE}
elif [ $tos_image ]; then
${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${tos_image} ${tee_output} ${tee_load_addr} ${PLATFORM_TRUST_IMG_SIZE}
else
echo "ERROR: No any tee bin"
exit 1
fi
echo "pack trust okay! Input: $ini"
if [ $tosta_image ]; then
${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${tosta_image} ${tee_output} ${tee_load_addr} ${PLATFORM_TRUST_IMG_SIZE}
elif [ $tos_image ]; then
${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${tos_image} ${tee_output} ${tee_load_addr} ${PLATFORM_TRUST_IMG_SIZE}
else
./scripts/fit-vboot-uboot.sh --no-vboot --no-rebuild
ls uboot.img trust*.img >/dev/null 2>&1 && rm uboot.img trust*.img -rf
echo "pack uboot.img (with uboot trust) okay! Input: $ini"
echo "ERROR: No any tee bin"
exit 1
fi
echo "pack trust okay! Input: $ini"
}
function pack_arm64_trust_image()
@ -654,6 +654,10 @@ function pack_arm64_trust_image()
function pack_trust_image()
{
if [ "$PACK_FORMAT" != "rk" ]; then
return
fi
ls trust*.img >/dev/null 2>&1 && rm trust*.img
if [ "$FILE" != "" ]; then
ini=$FILE;
@ -684,6 +688,39 @@ function pack_trust_image()
fi
}
function pack_fit_image()
{
./scripts/fit-vboot-uboot.sh --no-vboot --no-rebuild
ls uboot.img trust*.img >/dev/null 2>&1 && rm uboot.img trust*.img -rf
echo "pack uboot.img (with uboot trust) okay! Input: $ini"
}
function pack_images()
{
if [ "$NOPACK" != "y" ]; then
if [ "$PACK_FORMAT" = "rk" ]; then
pack_uboot_image
pack_trust_image
pack_loader_image
elif [ "$PACK_FORMAT" = "fit" ]; then
pack_fit_image
fi
fi
}
function clean_files()
{
if [ -f spl/u-boot-spl.dtb ]; then
rm spl/u-boot-spl.dtb
fi
if [ -f tpl/u-boot-tpl.dtb ]; then
rm tpl/u-boot-tpl.dtb
fi
if [ -f u-boot.dtb ]; then
rm u-boot.dtb
fi
}
function finish()
{
echo
@ -701,8 +738,7 @@ select_toolchain
select_chip_info
fixup_platform_configure
sub_commands
clean_files
make CROSS_COMPILE=${TOOLCHAIN_GCC} ${OPTION} all --jobs=${JOB}
pack_uboot_image
pack_trust_image
pack_loader_image
pack_images
finish

View File

@ -46,17 +46,16 @@ function usage_pack()
echo " $0 [args]"
echo
echo "args:"
echo " --rollback-index <decimal integer>"
if [[ "$0" = *fit-vboot-boot.sh ]]; then
echo " --rollback-index-boot <decimal integer>"
elif [[ "$0" = *fit-vboot-uboot.sh ]]; then
echo " --rollback-index-uboot <decimal integer>"
else
echo " --rollback-index-boot <decimal integer>"
echo " --rollback-index-uboot <decimal integer>"
fi
echo " --no-vboot"
echo
}
function usage_resign()
{
echo
echo "usage:"
echo " $0 -i [itb_image] -s [sig] -u // resign uboot"
echo " $0 -i [itb_image] -s [sig] -b // resign boot"
echo " --no-check"
echo
}
@ -88,15 +87,17 @@ function fit_process_args()
ARG_NO_REBUILD="y"
shift 1
;;
--rollback-index)
if [[ "$0" = *fit-vboot-uboot.sh ]]; then
ARG_ROLLBACK_IDX_UBOOT=$2
elif [[ "$0" = *fit-vboot-boot.sh ]]; then
ARG_ROLLBACK_IDX_BOOT=$2
else
usage_pack
exit 1
fi
--no-check)
ARG_NO_CHECK="y"
shift 1
;;
--rollback-index-boot)
ARG_ROLLBACK_IDX_BOOT=$2
arg_check_decimal $2
shift 2
;;
--rollback-index-uboot)
ARG_ROLLBACK_IDX_UBOOT=$2
arg_check_decimal $2
shift 2
;;
@ -123,7 +124,7 @@ function its_file_existence_check()
function fit_rebuild()
{
if [ "$ARG_NO_REBUILD" != "y" ]; then
./make.sh
./make.sh nopack
fi
if [ -d $FIT_DIR ]; then
@ -142,6 +143,7 @@ function fit_uboot_make_itb()
if [ "$ARG_NO_VBOOT" = "y" ]; then
SIGN_MSG="no-signed"
./tools/mkimage -f u-boot.its -E -p $FIT_NS_OFFS_UBOOT $FIT_ITB_UBOOT
./make.sh spl-s
else
SIGN_MSG="signed"
@ -158,10 +160,10 @@ function fit_uboot_make_itb()
exit 1
fi
if grep -q '^CONFIG_SPL_FIT_ROLLBACK_PROTECT=y' .config ; then
if grep -q '^CONFIG_SPL_FIT_ROLLBACK_PROTECT=y' .config ; then
SPL_ROLLBACK_PROTECT="y"
if [ -z $ARG_ROLLBACK_IDX_UBOOT ]; then
echo "ERROR: No args \"--rollback-index <n>\""
echo "ERROR: No args \"--rollback-index-uboot <n>\""
exit 1
fi
fi
@ -170,6 +172,13 @@ function fit_uboot_make_itb()
sed -i "s/rollback-index = <0x0>/rollback-index = <$ARG_ROLLBACK_IDX_UBOOT>/g" u-boot.its
fi
# We need a u-boot.dtb with RSA pub-key insert
if ! fdtget -l u-boot.dtb /signature >/dev/null 2>&1 ; then
./tools/mkimage -f u-boot.its -k $KEY_DIR/ -K u-boot.dtb -E -p $FIT_S_OFFS_UBOOT -r $FIT_ITB_UBOOT
echo "Insert RSA pub into u-boot.dtb"
fi
# Pack
./tools/mkimage -f u-boot.its -k $KEY_DIR/ -K spl/u-boot-spl.dtb -E -p $FIT_S_OFFS_UBOOT -r $FIT_ITB_UBOOT
mv data2sign.bin $FIT_DATA2SIG_UBOOT
@ -182,8 +191,9 @@ function fit_uboot_make_itb()
fi
fi
# host check sign
./tools/fit_check_sign -f $FIT_ITB_UBOOT -k spl/u-boot-spl.dtb -s
if [ "$ARG_NO_CHECK" != "y" ]; then
./tools/fit_check_sign -f $FIT_ITB_UBOOT -k spl/u-boot-spl.dtb -s
fi
# minimize spl dtb
if grep -q '^CONFIG_SPL_FIT_HW_CRYPTO=y' .config ; then
@ -199,7 +209,7 @@ function fit_uboot_make_itb()
fdtput -tx spl/u-boot-spl.dtb /signature/key-dev rsa,exponent-BN 0x0
fi
# repack spl
# repack spl which has rsa pub-key insert
ls *_loader_*.bin >/dev/null 2>&1 && rm *_loader_*.bin
cat spl/u-boot-spl-nodtb.bin > spl/u-boot-spl.bin
if ! grep -q '^CONFIG_SPL_SEPARATE_BSS=y' .config ; then
@ -210,20 +220,19 @@ function fit_uboot_make_itb()
fi
# clean
ls u-boot.itb >/dev/null 2>&1 && rm u-boot.itb
mv u-boot.its $FIT_DIR
cp tee.bin $FIT_DIR
cp u-boot-nodtb.bin $FIT_DIR
cp u-boot.dtb $FIT_DIR
cp spl/u-boot-spl.bin $FIT_DIR
cp spl/u-boot-spl.dtb $FIT_DIR
ls u-boot.itb u-boot.img u-boot-dtb.img >/dev/null 2>&1 && rm u-boot.itb u-boot.img u-boot-dtb.img -rf
./scripts/dtc/dtc -I dtb -O dts $FIT_ITB_UBOOT -o $FIT_UNMAP_ITB_UBOOT >/dev/null 2>&1
./scripts/dtc/dtc -I dtb -O dts spl/u-boot-spl.dtb -o $FIT_UNMAP_KEY_UBOOT >/dev/null 2>&1
}
function fit_boot_make_itb()
{
if grep -q '^CONFIG_ARM64=y' .config ; then
FIT_ITS_BOOT="kernel_arm64.its"
else
@ -239,7 +248,7 @@ function fit_boot_make_itb()
./tools/mkimage -f $FIT_ITS_BOOT -E -p $FIT_NS_OFFS_BOOT $FIT_ITB_BOOT
else
SIGN_MSG="signed"
# sanity
if [ ! -f $KEY_DIR/dev.key ]; then
echo "ERROR: No $KEY_DIR/dev.key"
exit 1
@ -256,7 +265,7 @@ function fit_boot_make_itb()
if grep -q '^CONFIG_FIT_ROLLBACK_PROTECT=y' .config ; then
ROLLBACK_PROTECT="y"
if [ -z $ARG_ROLLBACK_IDX_BOOT ]; then
echo "ERROR: No args \"--rollback-index <n>\""
echo "ERROR: No args \"--rollback-index-boot <n>\""
exit 1
fi
fi
@ -285,8 +294,9 @@ function fit_boot_make_itb()
fi
fi
# host check sign
./tools/fit_check_sign -f $FIT_ITB_BOOT -k u-boot.dtb
if [ "$ARG_NO_CHECK" != "y" ]; then
./tools/fit_check_sign -f $FIT_ITB_BOOT -k u-boot.dtb
fi
# minimize u-boot dtb
if grep -q '^CONFIG_FIT_HW_CRYPTO=y' .config ; then
@ -355,20 +365,24 @@ function fit_boot_make_img()
fi
}
function usage_resign()
{
echo
echo "usage:"
echo " $0 -f [itb_image] -s [sig]"
echo
}
function fit_resign()
{
if [ $# -ne 5 ]; then
if [ $# -ne 4 ]; then
usage_resign
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
-b|-u)
FIT_UK=$1
shift 1
;;
-i)
-f)
FIT_ITB=$2
shift 2
;;
@ -390,9 +404,6 @@ function fit_resign()
elif [ ! -f $FIT_SIG ]; then
echo "ERROR: No $FIT_SIG"
exit 1
elif [ -z $FIT_UK ]; then
echo "ERROR: No args -u or -b"
exit 1
fi
# confirm location
@ -422,7 +433,7 @@ function fit_resign()
# generate
echo
if [ "$FIT_UK" = "-u" ]; then
if fdtget -l $FIT_ITB /images/uboot@1 >/dev/null 2>&1 ; then
fit_uboot_make_img $FIT_ITB
echo "Image(re-signed): $FIT_IMG_UBOOT is ready"
else