History

dt-bindings: kbuild: Use DTB files for validation

Switch the DT validation to use DTB files directly instead of a DTS to YAML conversion. The original motivation for supporting validation on DTB files was to enable running validation on a running system (e.g. 'dt-validate /sys/firmware/fdt') or other cases where the original source DTS is not available. The YAML format was not without issues. Using DTBs with the schema type information solves some of those problems. The YAML format relies on the DTS source level information including bracketing of properties, size directives, and phandle tags all of which are lost in a DTB file. While standardizing the bracketing is a good thing, it does cause a lot of extra warnings and churn to fix them. Another issue has been signed types are not validated correctly as sign information is not propagated to YAML. Using the schema type information allows for proper handling of signed types. YAML also can't represent the full range of 64-bit integers as numbers are stored as floats by most/all parsers. The DTB validation works by decoding property values using the type information in the schemas themselves. The main corner case this does not work for is matrix types where neither dimension is fixed. For now, checking the dimensions in these cases are skipped.

Rob Herring committed 4 years ago

Commit ef8795f1 parent 2783a7f5 files · +16 −43Browse files

Unified · Split

5 files
  1. Documentation/devicetree/bindings/Makefile +3 −4
  2. Documentation/devicetree/bindings/writing-schema.rst +5 −12
  3. scripts/Makefile.lib +7 −13
  4. scripts/dtc/Makefile +0 −13
  5. scripts/dtc/update-dtc-source.sh +1 −1
