device_tree: Match debug output format to dtc -O dts output
This patch updates the device tree dumping functions (not compiled by default but available for debugging) to output properties and nodes in a format similar to .dts files that is very close to what dtc outputs when you decompile a .dtb with it. This makes it easier to match device tree dumps from coreboot with device tree dumps generated by other device tree tooling. This patch was adapted from depthcharge's http://crosreview.com/1536386 Change-Id: Ib40e50d906aff05473a70c4fc9b124d63232558c Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/32867 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
6d5695fac5
commit
0d74653bd4
|
@ -80,21 +80,36 @@ static int dt_prop_is_phandle(struct device_tree_property *prop)
|
||||||
|
|
||||||
static void print_indent(int depth)
|
static void print_indent(int depth)
|
||||||
{
|
{
|
||||||
while (depth--)
|
printk(BIOS_DEBUG, "%*s", depth * 8, "");
|
||||||
printk(BIOS_DEBUG, " ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_property(const struct fdt_property *prop, int depth)
|
static void print_property(const struct fdt_property *prop, int depth)
|
||||||
{
|
{
|
||||||
|
int is_string = prop->size > 0 &&
|
||||||
|
((char *)prop->data)[prop->size - 1] == '\0';
|
||||||
|
|
||||||
|
if (is_string)
|
||||||
|
for (const char *c = prop->data; *c != '\0'; c++)
|
||||||
|
if (!isprint(*c))
|
||||||
|
is_string = 0;
|
||||||
|
|
||||||
print_indent(depth);
|
print_indent(depth);
|
||||||
printk(BIOS_DEBUG, "prop \"%s\" (%d bytes).\n", prop->name, prop->size);
|
if (is_string) {
|
||||||
print_indent(depth + 1);
|
printk(BIOS_DEBUG, "%s = \"%s\";\n",
|
||||||
for (int i = 0; i < MIN(25, prop->size); i++) {
|
prop->name, (const char *)prop->data);
|
||||||
printk(BIOS_DEBUG, "%02x ", ((uint8_t *)prop->data)[i]);
|
} else {
|
||||||
|
printk(BIOS_DEBUG, "%s = < ", prop->name);
|
||||||
|
for (int i = 0; i < MIN(128, prop->size); i += 4) {
|
||||||
|
uint32_t val = 0;
|
||||||
|
for (int j = 0; j < MIN(4, prop->size - i); j++)
|
||||||
|
val |= ((uint8_t *)prop->data)[i + j] <<
|
||||||
|
(24 - j * 8);
|
||||||
|
printk(BIOS_DEBUG, "%#.2x ", val);
|
||||||
|
}
|
||||||
|
if (prop->size > 128)
|
||||||
|
printk(BIOS_DEBUG, "...");
|
||||||
|
printk(BIOS_DEBUG, ">;\n");
|
||||||
}
|
}
|
||||||
if (prop->size > 25)
|
|
||||||
printk(BIOS_DEBUG, "...");
|
|
||||||
printk(BIOS_DEBUG, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
|
static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
|
||||||
|
@ -109,7 +124,7 @@ static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
|
||||||
offset += size;
|
offset += size;
|
||||||
|
|
||||||
print_indent(depth);
|
print_indent(depth);
|
||||||
printk(BIOS_DEBUG, "name = %s\n", name);
|
printk(BIOS_DEBUG, "%s {\n", name);
|
||||||
|
|
||||||
struct fdt_property prop;
|
struct fdt_property prop;
|
||||||
while ((size = fdt_next_property(blob, offset, &prop))) {
|
while ((size = fdt_next_property(blob, offset, &prop))) {
|
||||||
|
@ -118,9 +133,14 @@ static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
|
||||||
offset += size;
|
offset += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printk(BIOS_DEBUG, "\n"); // empty line between props and nodes
|
||||||
|
|
||||||
while ((size = print_flat_node(blob, offset, depth + 1)))
|
while ((size = print_flat_node(blob, offset, depth + 1)))
|
||||||
offset += size;
|
offset += size;
|
||||||
|
|
||||||
|
print_indent(depth);
|
||||||
|
printk(BIOS_DEBUG, "}\n");
|
||||||
|
|
||||||
return offset - start_offset + sizeof(uint32_t);
|
return offset - start_offset + sizeof(uint32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,15 +478,22 @@ void dt_flatten(const struct device_tree *tree, void *start_dest)
|
||||||
static void print_node(const struct device_tree_node *node, int depth)
|
static void print_node(const struct device_tree_node *node, int depth)
|
||||||
{
|
{
|
||||||
print_indent(depth);
|
print_indent(depth);
|
||||||
printk(BIOS_DEBUG, "name = %s\n", node->name);
|
if (depth == 0) // root node has no name, print a starting slash
|
||||||
|
printk(BIOS_DEBUG, "/");
|
||||||
|
printk(BIOS_DEBUG, "%s {\n", node->name);
|
||||||
|
|
||||||
struct device_tree_property *prop;
|
struct device_tree_property *prop;
|
||||||
list_for_each(prop, node->properties, list_node)
|
list_for_each(prop, node->properties, list_node)
|
||||||
print_property(&prop->prop, depth + 1);
|
print_property(&prop->prop, depth + 1);
|
||||||
|
|
||||||
|
printk(BIOS_DEBUG, "\n"); // empty line between props and nodes
|
||||||
|
|
||||||
struct device_tree_node *child;
|
struct device_tree_node *child;
|
||||||
list_for_each(child, node->children, list_node)
|
list_for_each(child, node->children, list_node)
|
||||||
print_node(child, depth + 1);
|
print_node(child, depth + 1);
|
||||||
|
|
||||||
|
print_indent(depth);
|
||||||
|
printk(BIOS_DEBUG, "};\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void dt_print_node(const struct device_tree_node *node)
|
void dt_print_node(const struct device_tree_node *node)
|
||||||
|
|
Loading…
Reference in New Issue