summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-07-30 15:52:08 -0600
committerTom Rini <trini@konsulko.com>2022-08-12 08:14:23 -0400
commit331048471dee5c1d9cede54382256e6cfaee2370 (patch)
treed12f08911b3f33b1da5ec9970ee1995aef23e6fe /test
parent72b338aa2cd4afff8e92ab28199bc2db073cfea7 (diff)
dm: core: Introduce support for multiple trees
At present ofnode only works with a single device tree, for the most part. This is the control FDT used by U-Boot. When booting an OS we may obtain a different device tree and want to modify it. Add some initial support for this into the ofnode API. Note that we don't permit aliases in this other device tree, since the of_access implementation maintains a list of aliases collected at start-up. Also, we don't need aliases to do fixups in the other FDT. So make sure that flat tree and live tree processing are consistent in this area. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/ofnode.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 61ae1db62d7..6a252f3f504 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -3,6 +3,7 @@
#include <common.h>
#include <dm.h>
#include <log.h>
+#include <of_live.h>
#include <dm/of_extra.h>
#include <dm/test.h>
#include <test/test.h>
@@ -469,3 +470,69 @@ static int dm_test_ofnode_get_phy(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_get_phy, 0);
+
+/**
+ * make_ofnode_fdt() - Create an FDT for testing with ofnode
+ *
+ * The size is set to the minimum needed
+ *
+ * @uts: Test state
+ * @fdt: Place to write FDT
+ * @size: Maximum size of space for fdt
+ */
+static int make_ofnode_fdt(struct unit_test_state *uts, void *fdt, int size)
+{
+ ut_assertok(fdt_create(fdt, size));
+ ut_assertok(fdt_finish_reservemap(fdt));
+ ut_assert(fdt_begin_node(fdt, "") >= 0);
+
+ ut_assert(fdt_begin_node(fdt, "aliases") >= 0);
+ ut_assertok(fdt_property_string(fdt, "mmc0", "/new-mmc"));
+ ut_assertok(fdt_end_node(fdt));
+
+ ut_assert(fdt_begin_node(fdt, "new-mmc") >= 0);
+ ut_assertok(fdt_end_node(fdt));
+
+ ut_assertok(fdt_end_node(fdt));
+ ut_assertok(fdt_finish(fdt));
+
+ return 0;
+}
+
+static int dm_test_ofnode_root(struct unit_test_state *uts)
+{
+ struct device_node *root = NULL;
+ char fdt[256];
+ oftree tree;
+ ofnode node;
+
+ /* Check that aliases work on the control FDT */
+ node = ofnode_get_aliases_node("ethernet3");
+ ut_assert(ofnode_valid(node));
+ ut_asserteq_str("sbe5", ofnode_get_name(node));
+
+ ut_assertok(make_ofnode_fdt(uts, fdt, sizeof(fdt)));
+ if (of_live_active()) {
+ ut_assertok(unflatten_device_tree(fdt, &root));
+ tree.np = root;
+ } else {
+ tree.fdt = fdt;
+ }
+
+ /* Make sure they don't work on this new tree */
+ node = ofnode_path_root(tree, "mmc0");
+ ut_assert(!ofnode_valid(node));
+
+ /* It should appear in the new tree */
+ node = ofnode_path_root(tree, "/new-mmc");
+ ut_assert(ofnode_valid(node));
+
+ /* ...and not in the control FDT */
+ node = ofnode_path_root(oftree_default(), "/new-mmc");
+ ut_assert(!ofnode_valid(node));
+
+ free(root);
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_root, UT_TESTF_SCAN_FDT);