]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
libfdt: add convenience function fdt_find_and_setprop()
authorGrant Likely <grant.likely@secretlab.ca>
Thu, 6 Sep 2007 15:46:17 +0000 (09:46 -0600)
committerGrant Likely <grant.likely@secretlab.ca>
Thu, 6 Sep 2007 15:46:17 +0000 (09:46 -0600)
Given the path to a node, fdt_find_and_setprop() allows a property value
to be set directly.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
include/libfdt.h
libfdt/fdt_rw.c

index 340e89d9ce535a5fa72f60a6296841187be6fe9d..38c65a9899e41ff01c63c511f8fc9ecf86d97f2c 100644 (file)
@@ -140,6 +140,8 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
        })
 #define fdt_setprop_string(fdt, nodeoffset, name, str) \
        fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
+int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
+                        const void *val, int len, int create);
 int fdt_delprop(void *fdt, int nodeoffset, const char *name);
 int fdt_add_subnode_namelen(void *fdt, int parentoffset,
                            const char *name, int namelen);
index 693bfe43a263733238c3664bef0999e14a0ef67e..55fcc41d1a2abd2852878b9d9760d17a57998799 100644 (file)
@@ -188,6 +188,32 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
        return 0;
 }
 
+/**
+ * fdt_find_and_setprop: Find a node and set it's property
+ *
+ * @fdt: ptr to device tree
+ * @node: path of node
+ * @prop: property name
+ * @val: ptr to new value
+ * @len: length of new property value
+ * @create: flag to create the property if it doesn't exist
+ *
+ * Convenience function to directly set a property given the path to the node.
+ */
+int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
+                        const void *val, int len, int create)
+{
+       int nodeoff = fdt_find_node_by_path(fdt, node);
+
+       if (nodeoff < 0)
+               return nodeoff;
+
+       if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL))
+               return 0; /* create flag not set; so exit quietly */
+
+       return fdt_setprop(fdt, nodeoff, prop, val, len);
+}
+
 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
 {
        struct fdt_property *prop;