From: Michael Olbrich <m.olbrich@pengutronix.de>
To: Bruno Thomsen <bruno.thomsen@gmail.com>
Cc: ptxdist@pengutronix.de
Subject: Re: [ptxdist] [RFC PATCH 2/2] kernel: validate device trees against the DT schema
Date: Fri, 14 Aug 2026 10:06:24 +0200 [thread overview]
Message-ID: <an7MgCfriVe89gvD@pengutronix.de> (raw)
In-Reply-To: <20260730130740.10851-3-bruno.thomsen@gmail.com>
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 <bruno.thomsen@gmail.com>
> ---
> 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 |
prev parent reply other threads:[~2026-08-14 8:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 13:07 [ptxdist] [RFC PATCH 0/2] Run DT schema check on selected device trees Bruno Thomsen
2026-07-30 13:07 ` [ptxdist] [RFC PATCH 1/2] host-system-python: add dtschema Bruno Thomsen
2026-07-30 13:07 ` [ptxdist] [RFC PATCH 2/2] kernel: validate device trees against the DT schema Bruno Thomsen
2026-08-14 8:06 ` Michael Olbrich [this message]
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=an7MgCfriVe89gvD@pengutronix.de \
--to=m.olbrich@pengutronix.de \
--cc=bruno.thomsen@gmail.com \
--cc=ptxdist@pengutronix.de \
/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