hw/arm/virt: add serial-debug-level property for EDK2 firmware
PATCH 1/1 hw/arm/virt: add serial-debug-level property for EDK2 firmware
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
--- docs/system/arm/virt.rst | 6 ++++++ hw/arm/virt.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 46 insertions(+)
docs/system/arm/virt.rst +6 -0
@@ -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 """"""""""""""""""
hw/arm/virt.c +38 -0
@@ -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 );
include/hw/arm/virt.h +2 -0
@@ -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,
Signature · 1 line
Luigi Leonardi <[email protected]>
Hi Luigi,
Quoted 13 lines · 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_cfginterface is not yet initialized in early boot phases.Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
Quoted 8 lines
Suggested-by Gerd Hoffmann <[email protected]>Signed-off-by Luigi Leonardi <[email protected]>--- 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
Quoted 26 lines · Pierrick Bouvier
Hi Luigi,
Quoted 13 lines · 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_cfginterface is not yet initialized in early boot phases.Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
Quoted 8 lines
Suggested-by Gerd Hoffmann <[email protected]>Signed-off-by Luigi Leonardi <[email protected]>--- docs/system/arm/virt.rst | 6 ++++++ hw/arm/virt.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 46 insertions(+)
Quoted 5 lines
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.
Quoted 10 lines
$ ... modify dt ... $ ./build/qemu-system-aarch64 -M virt,dtb=file.dtbIt 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
Quoted 25 lines · Pierrick Bouvier
Hi Luigi,
Quoted 13 lines · 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_cfginterface is not yet initialized in early boot phases.Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
Quoted 8 lines
Suggested-by Gerd Hoffmann <[email protected]>Signed-off-by Luigi Leonardi <[email protected]>--- docs/system/arm/virt.rst | 6 ++++++ hw/arm/virt.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 46 insertions(+)
Quoted 2 lines
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.
Quoted 4 lines
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
Quoted 51 lines · Gerd Hoffmann
Quoted 25 lines · Pierrick Bouvier
Hi Luigi,
Quoted 13 lines · 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_cfginterface is not yet initialized in early boot phases.Corresponding edk2 PR: https://github.com/tianocore/edk2/pull/12277
Quoted 8 lines
Suggested-by Gerd Hoffmann <[email protected]>Signed-off-by Luigi Leonardi <[email protected]>--- docs/system/arm/virt.rst | 6 ++++++ hw/arm/virt.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 46 insertions(+)Quoted 2 lines
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.
Quoted 4 lines
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.dtbI'd like to have something more convenient than that to turn on firmware debug logging.
Quoted 7 lines
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 ...
My rough rule of thumb for DT properties is "if it is a binding officially documented in the binding specs in the kernel with the relevant semantics, then OK"; but not ad-hoc bootloader specific stuff (we have turned down requests from u-boot for that in the past).
Would using the fw_cfg mechanism work here? That's intended for passing configuration info (and "how verbose should debug be" seems like configuration info), and we already have a command line interface for it:
-fw_cfg name=edk2/debug-level,string=1
(or whatever). You could also then use the same mechanism for x86.
-- PMM
Hi,
Quoted 17 lines
Quoted 10 lines
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 ...
My rough rule of thumb for DT properties is "if it is a binding officially documented in the binding specs in the kernel with the relevant semantics, then OK"; but not ad-hoc bootloader specific stuff (we have turned down requests from u-boot for that in the past).
Quoted 6 lines
Would using the
fw_cfgmechanism work here? That's intended for passing configuration info (and "how verbose should debug be" seems like configuration info), and we already have a command line interface for it:
-fw_cfg name=edk2/debug-level,string=1
(or whatever).
I'd very much prefer to use device tree. A device property is maybe not the best choice. There is this /chosen node though which is already used to pass around guest configuration information (kernel command line for example). Maybe we can add properties there?
take care,
Gerd
Quoted 27 lines · Gerd Hoffmann
Hi,
Quoted 17 lines
Quoted 10 lines
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 ...
My rough rule of thumb for DT properties is "if it is a binding officially documented in the binding specs in the kernel with the relevant semantics, then OK"; but not ad-hoc bootloader specific stuff (we have turned down requests from u-boot for that in the past).
Quoted 6 lines
Would using the
fw_cfgmechanism work here? That's intended for passing configuration info (and "how verbose should debug be" seems like configuration info), and we already have a command line interface for it:
-fw_cfg name=edk2/debug-level,string=1
(or whatever).
Quoted 4 lines
I'd very much prefer to use device tree. A device property is maybe not the best choice. There is this /chosen node though which is already used to pass around guest configuration information (kernel command line for example). Maybe we can add properties there?
Sure, if you can get consensus on a device tree binding for it and get that documented in the kernel's Documentation/devicetree then we can implement something.
But fw-cfg seems to me to be a much better fit, and it has the advantage that it requires no changes to QEMU at all.
-- PMM
Hi,
Quoted 8 lines
Quoted 4 lines
I'd very much prefer to use device tree. A device property is maybe not the best choice. There is this /chosen node though which is already used to pass around guest configuration information (kernel command line for example). Maybe we can add properties there?
Sure, if you can get consensus on a device tree binding for it and get that documented in the kernel's
Documentation/devicetreethen we can implement something.
Documentation/devicetree/usage-model.rst (which documents 'bootargs' + 'initrd-*' properties in '/chosen' too) says:
The chosen node may also optionally contain an arbitrary number of additional properties for platform-specific configuration data.
Quoted 2 lines
But fw-cfg seems to me to be a much better fit, and it has the advantage that it requires no changes to QEMU at all.
On the firmware side fdt is easier because that needs to be parsed anyway to find the serial ports, and the firmware also checks whenever stdout-path exists in /chosen.
Adding a -chosen name=${property},string=${value} command line arg to qemu should not be too much of a problem, no?
take care,
Gerd
Quoted 21 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
Quoted 4 lines
I'd very much prefer to use device tree. A device property is maybe not the best choice. There is this /chosen node though which is already used to pass around guest configuration information (kernel command line for example). Maybe we can add properties there?
Sure, if you can get consensus on a device tree binding for it and get that documented in the kernel's
Documentation/devicetreethen we can implement something.
Documentation/devicetree/usage-model.rst(which documents 'bootargs' + 'initrd-*' properties in '/chosen' too) says:The chosen node may also optionally contain an arbitrary number of additional properties for platform-specific configuration data.
Quoted 2 lines
But fw-cfg seems to me to be a much better fit, and it has the advantage that it requires no changes to QEMU at all.
Quoted 6 lines
On the firmware side fdt is easier because that needs to be parsed anyway to find the serial ports, and the firmware also checks whenever stdout-path exists in /chosen.
Adding a -chosen name=${property},string=${value} command line arg to qemu should not be too much of a problem, no?
But we already have a mechanism for telling the firmware config information. I don't really want to implement a second one just because it would be easier for you to not use the one we already implement.
-- PMM