mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: fixup reset source device path into DT if known
@ 2024-11-20 14:49 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2024-11-20 14:49 UTC (permalink / raw)
  To: barebox; +Cc: ukleinek, Ahmad Fatoum

The existing code has several shortcomings:

  - reset_source_get_device returns a static variable that's never set
    due to a separate bug, so this could never have worked as-is.

  - A phandle to the barebox internal device tree is not a useful
    information to fix up into the kernel device tree.

  - phandles are unexpected in /chosen. Other chosen bindings use full
    node paths instead (e.g. stdout-path)

Fix this by using the full name of the kernel device tree's node instead.

Fixes: e208e049f98d ("oftree: expose reset_source device in device tree")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/oftree.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index b7762f1a2c57..1e506bbdddaf 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -139,6 +139,27 @@ static int of_fixup_bootargs_bootsource(struct device_node *root,
 	return ret;
 }
 
+static int of_fixup_bootargs_reset_source(struct device_node *root,
+					  struct device_node *chosen)
+{
+	struct device_node *np;
+	struct device *dev;
+	char *name;
+
+	dev = reset_source_get_device();
+	if (!dev || !dev->of_node)
+		return 0;
+
+	name = of_get_reproducible_name(dev->of_node);
+	np = of_find_node_by_reproducible_name(root, name);
+	free(name);
+
+	if (!np)
+		return 0;
+
+	return of_property_write_string(chosen, "reset-source-device", np->full_name);
+}
+
 static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_node *root)
 {
 	int alias_id;
@@ -200,7 +221,6 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 	struct device_node *node;
 	int err;
 	int instance = reset_source_get_instance();
-	struct device *dev;
 	const char *serialno;
 	const char *compat;
 
@@ -227,17 +247,9 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 		of_property_write_u32(node, "reset-source-instance", instance);
 
 
-	dev = reset_source_get_device();
-	if (dev && dev->of_node) {
-		phandle phandle;
-
-		phandle = of_node_create_phandle(dev->of_node);
-
-		err = of_property_write_u32(node,
-					    "reset-source-device", phandle);
-		if (err)
-			return err;
-	}
+	err = of_fixup_bootargs_reset_source(root, node);
+	if (err)
+		return err;
 
 	err = of_fixup_bootargs_bootsource(root, node);
 	if (err)
-- 
2.39.5




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-11-20 14:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-20 14:49 [PATCH] of: fixup reset source device path into DT if known Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox