public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware
@ 2026-03-11 13:43 Luigi Leonardi
  2026-03-11 22:24 ` Pierrick Bouvier
  0 siblings, 1 reply; 4+ messages in thread
From: Luigi Leonardi @ 2026-03-11 13:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Pierrick Bouvier, Oliver Steffen, qemu-arm,
	Gerd Hoffmann, Luigi Leonardi

Add a machine property to pass a debug level to EDK2 firmware via the
device tree. The value is set as an "edk2,debug-level" property on all
pl011 UART nodes.

This is to create a runtime parameter to set the verbosity of the debug
log on the serial ports in edk2. Currently, the only way to set the
verbosity is a compile-time option.

DT is used because the fw_cfg interface is not yet initialized in early
boot phases.

Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277

Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
 docs/system/arm/virt.rst |  6 ++++++
 hw/arm/virt.c            | 38 ++++++++++++++++++++++++++++++++++++++
 include/hw/arm/virt.h    |  2 ++
 3 files changed, 46 insertions(+)

diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
index fbe3ca9e129db514aeb7b0bddd6432a818d0a09d..adba8fff2157b62957f6c8770de44faa8449b34d 100644
--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -239,6 +239,12 @@ x-oem-table-id
   Set string (up to 8 bytes) to override the default value of field OEM Table ID
   in ACPI table header.
 
+serial-debug-level
+  Set the EDK2 firmware debug level for serial port output. Valid values are
+  the debug level bitmasks defined in the EDK2
+  `DebugLib.h <https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/DebugLib.h>`_
+  header (e.g. ``0x00400000`` for ``DEBUG_INFO``).
+
 SMMU configuration
 """"""""""""""""""
 
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 7456614d0585af52662c4eb5bb9c4eb76e729a7b..bbea1bb84a4f7613195f5d3fac5fba31a0fb6e89 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -986,6 +986,11 @@ static void create_uart(const VirtMachineState *vms, int uart,
 
     nodename = g_strdup_printf("/pl011@%" PRIx64, base);
     qemu_fdt_add_subnode(ms->fdt, nodename);
+    if (vms->serial_debug_level_set) {
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "edk2,debug-level",
+                              vms->serial_debug_level);
+    }
+
     /* Note that we can't use setprop_string because of the embedded NUL */
     qemu_fdt_setprop(ms->fdt, nodename, "compatible",
                          compat, sizeof(compat));
@@ -2869,6 +2874,31 @@ static void virt_set_dtb_randomness(Object *obj, bool value, Error **errp)
     vms->dtb_randomness = value;
 }
 
+static char *virt_get_serial_debug_level(Object *obj, Error **errp)
+{
+    VirtMachineState *vms = VIRT_MACHINE(obj);
+    return vms->serial_debug_level_set
+        ? g_strdup_printf("0x%" PRIx32, vms->serial_debug_level)
+        : g_strdup("");
+}
+
+static void
+virt_set_serial_debug_level(Object *obj, const char *value, Error **errp)
+{
+    VirtMachineState *vms = VIRT_MACHINE(obj);
+    uint64_t val;
+    int ret;
+
+    ret = qemu_strtou64(value, NULL, 0, &val);
+    if (ret < 0 || val > UINT32_MAX) {
+        error_setg(errp, "invalid serial-debug-level value '%s', "
+                   "must be a uint32 value", value);
+        return;
+    }
+    vms->serial_debug_level = (uint32_t)val;
+    vms->serial_debug_level_set = true;
+}
+
 static char *virt_get_oem_id(Object *obj, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
@@ -3643,6 +3673,12 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
                                           "in ACPI table header."
                                           "The string may be up to 8 bytes in size");
 
+    object_class_property_add_str(oc, "serial-debug-level",
+                                  virt_get_serial_debug_level,
+                                  virt_set_serial_debug_level);
+    object_class_property_set_description(oc, "serial-debug-level",
+                                          "Set the EDK2 firmware debug level bitmask for "
+                                          "serial port output");
 }
 
 static void virt_instance_init(Object *obj)
@@ -3692,6 +3728,8 @@ static void virt_instance_init(Object *obj)
 
     vms->virtio_transports = NUM_VIRTIO_TRANSPORTS;
 
+    vms->serial_debug_level_set = false;
+
     virt_flash_create(vms);
 
     vms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index dba8ac7f2f49fc07a857f8af55786cb0ef960bd2..1dddfa6a11c1309f82c241cb1756a3e8f28a4ad0 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -187,6 +187,8 @@ struct VirtMachineState {
     MemoryRegion *sysmem;
     MemoryRegion *secure_sysmem;
     bool pci_preserve_config;
+    uint32_t serial_debug_level;
+    bool serial_debug_level_set;
 };
 
 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)

---
base-commit: ae56950eac7b61b1abf42003329ee0f3ce111711
change-id: 20260311-edk2_arm_serial-e40226e695eb

Best regards,
-- 
Luigi Leonardi <leonardi@redhat.com>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware
  2026-03-11 13:43 [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware Luigi Leonardi
@ 2026-03-11 22:24 ` Pierrick Bouvier
  2026-03-13 14:31   ` Oliver Steffen
  2026-03-17  8:45   ` Gerd Hoffmann
  0 siblings, 2 replies; 4+ messages in thread
