mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Michael Olbrich <m.olbrich@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Bruno Thomsen <bruno.thomsen@gmail.com>
Subject: Re: [ptxdist] [APPLIED] kernel: validate device trees against the DT schema
Date: Fri, 18 Sep 2026 11:02:05 +0200	[thread overview]
Message-ID: <20260918090205.1691288-1-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <20260831131159.11771-3-bruno.thomsen@gmail.com>

Thanks, applied as 1a3fb66e36d4112238c9219cca47f56874668d6e.

Michael

[sent from post-receive hook]

On Fri, 18 Sep 2026 11:02:05 +0200, Bruno Thomsen <bruno.thomsen@gmail.com> 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>
> Message-Id: <20260831131159.11771-3-bruno.thomsen@gmail.com>
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> diff --git a/platforms/kernel.in b/platforms/kernel.in
> index 2c6d906e8bae..36a4f3cf0162 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
> @@ -200,6 +202,29 @@ config KERNEL_DTS
>  	  is used as a search path for the device tree files specified
>  	  here. Multiple dts files can be specified, separated by spaces.
>  
> +config KERNEL_DTB_CHECK
> +	bool
> +	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.
> +	  Schema problems are reported as warnings, so 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,
> +	  because the make targets are relative to arch/<arch>/boot/dts.
> +	  Each file in KERNEL_DTS is looked up in KERNEL_DTS_PATH and the
> +	  first match inside the kernel tree is validated. 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_DTS_SUPPORT_OVERLAYS
>  	bool
>  
> diff --git a/rules/kernel.make b/rules/kernel.make
> index af0dd3913faf..d32a0443c7f0 100644
> --- a/rules/kernel.make
> +++ b/rules/kernel.make
> @@ -282,6 +282,13 @@ KERNEL_INSTALL_OPT = \
>  	$(KERNEL_BASE_OPT) \
>  	modules_install
>  
> +ifdef PTXCONF_KERNEL_DTB_CHECK
> +# validate the device trees while building them in world/dtb
> +KERNEL_DTB_CHECK_OPT	= \
> +	$(KERNEL_SHARED_OPT) \
> +	CHECK_DTBS=y
> +endif
> +
>  $(STATEDIR)/kernel.install:
>  	@$(call targetinfo)
>  ifdef PTXCONF_KERNEL_MODULES_INSTALL
> diff --git a/rules/post/ptxd_make_world_dtb.make b/rules/post/ptxd_make_world_dtb.make
> index 37468c0bea94..81b237a872ec 100644
> --- a/rules/post/ptxd_make_world_dtb.make
> +++ b/rules/post/ptxd_make_world_dtb.make
> @@ -10,6 +10,7 @@ world/dtb/env = \
>  	$(call world/env, $(1)) \
>  	pkg_dts_path="$($(1)_DTS_PATH)" \
>  	pkg_dts="$($(1)_DTS)" \
> +	pkg_dtb_check_opt="$(call ptx/escape,$($(1)_DTB_CHECK_OPT))" \
>  	pkg_arch="$(GENERIC_KERNEL_ARCH)"
>  
>  world/dtb = \
> diff --git a/scripts/lib/ptxd_make_world_dtb.sh b/scripts/lib/ptxd_make_world_dtb.sh
> index dea9268ff5ef..22622b2adbe2 100644
> --- a/scripts/lib/ptxd_make_world_dtb.sh
> +++ b/scripts/lib/ptxd_make_world_dtb.sh
> @@ -109,10 +109,13 @@ export -f ptxd_make_world_dtbo
>  
>  ptxd_make_world_dtb() {
>      local dtb_deps_target dtb_source dtb_target
> +    local dts_file dts_in_tree dtb_check_dtstree
> +    local -a dtb_check_targets=()
>  
>      ptxd_make_world_init || return
>  
>      dtb_deps_target="${ptx_state_dir}/${pkg_stamp}"
> +    dtb_check_dtstree="${pkg_kernel_dir:-${pkg_dir}}/arch/${pkg_arch}/boot/dts"
>  
>      echo -e "\nBuilding device trees..."
>  
> @@ -128,7 +131,36 @@ ptxd_make_world_dtb() {
>  	dtb_source="${ptxd_reply}"
>  	dtb_target="${pkg_pkg_dir}/boot/$(basename ${dts_dts/%.dts/.dtb})"
>  
> +	#
> +	# The dtb targets of the kernel build system are relative to
> +	# arch/<arch>/boot/dts, so only device trees from the kernel tree
> +	# can be validated.
> +	#
> +	if [ -n "${pkg_dtb_check_opt}" ]; then
> +	    dts_file=""
> +	    for dts_in_tree in "${ptxd_reply[@]}"; do
> +		if [ "${dts_in_tree}" != "${dts_in_tree#${dtb_check_dtstree}/}" ]; then
> +		    dts_file="${dts_in_tree#${dtb_check_dtstree}/}"
> +		    break
> +		fi
> +	    done
> +	    if [ -n "${dts_file}" ]; then
> +		dtb_check_targets[${#dtb_check_targets[@]}]="${dts_file/%.dts/.dtb}"
> +	    else
> +		ptxd_warning "Device tree '${dts_dts}' is not part of the kernel tree. Skipping validation."
> +	    fi
> +	fi
> +
>  	ptxd_make_dtb || break
>      done
> +
> +    if [ ${#dtb_check_targets[@]} -ne 0 ]; then
> +	echo -e "\nValidating device trees..."
> +	ptxd_eval \
> +	    "${MAKE}" \
> +	    "${pkg_dtb_check_opt}" \
> +	    "${dtb_check_targets[@]}" ||
> +	ptxd_bailout "Unable to validate device trees."
> +    fi
>  }
>  export -f ptxd_make_world_dtb



      reply	other threads:[~2026-09-18  9:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 13:11 [ptxdist] [PATCH v2 0/2] Run DT schema check on selected device trees Bruno Thomsen
2026-08-31 13:11 ` [ptxdist] [PATCH v2 1/2] host-system-python3: add dtschema Bruno Thomsen
2026-09-04  7:17   ` Michael Olbrich
2026-09-18  9:02   ` [ptxdist] [APPLIED] " Michael Olbrich
2026-08-31 13:11 ` [ptxdist] [PATCH v2 2/2] kernel: validate device trees against the DT schema Bruno Thomsen
2026-09-18  9:02   ` 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=20260918090205.1691288-1-m.olbrich@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