Skip to contentSkip to conversation

xen/device-tree: FDT dump helper and common discard_initial_modules()

PATCH Superseded Oleksii Kurochko 2 participants 5 messages Oct 12 – Oct 14

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen/device-tree: FDT dump helper and common discard_initial_modules()

Two small, independent device-tree changes. Arm is the only user of both at the moment; RISC-V is going to use them as well.

Patch 1 moves discard_initial_modules() from Arm to common device-tree code, as everything it uses is already common, so that other device-tree based architectures can reuse it. No functional change.

Patch 2 adds device_tree_dump(), which prints an FDT in a DTS-like format under CONFIG_DEVICE_TREE_DEBUG, to make it possible to inspect the device tree Xen generates for a dom0less domain.

Build-tested on arm64 and arm32.

CI tests: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2930332473

---
v2:
- Update the order of the patches.
- Address other comments from ML.
---

Oleksii Kurochko (2):
xen/device-tree: move discard_initial_modules() to common code xen/device-tree: add a helper to dump an FDT in DTS-like format

 xen/Kconfig.debug                       |  10 ++
 xen/arch/arm/domain_build.c             |   2 +
 xen/arch/arm/include/asm/setup.h        |   2 -
 xen/arch/arm/setup.c                    |  39 +----
 xen/common/device-tree/Makefile         |   1 +
 xen/common/device-tree/bootinfo.c       |  30 ++++
 xen/common/device-tree/dom0less-build.c |   3 +
 xen/common/device-tree/fdt-dump.c       | 185 ++++++++++++++++++++++++
 xen/include/xen/bootfdt.h               |  16 ++
 xen/include/xen/bootinfo.h              |   8 +
 10 files changed, 257 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/device-tree/fdt-dump.c

base-commit: 63d0e8cc842975e786455f8a2e6502e85685f258

Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/2 xen/device-tree: move discard_initial_modules() to common code

Everything discard_initial_modules() touches is already common code:
bootinfo.modules, using_static_heap and fw_unreserved_regions(). Move it out of Arm into common/device-tree/bootinfo.c, next to the boot allocator handling of the same memory, and declare it in xen/bootinfo.h, so that other device-tree based architectures can reuse it instead of growing a copy of their own.

The arch-specific remove_early_mappings() is not moved along with it:
how the early FDT mapping is torn down is up to the architecture. As the DTB is one of the boot modules being released, the mapping has to go once they are discarded, so call it from start_xen() right after discard_initial_modules(), which keeps the common function free of any arch dependency.

While moving it, use unsigned int for the loop counter and replace the "goto out" by a plain return, as there is nothing left to do at the label.

No functional change.

---
Changes in v2:
- Drop the comment above the call of discard_initial_modules() from arm/setup.c as it duplicates the comment added in xen/bootfdt.h.
- Add Reviewed-by: Michal Orzel <[email protected]>.
---

---
 xen/arch/arm/include/asm/setup.h  |  2 --
 xen/arch/arm/setup.c              | 39 ++-----------------------------
 xen/common/device-tree/bootinfo.c | 30 ++++++++++++++++++++++++
 xen/include/xen/bootinfo.h        |  8 +++++++
 4 files changed, 40 insertions(+), 39 deletions(-)
xen/arch/arm/include/asm/setup.h +0 -2
index c491c567298f..02fdf2b56c9c 100644
@@ -40,8 +40,6 @@ int acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]);
 
 void create_dom0(void);
 
-void discard_initial_modules(void);
-
 void init_pdx(void);
 void setup_mm(void);
 
xen/arch/arm/setup.c +2 -37
index 16f899dff57b..2cd1c021b559 100644
@@ -210,39 +210,6 @@ static void __init processor_id(void)
     processor_setup();
 }
 
-void __init discard_initial_modules(void)
-{
-    struct boot_modules *mi = &bootinfo.modules;
-    int i;
-
-    /*
-     * When using static heap feature, don't give boot_modules memory back to
-     * the heap allocator
-     */
-    if ( using_static_heap )
-        goto out;
-
-    for ( i = 0; i < mi->nr_mods; i++ )
-    {
-        paddr_t s = mi->module[i].start;
-        paddr_t e = s + PAGE_ALIGN(mi->module[i].size);
-
-        if ( mi->module[i].kind == BOOTMOD_XEN )
-            continue;
-
-        if ( !mfn_valid(maddr_to_mfn(s)) ||
-             !mfn_valid(maddr_to_mfn(e)) )
-            continue;
-
-        fw_unreserved_regions(s, e, init_domheap_pages, 0);
-    }
-
-    mi->nr_mods = 0;
-
- out:
-    remove_early_mappings();
-}
-
 /* Relocate the FDT in Xen heap */
 static void __init relocate_fdt(const void **dtb_vaddr, size_t dtb_size)
 {
@@ -503,12 +470,10 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)
         alloc_static_evtchn();
     }
 
-    /*
-     * This needs to be called **before** heap_init_late() so modules
-     * will be scrubbed (unless suppressed).
-     */
     discard_initial_modules();
 
+    remove_early_mappings();
+
     heap_init_late();
 
     init_constructors();
xen/common/device-tree/bootinfo.c +30 -0
index c637c45ad594..6772bf2df002 100644
@@ -471,6 +471,36 @@ void __init populate_boot_allocator(void)
     }
 }
 
+void __init discard_initial_modules(void)
+{
+    struct boot_modules *mi = &bootinfo.modules;
+    unsigned int i;
+
+    /*
+     * When using static heap feature, don't give boot_modules memory back to
+     * the heap allocator
+     */
+    if ( using_static_heap )
+        return;
+
+    for ( i = 0; i < mi->nr_mods; i++ )
+    {
+        paddr_t s = mi->module[i].start;
+        paddr_t e = s + PAGE_ALIGN(mi->module[i].size);
+
+        if ( mi->module[i].kind == BOOTMOD_XEN )
+            continue;
+
+        if ( !mfn_valid(maddr_to_mfn(s)) ||
+             !mfn_valid(maddr_to_mfn(e)) )
+            continue;
+
+        fw_unreserved_regions(s, e, init_domheap_pages, 0);
+    }
+
+    mi->nr_mods = 0;
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/xen/bootinfo.h +8 -0
index dbf492c2e36e..60ef25f3cf83 100644
@@ -214,4 +214,12 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,
                            void (*cb)(paddr_t ps, paddr_t pe),
                            unsigned int first);
 
+/*
+ * Return the memory occupied by the boot modules to the heap allocator.
+ *
+ * It needs to be called **before** heap_init_late() so that the released
+ * modules are scrubbed (unless suppressed).
+ */
+void discard_initial_modules(void);
+
 #endif /* XEN_BOOTINFO_H */
Signature · 1 line
2.55.0
#2 lore raw

PATCH v2 2/2 xen/device-tree: add a helper to dump an FDT in DTS-like format

In reply to 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'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.

---
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                       |  10 ++
 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       | 185 ++++++++++++++++++++++++
 xen/include/xen/bootfdt.h               |  16 ++
 6 files changed, 217 insertions(+)
 create mode 100644 xen/common/device-tree/fdt-dump.c
xen/Kconfig.debug +10 -0
index d900d926c555..45cff9dbc467 100644
@@ -98,6 +98,16 @@ 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, so on a non-debug build it is
+	  only shown with "loglvl=all".
+	  If unsure, say N here.
+
 config SCRUB_DEBUG
 	bool "Page scrubbing test"
 	default DEBUG
xen/arch/arm/domain_build.c +2 -0
index 72d531618045..6a20af23e1bb 100644
@@ -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
index 9036e455d66a..730d202349eb 100644
@@ -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
index fcbeb8adbd73..24a9c6b1e3e1 100644
@@ -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 +185 -0

185 lines not on this page · raw message

xen/include/xen/bootfdt.h +16 -0
index 0e82ccea2f84..b19e0fa41a1b 100644
@@ -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,
Signature · 1 line
2.55.0
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] xen/device-tree: add a helper to dump an FDT in DTS-like format

Quoted 45 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'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.

---
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                       |  10 ++
 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       | 185 ++++++++++++++++++++++++
 xen/include/xen/bootfdt.h               |  16 ++
 6 files changed, 217 insertions(+)
 create mode 100644 xen/common/device-tree/fdt-dump.c
xen/Kconfig.debug +0 -0
index d900d926c555..45cff9dbc467 100644
@@ -98,6 +98,16 @@ config DEVICE_TREE_DEBUG
 	  logged in the Xen ring buffer.

xen/Kconfig.debug config DEVICE_TREE_DEBUG · line 108

Quoted 10 lines
xen/Kconfig.debug +8 -0
 	  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, so on a non-debug build it is
+	  only shown with "loglvl=all".

That's not correct. loglvl="debug" is enough. That said, I don't find it particularly necessary for the second part of the sentence to be part of the help message. If you want to keep it, fix the loglvl.

Quoted 74 lines
xen/Kconfig.debug +2 -0
+	  If unsure, say N here.
+
 config SCRUB_DEBUG
 	bool "Page scrubbing test"
 	default DEBUG
xen/arch/arm/domain_build.c +2 -0
index 72d531618045..6a20af23e1bb 100644
@@ -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
index 9036e455d66a..730d202349eb 100644
@@ -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
index fcbeb8adbd73..24a9c6b1e3e1 100644
@@ -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 +18 -0
new file mode 100644
index 000000000000..296ae0d90d12
@@ -0,0 +1,185 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Dump a flattened device tree blob in a DTS-like format.
+ *
+ * is_printable_string() and print_value() are derived from
+ * util_is_printable_string() and utilfdt_print_data() in the device tree
+ * compiler (dtc).
+ *
+ * Copyright 2011 The Chromium Authors, All Rights Reserved.
+ * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
+ * util_is_printable_string contributed by
+ *      Pantelis Antoniou <pantelis.antoniou AT gmail.com>
+ */
+
+#include <xen/bootfdt.h>
+#include <xen/ctype.h>
+#include <xen/init.h>
+#include <xen/lib.h>

