Linux kbuild/kconfig development
 help / color / mirror / Atom feed
* [PATCH v5 0/2] kbuild: Support directory targets for DTBs
@ 2026-10-23 22:32 Rob Herring (Arm)
  2026-10-23 22:32 ` [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules Rob Herring (Arm)
  2026-10-23 22:32 ` [PATCH v5 2/2] kbuild: Support directory targets for building DTBs Rob Herring (Arm)
  0 siblings, 2 replies; 4+ messages in thread
From: Rob Herring (Arm) @ 2026-10-23 22:32 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Saravana Kannan
  Cc: David Heidelberg, Arnd Bergmann, linux-kbuild, linux-kernel,
	devicetree

This series adds support for using directory targets to build DTBs. This 
is primarily useful for architectures with lots of vendor DTS 
subdirectories.

v2 had some issues reported after I applied. In fixing David's issue,
that introduced random parallel build issues Arnd reported. I didn't get
it figured out quickly, so I ended up dropping it. I finally got
around to revisiting it with some LLM help this time. Having multiple 
paths in the build system to building DTBs complicates things, so I've 
reworked things to always use the single target and directory targets 
for building.

Arnd, can you give this a spin on your randconfig builds?
    
Please ack and I'll take this in the DT tree.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
Changes in v5:
- Don't drop 'dtbs_prepare' for 'dtbs' rule to avoid parallel make issue
- Limit adding boot/dts subdir to DT targets (also a parallel make 
  issue)
- Link to v4: https://patch.msgid.link/20261016-dtb-dirs-v3-v4-0-0ec42fd8ef9b@kernel.org

Changes in v4:
- Don't create dtbs-list files in every directory
- Link to v3: https://patch.msgid.link/20261007-dtb-dirs-v3-v3-0-b3ab32b64fa6@kernel.org

Changes in v3:
 - Convert %.dtbo? rules to single target
 - Convert dtbs rule to use directory target
 - Link to v2: https://lore.kernel.org/all/20251120204812.1983452-4-robh@kernel.org/

---
Rob Herring (Arm) (2):
      kbuild: Convert %.dtb(o) targets to single target rules
      kbuild: Support directory targets for building DTBs

 Makefile                          | 36 +++++++++++++++++++++++++-----------
 drivers/of/unittest-data/Makefile |  5 +++++
 scripts/Makefile.build            |  7 +++++++
 scripts/Makefile.dtbs             |  2 ++
 4 files changed, 39 insertions(+), 11 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20261007-dtb-dirs-v3-008fa5ffbc74

Best regards,
--  
Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules
  2026-10-23 22:32 [PATCH v5 0/2] kbuild: Support directory targets for DTBs Rob Herring (Arm)
@ 2026-10-23 22:32 ` Rob Herring (Arm)
  2026-10-24 22:33   ` sashiko-bot
  2026-10-23 22:32 ` [PATCH v5 2/2] kbuild: Support directory targets for building DTBs Rob Herring (Arm)
  1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring (Arm) @ 2026-10-23 22:32 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.

Reviewed-by: Nicolas Schier <nsc@kernel.org>
Tested-by: Nicolas Schier <nsc@kernel.org>
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 related	[flat|nested] 4+ messages in thread

* [PATCH v5 2/2] kbuild: Support directory targets for building DTBs
  2026-10-23 22:32 [PATCH v5 0/2] kbuild: Support directory targets for DTBs Rob Herring (Arm)
  2026-10-23 22:32 ` [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules Rob Herring (Arm)
@ 2026-10-23 22:32 ` Rob Herring (Arm)
  1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring (Arm) @ 2026-10-23 22:32 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.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
v5:
 - Don't drop 'dtbs_prepare' for 'dtbs' rule to avoid parallel make
   issue
 - Limit adding boot/dts subdir to DT targets

v4:
 - Don't create a dtbs-list file in every directory

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                          | 12 +++++++++---
 drivers/of/unittest-data/Makefile |  5 +++++
 scripts/Makefile.build            |  7 +++++++
 scripts/Makefile.dtbs             |  2 ++
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index c307ee9293bc..8db22d02cceb 100644
--- a/Makefile
+++ b/Makefile
@@ -1665,7 +1665,7 @@ ifneq ($(dtstree),)
 
 PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
 dtbs: dtbs_prepare
-	$(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
+	$(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
@@ -2185,6 +2185,7 @@ modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
 #   make foo/bar/baz/
 
 single-build-prep := prepare
+single-dtbslist-arg :=
 
 ifdef single-build
 
@@ -2216,9 +2217,13 @@ 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 %/)
+ifneq ($(filter $(single-dt-patterns),$(single-no-ko)),)
+single-dtbslist-arg := need-dtbslist=1
+endif
 ifeq ($(filter-out $(single-dt-patterns),$(single-no-ko)),)
 single-build-prep := dtbs_prepare
+single-dtbslist-arg := need-dtbslist=1
 endif
 endif
 
@@ -2234,7 +2239,8 @@ 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 \
+		$(single-dtbslist-arg) $(single-goals)
 
 clean-dirs := $(addprefix _clean_, $(clean-dirs))
 PHONY += $(clean-dirs) clean
diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile
index 01a966e39f23..bac6ee9327e2 100644
--- a/drivers/of/unittest-data/Makefile
+++ b/drivers/of/unittest-data/Makefile
@@ -104,3 +104,8 @@ static_test_1-dtbs := static_base_1.dtb $(apply_static_overlay_1)
 static_test_2-dtbs := static_base_2.dtb $(apply_static_overlay_2)
 
 dtb-$(CONFIG_OF_OVERLAY) += static_test_1.dtb static_test_2.dtb
+
+# Include the static overlay tests in normal kernel builds.
+ifdef CONFIG_OF_OVERLAY
+need-dtbslist := 1
+endif
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 4349108e75e1..22fbd5199091 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))
+ifdef need-dtbslist
+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 related	[flat|nested] 4+ messages in thread

* Re: [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules
  2026-10-23 22:32 ` [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules Rob Herring (Arm)
@ 2026-10-24 22:33   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-10-24 22:33 UTC (permalink / raw)
  To: Rob Herring (Arm), Nathan Chancellor, Nicolas Schier,
	Saravana Kannan
  Cc: David Heidelberg, Arnd Bergmann, linux-kbuild, devicetree,
	conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kbuild: single-target .dtb and .dtbo rules fail to descend into boot/dts
- [Medium] kbuild: unconditional dtstree prefixing corrupts non-dtstree .dtb targets
--

commit 7e93223635a0ece771bb2b9e12840b3751ca5a16
Author: Rob Herring (Arm) <robh@kernel.org>

kbuild: Convert %.dtb(o) targets to single target rules

This commit replaces the dedicated top-level %.dtb and %.dtbo rules with the
generic kbuild single-target infrastructure, rewriting relative DTB paths to
include $(dtstree) and using dtbs_prepare as the prerequisite for DT-only
single builds.

> diff --git a/Makefile b/Makefile
> index 4ad67b737af7a..c307ee9293bcd 100644
> --- a/Makefile
> +++ b/Makefile

[ ... ]

> @@ -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))

[Severity: Medium]
What happens here when building an in-tree .dtb or .dtbo target located
outside $(dtstree), such as make drivers/of/empty_root.dtb or
make drivers/of/unittest-data/testcases.dtbo, or when $(dtstree) is empty?

Because single-dtb matches any %.dtb or %.dtbo target that does not begin
with $(dtstree)/, targets under drivers/of/ or drivers/clk/ have
$(dtstree)/ unconditionally prepended to their path, rewriting them to
non-existent paths under arch/$(SRCARCH)/boot/dts/drivers/....

In addition, unlike the single-dt-patterns check just below, this rewrite is
not guarded by ifneq ($(dtstree),). On architectures without a boot/dts
directory or during external module M= builds where $(dtstree) is empty,
$(addprefix $(dtstree)/, $(single-dtb)) prepends a leading / to the target.

Should this rewrite be guarded by ifneq ($(dtstree),) and restricted to
paths that actually exist under $(dtstree) (or do not already exist at their
given path)?

> +
>  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)

[Severity: High]
Does routing single .dtb and .dtbo targets through $(build-dir) allow
scripts/Makefile.build to descend into arch/$(SRCARCH)/boot/dts?

Previously, the %.dtb and %.dtbo rules invoked
$(MAKE) $(build)=$(dtstree) $(dtstree)/$@, starting scripts/Makefile.build
directly at obj=arch/$(SRCARCH)/boot/dts. With this change, $(build-dir)
starts at obj=. and descends into obj=arch/$(SRCARCH), which includes
arch/$(SRCARCH)/Kbuild. However, in arch/$(SRCARCH)/Kbuild (for example in
arch/arm64/Kbuild):

    # for cleaning
    subdir- += boot

neither boot nor boot/dts is in obj-y, obj-m, subdir-y, or subdir-m. When
scripts/Makefile.build evaluates single-subdirs at obj=arch/$(SRCARCH):

    single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d))
    single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS))

single-subdirs is empty, so Kbuild stops descending at obj=arch/$(SRCARCH)
and places arch/$(SRCARCH)/boot/dts/<vendor>/<target>.dtb(o) directly into
$(targets) at obj=arch/$(SRCARCH) without ever including
arch/$(SRCARCH)/boot/dts/Makefile or the vendor subdirectory Makefile.

This causes three regressions when building single targets at this commit:

1. Building any single .dtbo target (e.g. make <vendor>/<overlay>.dtbo)
   fails with "No rule to make target", because at obj=arch/$(SRCARCH),
   need-dtbslist, dtb-y, and dtb- are empty, and scripts/Makefile.build:

       ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
       include $(srctree)/scripts/Makefile.dtbs
       endif

   omits %.dtbo from the $(targets) filter, so scripts/Makefile.dtbs is
   never included.

2. Building any composite .dtb target defined via <name>-dtbs := base.dtb
   overlay.dtbo (such as make qcom/apq8016-sbc-usb-host.dtb) fails with
   "No rule to make target" because the vendor Makefile is not included and
   multi-dtb-y remains empty.

3. Building simple .dtb targets matches $(obj)/%.dtb: $(obj)/%.dts at
   obj=arch/$(SRCARCH) with target-stem set to boot/dts/<vendor>/<board>
   instead of <board>, silently dropping per-directory DTC_FLAGS,
   per-target DTC_FLAGS_<stem>, and base-dtb-y automatic -@ symbol
   generation.

Note that a subsequent commit in this series, commit 02ed329e5679 ("kbuild:
Support directory targets for building DTBs"), partially addresses traversal
by passing need-dtbslist=1 for DT builds and adding subdir-y += boot/dts in
scripts/Makefile.build when need-dtbslist is set, though this commit is
broken on its own during bisection (and the %.dtbo filter omission in
scripts/Makefile.build remains if need-dtbslist, dtb-y, and dtb- are empty).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261023-dtb-dirs-v3-v5-0-dfe13d47aa64@kernel.org?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-24 22:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 22:32 [PATCH v5 0/2] kbuild: Support directory targets for DTBs Rob Herring (Arm)
2026-10-23 22:32 ` [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules Rob Herring (Arm)
2026-10-24 22:33   ` sashiko-bot
2026-10-23 22:32 ` [PATCH v5 2/2] kbuild: Support directory targets for building DTBs Rob Herring (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox