kbuild: Support directory targets for DTBs
Subsystems (2)
Rob Herring (Arm)
maintainerv5 cover kbuild: Support directory targets for DTBs
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.
---
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/[email protected]
Changes in v4:
- Don't create dtbs-list files in every directory
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Convert %.dtbo? rules to single target
- Convert dtbs rule to use directory target
- Link to v2: https://lore.kernel.org/all/[email protected]/
---
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,
Signature · 1 line
Rob Herring (Arm) <[email protected]>
Rob Herring (Arm)
maintainerPATCH v5 1/2 kbuild: Convert %.dtb(o) targets to single target rules
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.
---
v3:
- New patch
--- Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
Makefile +17 -9
@@ -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))
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v5 1/2] kbuild: Convert %.dtb(o) targets to single target rules
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…
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) <[email protected]>
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.
Quoted 4 lines
Makefile +0
-0
[ ... ]
Makefile ifneq ($(KBUILD_MODPOST_NOFINAL),1) · line 2213
Quoted 7 lines
Makefile +3
-0@@ -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)?
Quoted 15 lines
Makefile +9
-0+ 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
Makefile prepare: outputmakefile · line 2237
Quoted 6 lines
Makefile +1
-1@@ -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- += bootneither 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
endifomits %.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).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rob Herring (Arm)
maintainerPATCH v5 2/2 kbuild: Support directory targets for building DTBs
In reply to Rob Herring (Arm)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.
---
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/[email protected]/
v2:
- Convert arm, mips and riscv. The other DT enabled arches don't have vendor directories.
- Link to v1: https://lore.kernel.org/all/[email protected]/
--- Makefile | 12 +++++++++--- drivers/of/unittest-data/Makefile | 5 +++++ scripts/Makefile.build | 7 +++++++ scripts/Makefile.dtbs | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-)
Makefile +9 -3
@@ -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
drivers/of/unittest-data/Makefile +5 -0
@@ -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
scripts/Makefile.build +7 -0
@@ -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)
scripts/Makefile.dtbs +2 -0
@@ -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
Signature · 1 line
2.53.0
Re: [PATCH v5 2/2] kbuild: Support directory targets for building DTBs
Quoted 9 lines
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) <[email protected]>---
[...]
Quoted 7 lines
--- Makefile | 12 +++++++++--- drivers/of/unittest-data/Makefile | 5 +++++ scripts/Makefile.build | 7 +++++++ scripts/Makefile.dtbs | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-)
[...]
Quoted 23 lines
scripts/Makefile.build +7
-0@@ -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)scripts/Makefile.dtbs +0
-0
scripts/Makefile.dtbs dtb-y := $(addprefix $(obj)/, $(dtb-y)) · line 28
Quoted 6 lines
scripts/Makefile.dtbs +2
-0@@ -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
Looks good to me, thanks!
To prevent too many ifdef/endif lines, we could use substution variable references in scripts/Makefile.{build,dtbs}, e.g.:
always-$(need-dtbslist:1=y) += $(dtb-y)
Signature · 1 line
Nicolas