summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-06 20:27:24 -0600
committerTom Rini <trini@konsulko.com>2022-09-29 22:43:43 -0400
commitb7bd94f1a8a63cd4f947036e0d42ee2e23852d64 (patch)
treecb26f7ac2255dd93940b22859fea9f1b7b34759f
parent2187cb7e4aaae7a4ed7318a073b26dff462cb7a1 (diff)
dm: core: Split ofnode_path_root() into two functions
This function turns out to be a little confusing since it looks up a path and also registers the tree. Split it into two, one that gets the root node and one that looks up a path, so the purpose is clear. Registering the tree will happen in a function to be added in a later patch, called oftree_from_fdt(). Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--boot/vbe_simple.c2
-rw-r--r--drivers/core/ofnode.c42
-rw-r--r--include/dm/ofnode.h16
-rw-r--r--test/boot/vbe_simple.c2
-rw-r--r--test/dm/ofnode.c6
5 files changed, 55 insertions, 13 deletions
diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c
index 0fc57388f3..61b6322ebe 100644
--- a/boot/vbe_simple.c
+++ b/boot/vbe_simple.c
@@ -240,7 +240,7 @@ static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event)
continue;
/* Check if there is a node to fix up */
- node = ofnode_path_root(tree, "/chosen/fwupd");
+ node = oftree_path(tree, "/chosen/fwupd");
if (!ofnode_valid(node))
continue;
node = ofnode_find_subnode(node, dev->name);
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index b1ba8c5ab4..7f6c47f0c0 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -18,6 +18,26 @@
#include <linux/ioport.h>
#include <asm/global_data.h>
+/**
+ * ofnode_from_tree_offset() - get an ofnode from a tree offset (flat tree)
+ *
+ * Looks up the tree and returns an ofnode with the correct of_offset
+ *
+ * If @offset is < 0 then this returns an ofnode with that offset
+ *
+ * @tree: tree to check
+ * @offset: offset within that tree (can be < 0)
+ * @return node for that offset
+ */
+static ofnode ofnode_from_tree_offset(oftree tree, int offset)
+{
+ ofnode node;
+
+ node.of_offset = offset;
+
+ return node;
+}
+
bool ofnode_name_eq(ofnode node, const char *name)
{
const char *node_name;
@@ -640,15 +660,27 @@ ofnode ofnode_path(const char *path)
return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
}
-ofnode ofnode_path_root(oftree tree, const char *path)
+ofnode oftree_root(oftree tree)
{
- if (of_live_active())
+ if (of_live_active()) {
+ return np_to_ofnode(tree.np);
+ } else {
+ return ofnode_from_tree_offset(tree, 0);
+ }
+}
+
+ofnode oftree_path(oftree tree, const char *path)
+{
+ if (of_live_active()) {
return np_to_ofnode(of_find_node_opts_by_path(tree.np, path,
NULL));
- else if (*path != '/' && tree.fdt != gd->fdt_blob)
+ } else if (*path != '/' && tree.fdt != gd->fdt_blob) {
return ofnode_null(); /* Aliases only on control FDT */
- else
- return offset_to_ofnode(fdt_path_offset(tree.fdt, path));
+ } else {
+ int offset = fdt_path_offset(tree.fdt, path);
+
+ return ofnode_from_tree_offset(tree, offset);
+ }
}
const void *ofnode_read_chosen_prop(const char *propname, int *sizep)
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index a53cffbed9..ad179a65e9 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -855,18 +855,28 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
ofnode ofnode_path(const char *path);
/**
- * ofnode_path_root() - find a node by full path from a root node
+ * oftree_path() - find a node by full path from a root node
*
* @tree: Device tree to use
* @path: Full path to node, e.g. "/bus/spi@1"
* Return: reference to the node found. Use ofnode_valid() to check if it exists
*/
-ofnode ofnode_path_root(oftree tree, const char *path);
+ofnode oftree_path(oftree tree, const char *path);
+
+/**
+ * oftree_root() - get the root node of a tree
+ *
+ * @tree: Device tree to use
+ * Return: reference to the root node
+ */
+ofnode oftree_root(oftree tree);
/**
* ofnode_read_chosen_prop() - get the value of a chosen property
*
- * This looks for a property within the /chosen node and returns its value
+ * This looks for a property within the /chosen node and returns its value.
+ *
+ * This only works with the control FDT.
*
* @propname: Property name to look for
* @sizep: Returns size of property, or `FDT_ERR_...` error code if function
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index 2f6979cafc..3f03fc3acd 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -96,7 +96,7 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
fixup.tree.np = np;
ut_assertok(event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup)));
- node = ofnode_path_root(fixup.tree, "/chosen/fwupd/firmware0");
+ node = oftree_path(fixup.tree, "/chosen/fwupd/firmware0");
version = ofnode_read_string(node, "cur-version");
ut_assertnonnull(version);
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index f6bb04642e..b73ab98828 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -532,15 +532,15 @@ static int dm_test_ofnode_root(struct unit_test_state *uts)
ut_assert(oftree_valid(tree));
/* Make sure they don't work on this new tree */
- node = ofnode_path_root(tree, "mmc0");
+ node = oftree_path(tree, "mmc0");
ut_assert(!ofnode_valid(node));
/* It should appear in the new tree */
- node = ofnode_path_root(tree, "/new-mmc");
+ node = oftree_path(tree, "/new-mmc");
ut_assert(ofnode_valid(node));
/* ...and not in the control FDT */
- node = ofnode_path_root(oftree_default(), "/new-mmc");
+ node = oftree_path(oftree_default(), "/new-mmc");
ut_assert(!ofnode_valid(node));
free(root);