mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] boards: qemu-virt: add overlay for when first flash is secure-world only
Date: Fri, 16 Jan 2026 18:15:14 +0100	[thread overview]
Message-ID: <20260116171530.2467685-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260116171530.2467685-1-a.fatoum@pengutronix.de>

When booting with OP-TEE, the first flash will be off-limits when
barebox starts executing and the device tree will have the flash
directly start at 0x4000000.

Detect this case and apply a different device tree overlay that
references only the non-secure flash.

To test this, one needs to prepare a flash image for QEMU with TF-A and
barebox inside a FIP image.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/boards/qemu-virt/Makefile              |   2 +
 common/boards/qemu-virt/board.c               |   9 +-
 .../qemu-virt/qemu-virt-flash-nonsecure.dtso  |   8 ++
 common/boards/qemu-virt/qemu-virt-flash.dtsi  | 105 ++++++++++++++++++
 common/boards/qemu-virt/qemu-virt-flash.dtso  | 100 +----------------
 common/boards/qemu-virt/qemu-virt-flash.h     |   4 +
 6 files changed, 128 insertions(+), 100 deletions(-)
 create mode 100644 common/boards/qemu-virt/qemu-virt-flash-nonsecure.dtso
 create mode 100644 common/boards/qemu-virt/qemu-virt-flash.dtsi

diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
index 457ee5cdc6c9..8d0cf2773402 100644
--- a/common/boards/qemu-virt/Makefile
+++ b/common/boards/qemu-virt/Makefile
@@ -2,11 +2,13 @@
 
 obj-y += board.o commandline.o
 obj-y += qemu-virt-flash.dtbo.o
+obj-$(CONFIG_ARM) += qemu-virt-flash-nonsecure.dtbo.o
 ifeq ($(CONFIG_RISCV),y)
 DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_RISCV
 endif
 ifeq ($(CONFIG_ARM),y)
 DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_ARM
+DTC_CPP_FLAGS_qemu-virt-flash-nonsecure.dtbo := -DCONFIG_ARM
 endif
 
 policy-y += qemu-virt-factory.sconfig
diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c
index 1e3b647f11e5..f2f7beec35db 100644
--- a/common/boards/qemu-virt/board.c
+++ b/common/boards/qemu-virt/board.c
@@ -38,6 +38,7 @@ static inline void arm_virt_init(void) {}
 #endif
 
 extern char __dtbo_qemu_virt_flash_start[];
+extern char __dtbo_qemu_virt_flash_nonsecure_start[];
 
 static const struct of_device_id virt_of_match[] = {
 	{ .compatible = "linux,dummy-virt", .data = arm_virt_init },
@@ -73,8 +74,14 @@ static int virt_board_driver_init(void)
 	 * configurations, where the first flash bank is secure-world only
 	 */
 	flash = of_find_node_by_path(PARTS_TARGET_PATH_STR);
-	if (flash && of_device_is_available(flash))
+	if (flash && of_device_is_available(flash)) {
 		of_overlay_apply_dtbo(root, __dtbo_qemu_virt_flash_start);
+	} else if (IS_ENABLED(CONFIG_ARM)) {
+		flash = of_find_node_by_path("/flash@4000000");
+		if (flash && of_device_is_available(flash))
+			of_overlay_apply_dtbo(root, __dtbo_qemu_virt_flash_nonsecure_start);
+	}
+
 
 	/* fragment may have added aliases to the DT */
 	of_alias_scan();
diff --git a/common/boards/qemu-virt/qemu-virt-flash-nonsecure.dtso b/common/boards/qemu-virt/qemu-virt-flash-nonsecure.dtso
new file mode 100644
index 000000000000..9a0c9442145b
--- /dev/null
+++ b/common/boards/qemu-virt/qemu-virt-flash-nonsecure.dtso
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/dts-v1/;
+/plugin/;
+
+#define USE_NONSECURE_SECOND_FLASH
+
+#include "qemu-virt-flash.dtsi"
diff --git a/common/boards/qemu-virt/qemu-virt-flash.dtsi b/common/boards/qemu-virt/qemu-virt-flash.dtsi
new file mode 100644
index 000000000000..582c213c948e
--- /dev/null
+++ b/common/boards/qemu-virt/qemu-virt-flash.dtsi
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/dts-v1/;
+/plugin/;
+
+#include "qemu-virt-flash.h"
+
+&{PARTS_TARGET_PATH} {
+#ifdef VIRTUAL_REG
+	virtual-reg = <VIRTUAL_REG>;
+#endif
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		partition@0 {
+			label = "initramfs";
+			reg = <0x0 0x3c00000>;
+		};
+
+		environment_flash: partition@3c00000 {
+			label = "barebox-environment";
+			reg = <0x3c00000 0x200000>;
+		};
+
+		backend_state_flash: partition@3e00000 {
+			label = "barebox-state";
+			reg = <0x3e00000 0x200000>;
+		};
+	};
+};
+
+&{/chosen} {
+	environment {
+		compatible = "barebox,environment";
+		device-path = ENV_DEVICE_PATH_STR;
+	};
+};
+
+&{/} {
+	aliases {
+		state = "/state";
+	};
+
+	state {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "barebox,state";
+		magic = <0x290cf8c6>;
+		backend-type = "raw";
+		backend = < &backend_state_flash >;
+		backend-stridesize = <0x200>;
+
+		bootstate {
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			system0 {
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				remaining_attempts@0 {
+					reg = <0x0 0x4>;
+					type = "uint32";
+					default = <3>;
+				};
+
+				priority@4 {
+					reg = <0x4 0x4>;
+					type = "uint32";
+					default = <20>;
+				};
+			};
+
+			system1 {
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				remaining_attempts@8 {
+					reg = <0x8 0x4>;
+					type = "uint32";
+					default = <0>;
+				};
+
+				priority@c {
+					reg = <0xc 0x4>;
+					type = "uint32";
+					default = <0>;
+				};
+			};
+
+			last_chosen@10 {
+				reg = <0x10 0x4>;
+				type = "uint32";
+			};
+
+			attempts_locked@14 {
+				reg = <0x14 0x4>;
+				type = "uint32";
+			};
+		};
+	};
+};
+
diff --git a/common/boards/qemu-virt/qemu-virt-flash.dtso b/common/boards/qemu-virt/qemu-virt-flash.dtso
index 0020ecfcea98..ac9fd34787a6 100644
--- a/common/boards/qemu-virt/qemu-virt-flash.dtso
+++ b/common/boards/qemu-virt/qemu-virt-flash.dtso
@@ -3,102 +3,4 @@
 /dts-v1/;
 /plugin/;
 
-#include "qemu-virt-flash.h"
-
-&{PARTS_TARGET_PATH} {
-#ifdef CONFIG_ARM
-	virtual-reg = <0x1000>;
-#endif
-	partitions {
-		compatible = "fixed-partitions";
-		#address-cells = <1>;
-		#size-cells = <1>;
-
-		partition@0 {
-			label = "initramfs";
-			reg = <0x0 0x3c00000>;
-		};
-
-		environment_flash: partition@3c00000 {
-			label = "barebox-environment";
-			reg = <0x3c00000 0x200000>;
-		};
-
-		backend_state_flash: partition@3e00000 {
-			label = "barebox-state";
-			reg = <0x3e00000 0x200000>;
-		};
-	};
-};
-
-&{/chosen} {
-	environment {
-		compatible = "barebox,environment";
-		device-path = ENV_DEVICE_PATH_STR;
-	};
-};
-
-&{/} {
-	aliases {
-		state = "/state";
-	};
-
-	state {
-		#address-cells = <1>;
-		#size-cells = <1>;
-		compatible = "barebox,state";
-		magic = <0x290cf8c6>;
-		backend-type = "raw";
-		backend = < &backend_state_flash >;
-		backend-stridesize = <0x200>;
-
-		bootstate {
-			#address-cells = <1>;
-			#size-cells = <1>;
-
-			system0 {
-				#address-cells = <1>;
-				#size-cells = <1>;
-
-				remaining_attempts@0 {
-					reg = <0x0 0x4>;
-					type = "uint32";
-					default = <3>;
-				};
-
-				priority@4 {
-					reg = <0x4 0x4>;
-					type = "uint32";
-					default = <20>;
-				};
-			};
-
-			system1 {
-				#address-cells = <1>;
-				#size-cells = <1>;
-
-				remaining_attempts@8 {
-					reg = <0x8 0x4>;
-					type = "uint32";
-					default = <0>;
-				};
-
-				priority@c {
-					reg = <0xc 0x4>;
-					type = "uint32";
-					default = <0>;
-				};
-			};
-
-			last_chosen@10 {
-				reg = <0x10 0x4>;
-				type = "uint32";
-			};
-
-			attempts_locked@14 {
-				reg = <0x14 0x4>;
-				type = "uint32";
-			};
-		};
-	};
-};
+#include "qemu-virt-flash.dtsi"
diff --git a/common/boards/qemu-virt/qemu-virt-flash.h b/common/boards/qemu-virt/qemu-virt-flash.h
index 85f67ff03057..e7c67b8e383a 100644
--- a/common/boards/qemu-virt/qemu-virt-flash.h
+++ b/common/boards/qemu-virt/qemu-virt-flash.h
@@ -8,9 +8,13 @@
 #ifdef CONFIG_RISCV
 #define PARTS_TARGET_PATH	/flash@20000000
 #define ENV_DEVICE_PATH		/flash@20000000/partitions/partition@3c00000
+#elif defined(CONFIG_ARM) && defined(USE_NONSECURE_SECOND_FLASH)
+#define PARTS_TARGET_PATH	/flash@4000000
+#define ENV_DEVICE_PATH		/flash@4000000/partitions/partition@0
 #elif defined CONFIG_ARM
 #define PARTS_TARGET_PATH	/flash@0
 #define ENV_DEVICE_PATH		/flash@0/partitions/partition@3c00000
+#define VIRTUAL_REG		0x1000
 #else
 #define PARTS_TARGET_PATH
 #define ENV_DEVICE_PATH
-- 
2.47.3




  reply	other threads:[~2026-01-16 17:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 17:15 [PATCH 1/2] boards: qemu-virt: drop unused __dtb_fitimage_pubkey_start Ahmad Fatoum
2026-01-16 17:15 ` Ahmad Fatoum [this message]
2026-01-19 12:18 ` Sascha Hauer

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=20260116171530.2467685-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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