Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel via buildroot <buildroot@buildroot.org>
To: Romain Naour <romain.naour@smile.fr>
Cc: "buildroot@buildroot.org" <buildroot@buildroot.org>,
	"Michael Walle" <michael@walle.cc>,
	"Gaël PORTAY" <gael.portay+rtone@gmail.com>,
	"Chris Packham" <judge.packham@gmail.com>,
	"Edgar Bonet" <bonet@grenoble.cnrs.fr>
Subject: Re: [Buildroot] [PATCH v5 3/6] linux: introduce BR2_LINUX_KERNEL_CUSTOM_DTS_DIR
Date: Thu, 20 Feb 2025 13:49:43 +0000	[thread overview]
Message-ID: <Z7cy9nU3Yg7x2RTd@ryzen> (raw)
In-Reply-To: <20250204163622.192932-3-romain.naour@smile.fr>

On Tue, Feb 04, 2025 at 05:36:18PM +0100, Romain Naour via buildroot wrote:
> Since Linux 6.12, the Buildroot option BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
> does not work as expected on arm, arm64, mips and ricv.[1] These are the

s/ricv/riscv/


> architectures that store the in-tree DTS files in vendor-specific
> subdirectories of arch/$ARCH/boot/dts/.
> 
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH was introduced in Buildroot 2012.08
> (commit 69fc497df0ae "Rework support for the device tree"). At the time,
> the kernel kept all in-tree DTS files directly in arch/$ARCH/boot/dts/,
> and this is where Buildroot drops the user's custom DTS. Vendor-specific
> subdirectories appeared in Linux v3.19 for the arm64 architecture, and
> this scheme was later adopted by mips, riscv and arm.
> 
> For these architectures, Linux 6.12 (commit e7e2941300d2, "kbuild: split
> device tree build rules into scripts/Makefile.dtbs") made the DTB build
> infrastructure incompatible with the way
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH is implemented. This infrastructure now
> expects all DTS files to be in vendor-specific subdirectories on the
> architectures that use this scheme.
> 
> We can't update easily the current behavior of
> BR2_LINUX_KERNEL_CUSTOM_DTS_PATH since it expect a list of files but
> can also be used "unexpectedly" with directories [2].
> 
>   BR2_LINUX_KERNEL_INTREE_DTS_NAME="st/stm32mp135f-dk-mx"
>   BR2_LINUX_KERNEL_CUSTOM_DTS_PATH="$(BR2_EXTERNAL_ST_PATH)/[...]/linux-dts/st"
> 
> In this case, the st directory is copied into the arch/$ARCH/boot/dts/
> and BR2_LINUX_KERNEL_INTREE_DTS_NAME is used to build stm32mp135f-dk-mx dtb
> as if it was intree.
> 
> Introduce BR2_LINUX_KERNEL_CUSTOM_DTS_DIR configuration
> parameter to specify a list of directories that are copied as-is over
> the arch/<arch>/boot/dts/ directory before building the device tree
> blob:
> 
>   board/acmesystems/acqua-a5/dts/
>   └── microchip
>       └── at91-sama5d3_acqua.dts
> 
> defconfig:
>   BR2_LINUX_KERNEL_CUSTOM_DTS_DIR="board/acmesystems/acqua-a5/dts"
> 
> Each dts file found is automatically added to the list of devicetree
> to build.
> 
> BR2_LINUX_KERNEL_CUSTOM_DTS_DIR can also be used for external
> devicetree overlays files:
> 
>   board/ti/am574x-idk/dts/
>   └── ti
>       └── omap
>           └── am57xx-evm.dtso
> 
> With this new option, BR2_LINUX_KERNEL_CUSTOM_DTS_PATH is now deprecated.
> 
> Note: We want to create a list of dts files (LINUX_DTS_LIST) present in
> diectrories listed by BR2_LINUX_KERNEL_CUSTOM_DTS_DIR. But
> LINUX_DTS_LIST must not contain BR2_LINUX_KERNEL_CUSTOM_DTS_DIR
> paths. Use GNU 'find' print format %P to print each dts file path
> without their respective dts overlay directory path.
> Do the same for LINUX_DTSO_LIST.
> 
> Thanks to Edgar Bonet for the initial contribution [3].
> 
> [1] https://lists.buildroot.org/pipermail/buildroot/2024-October/765463.html
> [2] https://github.com/bootlin/buildroot-external-st/blob/541ba7d96330cd7da5674b46806b549a7ccf9da8/configs/st_stm32mp135f_dk_demo_defconfig#L21
> [3] https://lore.kernel.org/buildroot/93f83afb-6987-441c-8e06-dab4d43b828f@grenoble.cnrs.fr/
> 
> Cc: Michael Walle <michael@walle.cc>
> Cc: Gaël PORTAY <gael.portay+rtone@gmail.com>
> Reported-by: Chris Packham <judge.packham@gmail.com>
> Signed-off-by: Edgar Bonet <bonet@grenoble.cnrs.fr>
> [Romain:
>   - Rework the initial contribution by Edgar Bonet by
>     BR2_LINUX_KERNEL_CUSTOM_DTS_DIR following
>     Michael Walle comments and Gaël PORTAY review.
>   - Reword the commit log accordingly.
> ]
> Signed-off-by: Romain Naour <romain.naour@smile.fr>
> ---
> Changes v4 -> v5:
>   - Rename LINUX_INSTALL_CUSTOM_DTS_OVERLAY to LINUX_COPY_CUSTOM_DTS_FILES
>   - Rename LINUX_KERNEL_CUSTOM_DTS_PATH_OVERLAY to LINUX_KERNEL_CUSTOM_DTS_DIR
>   - Add devicetree overlay support
>   - Update authorship of the commit:
>     https://lore.kernel.org/buildroot/98d47c49-0e68-4d07-b2c9-1d67a6fd0e13@grenoble.cnrs.fr/
> 
> Changes v3 -> v4:
>   - Replace hooks added in v2 and add a new option to provide DTS overlay
>     https://lore.kernel.org/buildroot/D6UG5Z1HUN9N.GWVHB4L823ZC@kernel.org/
> 
> Changes v2 -> v3:
>   - note, in the comment and in the log message, that this issue only
>     affects some architectures
>   - expand the log message with some historical context
> These changes were suggested by Romain Naour.
> 
> Changes v1 -> v2:
>   - define a hook for LINUX_POST_PATCH_HOOKS and LINUX_POST_RSYNC_HOOKS
>     instead of modifying LINUX_BUILD_CMDS
>   - use $(patsubst %.dts,%.dtb,$(dts)) instead of $(dts:%.dts=%.dtb)
> both changes suggested by Arnout Vandecappelle.
> 
> This was build-tested with an Acqua defconfig,
> in the same manner as v2:
> 
>     # Test with an old kernel: v6.6.30
>     make acmesystems_acqua_a5_512mb_defconfig
>     make linux
> 
>     # Test with a new kernel: v6.12.8
>     make linux-dirclean
>     git am bump_Acqua_kernel_to_v6.12.8.patch
>     make acmesystems_acqua_a5_512mb_defconfig
>     make linux
> 
>     # Test the OVERRIDE_SRCDIR case.
>     make linux-dirclean
>     git -C $HOME/src/linux checkout v6.12.8
>     echo "LINUX_OVERRIDE_SRCDIR = $HOME/src/linux" > local.mk
>     make acmesystems_acqua_a5_512mb_defconfig
>     make linux
> ---
>  linux/Config.in | 25 +++++++++++++++++++++++++
>  linux/linux.mk  | 17 +++++++++++++++++
>  2 files changed, 42 insertions(+)
> 
> diff --git a/linux/Config.in b/linux/Config.in
> index 90aed24775..104343a718 100644
> --- a/linux/Config.in
> +++ b/linux/Config.in
> @@ -435,6 +435,7 @@ config BR2_LINUX_KERNEL_INTREE_DTSO_NAMES
>  
>  config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
>  	string "Out-of-tree Device Tree Source file paths"
> +	depends on BR2_LINUX_KERNEL_CUSTOM_DTS_DIR = ""
>  	help
>  	  Paths to out-of-tree Device Tree Source (.dts), Device Tree
>  	  Source Include (.dtsi) and Device Tree Overlay Source (.dtso)
> @@ -442,6 +443,30 @@ config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
>  	  kernel sources and the .dts files will
>  	  be compiled from there.
>  
> +	  Due to a kernel build system changes in 6.12,
> +	  BR2_LINUX_KERNEL_CUSTOM_DTS_PATH is now deprecated and
> +	  replaced by BR2_LINUX_KERNEL_CUSTOM_DTS_DIR

Not sure how this legacy stuff works in buildroot.
Should this select BR2_LEGACY ?


> +
> +config BR2_LINUX_KERNEL_CUSTOM_DTS_DIR
> +	string "Out-of-tree Device Tree Source overlay directories"
> +	help
> +	  Specify a list of directories that are copied as-is over the
> +	  arch/<arch>/boot/dts/ directory before building the device
> +	  tree blob.
> +
> +	  This overlay can contain dts, dtso and dtsi files.
> +
> +	  For pre-6.12 kernels or older architectures, the dts files
> +	  appear directly under this directory. For newer kernels and
> +	  architectures, the dts files must be in the appropriate
> +	  subdirectory.

I think this should be rephrased.

Architechtures making use of vendor subdirectories did so even before 6.12.

If you want to reference the past, perhaps:
The legacy config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH points to a directory that
contains that dts files directly.


But I'm not sure if it makes sense to reference a legacy config, so perhaps
just omit this and instead write something like:

BR2_LINUX_KERNEL_CUSTOM_DTS_DIR should point to a directory containing a
vendor subdirectory (e.g. rockchip) which contains the dts files.
This vendor subdirectory should match the vendor subdirectory
used by the board in the kernel (e.g. arch/arm64/boot/dts/rockchip/).

While most architechtures make use of vendor subdirectories, like arm,
arm64 and riscv, some architectures like powerpc and xtensa do not.
In this case, BR2_LINUX_KERNEL_CUSTOM_DTS_DIR should point to a directory
containing the dts files directly.


> +
> +	  Newer architectures like ARM64 and RISC-V keep their device
> +	  tree sources organized by vendor sub-directories.
> +
> +	  Since the 6.12 release, each out-of-tree Device Tree Source
> +	  file must be copied into their corresponding sub-directory.
> +
>  config BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME
>  	bool "Keep the directory name of the Device Tree"
>  	help
> diff --git a/linux/linux.mk b/linux/linux.mk
> index 9c621c18d5..f915823dcf 100644
> --- a/linux/linux.mk
> +++ b/linux/linux.mk
> @@ -213,6 +213,22 @@ LINUX_CUSTOM_DTS_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH))
>  LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(LINUX_CUSTOM_DTS_PATH))))
>  LINUX_DTSO_NAMES += $(basename $(filter %.dtso,$(notdir $(LINUX_CUSTOM_DTS_PATH))))
>  
> +LINUX_KERNEL_CUSTOM_DTS_DIR = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_DIR))
> +ifneq ($(LINUX_KERNEL_CUSTOM_DTS_DIR),)
> +# Use evaluation-during-assignment using := to avoid any re-evaluation
> +# of LINUX_DTS_LIST when LINUX_DTS_NAME is used.
> +LINUX_DTS_LIST := $(shell find $(LINUX_KERNEL_CUSTOM_DTS_DIR) -name '*.dts' -printf '%P\n' 2>/dev/null)
> +LINUX_DTSO_LIST := $(shell find $(LINUX_KERNEL_CUSTOM_DTS_DIR) -name '*.dtso' -printf '%P\n' 2>/dev/null)
> +LINUX_DTS_NAME += $(basename $(LINUX_DTS_LIST))
> +LINUX_DTSO_NAMES += $(basename $(LINUX_DTSO_LIST))
> +
> +define LINUX_COPY_CUSTOM_DTS_FILES
> +	$(foreach d, $(LINUX_KERNEL_CUSTOM_DTS_DIR), \
> +		@$(call MESSAGE,"Copying devicetree overlay $(d)")$(sep) \
> +		$(Q)$(call SYSTEM_RSYNC,$(d),$(LINUX_ARCH_PATH)/boot/dts/)$(sep))
> +endef
> +endif
> +
>  LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME)) $(addsuffix .dtbo,$(LINUX_DTSO_NAMES))
>  
>  ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
> @@ -527,6 +543,7 @@ define LINUX_BUILD_CMDS
>  	$(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
>  		cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
>  	)
> +	$(LINUX_COPY_CUSTOM_DTS_FILES)
>  	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all
>  	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
>  	$(LINUX_BUILD_DTB)
> -- 
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2025-02-20 13:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 16:36 [Buildroot] [PATCH v5 1/6] linux: add support for device tree overlays Romain Naour via buildroot
2025-02-04 16:36 ` [Buildroot] [PATCH v5 2/6] configs/rock5b: build and install rock5b " Romain Naour via buildroot
2025-02-20 13:25   ` Niklas Cassel via buildroot
2025-02-04 16:36 ` [Buildroot] [PATCH v5 3/6] linux: introduce BR2_LINUX_KERNEL_CUSTOM_DTS_DIR Romain Naour via buildroot
2025-02-18 13:59   ` Niklas Cassel via buildroot
2025-02-20  8:58     ` Romain Naour via buildroot
2025-02-20 13:49   ` Niklas Cassel via buildroot [this message]
2025-02-21 22:29     ` Romain Naour via buildroot
2025-02-04 16:36 ` [Buildroot] [PATCH v5 4/6] configs/acmesystems_acqua_a5_*: bump to Linux 6.12.9 Romain Naour via buildroot
2025-02-20 13:25   ` Niklas Cassel
2025-02-21 22:36     ` Romain Naour via buildroot
2025-02-04 16:36 ` [Buildroot] [PATCH v5 5/6] [WIP] am57 kernel version bump 6.12 Romain Naour via buildroot
2025-02-20 13:25   ` Niklas Cassel via buildroot
2025-02-04 16:36 ` [Buildroot] [PATCH v5 6/6] [WIP] am57: add dtso example Romain Naour via buildroot
2025-02-20 13:25   ` Niklas Cassel via buildroot
2025-02-21 22:39     ` Romain Naour via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z7cy9nU3Yg7x2RTd@ryzen \
    --to=buildroot@buildroot.org \
    --cc=Niklas.Cassel@wdc.com \
    --cc=bonet@grenoble.cnrs.fr \
    --cc=gael.portay+rtone@gmail.com \
    --cc=judge.packham@gmail.com \
    --cc=michael@walle.cc \
    --cc=romain.naour@smile.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox