Merge branch 'next-dev' into thunder-boot

This commit is contained in:
Joseph Chen 2020-04-14 14:16:56 +08:00
commit a873a53297
13 changed files with 187 additions and 83 deletions

View File

@ -54,6 +54,10 @@ config PPC
select HAVE_PRIVATE_LIBGCC
select SUPPORT_OF_CONTROL
config RISCV
bool "riscv architecture"
select SUPPORT_OF_CONTROL
config SANDBOX
bool "Sandbox"
select BOARD_LATE_INIT

View File

@ -417,6 +417,21 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0;
}
#elif defined(CONFIG_RISCV)
int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
bd_t *bd = gd->bd;
print_num("arch_number", bd->bi_arch_number);
print_bi_boot_params(bd);
print_bi_dram(bd);
print_eth_ip_addr();
print_baudrate();
return 0;
}
#elif defined(CONFIG_ARC)
int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

View File

@ -237,7 +237,7 @@ static int setup_mon_len(void)
gd->mon_len = (ulong)&_end - (ulong)_init;
#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
gd->mon_len = CONFIG_SYS_MONITOR_LEN;
#elif defined(CONFIG_NDS32) || defined(CONFIG_SH)
#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
#elif defined(CONFIG_SYS_MONITOR_BASE)
/* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */

View File

@ -129,7 +129,7 @@ static int initr_reloc_global_data(void)
{
#ifdef __ARM__
monitor_flash_len = _end - __image_copy_start;
#elif defined(CONFIG_NDS32)
#elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
monitor_flash_len = (ulong)&_end - (ulong)&_start;
#elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
@ -849,7 +849,7 @@ static init_fnc_t init_sequence_r[] = {
board_early_init_r,
#endif
#if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
board_init, /* Setup chipselects */
#endif

View File

@ -1918,6 +1918,8 @@ static const char *fit_get_image_type_property(int type)
return FIT_LOADABLE_PROP;
case IH_TYPE_FPGA:
return FIT_FPGA_PROP;
case IH_TYPE_STANDALONE:
return FIT_STANDALONE_PROP;
}
return "unknown";

View File

@ -424,7 +424,8 @@ static int fit_config_verify_sig(const void *fit, int conf_noffset,
goto error;
}
return verified ? 0 : -EPERM;
if (verified)
return 0;
error:
printf(" error!\n%s for '%s' hash node in '%s' config node\n",
@ -442,9 +443,8 @@ int fit_config_verify_required_sigs(const void *fit, int conf_noffset,
/* Work out what we need to verify */
sig_node = fdt_subnode_offset(sig_blob, 0, FIT_SIG_NODENAME);
if (sig_node < 0) {
debug("%s: No signature node found: %s\n", __func__,
fdt_strerror(sig_node));
return 0;
printf("No signature node found: %s\n", fdt_strerror(sig_node));
return -EINVAL;
}
fdt_for_each_subnode(noffset, sig_blob, sig_node) {

View File

@ -86,6 +86,7 @@ static const table_entry_t uimage_arch[] = {
{ IH_ARCH_ARC, "arc", "ARC", },
{ IH_ARCH_X86_64, "x86_64", "AMD x86_64", },
{ IH_ARCH_XTENSA, "xtensa", "Xtensa", },
{ IH_ARCH_RISCV, "riscv", "RISC-V", },
{ -1, "", "", },
};

View File

@ -342,6 +342,11 @@ static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
#endif
}
__weak int spl_fit_standalone_release(void)
{
return 0;
}
static int spl_internal_load_simple_fit(struct spl_image_info *spl_image,
struct spl_load_info *info,
ulong sector, void *fit)
@ -429,6 +434,31 @@ static int spl_internal_load_simple_fit(struct spl_image_info *spl_image,
printf("rollback index: %d >= %d, OK\n", this_index, min_index);
#endif
#endif
/*
* If required to start the other core before load "loadables"
* firmwares, use the config "standalone" to load the other core's
* firmware, then start it.
* Normally, different cores' firmware is attach to the config
* "loadables" and load them together.
*/
if (node < 0)
node = spl_fit_get_image_node(fit, images, FIT_STANDALONE_PROP,
0);
if (node > 0) {
/* Load the image and set up the spl_image structure */
ret = spl_load_fit_image(info, sector, fit, base_offset, node,
spl_image);
if (!ret) {
ret = spl_fit_standalone_release();
if (ret)
printf("Start standalone fail, ret = %d\n",
ret);
}
node = -1;
}
/*
* Find the U-Boot image using the following search order:
* - start at 'firmware' (e.g. an ARM Trusted Firmware)

View File

@ -9,8 +9,6 @@ CONFIG_ROCKCHIP_VENDOR_PARTITION=y
CONFIG_DEFAULT_DEVICE_TREE="rk3399-evb"
CONFIG_DEBUG_UART=y
CONFIG_FIT=y
CONFIG_FIT_SIGNATURE=y
CONFIG_SPL_FIT_SIGNATURE=y
CONFIG_SPL_LOAD_FIT=y
CONFIG_BOOTDELAY=0
CONFIG_SYS_CONSOLE_INFO_QUIET=y

View File

@ -613,6 +613,11 @@ unsigned long elf_hash(const unsigned char *name);
#define R_AARCH64_NONE 0 /* No relocation. */
#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */
/* RISC-V relocations */
#define R_RISCV_32 1
#define R_RISCV_64 2
#define R_RISCV_RELATIVE 3
#ifndef __ASSEMBLER__
int valid_elf_image(unsigned long addr);
#endif

View File

@ -191,6 +191,7 @@ enum {
IH_ARCH_ARC, /* Synopsys DesignWare ARC */
IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */
IH_ARCH_XTENSA, /* Xtensa */
IH_ARCH_RISCV, /* RISC-V */
IH_ARCH_COUNT,
};
@ -937,6 +938,7 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
#define FIT_SETUP_PROP "setup"
#define FIT_FPGA_PROP "fpga"
#define FIT_FIRMWARE_PROP "firmware"
#define FIT_STANDALONE_PROP "standalone"
#define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE

102
make.sh
View File

@ -98,6 +98,7 @@ PLATFORM_SHA=
PLATFORM_UBOOT_IMG_SIZE=
PLATFORM_TRUST_IMG_SIZE=
PACK_FORMAT="rk"
NOPACK="n"
#########################################################################################################
function help()
@ -147,7 +148,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"
@ -166,7 +167,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)
;;
*)
@ -319,6 +320,10 @@ function sub_commands()
OPTION=${SUBCMD}
;;
nopack)
NOPACK="y"
;;
*)
# Search function and code position of address
RELOC_OFF=${FUNCADDR#*-}
@ -453,6 +458,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}'`
@ -470,15 +479,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"
}
@ -577,6 +583,10 @@ function pack_spl_loader_image()
function pack_loader_image()
{
if [ "$PACK_FORMAT" != "rk" ]; then
return
fi
if [ "$FILE" != "" ]; then
ini=$FILE;
else
@ -595,13 +605,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`
@ -627,21 +633,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()
@ -655,6 +655,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;
@ -685,6 +689,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
@ -702,8 +739,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