Skip to contentSkip to conversation

kbuild: create a list of DTBs and allow to install base dtb and overlays

PATCH In review Masahiro Yamada 2 participants 9 messages Jan 9, 2024 – Jan 19, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover kbuild: create a list of DTBs and allow to install base dtb and overlays

1/4 and 2/4 are less controvertial refactoring. This will be useful for future cleanups.

3/4 and 4/4 address the current dtbs_install limitation; when the generic -dtbs syntax is used in Makefiles, only the final assembled dtbs are installed. We need to manually copy base dtbs and overlays if necessary. It would be sometimes useful to install such base componennts.

Masahiro Yamada (4):
kbuild: create a list of all built DTB files
kbuild: simplify dtbs_install by reading the list of compiled DTBs
kbuild: create a list of base and overlays for each DTB
kbuild: allow 'make dtbs_install' to install primitive DTBs

 .gitignore                      |  2 ++
 Documentation/kbuild/kbuild.rst |  6 ++++++
 Makefile                        |  6 +++---
 scripts/Kbuild.include          |  6 ------
 scripts/Makefile.build          | 26 +++++++++++++++-------
 scripts/Makefile.dtbinst        | 38 +++++++++++++++++++++------------
 scripts/Makefile.lib            |  8 +++++++
 7 files changed, 61 insertions(+), 31 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/4 kbuild: create a list of all built DTB files

It is useful to have a list of all *.dtb and *.dtbo files generated from the current build.

With this commit, 'make dtbs' creates arch/*/boot/dts/dtbs-order, which lists the dtb(o) files created in the current build. It maintains the order of the dtb-y additions in Makefiles although the order is not important for DTBs. It is a (good) side effect through the reuse of the modules.order rule.

Please note this list only includes the files directly added to dtb-y.

For example, consider this case:

foo-dtbs := foo_base.dtb foo_overlay.dtbo
dtb-y := foo.dtb

In this example, the list will include foo.dtb, but not foo_base.dtb or foo_overlay.dtbo.

---

 .gitignore             |  1 +
 Makefile               |  4 ++--
 scripts/Makefile.build | 20 ++++++++++++--------
 scripts/Makefile.lib   |  6 ++++++
 4 files changed, 21 insertions(+), 10 deletions(-)
.gitignore +1 -0
index 689a4fa3f547..c59dc60ba62e 100644
@@ -52,6 +52,7 @@
 *.xz
 *.zst
 Module.symvers
+dtbs-list
 modules.order
 
 #
Makefile +2 -2
index 6204a3803a90..db7f9e34a24e 100644
@@ -1389,7 +1389,7 @@ ifneq ($(dtstree),)
 
 PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
 dtbs: dtbs_prepare
-	$(Q)$(MAKE) $(build)=$(dtstree)
+	$(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
 
 # include/config/kernel.release is actually needed when installing DTBs because
 # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
@@ -1927,7 +1927,7 @@ clean: $(clean-dirs)
 		-o -name '*.ko.*' \
 		-o -name '*.dtb' -o -name '*.dtbo' \
 		-o -name '*.dtb.S' -o -name '*.dtbo.S' \
-		-o -name '*.dt.yaml' \
+		-o -name '*.dt.yaml' -o -name 'dtbs-list' \
 		-o -name '*.dwo' -o -name '*.lst' \
 		-o -name '*.su' -o -name '*.mod' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
scripts/Makefile.build +12 -8
index 9a3063735e71..d23797dbca0f 100644
@@ -71,6 +71,7 @@ endif
 # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
 subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
 subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
+subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y)))
 
 targets-for-builtin := $(extra-y)
 
@@ -387,6 +388,7 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
 # To build objects in subdirs, we need to descend into the directories
 $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
 $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
+$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
 
 #
 # Rule to compile a set of .o files into one .a file (without symbol table)
@@ -403,19 +405,21 @@ $(obj)/built-in.a: $(real-obj-y) FORCE
 	$(call if_changed,ar_builtin)
 
 #
-# Rule to create modules.order file
+# Rule to create modules.order and dtbs-list
 #
-# Create commands to either record .ko file or cat modules.order from
-# a subdirectory
-# Add $(obj-m) as the prerequisite to avoid updating the timestamp of
-# modules.order unless contained modules are updated.
+# This is a list of build artifacts (module or dtb) from the current Makefile
+# and its sub-directories. The timestamp should be updated when any of the
+# member files.
 
-cmd_modules_order = { $(foreach m, $(real-prereqs), \
-	$(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
+cmd_gen_order = { $(foreach m, $(real-prereqs), \
+	$(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \
 	> $@
 
 $(obj)/modules.order: $(obj-m) FORCE
-	$(call if_changed,modules_order)
+	$(call if_changed,gen_order)
+
+$(obj)/dtbs-list: $(dtb-y) FORCE
+	$(call if_changed,gen_order)
 
 #
 # Rule to compile a set of .o files into one .a file (with symbol table)
scripts/Makefile.lib +6 -0
index cd5b181060f1..b35d39022a30 100644
@@ -45,6 +45,11 @@ else
 obj-y		:= $(filter-out %/, $(obj-y))
 endif
 
+ifdef need-dtbslist
+dtb-y		+= $(addsuffix /dtbs-list, $(subdir-ym))
+always-y	+= dtbs-list
+endif
+
 # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
 suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
 # List composite targets that are constructed by combining other targets
@@ -99,6 +104,7 @@ lib-y		:= $(addprefix $(obj)/,$(lib-y))
 real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
 real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
 multi-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
+dtb-y		:= $(addprefix $(obj)/, $(dtb-y))
 multi-dtb-y	:= $(addprefix $(obj)/, $(multi-dtb-y))
 real-dtb-y	:= $(addprefix $(obj)/, $(real-dtb-y))
 subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH 1/4] kbuild: create a list of all built DTB files

Quoted 5 lines · Masahiro Yamada

It is useful to have a list of all *.dtb and *.dtbo files generated from the current build.

With this commit, 'make dtbs' creates arch/*/boot/dts/dtbs-order, which