From: Pierrick Bouvier @ 2026-03-11 22:24 UTC (permalink / raw)
  To: Luigi Leonardi, qemu-devel
  Cc: Peter Maydell, Oliver Steffen, qemu-arm, Gerd Hoffmann

Hi Luigi,

On 3/11/26 6:43 AM, Luigi Leonardi wrote:
> Add a machine property to pass a debug level to EDK2 firmware via the
> device tree. The value is set as an "edk2,debug-level" property on all
> pl011 UART nodes.
> 
> This is to create a runtime parameter to set the verbosity of the debug
> log on the serial ports in edk2. Currently, the only way to set the
> verbosity is a compile-time option.
> 
> DT is used because the fw_cfg interface is not yet initialized in early
> boot phases.
> 
> Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
> 
> Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
> ---
>   docs/system/arm/virt.rst |  6 ++++++
>   hw/arm/virt.c            | 38 ++++++++++++++++++++++++++++++++++++++
>   include/hw/arm/virt.h    |  2 ++
>   3 files changed, 46 insertions(+)
> 

I am not sure if maintainer want to have bootloader specific options in 
machine code.

Alternatively, it's possible to dump virt dtb, modify it, and pass it.
$ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb
$ ... modify dt ...
$ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb

It has the advantage to be extensible to any other kind of options you 
want to pass through dtb without needing modification on QEMU itself, 
the downside being that it's less convenient than a command line option.

