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 = 2021.2.1 9 10PHONY += check_dtschema_version 11check_dtschema_version: 12 @which $(DT_DOC_CHECKER) >/dev/null || \ 13 { echo "Error: '$(DT_DOC_CHECKER)' not found!" >&2; \ 14 echo "Ensure dtschema python package is installed and in your PATH." >&2; \ 15 echo "Current PATH is:" >&2; \ 16 echo "$$PATH" >&2; false; } 17 @{ echo $(DT_SCHEMA_MIN_VERSION); \ 18 $(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \ 19 { echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; } 20 21quiet_cmd_extract_ex = DTEX $@ 22 cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@ 23 24$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE 25 $(call if_changed,extract_ex) 26 27# Use full schemas when checking %.example.dts 28DT_TMP_SCHEMA := $(obj)/processed-schema-examples.json 29 30find_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \ 31 -name 'processed-schema*' ! \ 32 -name '*.example.dt.yaml' \) 33 34ifeq ($(DT_SCHEMA_FILES),) 35find_cmd = $(find_all_cmd) 36else 37find_cmd = echo $(addprefix $(srctree)/, $(DT_SCHEMA_FILES)) 38endif 39 40quiet_cmd_yamllint = LINT $(src) 41 cmd_yamllint = ($(find_cmd) | \ 42 xargs -n200 -P$$(nproc) \ 43 $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) || true 44 45quiet_cmd_chk_bindings = CHKDT $@ 46 cmd_chk_bindings = ($(find_cmd) | \ 47 xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true 48 49quiet_cmd_mk_schema = SCHEMA $@ 50 cmd_mk_schema = f=$$(mktemp) ; \ 51 $(if $(DT_MK_SCHEMA_FLAGS), \ 52 printf '%s\n' $(real-prereqs), \ 53 $(find_all_cmd)) > $$f ; \ 54 $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \ 55 rm -f $$f 56 57define rule_chkdt 58 $(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),) 59 $(call cmd,chk_bindings) 60 $(call cmd,mk_schema) 61endef 62 63DT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_all_cmd))) 64 65override DTC_FLAGS := \ 66 -Wno-avoid_unnecessary_addr_size \ 67 -Wno-graph_child_address \ 68 -Wno-interrupt_provider 69 70# Disable undocumented compatible checks until warning free 71override DT_CHECKER_FLAGS ?= 72 73$(obj)/processed-schema-examples.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE 74 $(call if_changed_rule,chkdt) 75 76ifeq ($(DT_SCHEMA_FILES),) 77 78# Unless DT_SCHEMA_FILES is specified, use the full schema for dtbs_check too. 79# Just copy processed-schema-examples.json 80 81$(obj)/processed-schema.json: $(obj)/processed-schema-examples.json FORCE 82 $(call if_changed,copy) 83 84DT_SCHEMA_FILES = $(DT_DOCS) 85 86else 87 88# If DT_SCHEMA_FILES is specified, use it for processed-schema.json 89 90$(obj)/processed-schema.json: DT_MK_SCHEMA_FLAGS := -u 91$(obj)/processed-schema.json: $(DT_SCHEMA_FILES) check_dtschema_version FORCE 92 $(call if_changed,mk_schema) 93 94endif 95 96always-$(CHECK_DT_BINDING) += processed-schema-examples.json 97always-$(CHECK_DTBS) += processed-schema.json 98always-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES)) 99always-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES)) 100 101# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of 102# build artifacts here before they are processed by scripts/Makefile.clean 103clean-files = $(shell find $(obj) \( -name '*.example.dts' -o \ 104 -name '*.example.dt.yaml' \) -delete 2>/dev/null) 105