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>,
	Rouven Czerwinski <r.czerwinski@pengutronix.de>
Subject: [PATCH 4/7] ARM: qemu: enable deep probe support
Date: Thu, 25 Nov 2021 17:10:39 +0100	[thread overview]
Message-ID: <20211125161042.3829996-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20211125161042.3829996-1-a.fatoum@pengutronix.de>

It's a bug to call barebox_register_of at pure_initcall level, because
device tree probe may depend on other initialization done at pure_initcall.
For example, if the QEMU-supplied Virt device tree had a model, barebox
would attempt to register a new global variable before the global device
is even initialized. With the move to deep probe we can just do overlay
fixup in the board driver at safe postcore level.

Fixes: ff8b098a4ad2 ("ARM: qemu: support for state & env via DT overlay")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/qemu-virt/board.c | 37 ++++++-------------------------
 1 file changed, 7 insertions(+), 30 deletions(-)

diff --git a/arch/arm/boards/qemu-virt/board.c b/arch/arm/boards/qemu-virt/board.c
index b2a3cb29ab09..1333687918e1 100644
--- a/arch/arm/boards/qemu-virt/board.c
+++ b/arch/arm/boards/qemu-virt/board.c
@@ -6,8 +6,8 @@
 #include <common.h>
 #include <init.h>
 #include <of.h>
+#include <deep-probe.h>
 #include <asm/system_info.h>
-#include <asm/barebox-arm.h>
 
 #ifdef CONFIG_64BIT
 #define MACHINE "virt64"
@@ -17,38 +17,10 @@
 
 extern char __dtb_overlay_of_flash_start[];
 
-static int replace_dtb(void) {
-	struct device_node *overlay;
-	void *fdt;
-	struct device_node *root;
-
-	fdt = barebox_arm_boot_dtb();
-	if (fdt)
-		pr_debug("using boarddata provided DTB\n");
-
-	if (!fdt) {
-		pr_debug("No DTB found\n");
-		return 0;
-	}
-
-	root = of_unflatten_dtb(fdt, INT_MAX);
-
-	if (!of_device_is_compatible(root, "linux,dummy-virt")) {
-		of_delete_node(root);
-		return 0;
-	}
-
-	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX);
-	of_overlay_apply_tree(root, overlay);
-
-	return barebox_register_of(root);
-}
-
-pure_initcall(replace_dtb);
-
 static int virt_probe(struct device_d *dev)
 {
 	const char *hostname = MACHINE;
+	struct device_node *overlay;
 
 	if (cpu_is_cortex_a7())
 		hostname = "virt-a7";
@@ -58,6 +30,10 @@ static int virt_probe(struct device_d *dev)
 	barebox_set_model("ARM QEMU " MACHINE);
 	barebox_set_hostname(hostname);
 
+	overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX);
+	of_overlay_apply_tree(dev->device_node, overlay);
+	/* of_probe() will happen later at of_populate_initcall */
+
 	return 0;
 }
 
@@ -65,6 +41,7 @@ static const struct of_device_id virt_of_match[] = {
 	{ .compatible = "linux,dummy-virt" },
 	{ /* Sentinel */},
 };
+BAREBOX_DEEP_PROBE_ENABLE(virt_of_match);
 
 static struct driver_d virt_board_driver = {
 	.name = "board-qemu-virt",
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-11-25 16:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25 16:10 [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 1/7] state: mark state init errors specially Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 2/7] state: make first boot less verbose Ahmad Fatoum
2021-11-30 10:47   ` Sascha Hauer
2021-11-30 13:52     ` Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 3/7] of: overlay: rescan aliases calling of_overlay_apply_tree on live tree Ahmad Fatoum
2021-11-25 16:10 ` Ahmad Fatoum [this message]
2021-11-25 16:10 ` [PATCH 5/7] ARM: qemu: move board code to central location Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 6/7] common: boards: qemu-virt: genericize to support non-ARM architectures Ahmad Fatoum
2021-11-25 16:10 ` [PATCH 7/7] RISC-V: qemu-virt: add overlay for environment and state Ahmad Fatoum
2021-12-07 14:04 ` [PATCH 0/7] ARM/RISC-V: qemu-virt: share common cleaned up state/env support 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=20211125161042.3829996-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=r.czerwinski@pengutronix.de \
    /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