Skip to contentSkip to conversation

boot/uboot: support custom DTS with CONFIG_OF_UPSTREAM

PATCH Superseded Alexander Sverdlin 2 participants 2 messages Sep 1 – Sep 2

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot/uboot: support custom DTS with CONFIG_OF_UPSTREAM

Since U-Boot 2024.07, boards with CONFIG_OF_UPSTREAM build their device trees from dts/upstream/src/<arch>/<vendor>/ instead of arch/<arch>/dts/, so the files copied by BR2_TARGET_UBOOT_CUSTOM_DTS_PATH were ignored and the build failed with "No rule to make target".

Derive the destination from the U-Boot configuration, including the vendor sub-directory taken from CONFIG_DEFAULT_DEVICE_TREE. That tree keeps the Linux architecture naming, so aarch64 has to be mapped back from UBOOT_ARCH ("arm") to "arm64".

---
 boot/uboot/uboot.mk | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
boot/uboot/uboot.mk +19 -3
index 5b3f46ac74..06417da06f 100644
@@ -426,10 +426,26 @@ endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY
 
 UBOOT_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_DTS_PATH))
 
+# With CONFIG_OF_UPSTREAM the device trees are built from dts/upstream/src/
+# instead of arch/<arch>/dts/, in the vendor sub-directory encoded in the
+# device tree name. That tree keeps the Linux architecture naming, so aarch64
+# has to be mapped back from UBOOT_ARCH ("arm") to "arm64".
+define UBOOT_INSTALL_CUSTOM_DTS
+	dts_dir="arch/$(UBOOT_ARCH)/dts"; \
+	if grep -q "^CONFIG_OF_UPSTREAM=y" $(@D)/.config; then \
+		if grep -q "^CONFIG_ARM64=y" $(@D)/.config; then \
+			dts_dir="dts/upstream/src/arm64"; \
+		else \
+			dts_dir="dts/upstream/src/$(UBOOT_ARCH)"; \
+		fi; \
+		dt=$$(sed -n 's/^CONFIG_DEFAULT_DEVICE_TREE="\(.*\)"$$/\1/p' $(@D)/.config); \
+		case "$$dt" in */*) dts_dir="$$dts_dir/$${dt%/*}";; esac; \
+	fi; \
+	cp -f $(UBOOT_CUSTOM_DTS_PATH) $(@D)/$$dts_dir/
+endef
+
 define UBOOT_BUILD_CMDS
-	$(if $(UBOOT_CUSTOM_DTS_PATH),
-		cp -f $(UBOOT_CUSTOM_DTS_PATH) $(@D)/arch/$(UBOOT_ARCH)/dts/
-	)
+	$(if $(UBOOT_CUSTOM_DTS_PATH),$(UBOOT_INSTALL_CUSTOM_DTS))
 	$(TARGET_CONFIGURE_OPTS) \
 		PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
 		PKG_CONFIG_SYSROOT_DIR="/" \
Signature · 6 lines
2.55.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hello Alexander, All,

Le 01/09/2026 à 16:52, Alexander Sverdlin a écrit :

Quoted 9 lines

Since U-Boot 2024.07, boards with CONFIG_OF_UPSTREAM build their device trees from dts/upstream/src/<arch>/<vendor>/ instead of arch/<arch>/dts/, so the files copied by BR2_TARGET_UBOOT_CUSTOM_DTS_PATH were ignored and the build failed with "No rule to make target".

Derive the destination from the U-Boot configuration, including the vendor sub-directory taken from CONFIG_DEFAULT_DEVICE_TREE. That tree keeps the Linux architecture naming, so aarch64 has to be mapped back from UBOOT_ARCH ("arm") to "arm64".

True, but what if UBOOT_INSTALL_CUSTOM_DTS contains both <custom>-u-boot.dtsi (that need to be copied to "arch/$(UBOOT_ARCH)/dts) and <custom>.dts (that need to be copied to "dts/upstream/src/<arch>/<vendor>") because the kernel devicetree for the custom board needs tweaks for U-Boot?

Also, you may want to update the help text of BR2_TARGET_UBOOT_CUSTOM_DTS_PATH option about this new behavior for uboot >= 2024.07.

Best regards,
Romain

Quoted 30 lines
---
 boot/uboot/uboot.mk | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
boot/uboot/uboot.mk +16 -0
index 5b3f46ac74..06417da06f 100644
@@ -426,10 +426,26 @@ endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY
 
 UBOOT_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_DTS_PATH))
 
+# With CONFIG_OF_UPSTREAM the device trees are built from dts/upstream/src/
+# instead of arch/<arch>/dts/, in the vendor sub-directory encoded in the
+# device tree name. That tree keeps the Linux architecture naming, so aarch64
+# has to be mapped back from UBOOT_ARCH ("arm") to "arm64".
+define UBOOT_INSTALL_CUSTOM_DTS
+	dts_dir="arch/$(UBOOT_ARCH)/dts"; \
+	if grep -q "^CONFIG_OF_UPSTREAM=y" $(@D)/.config; then \
+		if grep -q "^CONFIG_ARM64=y" $(@D)/.config; then \
+			dts_dir="dts/upstream/src/arm64"; \
+		else \
+			dts_dir="dts/upstream/src/$(UBOOT_ARCH)"; \
+		fi; \
+		dt=$$(sed -n 's/^CONFIG_DEFAULT_DEVICE_TREE="\(.*\)"$$/\1/p' $(@D)/.config); \
+		case "$$dt" in */*) dts_dir="$$dts_dir/$${dt%/*}";; esac; \
+	fi; \
+	cp -f $(UBOOT_CUSTOM_DTS_PATH) $(@D)/$$dts_dir/

boot/uboot/uboot.mk endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY · line 451

Quoted 10 lines
boot/uboot/uboot.mk +3 -3
+endef
+
 define UBOOT_BUILD_CMDS
-	$(if $(UBOOT_CUSTOM_DTS_PATH),
-		cp -f $(UBOOT_CUSTOM_DTS_PATH) $(@D)/arch/$(UBOOT_ARCH)/dts/
-	)
+	$(if $(UBOOT_CUSTOM_DTS_PATH),$(UBOOT_INSTALL_CUSTOM_DTS))
 	$(TARGET_CONFIGURE_OPTS) \
 		PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
 		PKG_CONFIG_SYSROOT_DIR="/" \

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot