mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] bootm: always put a copy into data->of_root_node
@ 2023-09-21 11:04 Sascha Hauer
  2023-09-21 11:04 ` [PATCH 2/2] bootm: fix printing kernel command line Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2023-09-21 11:04 UTC (permalink / raw)
  To: Barebox List

Never put of_get_root_node() directly into data->of_root_node, but
always a copy. With this we can unconditionally free data->of_root_node
in the cleanup path.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 9ec4b127f8..27ada61f4e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -404,10 +404,13 @@ void *bootm_get_devicetree(struct image_data *data)
 		}
 
 	} else {
-		data->of_root_node = of_get_root_node();
-		if (!data->of_root_node)
+		struct device_node *root = of_get_root_node();
+
+		if (!root)
 			return NULL;
 
+		data->of_root_node = of_dup(root);
+
 		if (bootm_verbose(data) > 1 && data->of_root_node)
 			printf("using internal devicetree\n");
 	}
@@ -838,7 +841,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 		elf_close(data->elf);
 	if (IS_ENABLED(CONFIG_FITIMAGE) && data->os_fit)
 		fit_close(data->os_fit);
-	if (data->of_root_node && data->of_root_node != of_get_root_node())
+	if (data->of_root_node)
 		of_delete_node(data->of_root_node);
 
 	globalvar_remove("linux.bootargs.bootm.earlycon");
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] bootm: fix printing kernel command line
  2023-09-21 11:04 [PATCH 1/2] bootm: always put a copy into data->of_root_node Sascha Hauer
@ 2023-09-21 11:04 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-09-21 11:04 UTC (permalink / raw)
  To: Barebox List

Since af084cae41ce ("of: never fixup internal live tree")
of_get_fixed_tree() no longer fixes the tree passed into the function, but a copy thereof
instead. in bootm this has the side effect that data->of_root_node
will no longer contain a fixed tree, but the original tree instead.
data->of_root_node is used later for printing the kernel command line
and it's also printed with bootm -vv, so this pointer should really
hold a fixed tree.
Fix this by not using of_get_fixed_tree() but open coding it.

Fixes: af084cae41ce ("of: never fixup internal live tree")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 27ada61f4e..2469d43441 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -421,7 +421,9 @@ void *bootm_get_devicetree(struct image_data *data)
 		of_add_reserve_entry(data->initrd_res->start, data->initrd_res->end);
 	}
 
-	oftree = of_get_fixed_tree(data->of_root_node);
+	of_fix_tree(data->of_root_node);
+
+	oftree = of_flatten_dtb(data->of_root_node);
 	if (!oftree)
 		return ERR_PTR(-EINVAL);
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-21 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 11:04 [PATCH 1/2] bootm: always put a copy into data->of_root_node Sascha Hauer
2023-09-21 11:04 ` [PATCH 2/2] bootm: fix printing kernel command line Sascha Hauer

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