[PATCH v2 2/4] kbuild: dtc: introduce empty fallback device tree

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Oct 15 02:23:28 PDT 2026


CONFIG_EXTERNAL_DTS_FRAGMENTS can't be used with the EFI payload, because
it has no internal DT at build-time and until recently not even a DT at
runtime.

Instead of synthesizing a DT root node at runtime, just compile in an
empty DT that the user can extend with builtin state nodes via
CONFIG_EXTERNAL_DTS_FRAGMENTS.

x86 has had no device trees of its own so far, but gets a dts directory
here as well, so the fallback device tree is built the same way on every
architecture and efi/payload/Makefile needs no special case for the
architectures without one.

That makes it the first dtb in the tree that is built without
CONFIG_PBL_IMAGE, so define suffix_y for that case as well:
scripts/gen-dtb-s reads the size of the compressed dtb unconditionally,
but scripts/Makefile.pbl, which defines suffix_y, is only included for PBL
builds. Without it, the .dtb.z is never generated, the build prints an ls
error for the missing file and the dtb objects are regenerated on every
make.

Build the fallback device tree only along with the EFI payload. Fragments
are applied to every device tree built, so elsewhere it would just be an
unused dtb in the image that breaks the build when a fragment references
board labels.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/dts/Makefile   |  4 ++++
 arch/riscv/dts/Makefile |  4 ++++
 arch/x86/Kbuild         |  2 ++
 arch/x86/dts/Makefile   |  5 +++++
 common/fallback.dts     | 10 ++++++++++
 efi/payload/boarddata.c | 11 -----------
 efi/payload/fdt.c       | 25 +++++++++++++++++++++++++
 scripts/Makefile.dtbs   | 10 ++++++++++
 8 files changed, 60 insertions(+), 11 deletions(-)
 create mode 100644 arch/x86/dts/Makefile
 create mode 100644 common/fallback.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d9b731e0f286..14ec007770f3 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,5 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
+ifdef CONFIG_EFI_PAYLOAD
+obj-pbl-$(CONFIG_OFDEVICE) += fallback.dtb.o
+endif
+
 lwl-$(CONFIG_MACH_ADVANTECH_ROM_742X) += imx6dl-advantech-rom-7421.dtb.o
 lwl-$(CONFIG_MACH_AFI_GF) += am335x-afi-gf.dtb.o
 lwl-$(CONFIG_MACH_AM625_SK) += k3-am625-sk.dtb.o k3-am625-r5-sk.dtb.o k3-am625sip-r5-sk.dtb.o
diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
index 521c8407c5ae..8a136f96c7d9 100644
--- a/arch/riscv/dts/Makefile
+++ b/arch/riscv/dts/Makefile
@@ -1,5 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 
+ifdef CONFIG_EFI_PAYLOAD
+obj-pbl-$(CONFIG_OFDEVICE) += fallback.dtb.o
+endif
+
 lwl-$(CONFIG_BOARD_ERIZO_GENERIC) += erizo-generic.dtb.o
 lwl-$(CONFIG_BOARD_HIFIVE) += hifive-unmatched-a00.dtb.o \
                               hifive-unleashed-a00.dtb.o
diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild
index f5fa602122a5..28744c7dc511 100644
--- a/arch/x86/Kbuild
+++ b/arch/x86/Kbuild
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 obj-y += lib/
+
+obj-$(CONFIG_OFTREE) += dts/
diff --git a/arch/x86/dts/Makefile b/arch/x86/dts/Makefile
new file mode 100644
index 000000000000..25b653bc9b03
--- /dev/null
+++ b/arch/x86/dts/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-pbl-$(CONFIG_OFDEVICE) += fallback.dtb.o
+
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
diff --git a/common/fallback.dts b/common/fallback.dts
new file mode 100644
index 000000000000..7c88eba462b6
--- /dev/null
+++ b/common/fallback.dts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/dts-v1/;
+
+/*
+ * Fallback device tree for images not tied to a board, like the EFI payload.
+ * Empty, but can be populated via CONFIG_EXTERNAL_DTS_FRAGMENTS.
+ */
+
+/ {
+};
diff --git a/efi/payload/boarddata.c b/efi/payload/boarddata.c
index ec6ee7bbd98f..a2f4b8d21b4a 100644
--- a/efi/payload/boarddata.c
+++ b/efi/payload/boarddata.c
@@ -14,7 +14,6 @@
 #include <linux/printk.h>
 #include <debug_ll.h>
 #include <init.h>
