[PATCH 03/13] ARM: qemu-virt: add image for use as -bios

Ahmad Fatoum a.fatoum at barebox.org
Fri Jan 16 08:06:26 PST 2026


We previously used barebox-dt-2nd.img as image for Qemu Virt.
Adding a dedicated image however allows us to use -kernel to specify,
well, a kernel, which can make some testing scenarios more straight
forward, once we implement support for barebox to lookup -kernel and
-append QEMU options.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 arch/arm/boards/Makefile                |  1 +
 arch/arm/boards/qemu-virt/Makefile      |  2 +-
 arch/arm/boards/qemu-virt/lowlevel.c    | 80 +++++++++++++++++++++++++
 images/Makefile.vexpress                |  5 ++
 test/arm/dt-2nd at multi_v7_defconfig.yaml | 22 +++++++
 test/arm/dt-2nd at multi_v8_defconfig.yaml | 23 +++++++
 test/arm/virt at multi_v7_defconfig.yaml   |  4 +-
 test/arm/virt at multi_v8_defconfig.yaml   |  4 +-
 8 files changed, 136 insertions(+), 5 deletions(-)
 create mode 100644 arch/arm/boards/qemu-virt/lowlevel.c
 create mode 100644 test/arm/dt-2nd at multi_v7_defconfig.yaml
 create mode 100644 test/arm/dt-2nd at multi_v8_defconfig.yaml

diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 4c586de2a985..dd2f2c324e25 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -189,6 +189,7 @@ obj-$(CONFIG_MACH_RK3568_EVB)			+= rockchip-rk3568-evb/
 obj-$(CONFIG_MACH_RK3568_BPI_R2PRO)			+= rockchip-rk3568-bpi-r2pro/
 obj-$(CONFIG_MACH_PINE64_PINETAB2)		+= pine64-pinetab2/
 obj-$(CONFIG_MACH_PINE64_QUARTZ64)		+= pine64-quartz64/
+obj-$(CONFIG_BOARD_ARM_VIRT)			+= qemu-virt/
 obj-$(CONFIG_MACH_RADXA_ROCK3)			+= radxa-rock3/
 obj-$(CONFIG_MACH_RADXA_ROCK5)			+= radxa-rock5/
 obj-$(CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP)	+= variscite-dt8mcustomboard-imx8mp/
diff --git a/arch/arm/boards/qemu-virt/Makefile b/arch/arm/boards/qemu-virt/Makefile
index ad283446eaf1..458f5209008d 100644
--- a/arch/arm/boards/qemu-virt/Makefile
+++ b/arch/arm/boards/qemu-virt/Makefile
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-obj-y += board.o
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/qemu-virt/lowlevel.c b/arch/arm/boards/qemu-virt/lowlevel.c
new file mode 100644
index 000000000000..d6c48e367d08
--- /dev/null
+++ b/arch/arm/boards/qemu-virt/lowlevel.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/sizes.h>
+#include <asm/barebox-arm.h>
+#include <asm/reloc.h>
+#include <compressed-dtb.h>
+#include <debug_ll.h>
+#include <console.h>
+#include <stdio.h>
+#include <debug_ll/pl011.h>
+#include <pbl.h>
+
+#define RAM_BASE	0x40000000
+#define PL011_BASE	IOMEM(0x9000000)
+
+extern char __dtb_qemu_virt32_start[];
+extern char __dtb_qemu_virt64_start[];
+
+static void *find_fdt(void *r0)
+{
+	void *fdt, *ram = (void *)RAM_BASE;
+	const char *origin;
+
+	if (blob_is_fdt(ram)) {
+		origin = "-bios";
+		fdt = ram;
+	} else if (r0 >= ram && blob_is_fdt(r0)) {
+		origin = "-kernel";
+		fdt = r0;
+	} else if (IS_ENABLED(CONFIG_ARM32)) {
+		origin = "built-in";
+		fdt = __dtb_qemu_virt32_start;
+	} else {
+		origin = "built-in";
+		fdt = __dtb_qemu_virt64_start;
+	}
+
+	pr_info("Using %s device tree at %p\n", origin, fdt);
+	return fdt;
+}
+
+/*
+ * Entry point for QEMU virt firmware boot (-bios option).
+ *
+ * Memory layout:
+ *   0x00000000 - 0x08000000: Flash/ROM
+ *   0x08000000 - 0x40000000: Peripherals
+ *   0x40000000 - ...........: RAM
+ */
+static noinline void continue_qemu_virt_bios(ulong r0)
+{
+	ulong membase = RAM_BASE, memsize = SZ_32M - SZ_4M;
+	void *fdt;
+
+	pbl_set_putc(debug_ll_pl011_putc, PL011_BASE);
+
+	/* QEMU may put a DTB at the start of RAM */
+	fdt = find_fdt((void *)r0);
+
+	fdt_find_mem(fdt, &membase, &memsize);
+
+	barebox_arm_entry(membase, memsize, fdt);
+}
+
+ENTRY_FUNCTION_WITHSTACK(start_qemu_virt_bios, RAM_BASE + SZ_32M, r0, r1, r2)
+{
+
+	arm_cpu_lowlevel_init();
+
+	putc_ll('>');
+
+	if (get_pc() >= RAM_BASE)
+		relocate_to_current_adr();
+	else
+		relocate_to_adr_full(RAM_BASE + SZ_4M);
+
+	setup_c();
+
+	continue_qemu_virt_bios(r0);
+}
diff --git a/images/Makefile.vexpress b/images/Makefile.vexpress
index 11c49cca0cbd..81ab8caa4c24 100644
--- a/images/Makefile.vexpress
+++ b/images/Makefile.vexpress
@@ -10,3 +10,8 @@ image-$(CONFIG_MACH_VEXPRESS) += barebox-vexpress-ca9.img
 pblb-$(CONFIG_MACH_VEXPRESS) += start_vexpress_ca15
 FILE_barebox-vexpress-ca15.img = start_vexpress_ca15.pblb
 image-$(CONFIG_MACH_VEXPRESS) += barebox-vexpress-ca15.img
