mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Bruno Thomsen <bruno.thomsen@gmail.com>
To: ptxdist@pengutronix.de
Cc: Bruno Thomsen <bruno.thomsen@gmail.com>
Subject: [ptxdist] [RFC PATCH 2/2] kernel: validate device trees against the DT schema
Date: Thu, 30 Jul 2026 15:07:40 +0200	[thread overview]
Message-ID: <20260730130740.10851-3-bruno.thomsen@gmail.com> (raw)
In-Reply-To: <20260730130740.10851-1-bruno.thomsen@gmail.com>

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))))
+
+KERNEL_DTB_CHECK_OPT	= \
+	$(KERNEL_SHARED_OPT) \
+	CHECK_DTBS=y \
+	$(KERNEL_DTB_CHECK_FILES)
+
 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




      parent reply	other threads:[~2026-07-30 13:08 UTC|newest]

Thread overview: 3+ 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 ` Bruno Thomsen [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=20260730130740.10851-3-bruno.thomsen@gmail.com \
    --to=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