We originally implemented '-machine dumpdtb' in a fairly ad-hoc way:
every machine using FDT is supposed to call qemu_fdt_dumpdtb() once
it has finished creating and modifying the DTB; if the user passed in
the machine option then qemu_fdt_dumpdtb() will write the FDT to a
file and then exit QEMU.
Somewhat later we implemented the QMP and HMP dumpdtb commands; for
these to work we had to make all the FDT-using machines set
MachineState::fdt to point to the FDT blob.
This means we can clean up the handling of the -machine option, so we
can implement it in one place in machine.c. The benefit of this is:
* boards only need to do one thing, not two
* we can have better error messages for the "user asked us to
dump the DTB but this board doesn't have one" case
(In particular the bug report
https://gitlab.com/qemu-project/qemu/-/issues/2733
is essentially because we silently ignore the option if there
is no DTB to dump.)
The openrisc machines and the MIPS boston machine both were not
setting MachineState::fdt, so the HMP/QMP dumpdtb don't work for
those machines; the series starts by fixing those bugs. Then we can
implement the centralized handling of the machine option. Finally we
get to fix the "no error message" problem:
$ qemu-system-aarch64 -M raspi4b,dumpdtb=/tmp/d.dtb
qemu-system-aarch64: This machine doesn't have an FDT
(Perhaps it doesn't support FDT at all, or perhaps you need to
provide an FDT with the -fdt option?)
The fact that there are three places that report "this machine
doesn't have an FDT" is a bit of a wart, stemming largely from the
fact that the QMP dumpdtb command is only conditionally present if
CONFIG_FDT. In theory we could make it unconditional, but I opted to
leave that can of worms for another day...
thanks
-- PMM
Peter Maydell (6):
monitor/hmp-cmds.c: Clean up hmp_dumpdtb printf
hw/openrisc: Support monitor dumpdtb command
hw/mips/boston: Check for error return from boston_fdt_filter()
hw/mips/boston: Support dumpdtb monitor commands
hw: Centralize handling of -machine dumpdtb option
hw/core/machine.c: Make -machine dumpdtb=file.dtb with no DTB an error
include/hw/loader-fit.h | 21 +++++++++++++++++---
include/hw/openrisc/boot.h | 3 ++-
include/system/device_tree.h | 2 --
hw/arm/boot.c | 2 --
hw/core/loader-fit.c | 38 ++++++++++++++++++++----------------
hw/core/machine.c | 23 ++++++++++++++++++++++
hw/loongarch/virt.c | 1 -
hw/mips/boston.c | 16 ++++++++++-----
hw/openrisc/boot.c | 8 +++++---
hw/openrisc/openrisc_sim.c | 2 +-
hw/openrisc/virt.c | 2 +-
hw/ppc/e500.c | 1 -
hw/ppc/pegasos2.c | 1 -
hw/ppc/pnv.c | 1 -
hw/ppc/spapr.c | 1 -
hw/riscv/boot.c | 2 --
monitor/hmp-cmds.c | 2 +-
system/device_tree-stub.c | 5 ++++-
system/device_tree.c | 22 ++++++---------------
19 files changed, 93 insertions(+), 60 deletions(-)
--
2.34.1