diff mbox series

[v3,1/2] linux: add support for device tree overlays

Message ID 20241213083430.4121422-1-niklas.cassel@wdc.com
State New
Headers show
Series [v3,1/2] linux: add support for device tree overlays | expand

Commit Message

Niklas Cassel Dec. 13, 2024, 8:34 a.m. UTC
From: Michael Walle <michael@walle.cc>

The linux kernel can build device tree overlays (.dtbo) itself. Add
support to build and copy them along with the actual device trees.
These can only be in-tree device tree overlays.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
Changes since v2:
-Dropped support for out-of-tree device tree overlays, as Linux 6.12 no
 longer supports building an out-of-tree device tree by simply copying
 it to the kernel source directory (without also modifying the Makefile).

 linux/Config.in | 7 +++++++
 linux/linux.mk  | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Michael Walle Dec. 13, 2024, 8:53 a.m. UTC | #1
Hi Niklas,

> -Dropped support for out-of-tree device tree overlays, as Linux 6.12 no
>  longer supports building an out-of-tree device tree by simply copying
>  it to the kernel source directory (without also modifying the Makefile).

Why is that? As it seems, it is not possible to compile it by simply
copying to arch/<arch>/dts (which is buildroot doing currently)
anymore. But copying it to arch/<arch>/dts/<vendor>/ is working.
Correct?

In that case, we should work on getting support for that in
buildroot as well. Esp. buildroot is really lacking copying an
actual device tree into that subdir too and currently it's a PITA to
include a soc.dtsi for example. If you're using a device tree in
buildroot you'd have to use '#include "vendor/soc.dtsi"' while in
the kernel (as well as in yocto) you'll just use '#include
"soc.dtsi"'.

-michael
Niklas Cassel Dec. 13, 2024, 9:09 a.m. UTC | #2
[replying from an email address that is subscribed this time...]

On Fri, Dec 13, 2024 at 09:53:27AM +0100, Michael Walle wrote:
> Hi Niklas,
> 
> > -Dropped support for out-of-tree device tree overlays, as Linux 6.12 no
> >  longer supports building an out-of-tree device tree by simply copying
> >  it to the kernel source directory (without also modifying the Makefile).
> 
> Why is that? As it seems, it is not possible to compile it by simply
> copying to arch/<arch>/dts (which is buildroot doing currently)
> anymore. But copying it to arch/<arch>/dts/<vendor>/ is working.
> Correct?

I'm assuming that neither works anymore, see:
https://lore.kernel.org/buildroot/CAFOYHZDQmMRuK76TpOSAOFPdqAb4gpw=LNKfmpu=sqAD1EMhFg@mail.gmail.com/T/#u
https://lore.kernel.org/all/CAK7LNAR4h6NZ+D0BK+q4VQBeHWpjzRBQFQ9ovBrftM=6dHRcUg@mail.gmail.com/
https://lore.kernel.org/buildroot/Z1nq_gneO4ORw3EG@curiosity/T/#t


> 
> In that case, we should work on getting support for that in
> buildroot as well. Esp. buildroot is really lacking copying an
> actual device tree into that subdir too and currently it's a PITA to
> include a soc.dtsi for example. If you're using a device tree in
> buildroot you'd have to use '#include "vendor/soc.dtsi"' while in
> the kernel (as well as in yocto) you'll just use '#include
> "soc.dtsi"'.

Yes, it appears that buildroot folks have an idea that it should be possible to
restore BR2_LINUX_KERNEL_CUSTOM_DTS_PATH in newer kernels by sed:ing the
Makefile.

However, I don't see any reason to defer this patch until then.


Once someone has written a patch that restores BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
support for recent kernels, you can submit an incremental path on top of this
that adds support for out-of-tree device tree overlays, if you so wish.

But honestly, considering that the only buildroot configurations that make use of
BR2_LINUX_KERNEL_CUSTOM_DTS_PATH are:
- acmesystems_acqua_a5_256mb_defconfig (v6.6)
- acmesystems_acqua_a5_512mb_defconfig (v6.6)
- octavo_osd32mp1_brk_defconfig (v5.10)   
- octavo_osd32mp1_red_defconfig (v5.10)
- s6lx9_microboard_defconfig (v4.4.7)

are using really old kernel versions, nothing is broken in upstream buildroot,
so I expect that it might take quite a long time before anyone bothers to
restore BR2_LINUX_KERNEL_CUSTOM_DTS_PATH support in newer kernels.


Kind regards,
Niklas
Michael Walle Dec. 13, 2024, 9:35 a.m. UTC | #3
Hi Niklas,

> > > -Dropped support for out-of-tree device tree overlays, as Linux 6.12 no
> > >  longer supports building an out-of-tree device tree by simply copying
> > >  it to the kernel source directory (without also modifying the Makefile).
> > 
> > Why is that? As it seems, it is not possible to compile it by simply
> > copying to arch/<arch>/dts (which is buildroot doing currently)
> > anymore. But copying it to arch/<arch>/dts/<vendor>/ is working.
> > Correct?
>
> I'm assuming that neither works anymore, see:
> https://lore.kernel.org/buildroot/CAFOYHZDQmMRuK76TpOSAOFPdqAb4gpw=LNKfmpu=sqAD1EMhFg@mail.gmail.com/T/#u
> https://lore.kernel.org/all/CAK7LNAR4h6NZ+D0BK+q4VQBeHWpjzRBQFQ9ovBrftM=6dHRcUg@mail.gmail.com/
> https://lore.kernel.org/buildroot/Z1nq_gneO4ORw3EG@curiosity/T/#t

Thanks for the pointers.

But I've just tested both compiling .dts and .dtso from within a
vendor directory and it seems to be working on next-20241213 (?).

> > In that case, we should work on getting support for that in
> > buildroot as well. Esp. buildroot is really lacking copying an
> > actual device tree into that subdir too and currently it's a PITA to
> > include a soc.dtsi for example. If you're using a device tree in
> > buildroot you'd have to use '#include "vendor/soc.dtsi"' while in
> > the kernel (as well as in yocto) you'll just use '#include
> > "soc.dtsi"'.
>
> Yes, it appears that buildroot folks have an idea that it should be possible to
> restore BR2_LINUX_KERNEL_CUSTOM_DTS_PATH in newer kernels by sed:ing the
> Makefile.
>
> However, I don't see any reason to defer this patch until then.
>
>
> Once someone has written a patch that restores BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
> support for recent kernels, you can submit an incremental path on top of this
> that adds support for out-of-tree device tree overlays, if you so wish.
>
> But honestly, considering that the only buildroot configurations that make use of
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH are:
> - acmesystems_acqua_a5_256mb_defconfig (v6.6)
> - acmesystems_acqua_a5_512mb_defconfig (v6.6)
> - octavo_osd32mp1_brk_defconfig (v5.10)   
> - octavo_osd32mp1_red_defconfig (v5.10)
> - s6lx9_microboard_defconfig (v4.4.7)
>
> are using really old kernel versions, nothing is broken in upstream buildroot,
> so I expect that it might take quite a long time before anyone bothers to
> restore BR2_LINUX_KERNEL_CUSTOM_DTS_PATH support in newer kernels.

This is most useful for buildroot externals which you cannot grep
that easily :) Thus I'd imagine it is more common than you think.

-michael
Niklas Cassel Dec. 13, 2024, 9:48 a.m. UTC | #4
Hello Michael,

