* [PATCH v3 1/2] kbuild: Convert %.dtb(o) targets to single target rules
2026-10-07 18:39 [PATCH v3 0/2] kbuild: Support directory targets for DTBs Rob Herring (Arm)
@ 2026-10-07 18:39 ` Rob Herring (Arm)
2026-10-07 18:39 ` [PATCH v3 2/2] kbuild: Support directory targets for building DTBs Rob Herring (Arm)
1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring (Arm) @ 2026-10-07 18:39 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Saravana Kannan
Cc: David Heidelberg, Arnd Bergmann, linux-kbuild, linux-kernel, devicetree
Single .dtb and .dtbo targets can be built using the existing kbuild
single target infrastructure. The only difference is the custom rules
work on a relative path under the arch dts directory, so we have to
fixup the path for the single targets.
With this both relative and full paths work:
make arch/arm64/boot/dts/arm/juno.dtb
make arm/juno.dtb
Complicating matters is building DTBs works without $ARCH compiler as
only the host preprocessor is used. This is useful for building all the
DTBs in the tree without installing a bunch of cross-compilers. The
single target rule needs to depend on 'dtbs_prepare' rather the
'prepare' to maintain support for that.
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
v3:
- New patch
---
Makefile | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/Makefile b/Makefile
index 4ad67b737af7..c307ee9293bc 100644
--- a/Makefile
+++ b/Makefile
@@ -301,7 +301,7 @@ no-dot-config-targets := $(clean-targets) \
run-command
no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
image_name
-single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
+single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.dtb %.dtbo %/
config-build :=
mixed-build :=
@@ -1663,12 +1663,6 @@ dtbindingtree := Documentation/devicetree/bindings
ifneq ($(dtstree),)
-%.dtb: dtbs_prepare
- $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
-
-%.dtbo: dtbs_prepare
- $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
-
PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
dtbs: dtbs_prepare
$(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
@@ -1683,7 +1677,7 @@ export CHECK_DTBS=y
endif
ifneq ($(CHECK_DTBS),)
-dtbs_prepare: dt_binding_schemas
+scripts_dtc: dt_binding_schemas
endif
dtbs_check: dtbs
@@ -2190,6 +2184,8 @@ modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
#
# make foo/bar/baz/
+single-build-prep := prepare
+
ifdef single-build
# .ko is special because modpost is needed
@@ -2212,8 +2208,20 @@ ifneq ($(KBUILD_MODPOST_NOFINAL),1)
endif
$(Q)rm -f modules.order
+# For compatibility with existing %.dtb targets without full path
+single-dtb := $(filter-out $(dtstree)/%, $(filter %.dtb %.dtbo, $(single-no-ko)))
+single-no-ko := $(filter-out $(single-dtb), $(single-no-ko)) $(addprefix $(dtstree)/, $(single-dtb))
+
single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
+# DT-only targets need host tools, but no architecture-specific preparation.
+ifneq ($(dtstree),)
+single-dt-patterns := $(addprefix $(dtstree)/,%.dtb %.dtbo)
+ifeq ($(filter-out $(single-dt-patterns),$(single-no-ko)),)
+single-build-prep := dtbs_prepare
+endif
+endif
+
KBUILD_MODULES := y
endif
@@ -2225,7 +2233,7 @@ prepare: outputmakefile
# make menuconfig etc.
# Error messages still appears in the original language
PHONY += $(build-dir)
-$(build-dir): prepare
+$(build-dir): $(single-build-prep)
$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
clean-dirs := $(addprefix _clean_, $(clean-dirs))
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] kbuild: Support directory targets for building DTBs
2026-10-07 18:39 [PATCH v3 0/2] kbuild: Support directory targets for DTBs Rob Herring (Arm)
2026-10-07 18:39 ` [PATCH v3 1/2] kbuild: Convert %.dtb(o) targets to single target rules Rob Herring (Arm)
@ 2026-10-07 18:39 ` Rob Herring (Arm)
1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring (Arm) @ 2026-10-07 18:39 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Saravana Kannan
Cc: David Heidelberg, Arnd Bergmann, linux-kbuild, linux-kernel, devicetree
It is useful to be able to build all the DTBs for a vendor. One can list
all the .dts files in a directory and convert those to %.dtb targets,
but that doesn't work for base+overlay DTB targets.
The 'dtbs' and 'dtbs_check' targets can use the directory rule targets
as well which avoids different make paths for building DTBs.
Assisted-by: LLM
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
v3:
- Reworked on top of single target rule for %.dtb
- Make dtbs target use directory rule.
- Move adding boot/dts subdir out of the arch code. Now supported on
every arch (not that useful without vendor dirs).
- Removed the need to look at MAKECMDGOALS
- Fixed unnecessary rebuilding DT base+overlay targets
- Link to v2: https://lore.kernel.org/all/20251120204812.1983452-4-robh@kernel.org/
v2:
- Convert arm, mips and riscv. The other DT enabled arches don't have
vendor directories.
- Link to v1: https://lore.kernel.org/all/20251113225952.867138-1-robh@kernel.org/
---
Makefile | 8 ++++----
scripts/Makefile.build | 7 +++++++
scripts/Makefile.dtbs | 2 ++
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index c307ee9293bc..75d290c2b7d8 100644
--- a/Makefile
+++ b/Makefile
@@ -1664,8 +1664,8 @@ dtbindingtree := Documentation/devicetree/bindings
ifneq ($(dtstree),)
PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
-dtbs: dtbs_prepare
- $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
+dtbs:
+ $(Q)$(MAKE) $(dtstree)/
# include/config/kernel.release is actually needed when installing DTBs because
# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
@@ -2216,7 +2216,7 @@ single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
# DT-only targets need host tools, but no architecture-specific preparation.
ifneq ($(dtstree),)
-single-dt-patterns := $(addprefix $(dtstree)/,%.dtb %.dtbo)
+single-dt-patterns := $(dtstree)/ $(addprefix $(dtstree)/,%.dtb %.dtbo %/)
ifeq ($(filter-out $(single-dt-patterns),$(single-no-ko)),)
single-build-prep := dtbs_prepare
endif
@@ -2234,7 +2234,7 @@ prepare: outputmakefile
# Error messages still appears in the original language
PHONY += $(build-dir)
$(build-dir): $(single-build-prep)
- $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
+ $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 need-dtbslist=1 $(single-goals)
clean-dirs := $(addprefix _clean_, $(clean-dirs))
PHONY += $(clean-dirs) clean
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 4349108e75e1..d22b3b2d43b3 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -38,6 +38,13 @@ include $(srctree)/scripts/Makefile.compiler
include $(kbuild-file)
include $(srctree)/scripts/Makefile.lib
+# Make DT directory targets reachable for architectures with a DTS tree.
+ifeq ($(obj),arch/$(SRCARCH))
+ifneq ($(wildcard $(src)/boot/dts/),)
+subdir-y += boot/dts
+endif
+endif
+
# flags that take effect in current and sub directories
KBUILD_AFLAGS += $(subdir-asflags-y)
KBUILD_CFLAGS += $(subdir-ccflags-y)
diff --git a/scripts/Makefile.dtbs b/scripts/Makefile.dtbs
index c4e466390284..c7ec2a2a308e 100644
--- a/scripts/Makefile.dtbs
+++ b/scripts/Makefile.dtbs
@@ -23,7 +23,9 @@ dtb-y := $(addprefix $(obj)/, $(dtb-y))
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
+ifdef need-dtbslist
always-y += $(dtb-y)
+endif
targets += $(real-dtb-y)
# dtbs-list
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread