From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: Alistair Francis <alistair.francis@wdc.com>,
David Gibson <david@gibson.dropbear.id.au>,
Daniel Henrique Barboza <danielhb413@gmail.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: [PATCH for-7.2 05/10] hmp, device_tree.c: introduce 'info fdt' command
Date: Fri, 22 Jul 2022 17:00:02 -0300 [thread overview]
Message-ID: <20220722200007.1602174-6-danielhb413@gmail.com> (raw)
In-Reply-To: <20220722200007.1602174-1-danielhb413@gmail.com>
Reading the FDT requires that the user saves the fdt_blob and then use
'dtc' to read the contents. Saving the file and using 'dtc' is a strong
use case when we need to compare two FDTs, but it's a lot of steps if
you want to do quick check on a certain attribute.
'info fdt' retrieves FDT nodes (and properties, later on) and print it
to the user. This can be used to check the FDT on running machines
without having to save the blob and use 'dtc'.
The implementation is based on the premise that the machine thas a FDT
created using libfdt and pointed by 'machine->fdt'. As long as this
pre-requisite is met the machine should be able to support it.
For now we're going to add the required HMP boilerplate and the
capability of printing the name of the properties of a given node. Next
patches will extend 'info fdt' to be able to print nodes recursively.
This is an example of 'info fdt' fetching the '/chosen' node of the
pSeries machine:
(qemu) info fdt /chosen
chosen {
ibm,architecture-vec-5;
rng-seed;
ibm,arch-vec-5-platform-support;
linux,pci-probe-only;
stdout-path;
linux,stdout-path;
qemu,graphic-depth;
qemu,graphic-height;
qemu,graphic-width;
}
And the same node for the aarch64 'virt' machine:
(qemu) info fdt /chosen
chosen {
stdout-path;
rng-seed;
kaslr-seed;
}
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hmp-commands-info.hx | 13 +++++++++++
include/sysemu/device_tree.h | 1 +
monitor/misc.c | 12 ++++++++++
softmmu/device_tree.c | 43 ++++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 3ffa24bd67..abf277be7d 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -908,3 +908,16 @@ SRST
``stats``
Show runtime-collected statistics
ERST
+
+ {
+ .name = "fdt",
+ .args_type = "fullpath:s",
+ .params = "fullpath",
+ .help = "show firmware device tree node given its full path",
+ .cmd = hmp_info_fdt,
+ },
+
+SRST
+ ``info fdt``
+ Show firmware device tree (fdt).
+ERST
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index 1397adb21c..c0f98b1c88 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -124,6 +124,7 @@ int qemu_fdt_add_subnode(void *fdt, const char *name);
int qemu_fdt_add_path(void *fdt, const char *path);
void fdt_save(const char *filename, Error **errp);
+void fdt_info(const char *fullpath, Error **errp);
#define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \
do { \
diff --git a/monitor/misc.c b/monitor/misc.c
index 145285cec0..e709a7de91 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -973,6 +973,18 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
}
}
+static void hmp_info_fdt(Monitor *mon, const QDict *qdict)
+{
+ const char *fullpath = qdict_get_str(qdict, "fullpath");
+ Error *local_err = NULL;
+
+ fdt_info(fullpath, &local_err);
+
+ if (local_err) {
+ error_report_err(local_err);
+ }
+}
+
static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
{
int i;
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index eeab6a5ef0..899c239c5c 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -26,6 +26,7 @@
#include "hw/loader.h"
#include "hw/boards.h"
#include "qemu/config-file.h"
+#include "qemu/qemu-print.h"
#include <libfdt.h>
@@ -661,3 +662,45 @@ void fdt_save(const char *filename, Error **errp)
error_setg(errp, "Error when saving machine FDT to file %s", filename);
}
+
+static void fdt_print_node(int node, int depth)
+{
+ const struct fdt_property *prop = NULL;
+ const char *propname = NULL;
+ void *fdt = current_machine->fdt;
+ int padding = depth * 4;
+ int property = 0;
+ int prop_size;
+
+ qemu_printf("%*s%s {\n", padding, "", fdt_get_name(fdt, node, NULL));
+
+ padding += 4;
+
+ fdt_for_each_property_offset(property, fdt, node) {
+ prop = fdt_get_property_by_offset(fdt, property, &prop_size);
+ propname = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+
+ qemu_printf("%*s%s;\n", padding, "", propname);
+ }
+
+ padding -= 4;
+ qemu_printf("%*s}\n", padding, "");
+}
+
+void fdt_info(const char *fullpath, Error **errp)
+{
+ int node;
+
+ if (!current_machine->fdt) {
+ error_setg(errp, "Unable to find the machine FDT");
+ return;
+ }
+
+ node = fdt_path_offset(current_machine->fdt, fullpath);
+ if (node < 0) {
+ error_setg(errp, "node '%s' not found in FDT", fullpath);
+ return;
+ }
+
+ fdt_print_node(node, 0);
+}
--
2.36.1
next prev parent reply other threads:[~2022-07-22 20:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 19:59 [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands Daniel Henrique Barboza
2022-07-22 19:59 ` [PATCH for-7.2 01/10] hw/arm/boot.c: do not free machine->fdt in arm_load_dtb() Daniel Henrique Barboza
2022-07-22 23:09 ` BALATON Zoltan
2022-07-22 19:59 ` [PATCH for-7.2 02/10] hw/ppc/pegasos2.c: set machine->fdt in machine_reset() Daniel Henrique Barboza
2022-07-22 23:11 ` BALATON Zoltan
2022-07-22 20:00 ` [PATCH for-7.2 03/10] hw/ppc: set machine->fdt in spapr machine Daniel Henrique Barboza
2022-07-22 20:00 ` [PATCH for-7.2 04/10] hmp, device_tree.c: introduce fdt-save Daniel Henrique Barboza
2022-07-22 23:13 ` BALATON Zoltan
2022-07-25 13:17 ` Daniel Henrique Barboza
2022-07-25 12:12 ` Dr. David Alan Gilbert
2022-07-22 20:00 ` Daniel Henrique Barboza [this message]
2022-07-22 20:00 ` [PATCH for-7.2 06/10] device_tree.c: support printing of strings props Daniel Henrique Barboza
2022-07-22 20:00 ` [PATCH for-7.2 07/10] device_tree.c: support remaining FDT prop types Daniel Henrique Barboza
2022-07-22 20:00 ` [PATCH for-7.2 08/10] device_node.c: enable 'info fdt' to print subnodes Daniel Henrique Barboza
2022-07-22 20:00 ` [PATCH for-7.2 09/10] device_tree.c: add fdt_print_property() helper Daniel Henrique Barboza
2022-07-22 20:00 ` [PATCH for-7.2 10/10] hmp, device_tree.c: add 'info fdt <property>' support Daniel Henrique Barboza
2022-07-25 12:28 ` Dr. David Alan Gilbert
2022-07-22 23:16 ` [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands BALATON Zoltan
2022-07-25 9:11 ` Daniel P. Berrangé
2022-07-25 13:16 ` Daniel Henrique Barboza
2022-07-25 14:05 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220722200007.1602174-6-danielhb413@gmail.com \
--to=danielhb413@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=david@gibson.dropbear.id.au \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.