I meant arch/*/boot/dts/dtbs-list

--
Best Regards
Masahiro Yamada

#3 lore raw

PATCH 2/4 kbuild: simplify dtbs_install by reading the list of compiled DTBs

In reply to Masahiro Yamada

Retrieve the list of *.dtb(o) files from arch/*/boot/dts/dtbs-list instead of traversing the directory tree again.

Please note that 'make dtbs_install' installs *.dtb(o) files directly added to dtb-y because scripts/Makefile.dtbinst installs $(dtb-y) without expanding the -dtbs suffix.

This commit preserves this behavior.

---

 Makefile                 |  2 +-
 scripts/Kbuild.include   |  6 ------
 scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
 3 files changed, 19 insertions(+), 21 deletions(-)
Makefile +1 -1
index db7f9e34a24e..dae6825b8082 100644
@@ -1407,7 +1407,7 @@ endif
 dtbs_check: dtbs
 
 dtbs_install:
-	$(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH)
+	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
 
 ifdef CONFIG_OF_EARLY_FLATTREE
 all: dtbs
scripts/Kbuild.include +0 -6
index 7778cc97a4e0..2f331879816b 100644
@@ -113,12 +113,6 @@ endef
 # $(Q)$(MAKE) $(build)=dir
 build := -f $(srctree)/scripts/Makefile.build obj
 
-###
-# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
-# Usage:
-# $(Q)$(MAKE) $(dtbinst)=dir
-dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
-
 ###
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
 # Usage:
scripts/Makefile.dtbinst +18 -14
index 4405d5b67578..67956f6496a5 100644
@@ -8,32 +8,36 @@
 #   $INSTALL_PATH/dtbs/$KERNELRELEASE
 # ==========================================================================
 
-src := $(obj)
-
 PHONY := __dtbs_install
 __dtbs_install:
 
 include include/config/auto.conf
 include $(srctree)/scripts/Kbuild.include
-include $(kbuild-file)
 
-dtbs    := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-)))
-subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m))
-
-__dtbs_install: $(dtbs) $(subdirs)
-	@:
+dst := $(INSTALL_DTBS_PATH)
 
 quiet_cmd_dtb_install = INSTALL $@
       cmd_dtb_install = install -D $< $@
 
-$(dst)/%.dtb: $(obj)/%.dtb
+$(dst)/%: $(obj)/%
 	$(call cmd,dtb_install)
 
-$(dst)/%.dtbo: $(obj)/%.dtbo
-	$(call cmd,dtb_install)
+dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list))
 
-PHONY += $(subdirs)
-$(subdirs):
-	$(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@))
+ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+define gen_install_rules
+$(dst)/%: $(obj)/$(1)%
+	$$(call cmd,dtb_install)
+endef
+
+$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d))))
+
+dtbs := $(notdir $(dtbs))
+
+endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+__dtbs_install: $(addprefix $(dst)/, $(dtbs))
+	@:
 
 .PHONY: $(PHONY)
Signature · 1 line
2.40.1
maintainer
#4 lore raw

