Skip to contentSkip to conversation

linux: Add support for vendor directory in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH

PATCH In review Kory Maincent via buildroot 2 participants 5 messages Jul 10, 2024 – Feb 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: Add support for vendor directory in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH

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.

---
 linux/Config.in |  4 +++-
 linux/linux.mk  | 14 +++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
linux/Config.in +3 -1
index 34057a4893..6ca615cae3 100644
@@ -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"
linux/linux.mk +11 -3
index 16d9f19470..07d4ddf7f3 100644
@@ -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)
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 5 lines · Kory Maincent via buildroot

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.

Quoted 14 lines

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

---
  linux/Config.in |  4 +++-
  linux/linux.mk  | 14 +++++++++++---
  2 files changed, 14 insertions(+), 4 deletions(-)
linux/Config.in +0 -0
index 34057a4893..6ca615cae3 100644

linux/Config.in config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH · line 428

Quoted 7 lines
linux/Config.in +3 -1
@@ -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...

Quoted 8 lines
linux/Config.in +0 -0
  config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
  	bool "Keep the directory name of the Device Tree"
linux/linux.mk +0 -0
index 16d9f19470..07d4ddf7f3 100644

linux/linux.mk LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME)) · line 205

Quoted 9 lines
linux/linux.mk +5 -1
@@ -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/linux.mk LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME)) · line 208

Quoted 3 lines
linux/linux.mk +3 -0
+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

Quoted 5 lines
linux/linux.mk +1 -0
+endif
 
  LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
 

linux/linux.mk endif · line 520

Quoted 10 lines
linux/linux.mk +2 -2
@@ -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
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw

Hi Arnout, Kory,

Quoted 14 lines · Arnout Vandecappelle via buildroot
Quoted 5 lines · Kory Maincent via buildroot

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

Quoted 8 lines

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

Quoted 3 lines

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

Quoted 80 lines
Quoted 16 lines

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

---
  linux/Config.in |  4 +++-
  linux/linux.mk  | 14 +++++++++++---
  2 files changed, 14 insertions(+), 4 deletions(-)
linux/Config.in +0 -0
index 34057a4893..6ca615cae3 100644

linux/Config.in config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH · line 428

Quoted 7 lines
linux/Config.in +3 -1
@@ -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...

Quoted 8 lines
linux/Config.in +0 -0
  config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
  	bool "Keep the directory name of the Device Tree"
linux/linux.mk +0 -0
index 16d9f19470..07d4ddf7f3 100644

linux/linux.mk LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME)) · line 205

Quoted 9 lines
linux/linux.mk +5 -1
@@ -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/linux.mk LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME)) · line 208

Quoted 3 lines
linux/linux.mk +3 -0
+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

Quoted 4 lines
linux/linux.mk +1 -0
+endif
 
  LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
 
Quoted 15 lines

linux/linux.mk endif · line 520

Quoted 11 lines
linux/linux.mk +2 -2
@@ -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
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Hi Kory,

Quoted 13 lines · Brandon Maier via buildroot

Hi Arnout, Kory,

Quoted 9 lines · Arnout Vandecappelle via buildroot
Quoted 5 lines · Kory Maincent via buildroot

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.

[snip]

Which kernel version were you using? I noticed in 6.12 when I use the BR2_LINUX_KERNEL_CUSTOM_DTS_PATH, I get a "no make target for" error trying to build that dtb once placed in the root of arch/<arch>/boot/dts/. The file is there and if I move it into the vendor folder and update Buildroot to build it as a in-tree dts, it works OK.

Wanted to check if this is a known issue before sharing a basic example to reproduce.

Regards,
Matt
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw

Hello Matthew,

Quoted 27 lines · Matthew Weber

Hi Kory,

Quoted 13 lines · Brandon Maier via buildroot

Hi Arnout, Kory,

Quoted 9 lines · Arnout Vandecappelle via buildroot
Quoted 5 lines · Kory Maincent via buildroot

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.

[snip]

Which kernel version were you using? I noticed in 6.12 when I use the BR2_LINUX_KERNEL_CUSTOM_DTS_PATH, I get a "no make target for" error trying to build that dtb once placed in the root of arch/<arch>/boot/dts/. The file is there and if I move it into the vendor folder and update Buildroot to build it as a in-tree dts, it works OK.

Quoted 2 lines

Wanted to check if this is a known issue before sharing a basic example to reproduce.

Please have a look at:
https://lore.kernel.org/buildroot/[email protected]/T/#me44dcc9853e35589a0a64ab20fc75f038641a49a

Kind regards,
Niklas
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot