Skip to content

Commit 4f0e3a5

Browse files
committed
kbuild: Add support for DT binding schema checks
This adds the build infrastructure for checking DT binding schema documents and validating dts files using the binding schema. Check DT binding schema documents: make dt_binding_check Build dts files and check using DT binding schema: make dtbs_check Optionally, DT_SCHEMA_FILES can be passed in with a schema file(s) to use for validation. This makes it easier to find and fix errors generated by a specific schema. Currently, the validation targets are separate from a normal build to avoid a hard dependency on the external DT schema project and because there are lots of warnings generated. Cc: Jonathan Corbet <[email protected]> Cc: Mark Rutland <[email protected]> Acked-by: Masahiro Yamada <[email protected]> Cc: Michal Marek <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Rob Herring <[email protected]>
1 parent ccda4af commit 4f0e3a5

File tree

7 files changed

+67
-6
lines changed

7 files changed

+67
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*.bin
1616
*.bz2
1717
*.c.[012]*.*
18+
*.dt.yaml
1819
*.dtb
1920
*.dtb.S
2021
*.dwo

Documentation/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Makefile for Sphinx documentation
33
#
44

5-
subdir-y :=
5+
subdir-y := devicetree/bindings/
66

77
# You can set these variables from the command line.
88
SPHINXBUILD = sphinx-build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.example.dts
2+
processed-schema.yaml
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
DT_DOC_CHECKER ?= dt-doc-validate
3+
DT_EXTRACT_EX ?= dt-extract-example
4+
DT_MK_SCHEMA ?= dt-mk-schema
5+
DT_MK_SCHEMA_FLAGS := $(if $(DT_SCHEMA_FILES), -u)
6+
7+
quiet_cmd_chk_binding = CHKDT $(patsubst $(srctree)/%,%,$<)
8+
cmd_chk_binding = $(DT_DOC_CHECKER) $< ; \
9+
$(DT_EXTRACT_EX) $< > $@
10+
11+
$(obj)/%.example.dts: $(src)/%.yaml FORCE
12+
$(call if_changed,chk_binding)
13+
14+
DT_TMP_SCHEMA := processed-schema.yaml
15+
extra-y += $(DT_TMP_SCHEMA)
16+
17+
quiet_cmd_mk_schema = SCHEMA $@
18+
cmd_mk_schema = $(DT_MK_SCHEMA) $(DT_MK_SCHEMA_FLAGS) -o $@ $(filter-out FORCE, $^)
19+
20+
DT_DOCS = $(shell cd $(srctree)/$(src) && find * -name '*.yaml')
21+
DT_SCHEMA_FILES ?= $(addprefix $(src)/,$(DT_DOCS))
22+
23+
extra-y += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES))
24+
extra-y += $(patsubst $(src)/%.yaml,%.example.dtb, $(DT_SCHEMA_FILES))
25+
26+
$(obj)/$(DT_TMP_SCHEMA): $(DT_SCHEMA_FILES) FORCE
27+
$(call if_changed,mk_schema)

Makefile

+10-3
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,13 @@ ifneq ($(dtstree),)
12321232
%.dtb: prepare3 scripts_dtc
12331233
$(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
12341234

1235-
PHONY += dtbs dtbs_install
1236-
dtbs: prepare3 scripts_dtc
1235+
PHONY += dtbs dtbs_install dt_binding_check
1236+
dtbs dtbs_check: prepare3 scripts_dtc
12371237
$(Q)$(MAKE) $(build)=$(dtstree)
12381238

1239+
dtbs_check: export CHECK_DTBS=1
1240+
dtbs_check: dt_binding_check
1241+
12391242
dtbs_install:
12401243
$(Q)$(MAKE) $(dtbinst)=$(dtstree)
12411244

@@ -1249,6 +1252,9 @@ PHONY += scripts_dtc
12491252
scripts_dtc: scripts_basic
12501253
$(Q)$(MAKE) $(build)=scripts/dtc
12511254

1255+
dt_binding_check: scripts_dtc
1256+
$(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1257+
12521258
# ---------------------------------------------------------------------------
12531259
# Modules
12541260

@@ -1611,7 +1617,8 @@ clean: $(clean-dirs)
16111617
$(call cmd,rmfiles)
16121618
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
16131619
\( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
1614-
-o -name '*.ko.*' -o -name '*.dtb' -o -name '*.dtb.S' \
1620+
-o -name '*.ko.*' \
1621+
-o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
16151622
-o -name '*.dwo' -o -name '*.lst' \
16161623
-o -name '*.su' \
16171624
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \

scripts/Makefile.lib

+22-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))
6161
extra-y += $(dtb-y)
6262
extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
6363

64+
ifneq ($(CHECK_DTBS),)
65+
extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
66+
extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
67+
endif
68+
6469
# Add subdir path
6570

6671
extra-y := $(addprefix $(obj)/,$(extra-y))
@@ -284,13 +289,28 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
284289
quiet_cmd_dtc = DTC $@
285290
cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
286291
$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
287-
$(DTC) -O dtb -o $@ -b 0 \
292+
$(DTC) -O $(2) -o $@ -b 0 \
288293
$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
289294
-d $(depfile).dtc.tmp $(dtc-tmp) ; \
290295
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
291296

292297
$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
293-
$(call if_changed_dep,dtc)
298+
$(call if_changed_dep,dtc,dtb)
299+
300+
DT_CHECKER ?= dt-validate
301+
DT_BINDING_DIR := Documentation/devicetree/bindings
302+
DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.yaml
303+
304+
quiet_cmd_dtb_check = CHECK $@
305+
cmd_dtb_check = $(DT_CHECKER) -p $(DT_TMP_SCHEMA) $@ ;
306+
307+
define rule_dtc_dt_yaml
308+
$(call cmd_and_fixdep,dtc,yaml) \
309+
$(call echo-cmd,dtb_check) $(cmd_dtb_check)
310+
endef
311+
312+
$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
313+
$(call if_changed_rule,dtc_dt_yaml)
294314

295315
dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
296316

scripts/dtc/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
1212
HOST_EXTRACFLAGS := -I$(src)/libfdt
1313

1414
ifeq ($(wildcard /usr/include/yaml.h),)
15+
ifneq ($(CHECK_DTBS),)
16+
$(error dtc needs libyaml for DT schema validation support. \
17+
Install the necessary libyaml development package.)
18+
endif
1519
HOST_EXTRACFLAGS += -DNO_YAML
1620
else
1721
dtc-objs += yamltree.o

0 commit comments

Comments
 (0)