device tree: add add_subnode command
authorAlexander Graf <agraf@suse.de>
Fri, 22 Jul 2011 11:55:37 +0000 (13:55 +0200)
committerAlexander Graf <agraf@suse.de>
Thu, 6 Oct 2011 07:48:00 +0000 (09:48 +0200)
We want to be able to create subnodes in our device tree, so export it through
the qemu device tree abstraction framework.

Signed-off-by: Alexander Graf <agraf@suse.de>
device_tree.c
device_tree.h

index 23e89e3b90286d12c3fbe237f8de7341c600d5a2..f4a78c821735fdbc551b6ba3480fa771f3fdc4d9 100644 (file)
@@ -118,3 +118,27 @@ int qemu_devtree_nop_node(void *fdt, const char *node_path)
 
     return fdt_nop_node(fdt, offset);
 }
+
+int qemu_devtree_add_subnode(void *fdt, const char *name)
+{
+    int offset;
+    char *dupname = g_strdup(name);
+    char *basename = strrchr(dupname, '/');
+    int retval;
+
+    if (!basename) {
+        return -1;
+    }
+
+    basename[0] = '\0';
+    basename++;
+
+    offset = fdt_path_offset(fdt, dupname);
+    if (offset < 0) {
+        return offset;
+    }
+
+    retval = fdt_add_subnode(fdt, offset, basename);
+    g_free(dupname);
+    return retval;
+}
index 76fce5ffb2bba4073f54915fd100a954a99f3e62..4378685b7a9ce3f658a7eeaa4cbad9058fbf33c7 100644 (file)
@@ -23,5 +23,6 @@ int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
 int qemu_devtree_setprop_string(void *fdt, const char *node_path,
                                 const char *property, const char *string);
 int qemu_devtree_nop_node(void *fdt, const char *node_path);
+int qemu_devtree_add_subnode(void *fdt, const char *name);
 
 #endif /* __DEVICE_TREE_H__ */