[PATCH 16/19] arm: Add a new qemu_arm64_tpl board

Simon Glass sjg at chromium.org
Wed Sep 25 14:55:42 CEST 2024


We want to be able to test the relocating XPL loader. Add a new build
for ARM QEMU which supports booting from TPL into SPL

This builds an image containing TPL, SPL and U-Boot proper. To run it:

   qemu-system-aarch64 -machine virt -nographic -cpu cortex-a57 \
      -bios image.bin

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/arm/dts/qemu-arm64.dts           | 18 ++++++
 arch/arm/mach-qemu/Kconfig            | 20 +++++++
 board/emulation/qemu-arm/Kconfig      |  2 +-
 board/emulation/qemu-arm/MAINTAINERS  |  5 ++
 board/emulation/qemu-arm/Makefile     |  1 +
 board/emulation/qemu-arm/qemu-arm.env |  4 ++
 board/emulation/qemu-arm/xpl.c        | 35 ++++++++++++
 configs/qemu_arm64_tpl_defconfig      | 82 +++++++++++++++++++++++++++
 8 files changed, 166 insertions(+), 1 deletion(-)
 create mode 100644 board/emulation/qemu-arm/xpl.c
 create mode 100644 configs/qemu_arm64_tpl_defconfig

diff --git a/arch/arm/dts/qemu-arm64.dts b/arch/arm/dts/qemu-arm64.dts
index 096b3910728..de943642e76 100644
--- a/arch/arm/dts/qemu-arm64.dts
+++ b/arch/arm/dts/qemu-arm64.dts
@@ -8,4 +8,22 @@
 /dts-v1/;
 
 / {
+#ifdef CONFIG_BINMAN
+	binman {
+		u-boot-tpl {
+		};
+
+		u-boot-spl {
+			symbols-base = <0>;
+			offset = <CONFIG_SPL_TEXT_BASE>;
+		};
+
+		u-boot {
+			offset = <CONFIG_TEXT_BASE>;
+		};
+
+		fdtmap {
+		};
+	};
+#endif
 };
diff --git a/arch/arm/mach-qemu/Kconfig b/arch/arm/mach-qemu/Kconfig
index 186c3582ebf..8ade9028af6 100644
--- a/arch/arm/mach-qemu/Kconfig
+++ b/arch/arm/mach-qemu/Kconfig
@@ -25,6 +25,26 @@ config TARGET_QEMU_ARM_64BIT
 	select ARM64
 	select BOARD_LATE_INIT
 
+config TARGET_QEMU_ARM_64BIT_TPL
+	bool "ARMv8, 64bit, with TPL"
+	select ARM64
+	select BOARD_LATE_INIT
+	select SPL
+	select TPL
+	select SPL_LIBCOMMON_SUPPORT
+	select TPL_LIBCOMMON_SUPPORT
+	select SPL_LIBGENERIC_SUPPORT
+	select TPL_LIBGENERIC_SUPPORT
+	select SPL_OF_CONTROL
+	select TPL_OF_CONTROL
+	select SPL_DM
+	select TPL_DM
+	select BINMAN
+	select SPL_SERIAL
+	select TPL_SERIAL
+	imply SPL_FRAMEWORK_BOARD_INIT_F
+	imply RPL_FRAMEWORK_BOARD_INIT_F
+
 endchoice
 
 endif
diff --git a/board/emulation/qemu-arm/Kconfig b/board/emulation/qemu-arm/Kconfig
index e21c135e86f..32c71bb0421 100644
--- a/board/emulation/qemu-arm/Kconfig
+++ b/board/emulation/qemu-arm/Kconfig
@@ -1,4 +1,4 @@
-if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT
+if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT || TARGET_QEMU_ARM_64BIT_TPL
 
 config TEXT_BASE
 	default 0x00000000
diff --git a/board/emulation/qemu-arm/MAINTAINERS b/board/emulation/qemu-arm/MAINTAINERS
index 5154262f29e..559409c18bb 100644
--- a/board/emulation/qemu-arm/MAINTAINERS
+++ b/board/emulation/qemu-arm/MAINTAINERS
@@ -6,3 +6,8 @@ F:	board/emulation/common/
 F:	include/configs/qemu-arm.h
 F:	configs/qemu_arm_defconfig
 F:	configs/qemu_arm64_defconfig
+
+QEMU ARM 'VIRT' TPL BOARD
+M:	Simon Glass <sjg at chromium.org>
+S:	Maintained
+F:	configs/qemu_arm64_tpl_defconfig
diff --git a/board/emulation/qemu-arm/Makefile b/board/emulation/qemu-arm/Makefile
index a22d1237ff4..ef40943052c 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_SPL_BUILD) += xpl.o
diff --git a/board/emulation/qemu-arm/qemu-arm.env b/board/emulation/qemu-arm/qemu-arm.env
index fb4adef281e..0190db82e4e 100644
--- a/board/emulation/qemu-arm/qemu-arm.env
+++ b/board/emulation/qemu-arm/qemu-arm.env
@@ -13,3 +13,7 @@ pxefile_addr_r=0x40300000
 kernel_addr_r=0x40400000
 ramdisk_addr_r=0x44000000
 boot_targets=qfw usb scsi virtio nvme dhcp
