On Thu, Jul 30, 2026 at 03:07:40PM +0200, Bruno Thomsen wrote:
> Make it possible to do device tree validation on
> dts/dtsi during development and preparation for
> upstream.
> 
> Signed-off-by: Bruno Thomsen <[email protected]>
> ---
>  platforms/kernel.in | 25 +++++++++++++++++++++++++
>  rules/kernel.make   | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+)
> 
> diff --git a/platforms/kernel.in b/platforms/kernel.in
> index 2c6d906e8..79a414fd8 100644
> --- a/platforms/kernel.in
> +++ b/platforms/kernel.in
> @@ -11,6 +11,8 @@ menuconfig KERNEL
>       select HOST_LZ4                 if KERNEL_LZ4
>       select HOST_LIBKMOD             if KERNEL_MODULES
>       select HOST_SYSTEM_BC
> +     select HOST_SYSTEM_PYTHON3      if KERNEL_DTB_CHECK
> +     select HOST_SYSTEM_PYTHON3_DTSCHEMA     if KERNEL_DTB_CHECK
>       select HOST_OPENSSL             if KERNEL_OPENSSL
>       select HOST_LIBELF              if KERNEL_LIBELF
>       select HOST_BINDGEN_CLI         if KERNEL_RUST
> @@ -232,6 +234,29 @@ config KERNEL_DTSO
>  
>  endif
>  
> +config KERNEL_DTB_CHECK
> +     bool
> +     depends on KERNEL_DTB
> +     prompt "validate device trees against the DT schema"
> +     help
> +       Additionally build the device trees with the kernel build system
> +       ('make CHECK_DTBS=y <board>.dtb') to validate them against the
> +       device tree bindings in Documentation/devicetree/bindings.
> +       Problems are reported as warnings, they do not break the build.
> +
> +       This requires the 'dtschema' python package on the build host and
> +       it noticeably increases the build time of the kernel, because the
> +       schema of all bindings must be processed first.
> +
> +       Only device trees that are part of the kernel tree can be checked.
> +       Each file in KERNEL_DTS is looked up in KERNEL_DTS_PATH and the
> +       first match below a 'boot/dts' directory is checked, even if the
> +       device tree itself is built from an earlier entry in the search
> +       path. Device trees without such a match are skipped with a
> +       warning. So for device trees in a vendor directory, that directory
> +       must be part of KERNEL_DTS_PATH, e.g.
> +       "${KERNEL_DIR}/arch/${GENERIC_KERNEL_ARCH}/boot/dts/ti/omap".
> +
>  config KERNEL_CODE_SIGNING
>       prompt "use code signing infrastructure"
>       select KERNEL_OPENSSL
> diff --git a/rules/kernel.make b/rules/kernel.make
> index af0dd3913..eaed71023 100644
> --- a/rules/kernel.make
> +++ b/rules/kernel.make
> @@ -215,6 +215,36 @@ KERNEL_MAKE_OPT          = \
>       $(KERNEL_IMAGE) \
>       $(call ptx/ifdef, PTXCONF_KERNEL_MODULES,modules)
>  
> +#
> +# device tree validation
> +#
> +# The kernel build system can only validate device trees from the kernel 
> tree.
> +# Look up the device trees in KERNEL_DTS_PATH and use the first match below a
> +# 'boot/dts' directory.
> +#
> +kernel/dtb-check-file        = \
> +     $(firstword $(foreach dts, \
> +             $(call ptx/in-path-all,KERNEL_DTS_PATH,$(1)), \
> +             $(if $(findstring /boot/dts/,$(dts)),$(dts))))
> +
> +# the dtb make targets are relative to arch/<arch>/boot/dts
> +kernel/dtb-check-target      = \
> +     $(patsubst %.dts,%.dtb,$(patsubst /%,%,$(word 2, \
> +             $(subst /boot/dts,$(ptx/def/space), \
> +                     $(call kernel/dtb-check-file,$(1))))))
> +
> +KERNEL_DTB_CHECK_FILES       = $(strip \
> +     $(foreach dts,$(KERNEL_DTS),$(call kernel/dtb-check-target,$(dts))))
> +
> +KERNEL_DTB_CHECK_SKIPPED = $(strip \
> +     $(foreach dts,$(KERNEL_DTS), \
> +             $(if $(call kernel/dtb-check-file,$(dts)),,$(dts))))
> +

I think this is too much complexity for the kernel.make. Instead add this
to ptxd_make_world_dtb(). That really only works with the Linux kernel
anyways.

> +KERNEL_DTB_CHECK_OPT = \
> +     $(KERNEL_SHARED_OPT) \
> +     CHECK_DTBS=y \
> +     $(KERNEL_DTB_CHECK_FILES)

Make this conditional based on the kconfig option.

Add
        pkg_dtb_check_opt="$($(1)_DTB_CHECK_OPT)"

to world/dtb/env

and use that in ptxd_make_world_dtb() to run the check if set. It will be
much cleaner to find the in-tree files there as well.

Michael

> +
>  KERNEL_TOOL_PERF_OPTS        := \
>       -C $(KERNEL_DIR)/tools/perf \
>       O=$(KERNEL_BUILD_DIR)/tools/perf \
> @@ -263,6 +293,12 @@ $(STATEDIR)/kernel.compile:
>               $(KERNEL_BUILD_DIR)/usr/initramfs_data.cpio.* \
>               $(KERNEL_BUILD_DIR)/usr/.initramfs_data.cpio.*
>       @$(call world/compile, KERNEL)
> +ifdef PTXCONF_KERNEL_DTB_CHECK
> +     @$(foreach dts, $(KERNEL_DTB_CHECK_SKIPPED), \
> +             echo "dtb-check: skipping '$(dts)': no match below 'boot/dts' 
> in KERNEL_DTS_PATH";)
> +     @$(if $(KERNEL_DTB_CHECK_FILES), \
> +             $(call world/execute, KERNEL, $(MAKE) $(KERNEL_DTB_CHECK_OPT)))
> +endif
>  ifdef PTXCONF_KERNEL_TOOL_PERF
>       @mkdir -p $(KERNEL_BUILD_DIR)/tools/perf
>       @$(call compile, KERNEL, $(KERNEL_TOOL_PERF_OPTS))
> -- 
> 2.55.0
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Reply via email to