Re: [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs

Quoted 2 lines · Masahiro Yamada

Retrieve the list of *.dtb(o) files from arch/*/boot/dts/dtbs-list instead of traversing the directory tree again.

Don't you need dtbs-list in .gitignore?

Quoted 103 lines

Please note that 'make dtbs_install' installs *.dtb(o) files directly added to dtb-y because scripts/Makefile.dtbinst installs $(dtb-y) without expanding the -dtbs suffix.

This commit preserves this behavior.

---

 Makefile                 |  2 +-
 scripts/Kbuild.include   |  6 ------
 scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
 3 files changed, 19 insertions(+), 21 deletions(-)
Makefile +1 -1
index db7f9e34a24e..dae6825b8082 100644
@@ -1407,7 +1407,7 @@ endif
 dtbs_check: dtbs
 
 dtbs_install:
-	$(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH)
+	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
 
 ifdef CONFIG_OF_EARLY_FLATTREE
 all: dtbs
scripts/Kbuild.include +0 -6
index 7778cc97a4e0..2f331879816b 100644
@@ -113,12 +113,6 @@ endef
 # $(Q)$(MAKE) $(build)=dir
 build := -f $(srctree)/scripts/Makefile.build obj
 
-###
-# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
-# Usage:
-# $(Q)$(MAKE) $(dtbinst)=dir
-dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
-
 ###
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
 # Usage:
scripts/Makefile.dtbinst +18 -14
index 4405d5b67578..67956f6496a5 100644
@@ -8,32 +8,36 @@
 #   $INSTALL_PATH/dtbs/$KERNELRELEASE
 # ==========================================================================
 
-src := $(obj)
-
 PHONY := __dtbs_install
 __dtbs_install:
 
 include include/config/auto.conf
 include $(srctree)/scripts/Kbuild.include
-include $(kbuild-file)
 
-dtbs    := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-)))
-subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m))
-
-__dtbs_install: $(dtbs) $(subdirs)
-	@:
+dst := $(INSTALL_DTBS_PATH)
 
 quiet_cmd_dtb_install = INSTALL $@
       cmd_dtb_install = install -D $< $@
 
-$(dst)/%.dtb: $(obj)/%.dtb
+$(dst)/%: $(obj)/%
 	$(call cmd,dtb_install)
 
-$(dst)/%.dtbo: $(obj)/%.dtbo
-	$(call cmd,dtb_install)
+dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list))
 
-PHONY += $(subdirs)
-$(subdirs):
-	$(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@))
+ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+define gen_install_rules
+$(dst)/%: $(obj)/$(1)%
+	$$(call cmd,dtb_install)
+endef
+
+$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d))))
+
+dtbs := $(notdir $(dtbs))
+
+endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+__dtbs_install: $(addprefix $(dst)/, $(dtbs))
+	@:
 
 .PHONY: $(PHONY)
Signature · 1 line
2.40.1
#5 lore raw

Re: [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs

Quoted 6 lines · Rob Herring
Quoted 2 lines · Masahiro Yamada

Retrieve the list of *.dtb(o) files from arch/*/boot/dts/dtbs-list instead of traversing the directory tree again.

Don't you need dtbs-list in .gitignore?

Yes.

1/4 added it.

Quoted 103 lines
Quoted 103 lines

Please note that 'make dtbs_install' installs *.dtb(o) files directly added to dtb-y because scripts/Makefile.dtbinst installs $(dtb-y) without expanding the -dtbs suffix.

This commit preserves this behavior.

---

 Makefile                 |  2 +-
 scripts/Kbuild.include   |  6 ------
 scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
 3 files changed, 19 insertions(+), 21 deletions(-)
Makefile +1 -1
index db7f9e34a24e..dae6825b8082 100644
@@ -1407,7 +1407,7 @@ endif
 dtbs_check: dtbs
 
 dtbs_install:
-     $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH)
+     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
 
 ifdef CONFIG_OF_EARLY_FLATTREE
 all: dtbs
scripts/Kbuild.include +0 -6
index 7778cc97a4e0..2f331879816b 100644
@@ -113,12 +113,6 @@ endef
 # $(Q)$(MAKE) $(build)=dir
 build := -f $(srctree)/scripts/Makefile.build obj
 
-###
-# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
-# Usage:
-# $(Q)$(MAKE) $(dtbinst)=dir
-dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
-
 ###
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
 # Usage:
scripts/Makefile.dtbinst +18 -15
index 4405d5b67578..67956f6496a5 100644
@@ -8,32 +8,36 @@
 #   $INSTALL_PATH/dtbs/$KERNELRELEASE
 # ==========================================================================
 
-src := $(obj)
-
 PHONY := __dtbs_install
 __dtbs_install:
 
 include include/config/auto.conf
 include $(srctree)/scripts/Kbuild.include
-include $(kbuild-file)
 
-dtbs    := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-)))
-subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m))
-
-__dtbs_install: $(dtbs) $(subdirs)
-     @:
+dst := $(INSTALL_DTBS_PATH)
 
 quiet_cmd_dtb_install = INSTALL $@
       cmd_dtb_install = install -D $< $@
 
-$(dst)/%.dtb: $(obj)/%.dtb
+$(dst)/%: $(obj)/%
      $(call cmd,dtb_install)
 
-$(dst)/%.dtbo: $(obj)/%.dtbo
-     $(call cmd,dtb_install)
+dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list))
 
-PHONY += $(subdirs)
-$(subdirs):
-     $(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@))
+ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+define gen_install_rules
+$(dst)/%: $(obj)/$(1)%
+     $$(call cmd,dtb_install)
+endef
+
+$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d))))
+
+dtbs := $(notdir $(dtbs))
+
+endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
+
+__dtbs_install: $(addprefix $(dst)/, $(dtbs))
+     @:
 
 .PHONY: $(PHONY)
--

2.40.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#6 lore raw

PATCH 3/4 kbuild: create a list of base and overlays for each DTB

In reply to Masahiro Yamada

Some *.dtb files are assembled from a base DTB and overlays, but once they are built, there is no way to propagate such information to succeeding processes.

This commit introduces the generation of *.dtlst files, listing the component *.dtb(o) files that construct the corresponding *.dtb.

This is analogous to *.mod, which lists component objects for each module.

---

 .gitignore             | 1 +
 Makefile               | 2 +-
 scripts/Makefile.build | 6 ++++++
 scripts/Makefile.lib   | 2 ++
 4 files changed, 10 insertions(+), 1 deletion(-)
.gitignore +1 -0
index c59dc60ba62e..912cb713ad74 100644
@@ -21,6 +21,7 @@
 *.dtbo
 *.dtb.S
 *.dtbo.S
+*.dtlst
 *.dwo
 *.elf
 *.gcno
Makefile +1 -1
index dae6825b8082..3521bdad6db7 100644
@@ -1927,7 +1927,7 @@ clean: $(clean-dirs)
 		-o -name '*.ko.*' \
 		-o -name '*.dtb' -o -name '*.dtbo' \
 		-o -name '*.dtb.S' -o -name '*.dtbo.S' \
-		-o -name '*.dt.yaml' -o -name 'dtbs-list' \
+		-o -name '*.dt.yaml' -o -name '*.dtlst' -o -name 'dtbs-list' \
 		-o -name '*.dwo' -o -name '*.lst' \
 		-o -name '*.su' -o -name '*.mod' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
scripts/Makefile.build +6 -0
index d23797dbca0f..e9fcf330ff39 100644
@@ -252,6 +252,12 @@ cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
 $(obj)/%.mod: FORCE
 	$(call if_changed,mod)
 
+cmd_dt_list = printf '%s\n' $(call real-search, $*.dtb, .dtb, -dtbs) | \
+	$(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
+
+$(obj)/%.dtlst: FORCE
+	$(call if_changed,dt_list)
+
 quiet_cmd_cc_lst_c = MKLST   $@
       cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
 		     $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
scripts/Makefile.lib +2 -0
index b35d39022a30..0a492a4e4fbb 100644
@@ -93,6 +93,8 @@ base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
 
 always-y			+= $(dtb-y)
 
+always-y	+= $(patsubst %.dtb, %.dtlst, $(filter %.dtb, $(dtb-y)))
+
 # Add subdir path
 
 ifneq ($(obj),.)
Signature · 1 line
2.40.1
#7 lore raw

PATCH 4/4 kbuild: allow 'make dtbs_install' to install primitive DTBs

In reply to Masahiro Yamada

Commit 15d16d6dadf6 ("kbuild: Add generic rule to apply fdtoverlay") introduced the -dtbs syntax to apply overlays during the build process.

However, scripts/Makefile.dtbinst is not aware of the -dtbs syntax, so 'make dtbs_install' installs the files directly added to dtb-y. (Presumably, it was intentional.)

For example, consider this case:

foo1-dtbs := foo_base.dtb foo_overlay1.dtbo
foo2-dtbs := foo_base.dtb foo_overlay2.dtbo
dtb-y := foo1.dtb foo2.dtb

'make dtbs_install' only installs foo1.dtb and foo2.dtb. It is suitable when the boot image supports a single hardware configuration, or when the boot loader in use does not support applying overlays.

However, when creating a boot image with multiple board supports, it wastes storage space, as foo1.dtb and foo2.dtb have foo_base.dtb in common.

From a space perspective, a more optimal solution is to install foo_base.dtb, foo_overlay1.dtbo, and foo_overlay2.dtbo, then assemble the final dtb (either foo1.dtb or foo2.dtb) on the boot loader.

This commit adds a new flag, INSTALL_DTBS_PRIMITIVE.

With INSTALL_DTBS_PRIMITIVE=1, 'make dtbs_install' will install primitive files (such as foo_base.dtb, foo_overlay1.dtbo, and foo_overlay2.dtbo in this case).

Without INSTALL_DTBS_PRIMITIVE, the current behavior is maintained (foo1.dtb and foo2.dtb will be installed in this case).

---

 Documentation/kbuild/kbuild.rst | 6 ++++++
 scripts/Makefile.dtbinst        | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
Documentation/kbuild/kbuild.rst +6 -0
index 9c8d1d046ea5..d803ca5afc07 100644
@@ -249,6 +249,12 @@ INSTALL_DTBS_PATH specifies where to install device tree blobs for
 relocations required by build roots.  This is not defined in the
 makefile but the argument can be passed to make if needed.
 
+INSTALL_DTBS_PRIMITIVE
+----------------------
+INSTALL_DTBS_PRIMITIVE, if defined, will cause the dtbs_install target to
+install the base dtb and overlay dtbo files instead of assembled dtb files
+constructed by overlay application.
+
 KBUILD_ABS_SRCTREE
 --------------------------------------------------
 Kbuild uses a relative path to point to the tree when possible. For instance,
scripts/Makefile.dtbinst +7 -1
index 67956f6496a5..14111a86987a 100644
@@ -22,7 +22,13 @@ quiet_cmd_dtb_install = INSTALL $@
 $(dst)/%: $(obj)/%
 	$(call cmd,dtb_install)
 
-dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list))
+dtbs := $(call read-file, $(obj)/dtbs-list)
+
+ifdef INSTALL_DTBS_PRIMITIVE
+dtbs := $(foreach f, $(dtbs), $(if $(filter %.dtb,$(f)),$(call read-file, $(patsubst %.dtb,%.dtlst,$(f))),$(f)))
+endif
+
+dtbs := $(patsubst $(obj)/%,%,$(dtbs))
 
 ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
 
Signature · 1 line
2.40.1
maintainer
#8 lore raw

Re: [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs

Quoted 6 lines · Masahiro Yamada

Commit 15d16d6dadf6 ("kbuild: Add generic rule to apply fdtoverlay") introduced the -dtbs syntax to apply overlays during the build process.

However, scripts/Makefile.dtbinst is not aware of the -dtbs syntax, so 'make dtbs_install' installs the files directly added to dtb-y. (Presumably, it was intentional.)

Yes. The intent was the Makefile should define what's installed or not. There's 2 reasons to apply overlays in the build. The first is so a DTB can be refactored into a base plus overlay(s) and we keep the original full DTB. The second is to test that overlays actually apply because testing that at boot time in bootloader is a poor experience and we don't want overlays which don't apply to upstream DTs.

Whatever targets you want installed put in dtb-y. Whatever targets are just for testing, put in dtb-. The latter are then enabled with CONFIG_OF_ALL_DTBS.

Quoted 18 lines

For example, consider this case:

foo1-dtbs := foo_base.dtb foo_overlay1.dtbo
foo2-dtbs := foo_base.dtb foo_overlay2.dtbo
dtb-y := foo1.dtb foo2.dtb

'make dtbs_install' only installs foo1.dtb and foo2.dtb. It is suitable when the boot image supports a single hardware configuration, or when the boot loader in use does not support applying overlays.

However, when creating a boot image with multiple board supports, it wastes storage space, as foo1.dtb and foo2.dtb have foo_base.dtb in common.

From a space perspective, a more optimal solution is to install foo_base.dtb, foo_overlay1.dtbo, and foo_overlay2.dtbo, then assemble the final dtb (either foo1.dtb or foo2.dtb) on the boot loader.

Quoted 5 lines

This commit adds a new flag, INSTALL_DTBS_PRIMITIVE.

With INSTALL_DTBS_PRIMITIVE=1, 'make dtbs_install' will install primitive files (such as foo_base.dtb, foo_overlay1.dtbo, and foo_overlay2.dtbo in this case).

And not install foo1.dtb and foo2.dtb, right? What if one wants to install everything? Seems like this needs to be a 3-way option.

I'm not really convinced we need this in the first place though.

Quoted 3 lines

Without INSTALL_DTBS_PRIMITIVE, the current behavior is maintained (foo1.dtb and foo2.dtb will be installed in this case).