1# SPDX-License-Identifier: GPL-2.0-only 2 3all-dtb := $(dtb-y) $(dtb-) 4 5# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 6dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 7 8# Composite DTB (i.e. DTB constructed by overlay) 9multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs) 10# Primitive DTB compiled from *.dts 11real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs) 12# Base DTB that overlay is applied onto 13base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs)) 14 15# Ensure that any .dtbo is applied to at least one base .dtb. Otherwise, it 16# does not get validated. 17applied-dtbo := $(filter %.dtbo, \ 18 $(call real-search, $(call multi-search, $(all-dtb), .dtb, -dtbs), .dtb, -dtbs)) 19unapplied-dtbo := $(filter-out $(applied-dtbo),$(filter %.dtbo, $(dtb-y))) 20$(if $(unapplied-dtbo), $(warning .dtbo is not applied to any base: $(unapplied-dtbo))) 21 22dtb-y := $(addprefix $(obj)/, $(dtb-y)) 23multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y)) 24real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y)) 25 26always-y += $(dtb-y) 27targets += $(real-dtb-y) 28 29# dtbs-list 30# --------------------------------------------------------------------------- 31 32ifdef need-dtbslist 33subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym)) 34dtb-y += $(subdir-dtbslist) 35always-y += $(obj)/dtbs-list 36endif 37 38$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ; 39 40$(obj)/dtbs-list: $(dtb-y) FORCE 41 $(call if_changed,gen_order) 42 43# Assembly file to wrap dtb(o) 44# --------------------------------------------------------------------------- 45 46builtin-dtb-section = $(if $(filter arch/$(SRCARCH)/boot/dts%, $(obj)),.dtb.init.rodata,.rodata) 47 48# Generate an assembly file to wrap the output of the device tree compiler 49quiet_cmd_wrap_S_dtb = WRAP $@ 50 cmd_wrap_S_dtb = { \ 51 symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \ 52 echo '\#include <asm-generic/vmlinux.lds.h>'; \ 53 echo '.section $(builtin-dtb-section),"a"'; \ 54 echo '.balign STRUCT_ALIGNMENT'; \ 55 echo ".global $${symbase}_begin"; \ 56 echo "$${symbase}_begin:"; \ 57 echo '.incbin "$<" '; \ 58 echo ".global $${symbase}_end"; \ 59 echo "$${symbase}_end:"; \ 60 echo '.balign STRUCT_ALIGNMENT'; \ 61 } > $@ 62 63$(obj)/%.dtb.S: $(obj)/%.dtb FORCE 64 $(call if_changed,wrap_S_dtb) 65 66$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE 67 $(call if_changed,wrap_S_dtb) 68 69# Schema check 70# --------------------------------------------------------------------------- 71 72ifneq ($(CHECK_DTBS),) 73DT_CHECKER ?= dt-validate 74DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m) 75DT_BINDING_DIR := Documentation/devicetree/bindings 76DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json 77dtb-check-enabled = $(if $(filter %.dtb, $@),y) 78endif 79 80quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], ) 81cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true) 82 83# Overlay 84# --------------------------------------------------------------------------- 85 86# NOTE: 87# Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single 88# DTB is turned into a multi-blob DTB, $^ will contain header file dependencies 89# recorded in the .*.cmd file. 90quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@ 91 cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check) 92 93$(multi-dtb-y): $(DT_TMP_SCHEMA) FORCE 94 $(call if_changed,fdtoverlay) 95$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs) 96 97# DTC 98# --------------------------------------------------------------------------- 99 100DTC ?= $(objtree)/scripts/dtc/dtc 101DTC_FLAGS += -Wno-unique_unit_address 102 103# Disable noisy checks by default 104ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 105DTC_FLAGS += -Wno-unit_address_vs_reg \ 106 -Wno-avoid_unnecessary_addr_size \ 107 -Wno-alias_paths \ 108 -Wno-graph_child_address \ 109 -Wno-interrupt_map \ 110 -Wno-simple_bus_reg 111else 112DTC_FLAGS += -Wunique_unit_address_if_enabled 113endif 114 115ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) 116DTC_FLAGS += -Wnode_name_chars_strict \ 117 -Wproperty_name_chars_strict \ 118 -Wunique_unit_address 119endif 120 121DTC_FLAGS += $(DTC_FLAGS_$(target-stem)) 122 123# Set -@ if the target is a base DTB that overlay is applied onto 124DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) 125 126DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 127 128dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__ 129 130dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 131 132quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@ 133 cmd_dtc = \ 134 $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 135 $(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \ 136 $(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 137 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \ 138 $(cmd_dtb_check) 139 140$(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE 141 $(call if_changed_dep,dtc) 142 143$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE 144 $(call if_changed_dep,dtc) 145 146# targets 147# --------------------------------------------------------------------------- 148 149targets += $(always-y) 150 151# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts 152# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso 153targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \ 154 $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo) 155