From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 18 Sep 2026 11:02:12 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x7UU0-003Vc4-1i for lore@lore.pengutronix.de; Fri, 18 Sep 2026 11:02:12 +0200 Received: from [127.0.0.1] (helo=metis.whiteo.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1x7UTz-0003pC-E9; Fri, 18 Sep 2026 11:02:11 +0200 Received: from mx1.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::107]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1x7UTt-0003ii-PX for ptxdist@pengutronix.de; Fri, 18 Sep 2026 11:02:05 +0200 Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id B5CC520004A; Fri, 18 Sep 2026 11:02:05 +0200 (CEST) Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x7UTt-001Xkk-28; Fri, 18 Sep 2026 11:02:05 +0200 Received: from mol by dude05.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1x7UTt-000000075z0-2Yw3; Fri, 18 Sep 2026 11:02:05 +0200 From: Michael Olbrich To: ptxdist@pengutronix.de Date: Fri, 18 Sep 2026 11:02:05 +0200 Message-ID: <20260918090205.1691288-1-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260831131159.11771-3-bruno.thomsen@gmail.com> References: <20260831131159.11771-3-bruno.thomsen@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [ptxdist] [APPLIED] kernel: validate device trees against the DT schema X-BeenThere: ptxdist@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ptxdist@pengutronix.de Cc: Bruno Thomsen Sender: "ptxdist" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: ptxdist-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false Thanks, applied as 1a3fb66e36d4112238c9219cca47f56874668d6e. Michael [sent from post-receive hook] On Fri, 18 Sep 2026 11:02:05 +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 > Message-Id: <20260831131159.11771-3-bruno.thomsen@gmail.com> > Signed-off-by: Michael Olbrich > > 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 .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//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//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