[PATCH 2/5] qemu-arm: Get bloblist from boot arguments

Raymond Mao raymond.mao at linaro.org
Tue Dec 19 22:11:09 CET 2023


Add platform custom function to get bloblist from boot arguments.
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.mao at linaro.org>
---
 board/emulation/qemu-arm/Makefile        |  1 +
 board/emulation/qemu-arm/lowlevel_init.S | 19 +++++++++
 board/emulation/qemu-arm/qemu-arm.c      | 51 ++++++++++++++++++++++++
 configs/qemu_arm64_defconfig             |  3 ++
 4 files changed, 74 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..0eb262e4e2 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-y	+= 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..72e0a97567 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <bloblist.h>
 #include <cpu_func.h>
 #include <dm.h>
 #include <efi.h>
@@ -102,6 +103,14 @@ static struct mm_region qemu_arm64_mem_map[] = {
 struct mm_region *mem_map = qemu_arm64_mem_map;
 #endif
 
+/* 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");
+
 int board_init(void)
 {
 	return 0;
@@ -144,6 +153,48 @@ void *board_fdt_blob_setup(int *err)
 	return (void *)CFG_SYS_SDRAM_BASE;
 }
 
+int board_bloblist_from_boot_arg(unsigned long addr, unsigned long size)
+{
+	int ret = -ENOENT;
+	unsigned long reg_fdt;
+	unsigned long reg_zero;
+
+	if (!IS_ENABLED(CONFIG_OF_BOARD) || !IS_ENABLED(CONFIG_BLOBLIST))
+		return -ENOENT;
+
+	ret = bloblist_check(qemu_saved_args.arg3, 0);
+	if (ret)
+		return ret;
+
+	if (gd->bloblist->total_size > size) {
+		gd->bloblist = NULL; /* Reset the gd bloblist pointer */
+		log_err("Board bloblist total size:%d, reserved size:%ld\n",
+			gd->bloblist->total_size, size);
+		return -ENOSPC;
+	}
+
+	if (IS_ENABLED(CONFIG_ARM64)) {
+		reg_fdt = qemu_saved_args.arg0;
+		reg_zero = qemu_saved_args.arg2;
+	} else {
+		reg_fdt = qemu_saved_args.arg2;
+		reg_zero = qemu_saved_args.arg0;
+	}
+	/* Check the register conventions */
+	ret = bloblist_check_reg_conv(reg_fdt, reg_zero);
+
+	if (ret) {
+		gd->bloblist = NULL;  /* Reset the gd bloblist pointer */
+	} else {
+		/* Relocate the bloblist to the fixed address */
+		bloblist_reloc((void *)addr, gd->bloblist->total_size,
+			       gd->bloblist, gd->bloblist->total_size);
+		gd->bloblist = (struct bloblist_hdr *)addr;
+	}
+
+	return ret;
+}
+
 void enable_caches(void)
 {
 	 icache_enable();
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig
index c010c25a92..418f48001c 100644
--- a/configs/qemu_arm64_defconfig
+++ b/configs/qemu_arm64_defconfig
@@ -69,3 +69,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
-- 
2.25.1



More information about the U-Boot mailing list