1c66ec88fSEmmanuel Vadot# SPDX-License-Identifier: GPL-2.0 2c66ec88fSEmmanuel VadotDT_DOC_CHECKER ?= dt-doc-validate 3c66ec88fSEmmanuel VadotDT_EXTRACT_EX ?= dt-extract-example 4c66ec88fSEmmanuel VadotDT_MK_SCHEMA ?= dt-mk-schema 5c66ec88fSEmmanuel Vadot 66be33864SEmmanuel VadotDT_SCHEMA_LINT = $(shell which yamllint) 76be33864SEmmanuel Vadot 86be33864SEmmanuel VadotDT_SCHEMA_MIN_VERSION = 2020.8.1 9c66ec88fSEmmanuel Vadot 10c66ec88fSEmmanuel VadotPHONY += check_dtschema_version 11c66ec88fSEmmanuel Vadotcheck_dtschema_version: 12c66ec88fSEmmanuel Vadot @{ echo $(DT_SCHEMA_MIN_VERSION); \ 13*5def4c47SEmmanuel Vadot $(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \ 14c66ec88fSEmmanuel Vadot { echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; } 15c66ec88fSEmmanuel Vadot 166be33864SEmmanuel Vadotquiet_cmd_extract_ex = DTEX $@ 176be33864SEmmanuel Vadot cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@ 18c66ec88fSEmmanuel Vadot 19c66ec88fSEmmanuel Vadot$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE 206be33864SEmmanuel Vadot $(call if_changed,extract_ex) 21c66ec88fSEmmanuel Vadot 22c66ec88fSEmmanuel Vadot# Use full schemas when checking %.example.dts 236be33864SEmmanuel VadotDT_TMP_SCHEMA := $(obj)/processed-schema-examples.json 24c66ec88fSEmmanuel Vadot 25c66ec88fSEmmanuel Vadotfind_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \ 26c66ec88fSEmmanuel Vadot -name 'processed-schema*' ! \ 27c66ec88fSEmmanuel Vadot -name '*.example.dt.yaml' \) 28c66ec88fSEmmanuel Vadot 296be33864SEmmanuel Vadotquiet_cmd_yamllint = LINT $(src) 30*5def4c47SEmmanuel Vadot cmd_yamllint = ($(find_cmd) | \ 31*5def4c47SEmmanuel Vadot xargs $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint) || true 326be33864SEmmanuel Vadot 336be33864SEmmanuel Vadotquiet_cmd_chk_bindings = CHKDT $@ 34*5def4c47SEmmanuel Vadot cmd_chk_bindings = ($(find_cmd) | \ 35*5def4c47SEmmanuel Vadot xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true 366be33864SEmmanuel Vadot 37c66ec88fSEmmanuel Vadotquiet_cmd_mk_schema = SCHEMA $@ 386be33864SEmmanuel Vadot cmd_mk_schema = f=$$(mktemp) ; \ 39c66ec88fSEmmanuel Vadot $(if $(DT_MK_SCHEMA_FLAGS), \ 40*5def4c47SEmmanuel Vadot printf '%s\n' $(real-prereqs), \ 416be33864SEmmanuel Vadot $(find_cmd)) > $$f ; \ 426be33864SEmmanuel Vadot $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \ 436be33864SEmmanuel Vadot rm -f $$f 446be33864SEmmanuel Vadot 456be33864SEmmanuel Vadotdefine rule_chkdt 466be33864SEmmanuel Vadot $(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),) 476be33864SEmmanuel Vadot $(call cmd,chk_bindings) 486be33864SEmmanuel Vadot $(call cmd,mk_schema) 496be33864SEmmanuel Vadotendef 50c66ec88fSEmmanuel Vadot 51c66ec88fSEmmanuel VadotDT_DOCS = $(shell $(find_cmd) | sed -e 's|^$(srctree)/||') 52c66ec88fSEmmanuel Vadot 53c66ec88fSEmmanuel Vadotoverride DTC_FLAGS := \ 54c66ec88fSEmmanuel Vadot -Wno-avoid_unnecessary_addr_size \ 55c66ec88fSEmmanuel Vadot -Wno-graph_child_address \ 56c66ec88fSEmmanuel Vadot -Wno-interrupt_provider 57c66ec88fSEmmanuel Vadot 586be33864SEmmanuel Vadot$(obj)/processed-schema-examples.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE 596be33864SEmmanuel Vadot $(call if_changed_rule,chkdt) 60c66ec88fSEmmanuel Vadot 61c66ec88fSEmmanuel Vadotifeq ($(DT_SCHEMA_FILES),) 62c66ec88fSEmmanuel Vadot 63c66ec88fSEmmanuel Vadot# Unless DT_SCHEMA_FILES is specified, use the full schema for dtbs_check too. 646be33864SEmmanuel Vadot# Just copy processed-schema-examples.json 65c66ec88fSEmmanuel Vadot 666be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(obj)/processed-schema-examples.json FORCE 67c66ec88fSEmmanuel Vadot $(call if_changed,copy) 68c66ec88fSEmmanuel Vadot 69c66ec88fSEmmanuel VadotDT_SCHEMA_FILES = $(DT_DOCS) 70c66ec88fSEmmanuel Vadot 71c66ec88fSEmmanuel Vadotelse 72c66ec88fSEmmanuel Vadot 736be33864SEmmanuel Vadot# If DT_SCHEMA_FILES is specified, use it for processed-schema.json 74c66ec88fSEmmanuel Vadot 756be33864SEmmanuel Vadot$(obj)/processed-schema.json: DT_MK_SCHEMA_FLAGS := -u 766be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(DT_SCHEMA_FILES) check_dtschema_version FORCE 77c66ec88fSEmmanuel Vadot $(call if_changed,mk_schema) 78c66ec88fSEmmanuel Vadot 79c66ec88fSEmmanuel Vadotendif 80c66ec88fSEmmanuel Vadot 81*5def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += processed-schema-examples.json 82*5def4c47SEmmanuel Vadotalways-$(CHECK_DTBS) += processed-schema.json 83*5def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES)) 84*5def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES)) 85c66ec88fSEmmanuel Vadot 86c66ec88fSEmmanuel Vadot# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of 87c66ec88fSEmmanuel Vadot# build artifacts here before they are processed by scripts/Makefile.clean 88c66ec88fSEmmanuel Vadotclean-files = $(shell find $(obj) \( -name '*.example.dts' -o \ 89c66ec88fSEmmanuel Vadot -name '*.example.dt.yaml' \) -delete 2>/dev/null) 90