Documentation/devicetree/bindings/Makefile+3−4
@@ -26,8 +26,7 @@ $(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE · 25 unmodified lines
26 $(call if_changed,extract_ex)26 $(call if_changed,extract_ex)
27 27
28find_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \28find_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
29 -name 'processed-schema*' ! \29 -name 'processed-schema*' \)
30 -name '*.example.dt.yaml' \)
31 30
32find_cmd = $(find_all_cmd) | grep -F "$(DT_SCHEMA_FILES)"31find_cmd = $(find_all_cmd) | grep -F "$(DT_SCHEMA_FILES)"
33CHK_DT_DOCS := $(shell $(find_cmd))32CHK_DT_DOCS := $(shell $(find_cmd))
@@ -72,9 +71,9 @@ $(obj)/processed-schema.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version · 38 unmodified lines
72 71
73always-y += processed-schema.json72always-y += processed-schema.json
74always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dts, $(CHK_DT_DOCS))73always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dts, $(CHK_DT_DOCS))
75always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dt.yaml, $(CHK_DT_DOCS))74always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dtb, $(CHK_DT_DOCS))
76 75
77# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of76# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
78# build artifacts here before they are processed by scripts/Makefile.clean77# build artifacts here before they are processed by scripts/Makefile.clean
79clean-files = $(shell find $(obj) \( -name '*.example.dts' -o \78clean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
80 -name '*.example.dt.yaml' \) -delete 2>/dev/null)79 -name '*.example.dtb' \) -delete 2>/dev/null)
Documentation/devicetree/bindings/writing-schema.rst+5−12
@@ -120,20 +120,13 @@ project can be installed with pip:: · 119 unmodified lines
120 120
121 pip3 install dtschema121 pip3 install dtschema
122 122
123Several executables (dt-doc-validate, dt-mk-schema, dt-validate) will be123Note that 'dtschema' installation requires 'swig' and Python development files
124installed. Ensure they are in your PATH (~/.local/bin by default).124installed first. On Debian/Ubuntu systems::
125
126dtc must also be built with YAML output support enabled. This requires that
127libyaml and its headers be installed on the host system. For some distributions
128that involves installing the development package, such as:
129
130Debian::
131 125
132 apt-get install libyaml-dev126 apt install swig python3-dev
133 127
134Fedora::128Several executables (dt-doc-validate, dt-mk-schema, dt-validate) will be
135 129installed. Ensure they are in your PATH (~/.local/bin by default).
136 dnf -y install libyaml-devel
137 130
138Running checks131Running checks
139~~~~~~~~~~~~~~132~~~~~~~~~~~~~~
scripts/Makefile.lib+7−13
@@ -87,11 +87,6 @@ base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, · 86 unmodified lines
87 87
88always-y += $(dtb-y)88always-y += $(dtb-y)
89 89
90ifneq ($(CHECK_DTBS),)
91always-y += $(patsubst %.dtb,%.dt.yaml, $(real-dtb-y))
92always-y += $(patsubst %.dtbo,%.dt.yaml, $(real-dtb-y))
93endif
94
95# Add subdir path90# Add subdir path
96 91
97extra-y := $(addprefix $(obj)/,$(extra-y))92extra-y := $(addprefix $(obj)/,$(extra-y))
@@ -347,12 +342,6 @@ cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; · 249 unmodified lines
347 -d $(depfile).dtc.tmp $(dtc-tmp) ; \342 -d $(depfile).dtc.tmp $(dtc-tmp) ; \
348 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)343 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
349 344
350$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
351 $(call if_changed_dep,dtc)
352
353$(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
354 $(call if_changed_dep,dtc)
355
356quiet_cmd_fdtoverlay = DTOVL $@345quiet_cmd_fdtoverlay = DTOVL $@
357 cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)346 cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
358 347
@@ -360,22 +349,27 @@ $(multi-dtb-y): FORCE · 1 unmodified line
360 $(call if_changed,fdtoverlay)349 $(call if_changed,fdtoverlay)
361$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)350$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
362 351
352ifneq ($(CHECK_DTBS)$(CHECK_DT_BINDING),)
363DT_CHECKER ?= dt-validate353DT_CHECKER ?= dt-validate
364DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)354DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
365DT_BINDING_DIR := Documentation/devicetree/bindings355DT_BINDING_DIR := Documentation/devicetree/bindings
366DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json356DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
367 357
368quiet_cmd_dtb_check = CHECK $@358quiet_cmd_dtb_check = CHECK $@
369 cmd_dtb_check = $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@359 cmd_dtb_check = $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true
360endif
370 361
371define rule_dtc362define rule_dtc
372 $(call cmd_and_fixdep,dtc)363 $(call cmd_and_fixdep,dtc)
373 $(call cmd,dtb_check)364 $(call cmd,dtb_check)
374endef365endef
375 366
376$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE367$(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
377 $(call if_changed_rule,dtc)368 $(call if_changed_rule,dtc)
378 369
370$(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
371 $(call if_changed_dep,dtc)
372
379dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)373dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
380 374
381# Bzip2375# Bzip2
scripts/dtc/Makefile+0−13
@@ -17,20 +17,7 @@ fdtoverlay-objs := $(libfdt) fdtoverlay.o util.o · 16 unmodified lines
17 17
18# Source files need to get at the userspace version of libfdt_env.h to compile18# Source files need to get at the userspace version of libfdt_env.h to compile
19HOST_EXTRACFLAGS += -I $(srctree)/$(src)/libfdt19HOST_EXTRACFLAGS += -I $(srctree)/$(src)/libfdt
20
21ifeq ($(shell pkg-config --exists yaml-0.1 2>/dev/null && echo yes),)
22ifneq ($(CHECK_DT_BINDING)$(CHECK_DTBS),)
23$(error dtc needs libyaml for DT schema validation support. \
24 Install the necessary libyaml development package.)
25endif
26HOST_EXTRACFLAGS += -DNO_YAML20HOST_EXTRACFLAGS += -DNO_YAML
27else
28dtc-objs += yamltree.o
29# To include <yaml.h> installed in a non-default path
30HOSTCFLAGS_yamltree.o := $(shell pkg-config --cflags yaml-0.1)
31# To link libyaml installed in a non-default path
32HOSTLDLIBS_dtc := $(shell pkg-config --libs yaml-0.1)
33endif
34 21
35# Generated files need one more search path to include headers in source tree22# Generated files need one more search path to include headers in source tree
36HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)23HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
scripts/dtc/update-dtc-source.sh+1−1
@@ -32,7 +32,7 @@ DTC_UPSTREAM_PATH=`pwd`/../dtc · 31 unmodified lines
32DTC_LINUX_PATH=`pwd`/scripts/dtc32DTC_LINUX_PATH=`pwd`/scripts/dtc
33 33
34DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \34DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
35 srcpos.h treesource.c util.c util.h version_gen.h yamltree.c \35 srcpos.h treesource.c util.c util.h version_gen.h \
36 dtc-lexer.l dtc-parser.y"36 dtc-lexer.l dtc-parser.y"
37LIBFDT_SOURCE="fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \37LIBFDT_SOURCE="fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
38 fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \38 fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \