From a6c4f188948eaf957da8595dd76d947b8bad005a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Jun 2023 10:22:31 -0600 Subject: dm: core: Avoid registering an inaccessible tree At present there are various restrictions on the use of livetree: - It is only available once the tree is unflattened, i.e. after relocation - It is designed to be used with the control FDT - It can (in principle) be used with other FDTs, but only if they are unflattened first; this is not supported Add a few checks to make sure that any tree that is created is actually valid. Otherwise it can be confusing when nodes and properties cannot actually be accessed. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index ec574c44607..1d4ab5bb6f2 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -60,6 +60,11 @@ static oftree oftree_ensure(void *fdt) return oftree_null(); } + if (of_live_active()) { + log_err("Cannot register a flattree when OF_LIVE is active\n"); + return oftree_null(); + } + /* register the new tree */ i = oftree_count++; oftree_list[i] = fdt; @@ -133,6 +138,10 @@ oftree oftree_from_fdt(void *fdt) if (CONFIG_IS_ENABLED(OFNODE_MULTI_TREE)) return oftree_ensure(fdt); +#ifdef OF_CHECKS + if (of_live_active()) + return oftree_null(); +#endif tree.fdt = fdt; return tree; -- cgit v1.2.3 From c8a4e293863348c27d0119cbbe425b91d500cec1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Jun 2023 10:22:41 -0600 Subject: fdt: Clarify the fdt pre-relocation warning Reword this so it is easier to understand. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 1d4ab5bb6f2..dee890b5527 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -72,7 +72,7 @@ static oftree oftree_ensure(void *fdt) } } else { if (fdt != gd->fdt_blob) { - log_debug("Cannot only access control FDT before relocation\n"); + log_debug("Only the control FDT can be accessed before relocation\n"); return oftree_null(); } } -- cgit v1.2.3 From a8f2ac2ae6f15b675a55bcf3a20181f3bb223562 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Jun 2023 10:22:42 -0600 Subject: fdt: Allow more general use of livetree At present livetree can only be used for the control FDT. It is useful to be able to use the ofnode API for other FDTs, e.g. those used by the upcoming configuration editor. We already have most of the support present, and tests can be marked with the UT_TESTF_OTHER_FDT flag to use another FDT as a special case. But with this change, the functionality becomes more generally available. Plumb in the require support. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index dee890b5527..8df16e56af5 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,20 @@ static oftree oftree_ensure(void *fdt) oftree tree; int i; + if (of_live_active()) { + struct device_node *root; + int ret; + + ret = unflatten_device_tree(fdt, &root); + if (ret) { + log_err("Failed to create live tree: err=%d\n", ret); + return oftree_null(); + } + tree = oftree_from_np(root); + + return tree; + } + if (gd->flags & GD_FLG_RELOC) { i = oftree_find(fdt); if (i == -1) { @@ -60,11 +75,6 @@ static oftree oftree_ensure(void *fdt) return oftree_null(); } - if (of_live_active()) { - log_err("Cannot register a flattree when OF_LIVE is active\n"); - return oftree_null(); - } - /* register the new tree */ i = oftree_count++; oftree_list[i] = fdt; @@ -82,6 +92,12 @@ static oftree oftree_ensure(void *fdt) return tree; } +void oftree_dispose(oftree tree) +{ + if (of_live_active()) + of_live_free(tree.np); +} + void *ofnode_lookup_fdt(ofnode node) { if (gd->flags & GD_FLG_RELOC) { -- cgit v1.2.3