-#include <of.h>
 #include <pbl/handoff-data.h>
 
 static int handle_efi_boarddata(void)
@@ -47,13 +46,3 @@ static int handle_efi_boarddata(void)
 	return 0;
 }
 pure_initcall(handle_efi_boarddata);
-
-static __maybe_unused int efi_register_of(void)
-{
-	if (!BS)
-		return 0;
-	return barebox_register_of(of_new_node(NULL, NULL));
-}
-#ifdef CONFIG_OFDEVICE
-core_initcall(efi_register_of);
-#endif
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index 9cdb32370f22..f98fd86bfbd6 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -5,10 +5,35 @@
 #include <common.h>
 #include <init.h>
 #include <libfile.h>
+#include <of.h>
 #include <efi/payload.h>
 #include <efi/payload/init.h>
 #include <efi/guid.h>
 
+extern char __dtb_fallback_start[];
+
+/*
+ * EFI systems have no device tree, but barebox may still need one for its
+ * own purposes, e.g. to describe a state partition. Register a tree that's
+ * empty unless populated via CONFIG_EXTERNAL_DTS_FRAGMENTS.
+ */
+static __maybe_unused int efi_of_init(void)
+{
+	int ret;
+
+	ret = barebox_register_fdt(__dtb_fallback_start);
+	if (ret == -EBUSY) {
+		/* architecture code registered a device tree already */
+		pr_debug("keeping already registered device tree\n");
+		return 0;
+	}
+
+	return ret;
+}
+#ifdef CONFIG_OFDEVICE
+core_efi_initcall(efi_of_init);
+#endif
+
 static int efi_fdt_probe(void)
 {
 	struct efi_config_table *ect;
diff --git a/scripts/Makefile.dtbs b/scripts/Makefile.dtbs
index 9d50fc7fe6e0..5083da6a6273 100644
--- a/scripts/Makefile.dtbs
+++ b/scripts/Makefile.dtbs
@@ -93,6 +93,11 @@ cmd_dt_S_dtbo = $(srctree)/scripts/gen-dtbo-s $(subst -,_,$(*F)) $< \
 $(obj)/%.dtbo.S: $(obj)/%.dtbo $(srctree)/scripts/gen-dtbo-s FORCE
 	$(call if_changed,dt_S_dtbo)
 
+# scripts/Makefile.pbl defines suffix_y, but is only included for PBL builds.
+# The compressed dtb is unused without a PBL, but still needs to exist, as
+# scripts/gen-dtb-s reads its size unconditionally.
+suffix_y ?= comp_copy
+
 $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 	$(call if_changed,$(suffix_y))
 
@@ -115,6 +120,11 @@ cmd_dtco = $(cmd_dtc) $(if $(DTBO_BASE_$(target-stem)), ; \
 	$(srctree)/scripts/check-dt-overlay $(FDTOVERLAY) $(FDTGET) \
 		$(obj)/$(DTBO_BASE_$(target-stem)).dtb $@)
 
+# The fallback device tree is board-agnostic, so its source is shared by all
+# architectures instead of living in a dts directory
+$(obj)/fallback.dtb: $(obj)/%.dtb: $(srctree)/common/fallback.dts FORCE
+	$(call if_changed_dep,dtc,$(dts-frags))
+
 $(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
 	$(call if_changed_dep,dtco)
 
-- 
2.47.3




More information about the barebox mailing list