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

Reza Arbab arbab at linux.ibm.com
Thu Feb 20 04:17:47 AEDT 2020


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

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



More information about the Pdbg mailing list