Hi Raymond, On Mon, 27 Nov 2023 at 12:53, Raymond Mao <raymond....@linaro.org> wrote: > > Add platform custom function to get bloblist from boot arguments.
This should be the same for all ARM platforms. The ultimate goal is something like [1] > Check whether boot arguments aligns with the register conventions > defined in FW Handoff spec v0.9. > Add bloblist related options into qemu default config. > > Signed-off-by: Raymond Mao <raymond....@linaro.org> > --- > Changes in v2 > - New patch file created for v2. > > board/emulation/qemu-arm/Makefile | 1 + > board/emulation/qemu-arm/lowlevel_init.S | 19 +++++++++ > board/emulation/qemu-arm/qemu-arm.c | 54 ++++++++++++++++++++++++ > configs/qemu_arm64_defconfig | 3 ++ > configs/qemu_arm_defconfig | 3 ++ > 5 files changed, 80 insertions(+) > create mode 100644 board/emulation/qemu-arm/lowlevel_init.S > > diff --git a/board/emulation/qemu-arm/Makefile > b/board/emulation/qemu-arm/Makefile > index a22d1237ff..12821e7083 100644 > --- a/board/emulation/qemu-arm/Makefile > +++ b/board/emulation/qemu-arm/Makefile > @@ -1,3 +1,4 @@ > # SPDX-License-Identifier: GPL-2.0+ > > obj-y += qemu-arm.o > +obj-$(CONFIG_OF_BOARD) += lowlevel_init.o > diff --git a/board/emulation/qemu-arm/lowlevel_init.S > b/board/emulation/qemu-arm/lowlevel_init.S > new file mode 100644 > index 0000000000..d72d7c938a > --- /dev/null > +++ b/board/emulation/qemu-arm/lowlevel_init.S > @@ -0,0 +1,19 @@ > +/* SPDX-License-Identifier: BSD-2-Clause */ > +/* > + * Copyright (c) 2023, Linaro Limited > + */ > + > +#include <config.h> > + > +.global save_boot_params > +save_boot_params: > +#ifdef CONFIG_ARM64 > + adr x9, qemu_saved_args > + stp x0, x1, [x9] > + /* Increment the address by 16 bytes for the next pair of values */ > + stp x2, x3, [x9, #16] > +#else > + ldr r12, =qemu_saved_args > + stm r12, {r0, r1, r2, r3} > +#endif > + b save_boot_params_ret > diff --git a/board/emulation/qemu-arm/qemu-arm.c > b/board/emulation/qemu-arm/qemu-arm.c > index 942f1fff57..a3892630d8 100644 > --- a/board/emulation/qemu-arm/qemu-arm.c > +++ b/board/emulation/qemu-arm/qemu-arm.c > @@ -4,6 +4,9 @@ > */ > > #include <common.h> > +#if IS_ENABLED(CONFIG_OF_BOARD) && IS_ENABLED(CONFIG_BLOBLIST) > +#include <bloblist.h> > +#endif > #include <cpu_func.h> > #include <dm.h> > #include <efi.h> > @@ -102,6 +105,16 @@ static struct mm_region qemu_arm64_mem_map[] = { > struct mm_region *mem_map = qemu_arm64_mem_map; > #endif > > +#if IS_ENABLED(CONFIG_OF_BOARD) OF_BLOBLIST and please avoid #if > +/* Boot parameters saved from lowlevel_init.S */ > +struct { > + unsigned long arg0; > + unsigned long arg1; > + unsigned long arg2; > + unsigned long arg3; > +} qemu_saved_args __section(".data"); > +#endif > + > int board_init(void) > { > return 0; > @@ -144,6 +157,47 @@ void *board_fdt_blob_setup(int *err) > return (void *)CFG_SYS_SDRAM_BASE; > } > > +int board_bloblist_from_boot_arg(unsigned long __maybe_unused addr, > + unsigned long __maybe_unused size) > +{ > + int ret = -ENOENT; > + > +#if IS_ENABLED(CONFIG_OF_BOARD) && IS_ENABLED(CONFIG_BLOBLIST) > + unsigned long fdt; > + > + ret = bloblist_check(qemu_saved_args.arg3, 0); > + if (ret) > + return ret; > + > + bloblist_show_stats(); > + bloblist_show_list(); > + if (gd->bloblist->total_size > size) { > + gd->bloblist = NULL; /* Reset the gd bloblist pointer */ > + log_err("Bloblist total size:%d, board reserved size:%ld\n", > + gd->bloblist->total_size, size); > + return -ENOSPC; > + } > + > + /* Check the register conventions */ > + fdt = (unsigned long)bloblist_find(BLOBLISTT_CONTROL_FDT, 0); This should happen in fdtdec.c automatically. See [2] > + if (IS_ENABLED(CONFIG_ARM64)) { > + if (fdt != qemu_saved_args.arg0 || qemu_saved_args.arg2 != 0) > + ret = -EIO; > + } else { > + if (fdt != qemu_saved_args.arg2 || qemu_saved_args.arg0 != 0) > + ret = -EIO; > + } > + > + if (ret) > + gd->bloblist = NULL; /* Reset the gd bloblist pointer */ > + else > + memmove((void *)addr, (void *)qemu_saved_args.arg3, > + gd->bloblist->total_size); > +#endif > + > + return ret; > +} > + > void enable_caches(void) > { > icache_enable(); > diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig > index 5fdf496a45..60fabb5db7 100644 > --- a/configs/qemu_arm64_defconfig > +++ b/configs/qemu_arm64_defconfig > @@ -71,3 +71,6 @@ CONFIG_USB_EHCI_HCD=y > CONFIG_USB_EHCI_PCI=y > CONFIG_SEMIHOSTING=y > CONFIG_TPM=y > +CONFIG_BLOBLIST=y > +CONFIG_BLOBLIST_ADDR=0x40004000 > +CONFIG_BLOBLIST_SIZE=0x4000 > diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig > index 1347b86f34..d8a94ad038 100644 > --- a/configs/qemu_arm_defconfig > +++ b/configs/qemu_arm_defconfig > @@ -71,3 +71,6 @@ CONFIG_TPM2_MMIO=y > CONFIG_USB_EHCI_HCD=y > CONFIG_USB_EHCI_PCI=y > CONFIG_TPM=y > +CONFIG_BLOBLIST=y > +CONFIG_BLOBLIST_ADDR=0x40004000 > +CONFIG_BLOBLIST_SIZE=0x4000 > -- > 2.25.1 > Regards, Simon [1] https://patchwork.ozlabs.org/project/uboot/list/?series=281465&state=* [2] https://patchwork.ozlabs.org/project/uboot/patch/20230926141514.2101787-40-...@chromium.org/