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);
#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;
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)
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
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);
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);