[Pdbg] [PATCH] libpdbg: Parse "compatible" property of fdt nodes

Amitay Isaacs amitay at ozlabs.org
Tue Feb 25 12:33:09 AEDT 2020


On Wed, 2020-02-19 at 11:17 -0600, Reza Arbab wrote:
> Set node->compatible appropriately when parsing the fdt. Otherwise,
> we
> will later fail this assertion:
> 
> Found a POWER9 PPC host system
> dt_expand[559]: FDT: Parsing fdt @0x100370d0
> dt_expand[559]: FDT: Parsing fdt @0x10094330
> Assertion failed: !target_is_virtual(node) (libpdbg/device.c:
> pdbg_targets_init_virtual: 660)
> Aborted

You are hitting that assertion because you are using either the wrong
device tree, or the property "system-path" for wrong node. What device
tree are you using?

Also, we cannot blindly copy the compatible property from device tree. 
For in-memory tree, each target should only have a single compatible
property.  Whereas, in device tree there can be multiple values
specified for compatible property.

> 
> Signed-off-by: Reza Arbab <arbab at linux.ibm.com>
> ---
>  libpdbg/device.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index 66527edc6cf0..73851a0ee27e 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -500,7 +500,7 @@ static enum pdbg_target_status
> str_to_status(const char *status)
>  static int dt_expand_node(struct pdbg_target *node, void *fdt, int
> fdt_node)
>  {
>  	const struct fdt_property *prop;
> -	int offset, nextoffset, err;
> +	int offset, nextoffset, err, len;
>  	struct pdbg_target *child;
>  	const char *name;
>  	uint32_t tag;
> @@ -522,16 +522,19 @@ static int dt_expand_node(struct pdbg_target
> *node, void *fdt, int fdt_node)
>  		case FDT_PROP:
>  			prop = fdt_offset_ptr(fdt, offset, 0);
>  			name = fdt_string(fdt, fdt32_to_cpu(prop-
> >nameoff));
> +			len = fdt32_to_cpu(prop->len);
> +
>  			if (strcmp("index", name) == 0) {
>  				memcpy(&data, prop->data,
> sizeof(data));
>  				node->index = fdt32_to_cpu(data);
> -			}
> -
> -			if (strcmp("status", name) == 0)
> +			} else if (strcmp("status", name) == 0) {
>  				node->status = str_to_status(prop-
> >data);
> +			} else if (strcmp("compatible", name) == 0) {
> +				/* Just use the first string in the
> list */
> +				node->compatible = strndup(prop->data,
> len);
> +			}
>  
> -			dt_add_phandle(node, name, prop->data,
> -					fdt32_to_cpu(prop->len));
> +			dt_add_phandle(node, name, prop->data, len);
>  			break;
>  		case FDT_BEGIN_NODE:
>  			name = fdt_get_name(fdt, offset, NULL);
> -- 
> 2.18.1
> 

Amitay.
-- 

To be without some of the things you want is an indispensible part of
happiness. - Bertrand Russell



More information about the Pdbg mailing list