[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 29/38] qmp/hmp, device_tree.c: introduce dumpdtb
From: |
Daniel Henrique Barboza |
Subject: |
[PULL 29/38] qmp/hmp, device_tree.c: introduce dumpdtb |
Date: |
Mon, 17 Oct 2022 16:20:00 -0300 |
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' parameter and, if the FDT is
available via current_machine->fdt, save it in dtb format to 'filename'.
In short, this is a '-machine dumpdtb' that can be fired on demand via
QMP/HMP.
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>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20220926173855.1159396-2-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 | 37 ++++++++++++++++++++++++++++++++++++
5 files changed, 72 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 8ab8000acd..12b6d4e2dc 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1800,3 +1800,18 @@ ERST
.sub_table = hmp_info_cmds,
.flags = "p",
},
+
+#if defined(CONFIG_FDT)
+ {
+ .name = "dumpdtb",
+ .args_type = "filename:F",
+ .params = "filename",
+ .help = "dump the FDT in dtb format to 'filename'",
+ .cmd = hmp_dumpdtb,
+ },
+
+SRST
+``dumpdtb`` *filename*
+ Dump the FDT in dtb format to *filename*.
+ERST
+#endif
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index ef060a9759..e7c5441f56 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -136,6 +136,7 @@ int qemu_fdt_add_path(void *fdt, const char *path);
} while (0)
void qemu_fdt_dumpdtb(void *fdt, int size);
+void hmp_dumpdtb(Monitor *mon, const QDict *qdict);
/**
* qemu_fdt_setprop_sized_cells_from_array:
diff --git a/monitor/misc.c b/monitor/misc.c
index 6436a8786b..205487e2b9 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -49,6 +49,7 @@
#include "sysemu/blockdev.h"
#include "sysemu/sysemu.h"
#include "sysemu/tpm.h"
+#include "sysemu/device_tree.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qstring.h"
diff --git a/qapi/machine.json b/qapi/machine.json
index abb2f48808..b9228a5e46 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1664,3 +1664,21 @@
'*size': 'size',
'*max-size': 'size',
'*slots': 'uint64' } }
+
+##
+# @dumpdtb:
+#
+# Save the FDT in dtb format.
+#
+# @filename: name of the dtb file to be created
+#
+# Since: 7.2
+#
+# Example:
+# {"execute": "dumpdtb"}
+# "arguments": { "filename": "fdt.dtb" } }
+#
+##
+{ 'command': 'dumpdtb',
+ 'data': { 'filename': 'str' },
+ 'if': 'CONFIG_FDT' }
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 6ca3fad285..ce74f3d48d 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -26,6 +26,9 @@
#include "hw/loader.h"
#include "hw/boards.h"
#include "qemu/config-file.h"
+#include "qapi/qapi-commands-machine.h"
+#include "qapi/qmp/qdict.h"
+#include "monitor/hmp.h"
#include <libfdt.h>
@@ -643,3 +646,37 @@ out:
g_free(propcells);
return ret;
}
+
+void qmp_dumpdtb(const char *filename, Error **errp)
+{
+ g_autoptr(GError) err = NULL;
+ uint32_t size;
+
+ if (!current_machine->fdt) {
+ error_setg(errp, "This machine doesn't have a FDT");
+ return;
+ }
+
+ size = fdt_totalsize(current_machine->fdt);
+
+ g_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);
+ }
+}
+
+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);
+
+ if (hmp_handle_error(mon, local_err)) {
+ return;
+ }
+
+ info_report("dtb dumped to %s", filename);
+}
--
2.37.3
- [PULL 14/38] ppc440_sdram: Rename local variable for readability, (continued)
- [PULL 14/38] ppc440_sdram: Rename local variable for readability, Daniel Henrique Barboza, 2022/10/17
- [PULL 18/38] ppc440_uc.c: Move some macros to ppc4xx.h, Daniel Henrique Barboza, 2022/10/17
- [PULL 16/38] ppc440_sdram: Move RAM size check to ppc440_sdram_init, Daniel Henrique Barboza, 2022/10/17
- [PULL 17/38] ppc440_sdram: QOM'ify, Daniel Henrique Barboza, 2022/10/17
- [PULL 26/38] hw/ppc/e500: Remove if statement which is now always true, Daniel Henrique Barboza, 2022/10/17
- [PULL 22/38] docs/system/ppc/ppce500: Add heading for networking chapter, Daniel Henrique Barboza, 2022/10/17
- [PULL 27/38] target/ppc: Fix xvcmp* clearing FI bit, Daniel Henrique Barboza, 2022/10/17
- [PULL 19/38] ppc440_uc.c: Remove unneeded parenthesis, Daniel Henrique Barboza, 2022/10/17
- [PULL 20/38] hw/ppc/meson: Allow e500 boards to be enabled separately, Daniel Henrique Barboza, 2022/10/17
- [PULL 21/38] hw/gpio/meson: Introduce dedicated config switch for hw/gpio/mpc8xxx, Daniel Henrique Barboza, 2022/10/17
- [PULL 29/38] qmp/hmp, device_tree.c: introduce dumpdtb,
Daniel Henrique Barboza <=
- [PULL 31/38] hw/ppc: set machine->fdt in bamboo_load_device_tree(), Daniel Henrique Barboza, 2022/10/17
- [PULL 23/38] hw/ppc/e500: Reduce usage of sysbus API, Daniel Henrique Barboza, 2022/10/17
- [PULL 25/38] hw/ppc/mpc8544ds: Add platform bus, Daniel Henrique Barboza, 2022/10/17
- [PULL 24/38] hw/ppc/mpc8544ds: Rename wrongly named method, Daniel Henrique Barboza, 2022/10/17
- [PULL 33/38] hw/ppc: set machine->fdt in xilinx_load_device_tree(), Daniel Henrique Barboza, 2022/10/17
- [PULL 35/38] hw/ppc: set machine->fdt in pnv_reset(), Daniel Henrique Barboza, 2022/10/17
- [PULL 28/38] hw/ppc/spapr_pci.c: Use device_cold_reset() rather than device_legacy_reset(), Daniel Henrique Barboza, 2022/10/17
- [PULL 30/38] hw/nios2: set machine->fdt in nios2_load_dtb(), Daniel Henrique Barboza, 2022/10/17
- [PULL 32/38] hw/ppc: set machine->fdt in sam460ex_load_device_tree(), Daniel Henrique Barboza, 2022/10/17
- [PULL 34/38] hw/ppc: set machine->fdt in pegasos2_machine_reset(), Daniel Henrique Barboza, 2022/10/17