make.sh: clean up and simplify

There are so many commands in make.sh, we have to clean
and seperate command into individual script file. And
some command is to be the official option for outside.

By the way, adding nm command to analyze image size.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I37ba38b621216f6db79325fada5980a54ca987cb
This commit is contained in:
Joseph Chen 2020-08-05 09:45:54 +08:00
parent 3965b9dee4
commit b42d2103f1
7 changed files with 677 additions and 482 deletions

826
make.sh

File diff suppressed because it is too large Load Diff

54
scripts/atf.sh Executable file
View File

@ -0,0 +1,54 @@
#!/bin/bash
#
# Copyright (c) 2020 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
if [ $# -eq 0 ]; then
echo "ERROR: No args of $0"
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
--ini)
INI=$2 # mandory
shift 2
;;
--rsa)
RSA="$1 $2"
shift 2
;;
--sha)
SHA="$1 $2"
shift 2
;;
--size)
SIZE="$1 $2 $3"
shift 3
;;
*)
echo "ERROR: Unknown arg: $1"
exit 1
;;
esac
done
if [ ! -f ${INI} ]; then
echo "pack trust failed! Can't find: ${INI}"
exit 0
fi
rm trust*.img -f
COUNT=`cat ${INI} | wc -l`
if [ ${COUNT} -eq 1 ]; then
IMG=`sed -n "/PATH=/p" ${INI} | tr -d '\r' | cut -d '=' -f 2`
cp ${IMG} ./trust.img
else
./tools/trust_merger ${INI} ${SIZE} ${SHA} ${RSA}
fi
echo "pack trust okay! Input: ${INI}"
echo

View File

@ -62,7 +62,7 @@ function help()
echo " --uboot-itb"
echo " --boot-itb"
echo " --boot_img"
echo " --p-check"
echo " --arg-check"
echo
}
@ -118,7 +118,7 @@ function fit_process_args()
while [ $# -gt 0 ]; do
case $1 in
--p-check)
--arg-check)
ARG_VALIDATE=$2
shift 2
;;
@ -188,8 +188,9 @@ function fit_process_args()
function fit_rebuild()
{
# Verified-boot: should rebuild code but don't need to repack images.
if [ "${ARG_NO_REBUILD}" != "y" ]; then
./make.sh --no-pack # Always no pack
./make.sh --no-pack # Build but not pack loader/trust/uboot, etc.
fi
rm ${FIT_DIR} -rf
@ -198,13 +199,13 @@ function fit_rebuild()
function fit_gen_uboot_itb()
{
./make.sh itb ${ARG_INI_TRUST}
./make.sh itb ${ARG_INI_TRUST} >/dev/null 2>&1
check_its ${ITS_UBOOT}
if [ "${ARG_NO_VBOOT}" == "y" ]; then
${MKIMAGE} -f ${ITS_UBOOT} -E -p ${OFFS_NS_UBOOT} ${ITB_UBOOT} -v ${ARG_VER_UBOOT}
if [ "${ARG_SPL_NEW}" == "y" ]; then
./make.sh spl-s ${ARG_INI_LOADER}
./make.sh --spl ${ARG_INI_LOADER}
echo "pack loader with new: spl/u-boot-spl.bin"
else
./make.sh loader ${ARG_INI_LOADER}
@ -294,7 +295,7 @@ function fit_gen_uboot_itb()
fi
cat ${SPL_DTB} >> spl/u-boot-spl.bin
./make.sh spl-s ${ARG_INI_LOADER}
./make.sh --spl ${ARG_INI_LOADER}
echo "pack loader with new: spl/u-boot-spl.bin"
else
./make.sh loader ${ARG_INI_LOADER}

41
scripts/loader.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
#
# Copyright (c) 2020 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
if [ $# -eq 0 ]; then
echo "ERROR: No args of $0"
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
--ini)
INI=$2
shift 2
;;
*)
echo "ERROR: Unknown arg: $1"
exit 1
;;
esac
done
rm *_loader_*.bin -f
if [ ! -f ${INI} ]; then
echo "pack loader failed! Can't find: ${INI}"
exit 0
fi
COUNT=`cat ${INI} | wc -l`
if [ ${COUNT} -eq 1 ]; then
IMG=`sed -n "/PATH=/p" ${INI} | tr -d '\r' | cut -d '=' -f 2`
cp ${IMG} ./
else
./tools/boot_merger ${INI}
fi
echo "pack loader okay! Input: ${INI}"

98
scripts/spl.sh Executable file
View File

@ -0,0 +1,98 @@
#!/bin/bash
#
# Copyright (c) 2020 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
if [ $# -eq 0 ]; then
echo "ERROR: No args of $0"
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
--ini)
INI=$2
shift 2
;;
--spl)
SPL_BIN=$2
if [ ! -f ${SPL_BIN} ]; then
echo "ERROR: No ${SPL_BIN}"
exit 1
fi
shift 2
;;
--tpl)
TPL_BIN=$2
if [ ! -f ${TPL_BIN} ]; then
echo "ERROR: No ${TPL_BIN}"
exit 1
fi
shift 2
;;
*)
echo "ERROR: Unknown arg: $1"
exit 1
;;
esac
done
if [ ! -f ${INI} ]; then
echo "ERROR: No ${INI}"
exit 0
fi
if [ "${TPL_BIN}" == "" -a "${SPL_BIN}" == "" ]; then
echo "ERROR: No SPL and TPL file"
exit 0
fi
rm tmp -rf && mkdir tmp -p
TMP_INI="tmp/MINIALL.ini"
cp ${INI} ${TMP_INI}
# magic
MAGIC=`sed -n '/NAME=/s/NAME=//p' ${INI}`
if [ "${MAGIC}" == "RV1126" ]; then
MAGIC="110B"
elif [ "${MAGIC}" == "RKPX30" ]; then
MAGIC="RK33"
fi
# replace
if [ "${TPL_BIN}" != "" -a "${SPL_BIN}" != "" ]; then
cp ${TPL_BIN} tmp/u-boot-tpl.bin
cp ${SPL_BIN} tmp/u-boot-spl.bin
dd if=tmp/u-boot-tpl.bin of=tmp/tpl.bin bs=1 skip=4
sed -i "1s/^/${MAGIC:0:4}/" tmp/tpl.bin
sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI}
sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI}
sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI}
LABEL="TPL+SPL"
elif [ "${TPL_BIN}" != "" ]; then
cp ${TPL_BIN} tmp/u-boot-tpl.bin
dd if=tmp/u-boot-tpl.bin of=tmp/tpl.bin bs=1 skip=4
sed -i "1s/^/${MAGIC:0:4}/" tmp/tpl.bin
sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI}
sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI}
LABEL="TPL"
else
cp ${SPL_BIN} tmp/u-boot-spl.bin
sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI}
LABEL="SPL"
fi
rm *_loader_*.bin -f
./tools/boot_merger ${TMP_INI}
FNAME=`basename *_loader_*.bin`
if [[ ${FNAME} != *spl* ]]; then
rename 's/loader_/spl_loader_/' *_loader_*.bin
fi
rm tmp/ -rf
echo "pack loader(${LABEL}) okay! Input: ${INI}"
echo

74
scripts/tos.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
#
# Copyright (c) 2020 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
if [ $# -eq 0 ]; then
echo "ERROR: No args of $0"
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
--base)
DRAM_BASE=$2
shift 2
;;
--ini)
INI=$2
shift 2
;;
--size)
SIZE="$1 $2 $3"
shift 3
;;
*)
echo "ERROR: Unknown arg: $1"
exit 1
;;
esac
done
if [ ! -f ${INI} ]; then
echo "pack trust failed! Can't find: ${INI}"
exit 0
fi
TOS=`sed -n "/TOS=/s/TOS=//p" ${INI} | tr -d '\r'`
TOSTA=`sed -n "/TOSTA=/s/TOSTA=//p" ${INI} | tr -d '\r'`
OUTPUT=`sed -n "/OUTPUT=/s/OUTPUT=//p" ${INI} | tr -d '\r'`
if [ -z "${OUTPUT}" ]; then
OUTPUT="./trust.img"
fi
LOAD_OFFSET=`sed -n "/ADDR=/s/ADDR=//p" ${INI} | tr -d '\r'`
if [ -z "${LOAD_OFFSET}" ]; then
# default offset
LOAD_OFFSET=0x8400000
fi
LOAD_ADDR=$((DRAM_BASE+LOAD_OFFSET))
LOAD_ADDR=$(echo "obase=16;${LOAD_ADDR}"|bc) # Convert Dec to Hex
rm trust*.img -f
COUNT=`cat ${INI} | wc -l`
if [ ${COUNT} -eq 1 ]; then
IMG=`sed -n "/PATH=/p" ${INI} | tr -d '\r' | cut -d '=' -f 2`
cp ${IMG} ./trust.img
else
if [ ! -z "${TOSTA}" ]; then
./tools/loaderimage --pack --trustos ${TOSTA} ${OUTPUT} ${LOAD_ADDR} ${SIZE}
elif [ ! -z "${TOS}" ]; then
./tools/loaderimage --pack --trustos ${TOS} ${OUTPUT} ${LOAD_ADDR} ${SIZE}
else
echo "ERROR: No tee bin"
exit 1
fi
fi
echo "pack trust okay! Input: ${INI}"
echo

53
scripts/uboot.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
#
# Copyright (c) 2020 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
if [ $# -eq 0 ]; then
echo "ERROR: No args of $0"
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
--load)
LOAD_ADDR=$2
shift 2
;;
--size)
SIZE="$1 $2 $3"
shift 3
;;
*)
echo "ERROR: Unknown arg: $1"
exit 1
;;
esac
done
rm uboot.img -f
if [ -z "${LOAD_ADDR}" ]; then
echo "ERROR: No load address"
exit 1
fi
HEAD_KB=2
BIN_KB=`ls -l u-boot.bin | awk '{ print $5 }'`
if [ -z "${SIZE}" ]; then
MAX_KB=1046528
else
MAX_KB=`echo ${SIZE} | awk '{print strtonum($2)}'`
MAX_KB=$(((MAX_KB-HEAD_KB)*1024))
fi
if [ ${BIN_KB} -gt ${MAX_KB} ]; then
echo "ERROR: pack uboot failed! u-boot.bin actual: ${BIN_KB} bytes, max limit: ${MAX_KB} bytes"
exit 1
fi
./tools/loaderimage --pack --uboot u-boot.bin uboot.img ${LOAD_ADDR} ${SIZE}
echo "pack uboot okay! Input: u-boot.bin"
echo