On Tue, Aug 16, 2022 at 02:34:26PM -0300, Daniel Henrique Barboza wrote:
> Printing subnodes of a given node will allow us to show a whole subtree,
> which the additional perk of 'info fdt /' being able to print the whole
> FDT.
>
> Since we're now printing more than one subnode, change 'fdt_info' to
> print the full path of the first node. This small tweak helps
> identifying which node or subnode are being displayed.
>
> To demostrate this capability without printing the whole FDT, the
> '/cpus/cpu-map' node from the ARM 'virt' machine has a lot of subnodes:
>
> (qemu) info fdt /cpus/cpu-map
> /cpus/cpu-map {
> socket0 {
> cluster0 {
> core0 {
> cpu = <0x8001>
> }
> }
> }
> }
nit: dts format requires a ; after each closing }
foo {
bar {
};
};
> Signed-off-by: Daniel Henrique Barboza
> ---
> softmmu/device_tree.c | 21 +
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
> index 43f96e371b..a6bfbc0617 100644
> --- a/softmmu/device_tree.c
> +++ b/softmmu/device_tree.c
> @@ -766,17 +766,26 @@ static void fdt_prop_format_val(GString *buf, const
> char *propname,
> g_string_append_printf(buf, "];\n");
> }
>
> -static void fdt_format_node(GString *buf, int node, int depth)
> +
> +static void fdt_format_node(GString *buf, int node, int depth,
> +const char *fullpath)
> {
> const struct fdt_property *prop = NULL;
> +const char *nodename = NULL;
> const char *propname = NULL;
> void *fdt = current_machine->fdt;
> int padding = depth * 4;
> int property = 0;
> +int parent = node;
> int prop_size;
>
> -g_string_append_printf(buf, "%*s%s {\n", padding, "",
> - fdt_get_name(fdt, node, NULL));
> +if (fullpath != NULL) {
> +nodename = fullpath;
> +} else {
> +nodename = fdt_get_name(fdt, node, NULL);
> +}
> +
> +g_string_append_printf(buf, "%*s%s {\n", padding, "", nodename);
>
> padding += 4;
>
> @@ -801,6 +810,10 @@ static void fdt_format_node(GString *buf, int node, int
> depth)
> }
> }
>
> +fdt_for_each_subnode(node, fdt, parent) {
> +fdt_format_node(buf, node, depth + 1, NULL);
> +}
> +
> padding -= 4;
> g_string_append_printf(buf, "%*s}\n", padding, "");
> }
> @@ -821,7 +834,7 @@ HumanReadableText *qemu_fdt_qmp_query_fdt(const char
> *nodepath, Error **errp)
> return NULL;
> }
>
> -fdt_format_node(buf, node, 0);
> +fdt_format_node(buf, node, 0, nodepath);
>
> return human_readable_text_from_str(buf);
> }
--
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature