xen/device-tree: add a helper to dump an FDT in DTS-like format
PATCH v3 1/1 xen/device-tree: add a helper to dump an FDT in DTS-like format
The device tree Xen builds for dom0/hwdom or for a dom0less domain is only ever consumed by the guest, so a mistake in it surfaces as an obscure failure inside the domain, far away from the code which produced the tree.
Add device_tree_dump(). The output follows dtc's format so that a dump can be diffed against the source DTS or fed back to dtc; the value formatting heuristics are ported from dtc's utilfdt_print_data() for that reason. The walk itself goes through libfdt rather than decoding the tag stream by hand as dtc's fdtdump does.
Dumping a whole tree is only useful while debugging and costs both code size and a lot of console output, so it is put under its own option, CONFIG_DEVICE_TREE_DUMP. It is separate from CONFIG_DEVICE_TREE_DEBUG because the generated tree is often all that is needed, without the rest of the device tree debug messages.
---
CI tests:
https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2947342162
---
Changes in v3:
- Drop the loglvl remark from the CONFIG_DEVICE_TREE_DUMP help text.
- Indent the dump by 4 spaces per nesting level instead of 2. Introduce macros DUMP_INDENT_WIDTH for that.
---
Changes in v2:
- Dump the device tree generated for dom0/hwdom as well.
- Put the dump under its own CONFIG_DEVICE_TREE_DUMP instead of CONFIG_DEVICE_TREE_DEBUG.
- Pass the domain to device_tree_dump() and print the "Device tree for" header from it.
- Combine isprint() with isascii(), as Xen's isprint() also accepts the characters 0xa0-0xff, unlike the one dtc uses.
- Update the commit message.
---
--- xen/Kconfig.debug | 9 ++ xen/arch/arm/domain_build.c | 2 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/dom0less-build.c | 3 + xen/common/device-tree/fdt-dump.c | 188 ++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 16 ++ 6 files changed, 219 insertions(+) create mode 100644 xen/common/device-tree/fdt-dump.c
xen/Kconfig.debug +9 -0
@@ -98,6 +98,15 @@ config DEVICE_TREE_DEBUG logged in the Xen ring buffer. If unsure, say N here. +config DEVICE_TREE_DUMP + bool "Dump generated device trees" + depends on DEVICE_TREE_PARSE + help + The device tree Xen generates for dom0/hwdom and for each dom0less + domain is printed on the Xen console in a DTS-like format. + The dump is logged at debug level. + If unsure, say N here. + config SCRUB_DEBUG bool "Page scrubbing test" default DEBUG
xen/arch/arm/domain_build.c +2 -0
@@ -1705,6 +1705,8 @@ static int __init prepare_dtb_hwdom(struct domain *d, struct kernel_info *kinfo)if ( ret <0 ) goto err; +device_tree_dump (d, kinfo->fdt); +return 0 ; err:
xen/common/device-tree/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += domain-build.init.o obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) += dom0less-build.init.o obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-bindings.init.o obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o +obj-$(CONFIG_DEVICE_TREE_DUMP) += fdt-dump.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += intc.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o
xen/common/device-tree/dom0less-build.c +3 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/bootfdt.h> #include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/dom0less-build.h>
@@ -587,6 +588,8 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)if ( ret <0 ) goto err; +device_tree_dump (d, kinfo->fdt); +return 0 ; err:
xen/common/device-tree/fdt-dump.c new file +188 -0
188 lines not on this page · raw message
xen/include/xen/bootfdt.h +16 -0
@@ -99,6 +99,22 @@ int device_tree_for_each_node(const void *fdt, int node,device_tree_node_func func, void *data); +struct domain ; + +/* +* device_tree_dump - print a device tree blob in a DTS-like format +* @d: domain the device tree was generated for. +* @fdt: flat device tree. +* +* The tree is printed at debug log level and is only meant to be used for +* debugging, so it is a no-op unless CONFIG_DEVICE_TREE_DUMP is enabled. +*/ +#ifdef CONFIG_DEVICE_TREE_DUMP +void device_tree_dump (const struct domain *d,const void *fdt); +#else +static inline void device_tree_dump (const struct domain *d,const void *fdt) {} +#endif + typedef enum { BOOTMOD_XEN, BOOTMOD_FDT,
base-commit: 7168cc02f86fb069da6e7405afbf5c7a1c215b0d
Signature · 1 line
2.55.0
Quoted 11 lines · Oleksii Kurochko
The device tree Xen builds for dom0/hwdom or for a dom0less domain is only ever consumed by the guest, so a mistake in it surfaces as an obscure failure inside the domain, far away from the code which produced the tree.
Add
device_tree_dump(). The output follows dtc's format so that a dump can be diffed against the source DTS or fed back to dtc; the value formatting heuristics are ported from dtc'sutilfdt_print_data()for that reason. The walk itself goes through libfdt rather than decoding the tag stream by hand as dtc's fdtdump does.
Quoted 7 lines
Dumping a whole tree is only useful while debugging and costs both code size and a lot of console output, so it is put under its own option,
CONFIG_DEVICE_TREE_DUMP. It is separate fromCONFIG_DEVICE_TREE_DEBUGbecause the generated tree is often all that is needed, without the rest of the device tree debug messages.Signed-off-by Oleksii Kurochko <[email protected]>
~Michal