public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
@ 2025-11-20 14:06 Thomas De Schampheleire
  2025-11-21  6:42 ` Nathan Chancellor
  2025-11-24 13:07 ` Rob Herring
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas De Schampheleire @ 2025-11-20 14:06 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Thomas De Schampheleire, Masahiro Yamada, Nathan Chancellor,
	Nicolas Schier, linux-kernel

Since commit e7e2941300d2 ("kbuild: split device tree build rules into
scripts/Makefile.dtbs"), it is no longer possible to compile a device tree
blob that is not specified in a make rule
like:
    dtb-$(CONFIG_FOO) += foo.dtb

Before the mentioned commit, one could copy a dts file to e.g.
arch/arm64/boot/dts/ (or a new subdirectory) and then convert it to a dtb
file using:
    make ARCH=arm64 foo.dtb

In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
value of 'targets', however, is only final later in the code.

Move the conditional include of scripts/Makefile.dtbs down to where the
value of 'targets' is final.

Fixes: e7e2941300d2 ("kbuild: split device tree build rules into scripts/Makefile.dtbs")
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
---
 scripts/Makefile.build | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index d0ee33a487be..6e0f9e922c68 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -527,10 +527,6 @@ ifneq ($(userprogs),)
 include $(srctree)/scripts/Makefile.userprogs
 endif
 
-ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
-include $(srctree)/scripts/Makefile.dtbs
-endif
-
 # Build
 # ---------------------------------------------------------------------------
 
@@ -568,6 +564,11 @@ FORCE:
 targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
 targets := $(filter-out $(PHONY), $(targets))
 
+# Now that targets is fully known, include dtb rules if needed
+ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
+include $(srctree)/scripts/Makefile.dtbs
+endif
+
 # Read all saved command lines and dependencies for the $(targets) we
 # may be building above, using $(if_changed{,_dep}). As an
 # optimization, we don't need to read them if the target does not

base-commit: deab487e0f9b39ae4603e22d7d00908ebfc9753c
-- 
2.51.0


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

* Re: [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
  2025-11-20 14:06 [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule Thomas De Schampheleire
@ 2025-11-21  6:42 ` Nathan Chancellor
  2025-11-21 19:46   ` Nicolas Schier
  2025-11-24 13:07 ` Rob Herring
  1 sibling, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2025-11-21  6:42 UTC (permalink / raw)
  To: Thomas De Schampheleire
  Cc: linux-kbuild, Masahiro Yamada, Nicolas Schier, linux-kernel,
	devicetree, Rob Herring

+ Rob, as he reviewed e7e2941300d2

On Thu, Nov 20, 2025 at 03:06:43PM +0100, Thomas De Schampheleire wrote:
> Since commit e7e2941300d2 ("kbuild: split device tree build rules into
> scripts/Makefile.dtbs"), it is no longer possible to compile a device tree
> blob that is not specified in a make rule
> like:
>     dtb-$(CONFIG_FOO) += foo.dtb
> 
> Before the mentioned commit, one could copy a dts file to e.g.
> arch/arm64/boot/dts/ (or a new subdirectory) and then convert it to a dtb
> file using:
>     make ARCH=arm64 foo.dtb
> 
> In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
> scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
> value of 'targets', however, is only final later in the code.
> 
> Move the conditional include of scripts/Makefile.dtbs down to where the
> value of 'targets' is final.
> 
> Fixes: e7e2941300d2 ("kbuild: split device tree build rules into scripts/Makefile.dtbs")
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

Huh, TIL that .c and .S files can be built in the same way...

  $ touch init/foo.c init/bar.S
  $ make init/foo.o init/bar.o
  $ ls init/.foo.o.cmd init/.bar.o.cmd
  init/.bar.o.cmd
  init/.foo.o.cmd

I do not necessarily love splitting up the conditional includes from
each other but I am not sure it can be avoided... Nicolas, are you okay
with me taking this as a fix or do you want to take it via kbuild-next?
If the latter:

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  scripts/Makefile.build | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index d0ee33a487be..6e0f9e922c68 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -527,10 +527,6 @@ ifneq ($(userprogs),)
>  include $(srctree)/scripts/Makefile.userprogs
>  endif
>  
> -ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
> -include $(srctree)/scripts/Makefile.dtbs
> -endif
> -
>  # Build
>  # ---------------------------------------------------------------------------
>  
> @@ -568,6 +564,11 @@ FORCE:
>  targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
>  targets := $(filter-out $(PHONY), $(targets))
>  
> +# Now that targets is fully known, include dtb rules if needed
> +ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
> +include $(srctree)/scripts/Makefile.dtbs
> +endif
> +
>  # Read all saved command lines and dependencies for the $(targets) we
>  # may be building above, using $(if_changed{,_dep}). As an
>  # optimization, we don't need to read them if the target does not
> 
> base-commit: deab487e0f9b39ae4603e22d7d00908ebfc9753c
> -- 
> 2.51.0
> 

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

* Re: [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
  2025-11-21  6:42 ` Nathan Chancellor
@ 2025-11-21 19:46   ` Nicolas Schier
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Schier @ 2025-11-21 19:46 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thomas De Schampheleire, linux-kbuild, Masahiro Yamada,
	linux-kernel, devicetree, Rob Herring

[-- Attachment #1: Type: text/plain, Size: 1932 bytes --]

On Thu, Nov 20, 2025 at 11:42:56PM -0700, Nathan Chancellor wrote:
> + Rob, as he reviewed e7e2941300d2
> 
> On Thu, Nov 20, 2025 at 03:06:43PM +0100, Thomas De Schampheleire wrote:
> > Since commit e7e2941300d2 ("kbuild: split device tree build rules into
> > scripts/Makefile.dtbs"), it is no longer possible to compile a device tree
> > blob that is not specified in a make rule
> > like:
> >     dtb-$(CONFIG_FOO) += foo.dtb
> > 
> > Before the mentioned commit, one could copy a dts file to e.g.
> > arch/arm64/boot/dts/ (or a new subdirectory) and then convert it to a dtb
> > file using:
> >     make ARCH=arm64 foo.dtb
> > 
> > In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
> > scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
> > value of 'targets', however, is only final later in the code.
> > 
> > Move the conditional include of scripts/Makefile.dtbs down to where the
> > value of 'targets' is final.
> > 
> > Fixes: e7e2941300d2 ("kbuild: split device tree build rules into scripts/Makefile.dtbs")
> > Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> Huh, TIL that .c and .S files can be built in the same way...
> 
>   $ touch init/foo.c init/bar.S
>   $ make init/foo.o init/bar.o
>   $ ls init/.foo.o.cmd init/.bar.o.cmd
>   init/.bar.o.cmd
>   init/.foo.o.cmd
> 
> I do not necessarily love splitting up the conditional includes from
> each other but I am not sure it can be avoided... Nicolas, are you okay
> with me taking this as a fix or do you want to take it via kbuild-next?
> If the latter:
> 
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>

I am ok with you taking it via kbuild-fixed, thanks.

Kind regards,
Nicolas

PS: If I combine this here with [1], [1] does not work any more.
[1]: https://lore.kernel.org/linux-kbuild/20251120204812.1983452-4-robh@kernel.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
  2025-11-20 14:06 [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule Thomas De Schampheleire
  2025-11-21  6:42 ` Nathan Chancellor
@ 2025-11-24 13:07 ` Rob Herring
  2025-11-25 10:52   ` Thomas De Schampheleire
  1 sibling, 1 reply; 6+ messages in thread
From: Rob Herring @ 2025-11-24 13:07 UTC (permalink / raw)
  To: Thomas De Schampheleire
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
	linux-kernel

On Thu, Nov 20, 2025 at 03:06:43PM +0100, Thomas De Schampheleire wrote:
> Since commit e7e2941300d2 ("kbuild: split device tree build rules into
> scripts/Makefile.dtbs"), it is no longer possible to compile a device tree
> blob that is not specified in a make rule
> like:
>     dtb-$(CONFIG_FOO) += foo.dtb
> 
> Before the mentioned commit, one could copy a dts file to e.g.
> arch/arm64/boot/dts/ (or a new subdirectory) and then convert it to a dtb
> file using:
>     make ARCH=arm64 foo.dtb

News to me this was ever possible.

> 
> In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
> scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
> value of 'targets', however, is only final later in the code.
> 
> Move the conditional include of scripts/Makefile.dtbs down to where the
> value of 'targets' is final.

This breaks 'make dtbs' (and just 'make' for arm64).


> 
> Fixes: e7e2941300d2 ("kbuild: split device tree build rules into scripts/Makefile.dtbs")
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
>  scripts/Makefile.build | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index d0ee33a487be..6e0f9e922c68 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -527,10 +527,6 @@ ifneq ($(userprogs),)
>  include $(srctree)/scripts/Makefile.userprogs
>  endif
>  
> -ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
> -include $(srctree)/scripts/Makefile.dtbs
> -endif
> -
>  # Build
>  # ---------------------------------------------------------------------------
>  
> @@ -568,6 +564,11 @@ FORCE:
>  targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
>  targets := $(filter-out $(PHONY), $(targets))
>  
> +# Now that targets is fully known, include dtb rules if needed
> +ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
> +include $(srctree)/scripts/Makefile.dtbs
> +endif
> +
>  # Read all saved command lines and dependencies for the $(targets) we
>  # may be building above, using $(if_changed{,_dep}). As an
>  # optimization, we don't need to read them if the target does not
> 
> base-commit: deab487e0f9b39ae4603e22d7d00908ebfc9753c
> -- 
> 2.51.0
> 

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

* Re: [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
  2025-11-24 13:07 ` Rob Herring
@ 2025-11-25 10:52   ` Thomas De Schampheleire
  2025-11-25 13:25     ` Rob Herring
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas De Schampheleire @ 2025-11-25 10:52 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
	linux-kernel

On Mon, Nov 24, 2025 at 07:07:47AM -0600, Rob Herring wrote:
> On Thu, Nov 20, 2025 at 03:06:43PM +0100, Thomas De Schampheleire wrote:
[...]
> > In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
> > scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
> > value of 'targets', however, is only final later in the code.
> >
> > Move the conditional include of scripts/Makefile.dtbs down to where the
> > value of 'targets' is final.
> 
> This breaks 'make dtbs' (and just 'make' for arm64).

I see the 'make dtbs' failure, I will investigate.

I don't yet see a problem with 'make ARCH=arm64 CROSS_COMPILE=[...]' after a
standard 'defconfig'. Can you please clarify how it fails for you?

Thanks,
Thomas

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

* Re: [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule
  2025-11-25 10:52   ` Thomas De Schampheleire
@ 2025-11-25 13:25     ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2025-11-25 13:25 UTC (permalink / raw)
  To: Thomas De Schampheleire
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
	linux-kernel

On Tue, Nov 25, 2025 at 4:52 AM Thomas De Schampheleire
<thomas.de_schampheleire@nokia.com> wrote:
>
> On Mon, Nov 24, 2025 at 07:07:47AM -0600, Rob Herring wrote:
> > On Thu, Nov 20, 2025 at 03:06:43PM +0100, Thomas De Schampheleire wrote:
> [...]
> > > In this scenario, both 'dtb-y' and 'dtb-' are empty, and the inclusion of
> > > scripts/Makefile.dtbs relies on 'targets' to contain the MAKECMDGOALS. The
> > > value of 'targets', however, is only final later in the code.
> > >
> > > Move the conditional include of scripts/Makefile.dtbs down to where the
> > > value of 'targets' is final.
> >
> > This breaks 'make dtbs' (and just 'make' for arm64).
>
> I see the 'make dtbs' failure, I will investigate.
>
> I don't yet see a problem with 'make ARCH=arm64 CROSS_COMPILE=[...]' after a
> standard 'defconfig'. Can you please clarify how it fails for you?

Did it build the dtbs? "dtbs" is an implicit target for "all", so I'm
assuming that wouldn't work either.

Rob

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

end of thread, other threads:[~2025-11-25 13:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 14:06 [PATCH] kbuild: fix compilation of dtb specified on command-line without make rule Thomas De Schampheleire
2025-11-21  6:42 ` Nathan Chancellor
2025-11-21 19:46   ` Nicolas Schier
2025-11-24 13:07 ` Rob Herring
2025-11-25 10:52   ` Thomas De Schampheleire
2025-11-25 13:25     ` Rob Herring

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