linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays
@ 2024-01-09 12:07 Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 1/4] kbuild: create a list of all built DTB files Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 12:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Masahiro Yamada,
	Jonathan Corbet, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-doc, linux-kernel

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

-- 
2.40.1


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

* [PATCH 1/4] kbuild: create a list of all built DTB files
  2024-01-09 12:07 [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays Masahiro Yamada
@ 2024-01-09 12:07 ` Masahiro Yamada
  2024-01-09 14:22   ` Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 12:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Masahiro Yamada,
	Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
	linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 .gitignore             |  1 +
 Makefile               |  4 ++--
 scripts/Makefile.build | 20 ++++++++++++--------
 scripts/Makefile.lib   |  6 ++++++
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
index 689a4fa3f547..c59dc60ba62e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,7 @@
 *.xz
 *.zst
 Module.symvers
+dtbs-list
 modules.order
 
 #
diff --git a/Makefile b/Makefile
index 6204a3803a90..db7f9e34a24e 100644
--- a/Makefile
+++ b/Makefile
@@ -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' \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 9a3063735e71..d23797dbca0f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -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)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index cd5b181060f1..b35d39022a30 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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))
-- 
2.40.1


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

* [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs
  2024-01-09 12:07 [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 1/4] kbuild: create a list of all built DTB files Masahiro Yamada
@ 2024-01-09 12:07 ` Masahiro Yamada
  2024-01-17 14:52   ` Rob Herring
  2024-01-09 12:07 ` [PATCH 3/4] kbuild: create a list of base and overlays for each DTB Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs Masahiro Yamada
  3 siblings, 1 reply; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 12:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Masahiro Yamada,
	Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
	linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile                 |  2 +-
 scripts/Kbuild.include   |  6 ------
 scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index db7f9e34a24e..dae6825b8082 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 7778cc97a4e0..2f331879816b 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -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:
diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst
index 4405d5b67578..67956f6496a5 100644
--- a/scripts/Makefile.dtbinst
+++ b/scripts/Makefile.dtbinst
@@ -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


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

* [PATCH 3/4] kbuild: create a list of base and overlays for each DTB
  2024-01-09 12:07 [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 1/4] kbuild: create a list of all built DTB files Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs Masahiro Yamada
@ 2024-01-09 12:07 ` Masahiro Yamada
  2024-01-09 12:07 ` [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs Masahiro Yamada
  3 siblings, 0 replies; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 12:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Masahiro Yamada,
	Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
	linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 .gitignore             | 1 +
 Makefile               | 2 +-
 scripts/Makefile.build | 6 ++++++
 scripts/Makefile.lib   | 2 ++
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index c59dc60ba62e..912cb713ad74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,7 @@
 *.dtbo
 *.dtb.S
 *.dtbo.S
+*.dtlst
 *.dwo
 *.elf
 *.gcno
diff --git a/Makefile b/Makefile
index dae6825b8082..3521bdad6db7 100644
--- a/Makefile
+++ b/Makefile
@@ -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' \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index d23797dbca0f..e9fcf330ff39 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -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 \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index b35d39022a30..0a492a4e4fbb 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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),.)
-- 
2.40.1


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

* [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs
  2024-01-09 12:07 [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays Masahiro Yamada
                   ` (2 preceding siblings ...)
  2024-01-09 12:07 ` [PATCH 3/4] kbuild: create a list of base and overlays for each DTB Masahiro Yamada
@ 2024-01-09 12:07 ` Masahiro Yamada
  2024-01-17 15:37   ` Rob Herring
  3 siblings, 1 reply; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 12:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Masahiro Yamada,
	Jonathan Corbet, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-doc, linux-kernel

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

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Documentation/kbuild/kbuild.rst | 6 ++++++
 scripts/Makefile.dtbinst        | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index 9c8d1d046ea5..d803ca5afc07 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -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,
diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst
index 67956f6496a5..14111a86987a 100644
--- a/scripts/Makefile.dtbinst
+++ b/scripts/Makefile.dtbinst
@@ -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
 
-- 
2.40.1


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

* Re: [PATCH 1/4] kbuild: create a list of all built DTB files
  2024-01-09 12:07 ` [PATCH 1/4] kbuild: create a list of all built DTB files Masahiro Yamada
@ 2024-01-09 14:22   ` Masahiro Yamada
  0 siblings, 0 replies; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-09 14:22 UTC (permalink / raw)
  To: linux-kbuild
  Cc: devicetree, Rob Herring, Simon Glass, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

On Tue, Jan 9, 2024 at 9:07 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> 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

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

* Re: [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs
  2024-01-09 12:07 ` [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs Masahiro Yamada
@ 2024-01-17 14:52   ` Rob Herring
  2024-01-19  5:30     ` Masahiro Yamada
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2024-01-17 14:52 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, devicetree, Simon Glass, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

On Tue, Jan 09, 2024 at 09:07:35PM +0900, Masahiro Yamada wrote:
> 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?

> 
> 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.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  Makefile                 |  2 +-
>  scripts/Kbuild.include   |  6 ------
>  scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
>  3 files changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index db7f9e34a24e..dae6825b8082 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 7778cc97a4e0..2f331879816b 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -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:
> diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst
> index 4405d5b67578..67956f6496a5 100644
> --- a/scripts/Makefile.dtbinst
> +++ b/scripts/Makefile.dtbinst
> @@ -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
> 

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

* Re: [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs
  2024-01-09 12:07 ` [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs Masahiro Yamada
@ 2024-01-17 15:37   ` Rob Herring
  0 siblings, 0 replies; 9+ messages in thread
From: Rob Herring @ 2024-01-17 15:37 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, devicetree, Simon Glass, Jonathan Corbet,
	Nathan Chancellor, Nick Desaulniers, Nicolas Schier, linux-doc,
	linux-kernel

On Tue, Jan 09, 2024 at 09:07:37PM +0900, Masahiro Yamada wrote:
> 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.

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

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.

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

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

* Re: [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs
  2024-01-17 14:52   ` Rob Herring
@ 2024-01-19  5:30     ` Masahiro Yamada
  0 siblings, 0 replies; 9+ messages in thread
From: Masahiro Yamada @ 2024-01-19  5:30 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-kbuild, devicetree, Simon Glass, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

On Wed, Jan 17, 2024 at 11:52 PM Rob Herring <robh@kernel.org> wrote:
>
> On Tue, Jan 09, 2024 at 09:07:35PM +0900, Masahiro Yamada wrote:
> > 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.












> >
> > 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.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> >
> >  Makefile                 |  2 +-
> >  scripts/Kbuild.include   |  6 ------
> >  scripts/Makefile.dtbinst | 32 ++++++++++++++++++--------------
> >  3 files changed, 19 insertions(+), 21 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index db7f9e34a24e..dae6825b8082 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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
> > diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> > index 7778cc97a4e0..2f331879816b 100644
> > --- a/scripts/Kbuild.include
> > +++ b/scripts/Kbuild.include
> > @@ -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:
> > diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst
> > index 4405d5b67578..67956f6496a5 100644
> > --- a/scripts/Makefile.dtbinst
> > +++ b/scripts/Makefile.dtbinst
> > @@ -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
> >



-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2024-01-19  5:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 12:07 [PATCH 0/4] kbuild: create a list of DTBs and allow to install base dtb and overlays Masahiro Yamada
2024-01-09 12:07 ` [PATCH 1/4] kbuild: create a list of all built DTB files Masahiro Yamada
2024-01-09 14:22   ` Masahiro Yamada
2024-01-09 12:07 ` [PATCH 2/4] kbuild: simplify dtbs_install by reading the list of compiled DTBs Masahiro Yamada
2024-01-17 14:52   ` Rob Herring
2024-01-19  5:30     ` Masahiro Yamada
2024-01-09 12:07 ` [PATCH 3/4] kbuild: create a list of base and overlays for each DTB Masahiro Yamada
2024-01-09 12:07 ` [PATCH 4/4] kbuild: allow 'make dtbs_install' to install primitive DTBs Masahiro Yamada
2024-01-17 15:37   ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).