* [PATCH v2 2/3] scripts: Makefile.lib: add check of -u-boot.dtsi in the device tree source
2026-11-10 7:52 [PATCH v2 0/3] dts: build the DTS from a directory outside the tree Vincent Jardin
2026-11-10 7:52 ` [PATCH v2 1/3] scripts: Makefile.dts: build the device tree with DEVICE_TREE= too Vincent Jardin
@ 2026-11-10 7:52 ` Vincent Jardin
2026-11-10 7:52 ` [PATCH v2 3/3] dts: build the device tree from a directory outside the tree, EXT_DTS_DIR Vincent Jardin
2026-11-20 17:46 ` [PATCH v2 0/3] dts: build the DTS from a directory outside the tree Tom Rini
3 siblings, 0 replies; 6+ messages in thread
From: Vincent Jardin @ 2026-11-10 7:52 UTC (permalink / raw)
To: u-boot
Cc: Markus Schneider-Pargmann, Denis Mukhin, E Shattow,
Rasmus Villemoes, Simon Glass, Tom Rini, Suraj Kakade,
Marek Vasut, Vincent Jardin
The U-Boot extensions of a device tree, <name>-u-boot.dtsi, are looked up
only in arch/$(ARCH)/dts.
Let's try <name>-u-boot.dtsi in the directory of the .dts first, then the
usual candidates of arch/$(ARCH)/dts.
Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
(no changes since v1)
doc/develop/devicetree/control.rst | 4 ++--
scripts/Makefile.lib | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
index 7d6117d5c4b..5c1b46b94ab 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -203,8 +203,8 @@ constraints are even more extreme and the devicetree is shrunk to remove
unwanted nodes, or even turned into C code to avoid access overhead.
U-Boot automatically looks for and includes a file with updates to the standard
-devicetree for your board, searching for them in `arch/<arch>/dts/` in this
-order::
+devicetree for your board, searching first for `<orig_filename>-u-boot.dtsi`
+in the devicetree source, then in `arch/<arch>/dts/` in this order::
<orig_filename>-u-boot.dtsi
<CONFIG_SYS_SOC>-u-boot.dtsi
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7cdfacd3ae5..e3b49148b7c 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -223,13 +223,15 @@ ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
# Try these files in order to find the U-Boot-specific .dtsi include file
u_boot_dtsi_loc = $(srctree)/arch/$(ARCH)/dts/
-u_boot_dtsi_options = $(strip $(wildcard $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi) \
+u_boot_dtsi_options = $(strip $(wildcard $(dir $<)$(basename $(notdir $<))-u-boot.dtsi) \
+ $(wildcard $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi) \
$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi) \
$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi) \
$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi) \
$(wildcard $(u_boot_dtsi_loc)u-boot.dtsi))
u_boot_dtsi_options_raw = $(warning Automatic .dtsi inclusion: options: \
+ $(dir $<)$(basename $(notdir $<))-u-boot.dtsi \
$(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi \
$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi \
$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi \
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/3] dts: build the device tree from a directory outside the tree, EXT_DTS_DIR
2026-11-10 7:52 [PATCH v2 0/3] dts: build the DTS from a directory outside the tree Vincent Jardin
2026-11-10 7:52 ` [PATCH v2 1/3] scripts: Makefile.dts: build the device tree with DEVICE_TREE= too Vincent Jardin
2026-11-10 7:52 ` [PATCH v2 2/3] scripts: Makefile.lib: add check of -u-boot.dtsi in the device tree source Vincent Jardin
@ 2026-11-10 7:52 ` Vincent Jardin
2026-11-20 17:46 ` [PATCH v2 0/3] dts: build the DTS from a directory outside the tree Tom Rini
3 siblings, 0 replies; 6+ messages in thread
From: Vincent Jardin @ 2026-11-10 7:52 UTC (permalink / raw)
To: u-boot
Cc: Markus Schneider-Pargmann, Denis Mukhin, E Shattow,
Rasmus Villemoes, Simon Glass, Tom Rini, Suraj Kakade,
Marek Vasut, Vincent Jardin,
Jérémie Dautheribes (Schneider Electric)
A board whose device tree is not in U-Boot directories has to be
copied in:
- Buildroot copies the .dts of BR2_TARGET_UBOOT_CUSTOM_DTS_PATH into
arch/<arch>/dts, it adds/patches a dtb-y line with sed, it copies
into dts/upstream/src/<arch>/<vendor>
- A Yocto layer does about the same in its do_configure. Each copy depends
on the layout of the release it targets, and the -u-boot.dtsi has to go to
yet another place. EXT_DTB takes a .dtb compiled elsewhere, without the
include paths, the -u-boot.dtsi and the DEVICE_TREE_INCLUDES of the
U-Boot build.
Let's add EXT_DTS_DIR=<dir>:
the .dts of DEVICE_TREE, OF_LIST, SPL_OF_LIST and OF_OVERLAY_LIST
which are compiled from that directory instead of dt_dir.
It can use scripts/Makefile.dts as dts/upstream is, with the same automatic
.dtsi handling and the same include paths, where the directory stands in
for dt_dir: an OF_UPSTREAM board which keeps its <vendor>/ subdirectory
finds the SoC files of dts/upstream before the older copies of
arch/<arch>/dts, as in the tree.
The directory is only read: the .dtb files are generated into dts/external
of the build tree, based on dt_dir, so dt.dtb, u-boot.img, fit-dtb.blob
and binman use them from there.
A Makefile or Kbuild in the directory is used if present, to add DTC_FLAGS
or dtb-y entries, if not scripts/Makefile.dts is used.
Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
Changes in v2:
- Rebase on next, v2027.01-rc2
- control.rst: for a WIP board that (Tom Rini)
- 3/3 log: wording: directories, not folders (Marek Vasut)
.gitignore | 1 +
Makefile | 9 +++++-
doc/develop/devicetree/control.rst | 45 +++++++++++++++++++++++++++++-
dts/Makefile | 20 +++++++++++--
scripts/Makefile.build | 11 +++++++-
scripts/Makefile.dts | 9 ++++++
scripts/Makefile.lib | 10 +++++--
7 files changed, 98 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5cb135fc58c..f829c0e05ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@
*.dtb.clean.dts
*.dtb.diff
*.dtb.full.dts
+/dts/external/
*.elf
*.exe
*.fit
diff --git a/Makefile b/Makefile
index 519866b82ea..ceecb92a281 100644
--- a/Makefile
+++ b/Makefile
@@ -834,6 +834,13 @@ else
dt_dir := arch/$(ARCH)/dts
endif
+ifneq ($(EXT_DTS_DIR),)
+dt_src_dir := $(abspath $(EXT_DTS_DIR))
+dt_dir := dts/external
+else
+dt_src_dir := $(dt_dir)
+endif
+
include $(srctree)/arch/$(ARCH)/Makefile
endif
endif
@@ -1468,7 +1475,7 @@ fit-dtb.blob.gz: fit-dtb.blob
fit-dtb.blob.lzo: fit-dtb.blob
@lzop -f9 $< > $@
-of_list_srcs := $(patsubst %,$(dt_dir)/%.dts,$(subst ",,$(CONFIG_OF_LIST)))
+of_list_srcs := $(patsubst %,$(dt_src_dir)/%.dts,$(subst ",,$(CONFIG_OF_LIST)))
fit-dtb.blob: dts/dt.dtb $(of_list_srcs) FORCE
$(call if_changed,mkimage)
ifneq ($(SOURCE_DATE_EPOCH),)
diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
index 5c1b46b94ab..83af5eab309 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -120,6 +120,13 @@ prompted by Kconfig. Another option is that you can use the "pick" option of
`tools/update-subtree.sh` mentioned above to bring in the commits that you
need.
+A board that is not finalized yet, during its bring-up or while its
+devicetree source is maintained with the kernel's, can build it from a
+directory outside the tree using `EXT_DTS_DIR` (see :ref:`extdtsdir`). It is a
+make variable, like `EXT_DTB` and `DEVICE_TREE`: no defconfig sets it and no
+board in the tree depends on it. A board sent upstream shall still come with its
+devicetree source, in `dts/upstream` or `arch/<arch>/dts` as above.
+
This should include your CPU or SoC's devicetree file. On top of that any U-Boot
specific tweaks (see: :ref:`dttweaks`) can be made for your board.
@@ -152,7 +159,8 @@ EXT_DTB=<filename> to 'make', as in::
make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
Then U-Boot will copy that file to u-boot.dtb, put it in the .img file
-if used, and u-boot-dtb.bin.
+if used, and u-boot-dtb.bin. To compile the devicetree from files
+outside the tree instead, see :ref:`extdtsdir`.
If you wish to put the fdt at a different address in memory, you can
define the "fdtcontroladdr" environment variable. This is the hex
@@ -232,6 +240,41 @@ outside the U-Boot repository. You can use `DEVICE_TREE_INCLUDES` Kconfig
option to specify a list of .dtsi files that will also be included when
building .dtb files.
+.. _extdtsdir:
+
+Devicetree sources outside the tree
+-----------------------------------
+
+A board may keep its devicetree sources outside U-Boot: in a board support
+layer of Yocto or Buildroot, or in a repository shared with the kernel during
+a bring-up. Point the build at that directory with `EXT_DTS_DIR`::
+
+ make EXT_DTS_DIR=/path/to/dts DEVICE_TREE=myboard
+
+The `.dts` files of `DEVICE_TREE`, `OF_LIST`, `SPL_OF_LIST` and
+`OF_OVERLAY_LIST` are then compiled from that directory instead of
+`arch/<arch>/dts` or `dts/upstream/src/<arch>`, with the same include paths,
+so they may include the SoC files of either, and with the same automatic
+`*-u-boot.dtsi` and `DEVICE_TREE_INCLUDES` handling. A `<name>-u-boot.dtsi`
+next to the source is used first (see :ref:`dttweaks`). The names are
+relative to the directory, as they are to `dts/upstream/src/<arch>` for
+`OF_UPSTREAM` boards: keep the `<vendor>/` subdirectory, the sources then
+find the SoC files of `dts/upstream/src/<arch>/<vendor>` before the older
+copies of `arch/<arch>/dts`, as they do in the tree. Every name of those lists
+comes from the directory: a missing one stops the build with a message, so
+trim `OF_LIST` to what the directory provides.
+
+The directory is only read: the `.dtb` files are written to `dts/external` in
+the build tree, and the rest of the build, binman included, takes them from
+there. This directory does not need a Makefile: `scripts/Makefile.dts` builds
+it, with the directory-wide `DTC_FLAGS` of the directory it stands in for, so
+the `.dtb` comes out as it does from the tree. If it has a Makefile or a Kbuild
+file of its own, that one is used instead: it should include
+`scripts/Makefile.dts`, as `dts/upstream/src/arm64/Makefile` does, and may add
+`DTC_FLAGS` or `dtb-y` entries.
+The path is taken as given, so for an `O=` build pass an absolute one.
+`EXT_DTB` remains the way to use a devicetree compiled elsewhere.
+
Scripts embedded in control DTB
-------------------------------
diff --git a/dts/Makefile b/dts/Makefile
index befc6de1805..2793e0dcde3 100644
--- a/dts/Makefile
+++ b/dts/Makefile
@@ -24,6 +24,22 @@ else
dt_dir := arch/$(ARCH)/dts
endif
+# EXT_DTS_DIR=<dir>: compile the device tree sources of that directory, outside
+# the tree, instead of those of dt_dir: the .dtb files land in dts/external of
+# the build tree.
+ifneq ($(EXT_DTS_DIR),)
+dt_src_dir := $(abspath $(EXT_DTS_DIR))
+# built by a Makefile or Kbuild of its own if it has one, else by
+# scripts/Makefile.dts
+ext_dts_mk := $(firstword $(wildcard $(dt_src_dir)/Kbuild $(dt_src_dir)/Makefile) \
+ $(srctree)/scripts/Makefile.dts)
+ext_dts_flags := $(shell MAKEFLAGS= $(MAKE) -s -rR --include-dir=$(srctree) \
+ -f $(srctree)/scripts/Makefile.build obj=$(dt_dir) __dtc_flags)
+ext_dts_args := src=$(dt_src_dir) kbuild-file=$(ext_dts_mk) \
+ ext_dts_shadow=$(srctree)/$(dt_dir) ext_dts_flags="$(ext_dts_flags)"
+dt_dir := dts/external
+endif
+
ifneq ($(CONFIG_OF_UPSTREAM_INCLUDE_LOCAL_FALLBACK_DTBOS),)
local_dtbos := local-dtbos
else
@@ -61,7 +77,7 @@ $(DTB): arch-dtbs $(local_dtbos)
PHONY += arch-dtbs
arch-dtbs:
- $(Q)$(MAKE) $(build)=$(dt_dir) dtbs
+ $(Q)$(MAKE) $(build)=$(dt_dir) $(ext_dts_args) dtbs
ifneq ($(CONFIG_OF_UPSTREAM_INCLUDE_LOCAL_FALLBACK_DTBOS),)
PHONY += local-dtbos
@@ -86,7 +102,7 @@ dtbs: $(obj)/dt.dtb
spl_dtbs: $(obj)/dt-$(SPL_NAME).dtb
@:
-clean-files := dt.dtb.S
+clean-files := dt.dtb.S external
# Let clean descend into dts directories
subdir- += ../arch/arc/dts ../arch/arm/dts ../arch/m68k/dts ../arch/microblaze/dts \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 73b6769ab90..8b0bef91cf2 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -4,6 +4,9 @@
# ==========================================================================
# Modified for U-Boot
+ifeq ($(origin src),command line)
+prefix := .
+else
prefix := vpl
src := $(patsubst $(prefix)/%,%,$(obj))
ifeq ($(obj),$(src))
@@ -17,6 +20,7 @@ prefix := .
endif
endif
endif
+endif
PHONY := __build
__build:
@@ -57,7 +61,8 @@ include scripts/Makefile.compiler
# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
-include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
+kbuild-file := $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
+include $(kbuild-file)
# Added for U-Boot
asflags-y += $(PLATFORM_CPPFLAGS)
@@ -499,6 +504,10 @@ $(subdir-ym):
need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1)
+PHONY += __dtc_flags
+__dtc_flags:
+ @echo $(DTC_FLAGS)
+
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.dts b/scripts/Makefile.dts
index fd9ff420585..bcf89b3b3a0 100644
--- a/scripts/Makefile.dts
+++ b/scripts/Makefile.dts
@@ -17,6 +17,15 @@ dtb-y += $(subst $(dt_dir)/,,$(dtb-vendor_dts))
endif
+ifneq ($(ext_dts_shadow),)
+ext_dts_missing := $(strip $(foreach f,$(dtb-y),$(if $(wildcard \
+ $(src)/$(patsubst %.dtb,%.dts,$(patsubst %.dtbo,%.dtso,$(f)))),,$(f))))
+ifneq ($(ext_dts_missing),)
+$(error EXT_DTS_DIR: $(src) has no source for $(strip $(ext_dts_missing)); the device \
+ trees of DEVICE_TREE, OF_LIST, SPL_OF_LIST and OF_OVERLAY_LIST all come from it)
+endif
+endif
+
ifneq ($(CONFIG_SYS_DTC_PAD_BYTES),0)
DTC_FLAGS += -p $(CONFIG_SYS_DTC_PAD_BYTES)
endif
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e3b49148b7c..1910e08f30c 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -256,9 +256,15 @@ upstream_dtsi_include = $(addprefix -I, $(srctree)/dts/upstream/src/ \
$(if (CONFIG_ARM64), \
$(sort $(dir $(wildcard $(srctree)/dts/upstream/src/arm64/*/*))) \
$(sort $(dir $(wildcard $(srctree)/dts/upstream/src/arm64/*/*/*)))))
+ext_dts_flags_extra = $(filter-out $(DTC_FLAGS),$(ext_dts_flags))
+ext_dts_shadow_include = $(if $(ext_dts_shadow),\
+ -I$(ext_dts_shadow)/$(dir $(patsubst $(obj)/%,%,$@)) \
+ -I$(ext_dts_shadow)/$(dir $(subst $(quote),,$(CONFIG_DEFAULT_DEVICE_TREE))))
+
dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
$(UBOOTINCLUDE) \
-I$(dir $<) \
+ $(ext_dts_shadow_include) \
-I$(u_boot_dtsi_loc) \
-I$(srctree)/arch/$(ARCH)/dts/include \
-I$(srctree)/include \
@@ -443,7 +449,7 @@ cmd_dtc_diff = \
-i $(dir $<) $(DTC_FLAGS) $(dtn-tmp) || \
(echo "Check $(shell pwd)/$< for errors" && false); \
$(DTC) -s -O dts -o $@.full.dts -b 0 \
- -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) $(dtc-tmp) || \
+ -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) $(ext_dts_flags_extra) $(dtc-tmp) || \
(echo "Check $(shell pwd)/$(pre-tmp) for errors" && false); \
sed -i '/\<phandle\> = <0x[0-9a-f]\+>;/ d' $@.clean.dts; \
sed -i '/\<phandle\> = <0x[0-9a-f]\+>;/ d' $@.full.dts; \
@@ -464,7 +470,7 @@ cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
echo '$(pound)include "$(f)"' >> $(pre-tmp);) \
$(HOSTCC) -E @$(dtc-flags-tmp) -x assembler-with-cpp -o $(dtc-tmp) $(pre-tmp) ; \
$(DTC) -O dtb -o $@ -b 0 \
- -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) \
+ -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) $(ext_dts_flags_extra) \
-d $(depfile).dtc.tmp $(dtc-tmp) || \
(echo "Check $(shell pwd)/$(pre-tmp) for errors" && false) \
; \
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread