summaryrefslogtreecommitdiff
path: root/lib/libfdt
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-07-02 02:18:32 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:58:42 -0700
commit735004e2151521ea06439b32e6a88b5f65e343f9 (patch)
treec9a14a14abe7970bbb224191e4bb6576af541609 /lib/libfdt
parente6810c3099876d58f0525d592a391ed2031a3298 (diff)
fdt: add sub nodes from a path
BUG=chromium-os:15744 TEST=recompile in user space and run unit tests Change-Id: Ie3d0eb0656650bb36d2daea83a60c4f9f1b15970 Reviewed-on: http://gerrit.chromium.org/gerrit/3571 Tested-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/libfdt')
-rw-r--r--lib/libfdt/fdt_rw.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c
index 5c27a677e35..bc5f60a764a 100644
--- a/lib/libfdt/fdt_rw.c
+++ b/lib/libfdt/fdt_rw.c
@@ -354,6 +354,35 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name)
return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));
}
+int fdt_add_subnodes_from_path(void *fdt, int parentoffset, char *path)
+{
+ int err;
+ char *sep;
+
+ /* skip leading '/' */
+ while (*path == '/')
+ path++;
+
+ /* if sep is NULL, there is no more nodes to add */
+ for (err = parentoffset, sep = path;
+ parentoffset >= 0 && sep && *path;
+ parentoffset = err, path = sep + 1) {
+ sep = strchr(path, '/');
+ if (path == sep) /* repeating '/' */
+ continue;
+
+ if (sep)
+ *sep = '\0';
+ err = fdt_add_subnode(fdt, parentoffset, path);
+ if (err == -FDT_ERR_EXISTS)
+ err = fdt_subnode_offset(fdt, parentoffset, path);
+ if (sep)
+ *sep = '/';
+ }
+
+ return parentoffset;
+}
+
int fdt_del_node(void *fdt, int nodeoffset)
{
int endoffset;