Thomas Huth <[email protected]> writes:
> Hi!
>
> On 19/02/2026 15.48, Ruslan Ruslichenko wrote:
>> From: Ruslan Ruslichenko <[email protected]>
>> Add new '-hw-dtb' command-line option and corresponding
>> MachineState property.
>> The 'hw-dtb' option allows to specify a Device tree
>> binary with hardware description which Qemu should
>> emulate.
>> Signed-off-by: Ruslan Ruslichenko <[email protected]>
>> ---
>> hw/core/machine.c | 19 +++++++++++++++++++
>> include/hw/core/boards.h | 1 +
>> qemu-options.hx | 9 +++++++++
>> system/vl.c | 3 +++
>> 4 files changed, 32 insertions(+)
>> diff --git a/hw/core/machine.c b/hw/core/machine.c
>> index d4ef620c17..affd24cd49 100644
>> --- a/hw/core/machine.c
>> +++ b/hw/core/machine.c
>> @@ -363,6 +363,20 @@ static void machine_set_dtb(Object *obj, const char
>> *value, Error **errp)
>> ms->dtb = g_strdup(value);
>> }
>> +static char *machine_get_hw_dtb(Object *obj, Error **errp)
>> +{
>> + MachineState *ms = MACHINE(obj);
>> +
>> + return g_strdup(ms->hw_dtb);
>> +}
>> +
>> +static void machine_set_hw_dtb(Object *obj, const char *value, Error **errp)
>> +{
>> + MachineState *ms = MACHINE(obj);
>> +
>> + ms->hw_dtb = g_strdup(value);
>> +}
>> +
>> static char *machine_get_dumpdtb(Object *obj, Error **errp)
>> {
>> MachineState *ms = MACHINE(obj);
>> @@ -1145,6 +1159,11 @@ static void machine_class_init(ObjectClass *oc, const
>> void *data)
>> object_class_property_set_description(oc, "dtb",
>> "Linux kernel device tree file");
>> + object_class_property_add_str(oc, "hw-dtb",
>> + machine_get_hw_dtb, machine_set_hw_dtb);
>> + object_class_property_set_description(oc, "hw-dtb",
>> + "A device tree binary used to describe the hardware to
>> QEMU");
>
> Do the hardware dtbs differ from the ones that are passed to the Linux
> kernel? If not, I think you likely could use the existing "dtb"
> property for your new feature?
They have to - the normal DTB cannot define the whole system because its
only concerned with reporting what the kernel can see to the kernel and
not defining the whole system including what the firmware sees.
>
> ...
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index 33fcfe7ce6..1568f3ce4c 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -4518,6 +4518,15 @@ SRST(initrd)
>> ERST
>> +DEF("hw-dtb", HAS_ARG, QEMU_OPTION_hw_dtb, \
>> + "-hw-dtb file use 'file' as device tree image\n", QEMU_ARCH_ALL)
>> +SRST
>> +``-hw-dtb file``
>> + Use <file> as a device tree binary (dtb) image used to create the
>> + emulated machine. This dtb will not be passed to the kernel, use -dtb
>> + for that.
>> +ERST
>
> Please don't add any new top level options if it is not really
> necessary. We already got too much duplicated logic in QEMU, so we try
> to avoid this nowadays. In your case here, it should be fine to simply
> configure the hw-dtb via the -machine property.
>
> Thanks,
> Thomas
--
Alex Bennée
Virtualisation Tech Lead @ Linaro