diff mbox series

linux: Add support for vendor directory in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH

Message ID 20240710152941.334195-1-kory.maincent@bootlin.com
State Rejected
Headers show
Series linux: Add support for vendor directory in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH | expand

Commit Message

Kory Maincent July 10, 2024, 3:29 p.m. UTC
Linux organizes devicetree files under vendor subdirectories for arm and
arm64 architectures, such as arch/<arch>/boot/dts/<vendor>/. The
BR2_LINUX_KERNEL_CUSTOM_DTS_PATH was only copying devicetree files to
arch/<arch>/boot/dts/, which is incompatible with the vendor
subdirectory structure.

This patch adds support for using a directory in
BR2_LINUX_KERNEL_CUSTOM_DTS_PATH that matches the vendor subdirectory name.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 linux/Config.in |  4 +++-
 linux/linux.mk  | 14 +++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Arnout Vandecappelle July 15, 2024, 2:07 p.m. UTC | #1
On 10/07/2024 17:29, Kory Maincent via buildroot wrote:
> Linux organizes devicetree files under vendor subdirectories for arm and
> arm64 architectures, such as arch/<arch>/boot/dts/<vendor>/. The
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH was only copying devicetree files to
> arch/<arch>/boot/dts/, which is incompatible with the vendor
> subdirectory structure.

  I don't see what the problem is though? If a DT is put in 
arch/<arch>/boot/dts, it can still be built with the current Buildroot.

  The only thing you need to do is to make sure to do

#include "vendor/cpu.dtsi"

instead of

#include "cpu.dtsi"

  The in-tree DTSes don't have the vendor/ part in the include, of course, but 
for custom DTSes you can do what you want, right?

  I'm going to mark it as Rejected for now, but feel free to resubmit if there 
is a good reason to have this feature.


> This patch adds support for using a directory in
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH that matches the vendor subdirectory name.
> 
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
>   linux/Config.in |  4 +++-
>   linux/linux.mk  | 14 +++++++++++---
>   2 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/linux/Config.in b/linux/Config.in
> index 34057a4893..6ca615cae3 100644
> --- a/linux/Config.in
> +++ b/linux/Config.in
> @@ -423,7 +423,9 @@ config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
>   	  Paths to out-of-tree Device Tree Source (.dts) and Device Tree
>   	  Source Include (.dtsi) files, separated by spaces. These files
>   	  will be copied to the kernel sources and the .dts files will
> -	  be compiled from there.
> +	  be compiled from there. You can also use a directory which
> +	  name match the vendor name as in
> +	  arch/<arch>/boot/dts/<vendor>/

  I think the explanation could be better:

	  Starting from Linux 6.5, the device trees are put in a <vendor>
	  subdirectory. To emulate this, you can put custom device trees
	  in a directory with that same <vendor> name, and specify the
	  path to that directory here instead of to individual dts files.

  I feel this is pretty complicated for a user to understand though...

>   
>   config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
>   	bool "Keep the directory name of the Device Tree"
> diff --git a/linux/linux.mk b/linux/linux.mk
> index 16d9f19470..07d4ddf7f3 100644
> --- a/linux/linux.mk
> +++ b/linux/linux.mk
> @@ -198,7 +198,15 @@ LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
>   # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
>   # copied to arch/<arch>/boot/dts, but only the .dts files will
>   # actually be generated as .dtb.
> -LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
> +# In case we are copying a vendor dts subdirectory as in
> +# arch/<arch>/boot/dts/<vendor>/ we have to append the wildcard to the
> +# folder to list the devicetree.
> +LINUX_KERNEL_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH))
> +ifneq ($(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/.*),)

  You don't actually need the * here.

  Also, better use positive logic (ifeq instead of ifneq, and swap the branches).

> +LINUX_DTS_NAME += $(addprefix $(notdir $(LINUX_KERNEL_CUSTOM_DTS_PATH))/,$(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/*)))))
> +else
> +LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)))))

  This is also getting pretty complicated, could it be refactored so there are a 
bit more common parts? Something like:

ifeq ($(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/.),)
LINUX_CUSTOM_DTS_FILES = $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/*))
LINUX_CUSTOM_DTS_PREFIX = $(notdir $(LINUX_KERNEL_CUSTOM_DTS_PATH))/
else
LINUX_CUSTOM_DTS_FILES = $(LINUX_KERNEL_CUSTOM_DTS_PATH)
endif
LINUX_DTS_NAME += $(addprefix $(LINUX_CUSTOM_DTS_PREFIX),$(basename $(filter 
%.dts,$(LINUX_CUSTOM_DTS_FILES))))

(parenthesis added in an email editor so probably unbalanced :-)

  Regards,
  Arnout

> +endif
>   
>   LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
>   
> @@ -505,8 +513,8 @@ endif
>   #   http://lists.busybox.net/pipermail/buildroot/2020-May/282727.html
>   define LINUX_BUILD_CMDS
>   	$(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS)
> -	$(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
> -		cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
> +	$(foreach dts,$(LINUX_KERNEL_CUSTOM_DTS_PATH), \
> +		cp -rf $(dts) $(LINUX_ARCH_PATH)/boot/dts/
>   	)
>   	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all
>   	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
Brandon Maier July 15, 2024, 3:22 p.m. UTC | #2
Hi Arnout, Kory,

On Mon Jul 15, 2024 at 2:07 PM UTC, Arnout Vandecappelle via buildroot wrote:
>
>
> On 10/07/2024 17:29, Kory Maincent via buildroot wrote:
> > Linux organizes devicetree files under vendor subdirectories for arm and
> > arm64 architectures, such as arch/<arch>/boot/dts/<vendor>/. The
> > BR2_LINUX_KERNEL_CUSTOM_DTS_PATH was only copying devicetree files to
> > arch/<arch>/boot/dts/, which is incompatible with the vendor
> > subdirectory structure.
>
>   I don't see what the problem is though? If a DT is put in
> arch/<arch>/boot/dts, it can still be built with the current Buildroot.
>
>   The only thing you need to do is to make sure to do
>
> #include "vendor/cpu.dtsi"
>
> instead of
>
> #include "cpu.dtsi"
>
>   The in-tree DTSes don't have the vendor/ part in the include, of course, but
> for custom DTSes you can do what you want, right?

This does work, I do this for Xilinx devicetrees which go into a
'xilinx' vendor directory.

>
>   I'm going to mark it as Rejected for now, but feel free to resubmit if there
> is a good reason to have this feature.

This does solve one problem for me. I compile the same devicetree into
Linux and U-Boot. But Linux migrated the Xilinx devicetrees into a
'xilinx/' vendor directory. But U-Boot has not made the same migration
as their Makefiles don't support dts sub-directories. So the #include
path is the only thing different between the Linux and U-Boot
devicetrees.

I work around it for now by patching a symlink into U-Boot
'arch/arm/dts/xilinx -> ./'.

Though ideally U-Boot would be updated to use the same devicetree layout
as Linux.

Thanks,
Brandon

>
>
> > This patch adds support for using a directory in
> > BR2_LINUX_KERNEL_CUSTOM_DTS_PATH that matches the vendor subdirectory name.
> >
> > Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> > ---
> >   linux/Config.in |  4 +++-
> >   linux/linux.mk  | 14 +++++++++++---
> >   2 files changed, 14 insertions(+), 4 deletions(-)
> >
> > diff --git a/linux/Config.in b/linux/Config.in
> > index 34057a4893..6ca615cae3 100644
> > --- a/linux/Config.in
> > +++ b/linux/Config.in
> > @@ -423,7 +423,9 @@ config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
> >   	  Paths to out-of-tree Device Tree Source (.dts) and Device Tree
> >   	  Source Include (.dtsi) files, separated by spaces. These files
> >   	  will be copied to the kernel sources and the .dts files will
> > -	  be compiled from there.
> > +	  be compiled from there. You can also use a directory which
> > +	  name match the vendor name as in
> > +	  arch/<arch>/boot/dts/<vendor>/
>
>   I think the explanation could be better:
>
> 	  Starting from Linux 6.5, the device trees are put in a <vendor>
> 	  subdirectory. To emulate this, you can put custom device trees
> 	  in a directory with that same <vendor> name, and specify the
> 	  path to that directory here instead of to individual dts files.
>
>   I feel this is pretty complicated for a user to understand though...
>
> >
> >   config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
> >   	bool "Keep the directory name of the Device Tree"
> > diff --git a/linux/linux.mk b/linux/linux.mk
> > index 16d9f19470..07d4ddf7f3 100644
> > --- a/linux/linux.mk
> > +++ b/linux/linux.mk
> > @@ -198,7 +198,15 @@ LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
> >   # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
> >   # copied to arch/<arch>/boot/dts, but only the .dts files will
> >   # actually be generated as .dtb.
> > -LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
> > +# In case we are copying a vendor dts subdirectory as in
> > +# arch/<arch>/boot/dts/<vendor>/ we have to append the wildcard to the
> > +# folder to list the devicetree.
> > +LINUX_KERNEL_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH))
> > +ifneq ($(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/.*),)
>
>   You don't actually need the * here.
>
>   Also, better use positive logic (ifeq instead of ifneq, and swap the branches).
>
> > +LINUX_DTS_NAME += $(addprefix $(notdir $(LINUX_KERNEL_CUSTOM_DTS_PATH))/,$(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/*)))))
> > +else
> > +LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)))))
>
>   This is also getting pretty complicated, could it be refactored so there are a
> bit more common parts? Something like:
>
> ifeq ($(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/.),)
> LINUX_CUSTOM_DTS_FILES = $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/*))
> LINUX_CUSTOM_DTS_PREFIX = $(notdir $(LINUX_KERNEL_CUSTOM_DTS_PATH))/
> else
> LINUX_CUSTOM_DTS_FILES = $(LINUX_KERNEL_CUSTOM_DTS_PATH)
> endif
> LINUX_DTS_NAME += $(addprefix $(LINUX_CUSTOM_DTS_PREFIX),$(basename $(filter
> %.dts,$(LINUX_CUSTOM_DTS_FILES))))
>
> (parenthesis added in an email editor so probably unbalanced :-)
>
>   Regards,
>   Arnout
>
> > +endif
> >
> >   LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
> >
> > @@ -505,8 +513,8 @@ endif
> >   #   http://lists.busybox.net/pipermail/buildroot/2020-May/282727.html
> >   define LINUX_BUILD_CMDS
> >   	$(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS)
> > -	$(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
> > -		cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
> > +	$(foreach dts,$(LINUX_KERNEL_CUSTOM_DTS_PATH), \
> > +		cp -rf $(dts) $(LINUX_ARCH_PATH)/boot/dts/
> >   	)
> >   	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all
> >   	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/linux/Config.in b/linux/Config.in
index 34057a4893..6ca615cae3 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -423,7 +423,9 @@  config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
 	  Paths to out-of-tree Device Tree Source (.dts) and Device Tree
 	  Source Include (.dtsi) files, separated by spaces. These files
 	  will be copied to the kernel sources and the .dts files will
-	  be compiled from there.
+	  be compiled from there. You can also use a directory which
+	  name match the vendor name as in
+	  arch/<arch>/boot/dts/<vendor>/
 
 config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
 	bool "Keep the directory name of the Device Tree"
diff --git a/linux/linux.mk b/linux/linux.mk
index 16d9f19470..07d4ddf7f3 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -198,7 +198,15 @@  LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
 # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
 # copied to arch/<arch>/boot/dts, but only the .dts files will
 # actually be generated as .dtb.
-LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
+# In case we are copying a vendor dts subdirectory as in
+# arch/<arch>/boot/dts/<vendor>/ we have to append the wildcard to the
+# folder to list the devicetree.
+LINUX_KERNEL_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH))
+ifneq ($(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/.*),)
+LINUX_DTS_NAME += $(addprefix $(notdir $(LINUX_KERNEL_CUSTOM_DTS_PATH))/,$(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)/*)))))
+else
+LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(wildcard $(LINUX_KERNEL_CUSTOM_DTS_PATH)))))
+endif
 
 LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
 
@@ -505,8 +513,8 @@  endif
 #   http://lists.busybox.net/pipermail/buildroot/2020-May/282727.html
 define LINUX_BUILD_CMDS
 	$(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS)
-	$(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
-		cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
+	$(foreach dts,$(LINUX_KERNEL_CUSTOM_DTS_PATH), \
+		cp -rf $(dts) $(LINUX_ARCH_PATH)/boot/dts/
 	)
 	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all
 	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)