On Fri, Dec 13, 2024 at 10:35:37AM +0100, Michael Walle wrote:
> Hi Niklas,
> 
> > > > -Dropped support for out-of-tree device tree overlays, as Linux 6.12 no
> > > >  longer supports building an out-of-tree device tree by simply copying
> > > >  it to the kernel source directory (without also modifying the Makefile).
> > > 
> > > Why is that? As it seems, it is not possible to compile it by simply
> > > copying to arch/<arch>/dts (which is buildroot doing currently)
> > > anymore. But copying it to arch/<arch>/dts/<vendor>/ is working.
> > > Correct?
> >
> > I'm assuming that neither works anymore, see:
> > https://lore.kernel.org/buildroot/CAFOYHZDQmMRuK76TpOSAOFPdqAb4gpw=LNKfmpu=sqAD1EMhFg@mail.gmail.com/T/#u
> > https://lore.kernel.org/all/CAK7LNAR4h6NZ+D0BK+q4VQBeHWpjzRBQFQ9ovBrftM=6dHRcUg@mail.gmail.com/
> > https://lore.kernel.org/buildroot/Z1nq_gneO4ORw3EG@curiosity/T/#t
> 
> Thanks for the pointers.
> 
> But I've just tested both compiling .dts and .dtso from within a
> vendor directory and it seems to be working on next-20241213 (?).

If you say that copying to arch/<arch>/dts/<vendor>/ is still working, then
most likely it is only copying to arch/<arch>/dts that is no longer working.

I still think that this patch can be merged as is.

Once the BR2_LINUX_KERNEL_CUSTOM_DTS_PATH mess has been sorted, someone could
add support for out-of-tree device tree overlays, if anyone wants/needs that.

Adding support for in-tree device tree overlays now, does not make life harder
for anyone if they want to add support for out-of-tree device tree overlays in
the future.


Kind regards,
Niklas
Michael Walle Dec. 13, 2024, 10:03 a.m. UTC | #5
Hi Niklas,

> > But I've just tested both compiling .dts and .dtso from within a
> > vendor directory and it seems to be working on next-20241213 (?).
>
> If you say that copying to arch/<arch>/dts/<vendor>/ is still working, then
> most likely it is only copying to arch/<arch>/dts that is no longer working.

Copying it to dts/ was wrong for arch's which had a subdir structure
anyway.

>
> I still think that this patch can be merged as is.
>
> Once the BR2_LINUX_KERNEL_CUSTOM_DTS_PATH mess has been sorted, someone could
> add support for out-of-tree device tree overlays, if anyone wants/needs that.

Well, that was actually the intention of my patch :)

> Adding support for in-tree device tree overlays now, does not make life harder
> for anyone if they want to add support for out-of-tree device tree overlays in
> the future.

Agreed.

-michael
Niklas Cassel Dec. 20, 2024, 10:06 a.m. UTC | #6
Hello Thomas,

Any chance of this series getting picked up?


Kind regards,
Niklas
Niklas Cassel Jan. 2, 2025, 11:48 a.m. UTC | #7
Hello Thomas,

Any chance of this series getting picked up?


Kind regards,
Niklas
diff mbox series

Patch

diff --git a/linux/Config.in b/linux/Config.in
index f537dd7adf..c59b56786f 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -417,6 +417,13 @@  config BR2_LINUX_KERNEL_INTREE_DTS_NAME
 	  the trailing .dts. You can provide a list of
 	  dts files to build, separated by spaces.
 
+config BR2_LINUX_KERNEL_INTREE_DTSO_NAMES
+	string "In-tree Device Tree Overlay file names"
+	help
+	  Names of in-tree device tree overlay, without the trailing
+	  .dtso which should be built and installed into the target
+	  system, separated by spaces.
+
 config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
 	string "Out-of-tree Device Tree Source file paths"
 	help
diff --git a/linux/linux.mk b/linux/linux.mk
index 1d3d8fffa6..54b34d8281 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -203,6 +203,7 @@  endif
 LINUX_VERSION_PROBED = `MAKEFLAGS='$(filter-out w,$(MAKEFLAGS))' $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
 
 LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
+LINUX_DTSO_NAMES += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTSO_NAMES))
 
 # We keep only the .dts files, so that the user can specify both .dts
 # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
@@ -210,7 +211,7 @@  LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
 # actually be generated as .dtb.
 LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
 
-LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
+LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME)) $(addsuffix .dtbo,$(LINUX_DTSO_NAMES))
 
 ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
 LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))