at commit 0fa99358

1 # SPDX-License-Identifier: GPL-2.0-only
2
3 all-dtb := $(dtb-y) $(dtb-)
4
5 # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
6 dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
7
8 # Composite DTB (i.e. DTB constructed by overlay)
9 multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
10 # Primitive DTB compiled from *.dts
11 real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
12 # Base DTB that overlay is applied onto
13 base-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.
17 applied-dtbo := $(filter %.dtbo, \
18 $(call real-search, $(call multi-search, $(all-dtb), .dtb, -dtbs), .dtb, -dtbs))
19 unapplied-dtbo := $(filter-out $(applied-dtbo),$(filter %.dtbo, $(dtb-y)))
20 $(if $(unapplied-dtbo), $(warning .dtbo is not applied to any base: $(unapplied-dtbo)))
21
22 dtb-y := $(addprefix $(obj)/, $(dtb-y))
23 multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
24 real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
25
26 always-y += $(dtb-y)
27 targets += $(real-dtb-y)
28
29 # dtbs-list
30 # ---------------------------------------------------------------------------
31
32 ifdef need-dtbslist
33 subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym))
34 dtb-y += $(subdir-dtbslist)
35 always-y += $(obj)/dtbs-list
36 endif
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
46 builtin-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
49 quiet_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
72 ifneq ($(CHECK_DTBS),)
73 DT_CHECKER ?= dt-validate
74 DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
75 DT_BINDING_DIR := Documentation/devicetree/bindings
76 DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
77 dtb-check-enabled = $(if $(filter %.dtb, $@),y)
78 endif
79
80 quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], )
81 cmd_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.
90 quiet_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
100 DTC ?= $(objtree)/scripts/dtc/dtc
101 DTC_FLAGS += -Wno-unique_unit_address
102
103 # Disable noisy checks by default
104 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
105 DTC_FLAGS += -Wno-unit_address_vs_reg \
106 -Wno-avoid_unnecessary_addr_size \
107 -Wno-alias_paths \
108 -Wno-interrupt_map \
109 -Wno-simple_bus_reg
110 else
111 DTC_FLAGS += -Wunique_unit_address_if_enabled
112 endif
113
114 ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
115 DTC_FLAGS += -Wnode_name_chars_strict \
116 -Wproperty_name_chars_strict \
117 -Wunique_unit_address
118 endif
119
120 DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
121
122 # Set -@ if the target is a base DTB that overlay is applied onto
123 DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
124
125 DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
126
127 dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__
128
129 dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
130
131 quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@
132 cmd_dtc = \
133 $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
134 $(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \
135 $(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \
136 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \
137 $(cmd_dtb_check)
138
139 $(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
140 $(call if_changed_dep,dtc)
141
142 $(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
143 $(call if_changed_dep,dtc)
144
145 # targets
146 # ---------------------------------------------------------------------------
147
148 targets += $(always-y)
149
150 # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
151 # %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
152 targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
153 $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)