]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Avoid registering an inaccessible tree
authorSimon Glass <sjg@chromium.org>
Thu, 1 Jun 2023 16:22:31 +0000 (10:22 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 14 Jul 2023 16:54:50 +0000 (12:54 -0400)
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 <sjg@chromium.org>
drivers/core/ofnode.c

index ec574c4460790af132e288b064555d3122f7cba7..1d4ab5bb6f2fe9aee40a9324171d44d35b21a21c 100644 (file)
@@ -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;