+
+#ifdef CONFIG_TARGET_QEMU_ARM_64BIT_TPL
+board_name="qemu-arm64_tpl"
+#endif
diff --git a/board/emulation/qemu-arm/xpl.c b/board/emulation/qemu-arm/xpl.c
new file mode 100644
index 00000000000..ec59e0ff327
--- /dev/null
+++ b/board/emulation/qemu-arm/xpl.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#define LOG_DEBUG
+#define LOG_CATEGORY	LOGC_BOOT
+
+#include <mapmem.h>
+#include <spl.h>
+
+unsigned int spl_boot_device(void)
+{
+	return BOOT_DEVICE_BOARD;
+}
+
+static int binman_load_image(struct spl_image_info *img,
+			     struct spl_boot_device *bootdev)
+{
+	ulong base = spl_get_image_pos();
+	ulong size = spl_get_image_size();
+
+	log_debug("Booting from address %lx size %lx\n", base, size);
+	img->name = spl_phase_name(spl_next_phase());
+	img->load_addr = base;
+	img->entry_point = base;
+
+	return 0;
+}
+SPL_LOAD_IMAGE_METHOD("binman", 0, BOOT_DEVICE_BOARD, binman_load_image);
+
+void reset_cpu(void)
+{
+}
diff --git a/configs/qemu_arm64_tpl_defconfig b/configs/qemu_arm64_tpl_defconfig
new file mode 100644
index 00000000000..f09e357e5cc
--- /dev/null
+++ b/configs/qemu_arm64_tpl_defconfig
@@ -0,0 +1,82 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_ARCH_QEMU=y
+CONFIG_TEXT_BASE=0x13000
+CONFIG_SYS_MALLOC_LEN=0x1000000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
+CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x40200000
+CONFIG_ENV_SIZE=0x40000
+CONFIG_ENV_SECT_SIZE=0x40000
+CONFIG_DEFAULT_DEVICE_TREE="qemu-arm64"
+CONFIG_SPL_TEXT_BASE=0x6000
+CONFIG_TARGET_QEMU_ARM_64BIT_TPL=y
+CONFIG_SPL_BSS_MAX_SIZE=0x10000
+CONFIG_DEBUG_UART_BASE=0x9000000
+CONFIG_DEBUG_UART_CLOCK=0
+CONFIG_ARMV8_CRYPTO=y
+CONFIG_SYS_LOAD_ADDR=0x40200000
+CONFIG_ENV_ADDR=0x4000000
+CONFIG_TPL_MAX_SIZE=0x10000
+CONFIG_PCI=y
+CONFIG_DEBUG_UART=y
+CONFIG_AHCI=y
+CONFIG_EFI_HTTP_BOOT=y
+CONFIG_FIT=y
+CONFIG_FIT_SIGNATURE=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_BEST_MATCH=y
+CONFIG_BOOTSTD_FULL=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_USE_PREBOOT=y
+# CONFIG_PRE_CONSOLE_BUFFER is not set
+# CONFIG_DISPLAY_CPUINFO is not set
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_PCI_INIT_R=y
+CONFIG_SPL_MAX_SIZE=0x10000
+# CONFIG_SPL_SEPARATE_BSS is not set
+CONFIG_CMD_SMBIOS=y
+CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_BOOTEFI_SELFTEST=y
+CONFIG_CMD_NVEDIT_EFI=y
+CONFIG_CMD_DFU=y
+CONFIG_CMD_MTD=y
+CONFIG_CMD_PCI=y
+CONFIG_CMD_EFIDEBUG=y
+CONFIG_CMD_TPM=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_ENV_IS_IN_FLASH=y
+CONFIG_SCSI_AHCI=y
+CONFIG_AHCI_PCI=y
+CONFIG_DFU_TFTP=y
+CONFIG_DFU_MTD=y
+CONFIG_DFU_RAM=y
+# CONFIG_MMC is not set
+CONFIG_MTD=y
+CONFIG_DM_MTD=y
+CONFIG_MTD_NOR_FLASH=y
+CONFIG_FLASH_SHOW_PROGRESS=0
+CONFIG_CFI_FLASH=y
+CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS=y
+CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
+CONFIG_FLASH_CFI_MTD=y
+CONFIG_SYS_FLASH_CFI=y
+CONFIG_SYS_MAX_FLASH_SECT=256
+CONFIG_SYS_MAX_FLASH_BANKS=2
+CONFIG_SYS_MAX_FLASH_BANKS_DETECT=y
+CONFIG_E1000=y
+CONFIG_NVME_PCI=y
+CONFIG_PCIE_ECAM_GENERIC=y
+CONFIG_SCSI=y
+CONFIG_DEBUG_UART_PL011=y
+CONFIG_DEBUG_UART_SHIFT=2
+CONFIG_SYSRESET=y
+CONFIG_SYSRESET_CMD_POWEROFF=y
+CONFIG_SYSRESET_PSCI=y
+CONFIG_TPM2_MMIO=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_PCI=y
+# CONFIG_BINMAN_FDT is not set
+CONFIG_SEMIHOSTING=y
+CONFIG_TPM=y
+CONFIG_TPL_LZ4=y
-- 
2.43.0



More information about the U-Boot mailing list