From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: David Dgien <dgienda125@gmail.com>, Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 02/12] ARM: qemu-virt: add image for use as -bios
Date: Thu, 15 Jan 2026 12:54:28 +0100 [thread overview]
Message-ID: <20260115115924.3428886-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260115115924.3428886-1-a.fatoum@barebox.org>
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@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 ++
include/compressed-dtb.h | 1 +
test/arm/virt-el2@multi_v8_defconfig.yaml | 23 +++++++
test/arm/virt@multi_v8_defconfig.yaml | 4 +-
7 files changed, 113 insertions(+), 3 deletions(-)
create mode 100644 arch/arm/boards/qemu-virt/lowlevel.c
create mode 100644 test/arm/virt-el2@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..6397bf165d4c
--- /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;
+ }
+
+ printf("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/include/compressed-dtb.h b/include/compressed-dtb.h
index cc5fbb276984..7441f9f6f650 100644
--- a/include/compressed-dtb.h
+++ b/include/compressed-dtb.h
@@ -5,6 +5,7 @@
#include <linux/types.h>
#include <linux/sizes.h>
#include <asm/unaligned.h>
+#include <fdt.h>
struct barebox_boarddata_compressed_dtb {
#define BAREBOX_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
diff --git a/test/arm/virt-el2@multi_v8_defconfig.yaml b/test/arm/virt-el2@multi_v8_defconfig.yaml
new file mode 100644
index 000000000000..8aa514fb4179
--- /dev/null
+++ b/test/arm/virt-el2@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@multi_v8_defconfig.yaml b/test/arm/virt@multi_v8_defconfig.yaml
index 8aa514fb4179..2e654359709e 100644
--- a/test/arm/virt@multi_v8_defconfig.yaml
+++ b/test/arm/virt@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
next prev parent reply other threads:[~2026-01-15 12:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 11:54 [PATCH 00/12] ARM32: modules: fix bitrot and add test Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 01/12] boards: qemu-virt: reserve BIOS device tree Ahmad Fatoum
2026-01-15 11:54 ` Ahmad Fatoum [this message]
2026-01-16 8:33 ` [PATCH 02/12] ARM: qemu-virt: add image for use as -bios Sascha Hauer
2026-01-16 10:21 ` Ahmad Fatoum
2026-01-16 12:52 ` Ahmad Fatoum
2026-01-16 15:16 ` Sascha Hauer
2026-01-15 11:54 ` [PATCH 03/12] kbuild: build *.mod.c with -std=gnu11 Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 04/12] ARM32: mark modules as incompatible with ARM_MMU_PERMISSIONS Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 05/12] treewide: fix some missing EXPORT_SYMBOL Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 06/12] pci: ecam: enable build as module Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 07/12] kbuild: add support for installing and stripping modules Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 08/12] ARM32: module: handle more relocations Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 09/12] commands: pm_domain: make command tristate Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 10/12] test: conftest: add support for describing FW_CFG environment in YAML Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 11/12] defaultenv: add barebox_modules_env target Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 12/12] test: arm: add simple driver/command module test Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260115115924.3428886-3-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=dgienda125@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox