From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 3/3] boards: qemu-virt: apply state/env overlay only if flash exists
Date: Tue, 22 Aug 2023 09:47:38 +0200 [thread overview]
Message-ID: <20230822074738.3905283-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230822074738.3905283-1-a.fatoum@pengutronix.de>
/flash@0 on ARM64 may not always exist:
- Older Qemu versions place the flash at /soc/flash@0
- With secure=on, /flash@0 is renamed to /secflash@0 and is
off-limits to barebox running in the normal world
Solve both issues by only applying the overlay if the node being
partitioned actually exists and is not disabled in the DT.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/boards/qemu-virt/Makefile | 4 ++--
common/boards/qemu-virt/board.c | 14 ++++++++++---
common/boards/qemu-virt/qemu-virt-flash.dtso | 12 +++--------
common/boards/qemu-virt/qemu-virt-flash.h | 22 ++++++++++++++++++++
4 files changed, 38 insertions(+), 14 deletions(-)
create mode 100644 common/boards/qemu-virt/qemu-virt-flash.h
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
index b6883ff7672e..30bf4f1955ee 100644
--- a/common/boards/qemu-virt/Makefile
+++ b/common/boards/qemu-virt/Makefile
@@ -3,10 +3,10 @@
obj-y += board.o
obj-y += qemu-virt-flash.dtbo.o fitimage-pubkey.dtb.o
ifeq ($(CONFIG_RISCV),y)
-DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DRISCV_VIRT=1
+DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_RISCV
endif
ifeq ($(CONFIG_ARM),y)
-DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DARM_VIRT=1
+DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_ARM
endif
clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c
index 4c6df5e30252..b9df129834d9 100644
--- a/common/boards/qemu-virt/board.c
+++ b/common/boards/qemu-virt/board.c
@@ -7,6 +7,7 @@
#include <init.h>
#include <of.h>
#include <deep-probe.h>
+#include "qemu-virt-flash.h"
#ifdef CONFIG_64BIT
#define MACHINE "virt64"
@@ -53,7 +54,7 @@ BAREBOX_DEEP_PROBE_ENABLE(virt_of_match);
static int virt_board_driver_init(void)
{
struct device_node *root = of_get_root_node();
- struct device_node *overlay, *pubkey;
+ struct device_node *flash, *overlay, *pubkey;
const struct of_device_id *id;
void (*init)(void);
@@ -66,8 +67,15 @@ static int virt_board_driver_init(void)
init();
}
- overlay = of_unflatten_dtb(__dtbo_qemu_virt_flash_start, INT_MAX);
- of_overlay_apply_tree(root, overlay);
+ /*
+ * Catch both old Qemu versions that place /flash in /soc and
+ * 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)) {
+ overlay = of_unflatten_dtb(__dtbo_qemu_virt_flash_start, INT_MAX);
+ of_overlay_apply_tree(root, overlay);
+ }
pubkey = of_unflatten_dtb(__dtb_fitimage_pubkey_start, INT_MAX);
of_merge_nodes(root, pubkey);
diff --git a/common/boards/qemu-virt/qemu-virt-flash.dtso b/common/boards/qemu-virt/qemu-virt-flash.dtso
index 16b1c7923d58..087568a26d2a 100644
--- a/common/boards/qemu-virt/qemu-virt-flash.dtso
+++ b/common/boards/qemu-virt/qemu-virt-flash.dtso
@@ -3,16 +3,10 @@
/dts-v1/;
/plugin/;
-#ifdef RISCV_VIRT
-#define PARTS_TARGET_PATH /flash@20000000
-#define ENV_DEVICE_PATH "/flash@20000000/partitions/partition@3c00000"
-#elif defined ARM_VIRT
-#define PARTS_TARGET_PATH /flash@0
-#define ENV_DEVICE_PATH "/flash@0/partitions/partition@3c00000"
-#endif
+#include "qemu-virt-flash.h"
&{PARTS_TARGET_PATH} {
-#ifdef ARM_VIRT
+#ifdef CONFIG_ARM
virtual-reg = <0x1000>;
#endif
partitions {
@@ -40,7 +34,7 @@ backend_state_flash: partition@3e00000 {
&{/chosen} {
environment {
compatible = "barebox,environment";
- device-path = ENV_DEVICE_PATH;
+ device-path = ENV_DEVICE_PATH_STR;
};
};
diff --git a/common/boards/qemu-virt/qemu-virt-flash.h b/common/boards/qemu-virt/qemu-virt-flash.h
new file mode 100644
index 000000000000..85f67ff03057
--- /dev/null
+++ b/common/boards/qemu-virt/qemu-virt-flash.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __QEMU_VIRT_FLASH_H__
+#define __QEMU_VIRT_FLASH_H__
+
+#include <linux/stringify.h>
+
+#ifdef CONFIG_RISCV
+#define PARTS_TARGET_PATH /flash@20000000
+#define ENV_DEVICE_PATH /flash@20000000/partitions/partition@3c00000
+#elif defined CONFIG_ARM
+#define PARTS_TARGET_PATH /flash@0
+#define ENV_DEVICE_PATH /flash@0/partitions/partition@3c00000
+#else
+#define PARTS_TARGET_PATH
+#define ENV_DEVICE_PATH
+#endif
+
+#define PARTS_TARGET_PATH_STR __stringify(PARTS_TARGET_PATH)
+#define ENV_DEVICE_PATH_STR __stringify(ENV_DEVICE_PATH)
+
+#endif
--
2.39.2
next prev parent reply other threads:[~2023-08-22 7:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 7:47 [PATCH master 1/3] param: drop priv from dev_add_param_string_ro Ahmad Fatoum
2023-08-22 7:47 ` [PATCH master 2/3] restart: fix restart_handler_get_by_name documentation Ahmad Fatoum
2023-08-22 7:47 ` Ahmad Fatoum [this message]
2023-08-22 14:28 ` [PATCH master 1/3] param: drop priv from dev_add_param_string_ro Sascha Hauer
2023-08-22 16:36 ` Ahmad Fatoum
2023-08-23 5:50 ` 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=20230822074738.3905283-3-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