+
+# Firmware image for -bios option
+pblb-$(CONFIG_BOARD_ARM_VIRT) += start_qemu_virt_bios
+FILE_barebox-qemu-virt.img = start_qemu_virt_bios.pblb
+image-$(CONFIG_BOARD_ARM_VIRT) += barebox-qemu-virt.img
diff --git a/test/arm/dt-2nd at multi_v7_defconfig.yaml b/test/arm/dt-2nd at multi_v7_defconfig.yaml
new file mode 100644
index 000000000000..891581205898
--- /dev/null
+++ b/test/arm/dt-2nd at multi_v7_defconfig.yaml
@@ -0,0 +1,22 @@
+targets:
+  main:
+    drivers:
+      QEMUDriver:
+        qemu_bin: qemu-system-arm
+        machine: virt
+        cpu: cortex-a7
+        memory: 1024M
+        kernel: barebox-dt-2nd.img
+        display: qemu-default
+      BareboxDriver:
+        prompt: 'barebox@[^:]+:[^ ]+ '
+        bootstring: 'commandline:'
+      BareboxTestStrategy: {}
+    features:
+      - virtio-mmio
+      - barebox-state
+      - testfs
+images:
+  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
+imports:
+  -  ../strategy.py
diff --git a/test/arm/dt-2nd at multi_v8_defconfig.yaml b/test/arm/dt-2nd at multi_v8_defconfig.yaml
new file mode 100644
index 000000000000..8aa514fb4179
--- /dev/null
+++ b/test/arm/dt-2nd at multi_v8_defconfig.yaml
@@ -0,0 +1,23 @@
+targets:
+  main:
+    drivers:
+      QEMUDriver:
+        qemu_bin: qemu-system-aarch64
+        machine: virt,highmem=off
+        cpu: cortex-a57
+        memory: 1024M
+        kernel: barebox-dt-2nd.img
+        display: qemu-default
+      BareboxDriver:
+        prompt: 'barebox@[^:]+:[^ ]+ '
+        bootstring: 'commandline:'
+      BareboxTestStrategy: {}
+    features:
+      - virtio-mmio
+      - network
+      - barebox-state
+      - testfs
+images:
+  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
+imports:
+  -  ../strategy.py
diff --git a/test/arm/virt at multi_v7_defconfig.yaml b/test/arm/virt at multi_v7_defconfig.yaml
index 891581205898..eef08a5b345b 100644
--- a/test/arm/virt at multi_v7_defconfig.yaml
+++ b/test/arm/virt at multi_v7_defconfig.yaml
@@ -6,7 +6,7 @@ targets:
         machine: virt
         cpu: cortex-a7
         memory: 1024M
-        kernel: barebox-dt-2nd.img
+        bios: barebox-qemu-virt.img
         display: qemu-default
       BareboxDriver:
         prompt: 'barebox@[^:]+:[^ ]+ '
@@ -17,6 +17,6 @@ targets:
       - barebox-state
       - testfs
 images:
-  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
+  barebox-qemu-virt.img: !template "$LG_BUILDDIR/images/barebox-qemu-virt.img"
 imports:
   -  ../strategy.py
diff --git a/test/arm/virt at multi_v8_defconfig.yaml b/test/arm/virt at multi_v8_defconfig.yaml
index 8aa514fb4179..2e654359709e 100644
--- a/test/arm/virt at multi_v8_defconfig.yaml
+++ b/test/arm/virt at multi_v8_defconfig.yaml
@@ -6,7 +6,7 @@ targets:
         machine: virt,highmem=off
         cpu: cortex-a57
         memory: 1024M
-        kernel: barebox-dt-2nd.img
+        bios: barebox-qemu-virt.img
         display: qemu-default
       BareboxDriver:
         prompt: 'barebox@[^:]+:[^ ]+ '
@@ -18,6 +18,6 @@ targets:
       - barebox-state
       - testfs
 images:
-  barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
+  barebox-qemu-virt.img: !template "$LG_BUILDDIR/images/barebox-qemu-virt.img"
 imports:
   -  ../strategy.py
-- 
2.47.3




More information about the barebox mailing list