[Pdbg] [PATCH 07/23] libpdbg: Create virtual nodes based on device-tree-path property

Amitay Isaacs amitay at ozlabs.org
Thu Sep 19 12:33:17 AEST 2019


To create a virtual node, "device-tree-path" property is used to denote
the attachment point in the system device tree view.

It's also possible to create virtual nodes from backend device tree as
nodes without compatible property.

All nodes without "compatible" property will be treated as virtual
nodes.

Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/device.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/libpdbg/device.c b/libpdbg/device.c
index ce88609..4160ea8 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -649,6 +649,75 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size)
 	return dt_get_number(p->prop, na);
 }
 
+static void pdbg_targets_init_virtual(struct pdbg_target *node, struct pdbg_target *root)
+{
+	struct pdbg_target *vnode, *parent, *child = NULL;
+	struct dt_property *prop;
+	const char *dtree_path;
+	char *parent_path, *sep;
+	size_t len;
+
+	dtree_path = (const char *)pdbg_target_property(node, "device-tree-path", &len);
+	if (!dtree_path)
+		goto skip;
+
+	vnode = dt_find_by_path(root, dtree_path);
+	if (vnode) {
+		if (vnode->vnode)
+			goto skip;
+		else
+			goto link_vnode;
+	}
+
+	parent_path = strdup(dtree_path);
+	assert(parent_path);
+
+	sep = strrchr(parent_path, '/');
+	if (!sep || sep[1] == '\0') {
+		char *path = dt_get_path(node);
+		PR_ERROR("Invalid path reference \"%s\" for node %s\n", dtree_path, path);
+		free(path);
+		free(parent_path);
+		goto skip;
+	}
+
+	*sep = '\0';
+
+	parent = dt_find_by_path(root, parent_path);
+	if (!parent) {
+		char *path = dt_get_path(node);
+		PR_ERROR("Invalid path reference \"%s\" for node %s\n", dtree_path, path);
+		free(path);
+		free(parent_path);
+		goto skip;
+	}
+
+	vnode = dt_new_node(sep+1, NULL, 0);
+	assert(vnode);
+
+	free(parent_path);
+
+	if (!dt_attach_node(parent, vnode))
+		goto skip;
+
+	PR_DEBUG("Created virtual node %s\n", dtree_path);
+
+link_vnode:
+	node->vnode = vnode;
+	vnode->vnode = node;
+
+	while ((prop = list_pop(&vnode->properties, struct dt_property, list)))
+		list_add_tail(&node->properties, &prop->list);
+
+skip:
+	list_for_each(&node->children, child, list) {
+		if (child->vnode && !child->compatible)
+			continue;
+
+		pdbg_targets_init_virtual(child, root);
+	}
+}
+
 void pdbg_targets_init(void *fdt)
 {
 	/* Root node needs to be valid when this function returns */
@@ -663,6 +732,7 @@ void pdbg_targets_init(void *fdt)
 	}
 
 	dt_expand(pdbg_dt_root, fdt);
+	pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);
 }
 
 char *pdbg_target_path(struct pdbg_target *target)
-- 
2.21.0



More information about the Pdbg mailing list