xen/common/device-tree/fdt-dump.c line 28

Quoted 10 lines
xen/common/device-tree/fdt-dump.c new file +10 -0
+#include <xen/libfdt/libfdt.h>
+#include <xen/types.h>
+
+/* Deeper nodes are still printed, but not indented any further. */
+#define DUMP_MAX_INDENT_DEPTH 32
+
+/* Indentation, in characters, of a node at depth @depth. */
+static int __init indent_of(int depth)
+{
+    return 2 * min(depth, DUMP_MAX_INDENT_DEPTH);

Can we use 4 spaces instead of 2 here and in print_properties() call. It does look more readable IMO and matches the indentation (1 tab = 4 spaces) of dtc when converting dtb to dts.

Other than that:

~Michal

#4 lore raw

Re: [PATCH v2 2/2] xen/device-tree: add a helper to dump an FDT in DTS-like format

Quoted 50 lines · Michal
Quoted 47 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'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.

---
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                       |  10 ++
  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       | 185 ++++++++++++++++++++++++
  xen/include/xen/bootfdt.h               |  16 ++
  6 files changed, 217 insertions(+)

create mode 100644 xen/common/device-tree/fdt-dump.c

xen/Kconfig.debug +0 -0
index d900d926c555..45cff9dbc467 100644
@@ -98,6 +98,16 @@ config DEVICE_TREE_DEBUG
  	  logged in the Xen ring buffer.
  	  If unsure, say N here.
 
Quoted 11 lines

xen/Kconfig.debug config DEVICE_TREE_DEBUG · line 108

Quoted 8 lines
xen/Kconfig.debug +8 -0
+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, so on a non-debug build it is
+	  only shown with "loglvl=all".

That's not correct. loglvl="debug" is enough. That said, I don't find it particularly necessary for the second part of the sentence to be part of the help message. If you want to keep it, fix the loglvl.

I am okay to drop the second part of the sentence to be part of the help message.

Quoted 80 lines
Quoted 80 lines
xen/Kconfig.debug +2 -0
+	  If unsure, say N here.
+
  config SCRUB_DEBUG
  	bool "Page scrubbing test"
  	default DEBUG
xen/arch/arm/domain_build.c +2 -0
index 72d531618045..6a20af23e1bb 100644
@@ -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
index 9036e455d66a..730d202349eb 100644
@@ -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
index fcbeb8adbd73..24a9c6b1e3e1 100644
@@ -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 +23 -0
new file mode 100644
index 000000000000..296ae0d90d12
@@ -0,0 +1,185 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Dump a flattened device tree blob in a DTS-like format.
+ *
+ * is_printable_string() and print_value() are derived from
+ * util_is_printable_string() and utilfdt_print_data() in the device tree
+ * compiler (dtc).
+ *
+ * Copyright 2011 The Chromium Authors, All Rights Reserved.
+ * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
+ * util_is_printable_string contributed by
+ *      Pantelis Antoniou <pantelis.antoniou AT gmail.com>
+ */
+
+#include <xen/bootfdt.h>
+#include <xen/ctype.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/types.h>
+
+/* Deeper nodes are still printed, but not indented any further. */
+#define DUMP_MAX_INDENT_DEPTH 32
Quoted 8 lines

xen/common/device-tree/fdt-dump.c line 28

Quoted 5 lines
xen/common/device-tree/fdt-dump.c new file +5 -0
+
+/* Indentation, in characters, of a node at depth @depth. */
+static int __init indent_of(int depth)
+{
+    return 2 * min(depth, DUMP_MAX_INDENT_DEPTH);

Can we use 4 spaces instead of 2 here and in print_properties() call. It does look more readable IMO and matches the indentation (1 tab = 4 spaces) of dtc when converting dtb to dts.

Fair enough.

I will introduce then DUMP_IDENT_WIDTH and use it in the correspondent places:

xen/common/device-tree/fdt-dump.c +5 -2
@@ -22,10 +22,13 @@
 /* Deeper nodes are still printed, but not indented any further. */
 #define DUMP_MAX_INDENT_DEPTH 32
 
+/* Spaces per nesting level. */
+#define DUMP_INDENT_WIDTH 4
+
 /* Indentation, in characters, of a node at depth @depth. */
 static int __init indent_of(int depth)
 {
-    return 2 * min(depth, DUMP_MAX_INDENT_DEPTH);
+    return DUMP_INDENT_WIDTH * min(depth, DUMP_MAX_INDENT_DEPTH);
 }
@@ -161,7 +164,7 @@ void __init device_tree_dump(const struct domain *d, const void *fdt)
 
         printk(XENLOG_DEBUG "%*s%s {\n", indent_of(depth), "",
                (depth == 0) ? "/" : (name ?: "<unknown>"));
-        print_properties(fdt, node, indent_of(depth) + 2);
+        print_properties(fdt, node, indent_of(depth) + DUMP_INDENT_WIDTH);
 
Quoted 3 lines

Other than that:

Thanks!

~ Oleksii