• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2DT_DOC_CHECKER ?= dt-doc-validate
3DT_EXTRACT_EX ?= dt-extract-example
4DT_MK_SCHEMA ?= dt-mk-schema
5
6DT_SCHEMA_LINT = $(shell which yamllint)
7
8DT_SCHEMA_MIN_VERSION = 2020.8.1
9
10PHONY += check_dtschema_version
11check_dtschema_version:
12	@{ echo $(DT_SCHEMA_MIN_VERSION); \
13	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -VC || \
14	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
15
16quiet_cmd_extract_ex = DTEX    $@
17      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
18
19$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
20	$(call if_changed,extract_ex)
21
22# Use full schemas when checking %.example.dts
23DT_TMP_SCHEMA := $(obj)/processed-schema-examples.json
24
25find_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
26		-name 'processed-schema*' ! \
27		-name '*.example.dt.yaml' \)
28
29quiet_cmd_yamllint = LINT    $(src)
30      cmd_yamllint = $(find_cmd) | \
31                     xargs $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint
32
33quiet_cmd_chk_bindings = CHKDT   $@
34      cmd_chk_bindings = $(find_cmd) | \
35                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)
36
37quiet_cmd_mk_schema = SCHEMA  $@
38      cmd_mk_schema = f=$$(mktemp) ; \
39                      $(if $(DT_MK_SCHEMA_FLAGS), \
40                           echo $(real-prereqs), \
41                           $(find_cmd)) > $$f ; \
42                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
43		      rm -f $$f
44
45define rule_chkdt
46	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
47	$(call cmd,chk_bindings)
48	$(call cmd,mk_schema)
49endef
50
51DT_DOCS = $(shell $(find_cmd) | sed -e 's|^$(srctree)/||')
52
53override DTC_FLAGS := \
54	-Wno-avoid_unnecessary_addr_size \
55	-Wno-graph_child_address \
56	-Wno-interrupt_provider
57
58$(obj)/processed-schema-examples.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
59	$(call if_changed_rule,chkdt)
60
61ifeq ($(DT_SCHEMA_FILES),)
62
63# Unless DT_SCHEMA_FILES is specified, use the full schema for dtbs_check too.
64# Just copy processed-schema-examples.json
65
66$(obj)/processed-schema.json: $(obj)/processed-schema-examples.json FORCE
67	$(call if_changed,copy)
68
69DT_SCHEMA_FILES = $(DT_DOCS)
70
71else
72
73# If DT_SCHEMA_FILES is specified, use it for processed-schema.json
74
75$(obj)/processed-schema.json: DT_MK_SCHEMA_FLAGS := -u
76$(obj)/processed-schema.json: $(DT_SCHEMA_FILES) check_dtschema_version FORCE
77	$(call if_changed,mk_schema)
78
79endif
80
81extra-$(CHECK_DT_BINDING) += processed-schema-examples.json
82extra-$(CHECK_DTBS) += processed-schema.json
83extra-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES))
84extra-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES))
85
86# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
87# build artifacts here before they are processed by scripts/Makefile.clean
88clean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
89			-name '*.example.dt.yaml' \) -delete 2>/dev/null)
90