[Pdbg] [PATCH v2 07/22] libpdbg: Create virtual nodes based on system-path property

Amitay Isaacs amitay at ozlabs.org
Mon Sep 23 16:30:45 AEST 2019


On Mon, 2019-09-23 at 11:58 +1000, Alistair Popple wrote:
> I still think making link_vnode a separate function as well would
> have made 
> things marginally easier to follow but this isn't hard to follow so:

Sure.  I will separate the code linking node and virtual node.

> 
> Reviewed-by: Alistair Popple <alistair at popple.id.au>
> 
> On Friday, 20 September 2019 3:16:36 PM AEST Amitay Isaacs wrote:
> > To create a virtual node, "system-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 | 83
> > ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 83 insertions(+)
> > 
> > diff --git a/libpdbg/device.c b/libpdbg/device.c
> > index 9cb2a0a..77eac21 100644
> > --- a/libpdbg/device.c
> > +++ b/libpdbg/device.c
> > @@ -649,6 +649,88 @@ uint64_t pdbg_target_address(struct
> > pdbg_target 
> *target, uint64_t *out_size)
> >  	return dt_get_number(p->prop, na);
> >  }
> >  
> > +static struct pdbg_target *dt_new_virtual(struct pdbg_target
> > *root, const 
> char *system_path)
> > +{
> > +	char *parent_path, *sep;
> > +	struct pdbg_target *parent, *vnode;
> > +
> > +	parent_path = strdup(system_path);
> > +	assert(parent_path);
> > +
> > +	sep = strrchr(parent_path, '/');
> > +	if (!sep || sep[1] == '\0') {
> > +		PR_ERROR("Invalid path reference \"%s\"\n",
> > system_path);
> > +		free(parent_path);
> > +		return NULL;
> > +	}
> > +
> > +	*sep = '\0';
> > +
> > +	parent = dt_find_by_path(root, parent_path);
> > +	if (!parent) {
> > +		PR_ERROR("Invalid path reference \"%s\"\n",
> > system_path);
> > +		free(parent_path);
> > +		return NULL;
> > +	}
> > +
> > +	vnode = dt_new_node(sep+1, NULL, 0);
> > +	assert(vnode);
> > +
> > +	free(parent_path);
> > +
> > +	if (!dt_attach_node(parent, vnode)) {
> > +		free(vnode);
> > +		return NULL;
> > +	}
> > +
> > +	PR_DEBUG("Created virtual node %s\n", system_path);
> > +	return vnode;
> > +}
> > +
> > +static void pdbg_targets_init_virtual(struct pdbg_target *node,
> > struct 
> pdbg_target *root)
> > +{
> > +	struct pdbg_target *vnode, *child = NULL;
> > +	struct dt_property *prop;
> > +	const char *system_path;
> > +	size_t len;
> > +
> > +	system_path = (const char *)pdbg_target_property(node, "system-
> > path", 
> &len);
> > +	if (!system_path)
> > +		goto skip;
> > +
> > +	/*
> > +	 * If the virtual node exists,
> > +	 *   - if it is already linked, skip
> > +	 *   - else link the node
> > +	 */
> > +	vnode = dt_find_by_path(root, system_path);
> > +	if (vnode) {
> > +		if (vnode->vnode)
> > +			goto skip;
> > +		else
> > +			goto link_vnode;
> > +	}
> > +
> > +	vnode = dt_new_virtual(root, system_path);
> > +	if (!vnode)
> > +		goto skip;
> > +
> > +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 +745,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)
> > 
> 
> 
> 

Amitay.
-- 

Fathers are pals nowadays because they don't have the guts to be fathers.



More information about the Pdbg mailing list