Regards,
Pierrick


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware
  2026-03-11 22:24 ` Pierrick Bouvier
@ 2026-03-13 14:31   ` Oliver Steffen
  2026-03-17  8:45   ` Gerd Hoffmann
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Steffen @ 2026-03-13 14:31 UTC (permalink / raw)
  To: Pierrick Bouvier
  Cc: Luigi Leonardi, qemu-devel, Peter Maydell, qemu-arm,
	Gerd Hoffmann

On Wed, Mar 11, 2026 at 11:24 PM Pierrick Bouvier
<pierrick.bouvier@linaro.org> wrote:
>
> Hi Luigi,
>
> On 3/11/26 6:43 AM, Luigi Leonardi wrote:
> > Add a machine property to pass a debug level to EDK2 firmware via the
> > device tree. The value is set as an "edk2,debug-level" property on all
> > pl011 UART nodes.
> >
> > This is to create a runtime parameter to set the verbosity of the debug
> > log on the serial ports in edk2. Currently, the only way to set the
> > verbosity is a compile-time option.
> >
> > DT is used because the fw_cfg interface is not yet initialized in early
> > boot phases.
> >
> > Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
> >
> > Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
> > Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
> > ---
> >   docs/system/arm/virt.rst |  6 ++++++
> >   hw/arm/virt.c            | 38 ++++++++++++++++++++++++++++++++++++++
> >   include/hw/arm/virt.h    |  2 ++
> >   3 files changed, 46 insertions(+)
> >
>
> I am not sure if maintainer want to have bootloader specific options in
> machine code.
>
> Alternatively, it's possible to dump virt dtb, modify it, and pass it.
> $ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb

I am sure you meant
qemu-system-aarch64 -M virt -machine dumpdtb=file.dtb

Yes, that works. Thanks for pointing this out.

> $ ... modify dt ...
> $ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb
>
> It has the advantage to be extensible to any other kind of options you
> want to pass through dtb without needing modification on QEMU itself,
> the downside being that it's less convenient than a command line option.
>
> Regards,
> Pierrick
>

Regards,
  Oliver



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware
  2026-03-11 22:24 ` Pierrick Bouvier
  2026-03-13 14:31   ` Oliver Steffen
@ 2026-03-17  8:45   ` Gerd Hoffmann
  1 sibling, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2026-03-17  8:45 UTC (permalink / raw)
  To: Pierrick Bouvier
  Cc: Luigi Leonardi, qemu-devel, Peter Maydell, Oliver Steffen,
	qemu-arm

On Wed, Mar 11, 2026 at 03:24:04PM -0700, Pierrick Bouvier wrote:
> Hi Luigi,
> 
> On 3/11/26 6:43 AM, Luigi Leonardi wrote:
> > Add a machine property to pass a debug level to EDK2 firmware via the
> > device tree. The value is set as an "edk2,debug-level" property on all
> > pl011 UART nodes.
> > 
> > This is to create a runtime parameter to set the verbosity of the debug
> > log on the serial ports in edk2. Currently, the only way to set the
> > verbosity is a compile-time option.
> > 
> > DT is used because the fw_cfg interface is not yet initialized in early
> > boot phases.
> > 
> > Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
> > 
> > Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
> > Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
> > ---
> >   docs/system/arm/virt.rst |  6 ++++++
> >   hw/arm/virt.c            | 38 ++++++++++++++++++++++++++++++++++++++
> >   include/hw/arm/virt.h    |  2 ++
> >   3 files changed, 46 insertions(+)
> > 
> 
> I am not sure if maintainer want to have bootloader specific options in
> machine code.

Does that mean "yes" or "no" or "maybe" ?

Some background:  Traditionally firmware logging in edk2/ArmVirtPkg is a
compile time option, so typically distributions ship two builds, one
with logging turned on and one with logging turned off.

Last year edk2 got support for logging to a memory buffer which can be
accessed from the booted OS or via qemu monitor.  Ideally we have this
always enabled, but without also spamming the serial console with the
firmware log (by default).  While working on that it would be nice to
also get rid of the two builds by moving from a compile time to a
runtime switch for the serial debug log.

> Alternatively, it's possible to dump virt dtb, modify it, and pass it.
> $ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb
> $ ... modify dt ...
> $ ./build/qemu-system-aarch64 -M virt,dtb=file.dtb

I'd like to have something more convenient than that to turn on firmware
debug logging.

On x86 we have a dedicated device for firmware logging (isa-debugcon),
so logging can be easily enabled on the qemu command line by adding that
device.

So the idea here is to have a dt property added to serial port to
setup firmware logging, so we have something roughly comparable to the
x86 functionality ...

take care,
  Gerd



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-17  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 13:43 [PATCH] hw/arm/virt: add serial-debug-level property for EDK2 firmware Luigi Leonardi
2026-03-11 22:24 ` Pierrick Bouvier
2026-03-13 14:31   ` Oliver Steffen
2026-03-17  8:45   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox