On 8/9/22 21:40, Daniel Henrique Barboza wrote:
To save the FDT blob we have the '-machine dumpdtb=<file>' property.
With this property set, the machine saves the FDT in <file> and exit.
The created file can then be converted to plain text dts format using
'dtc'.
There's nothing particularly sophisticated into saving the FDT that
can't be done with the machine at any state, as long as the machine has
a valid FDT to be saved.
The 'dumpdtb' command receives a 'filename' paramenter and, if a valid
Typo "parameter".
FDT is available, it'll save it in a file 'filename'. In short, this is
a '-machine dumpdtb' that can be fired on demand via QMP/HMP.
A valid FDT consists of a FDT that was created using libfdt being
retrieved via 'current_machine->fdt' in device_tree.c.
This sentence is odd.
This condition is
met by most FDT users in QEMU.
This command will always be executed in-band (i.e. holding BQL),
avoiding potential race conditions with machines that might change the
FDT during runtime (e.g. PowerPC 'pseries' machine).
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Alistair Francis <alistair.francis@wdc.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hmp-commands.hx | 15 +++++++++++++++
include/sysemu/device_tree.h | 1 +
monitor/misc.c | 1 +
qapi/machine.json | 18 ++++++++++++++++++
softmmu/device_tree.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 66 insertions(+)
+void qmp_dumpdtb(const char *filename, Error **errp)
+{
+ g_autoptr(GError) err = NULL;
+ int size;
fdt_totalsize() returns an uint32_t. Maybe use "unsigned" if you
don't want to use uint32_t?
+
+ if (!current_machine->fdt) {
+ error_setg(errp, "This machine doesn't have a FDT");
+ return;
+ }
+
+ size = fdt_totalsize(current_machine->fdt);
assert(size > 0); ?
+
+ if (!g_file_set_contents(filename, current_machine->fdt, size,
&err)) {
+ error_setg(errp, "Error saving FDT to file %s: %s",
+ filename, err->message);
+ }
Eventually:
info_report("Dumped %u bytes of FDT to %s\n", size, filename);
To have a feedback in HMP.
+}
+
+void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
+{
+ const char *filename = qdict_get_str(qdict, "filename");
+ Error *local_err = NULL;
+
+ qmp_dumpdtb(filename, &local_err);
+
+ hmp_handle_error(mon, local_err);
+}
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>