hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/scripts/Makefile.lib
....@@ -4,6 +4,18 @@
44 ccflags-y += $(EXTRA_CFLAGS)
55 cppflags-y += $(EXTRA_CPPFLAGS)
66 ldflags-y += $(EXTRA_LDFLAGS)
7
+ifneq ($(always),)
8
+$(warning 'always' is deprecated. Please use 'always-y' instead)
9
+always-y += $(always)
10
+endif
11
+ifneq ($(hostprogs-y),)
12
+$(warning 'hostprogs-y' is deprecated. Please use 'hostprogs' instead)
13
+hostprogs += $(hostprogs-y)
14
+endif
15
+ifneq ($(hostprogs-m),)
16
+$(warning 'hostprogs-m' is deprecated. Please use 'hostprogs' instead)
17
+hostprogs += $(hostprogs-m)
18
+endif
719
820 # flags that take effect in current and sub directories
921 KBUILD_AFLAGS += $(subdir-asflags-y)
....@@ -20,84 +32,121 @@
2032 # Filter out objects already built-in
2133 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
2234
23
-# Determine modorder.
24
-# Unfortunately, we don't have information about ordering between -y
25
-# and -m subdirs. Just put -y's first.
26
-modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
27
-
28
-# Handle objects in subdirs
29
-# ---------------------------------------------------------------------------
30
-# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a
31
-# and add the directory to the list of dirs to descend into: $(subdir-y)
32
-# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
33
-# and add the directory to the list of dirs to descend into: $(subdir-m)
34
-__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
35
-subdir-y += $(__subdir-y)
36
-__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
37
-subdir-m += $(__subdir-m)
38
-obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
39
-obj-m := $(filter-out %/, $(obj-m))
40
-
4135 # Subdirectories we need to descend into
42
-subdir-ym := $(sort $(subdir-y) $(subdir-m))
36
+subdir-ym := $(sort $(subdir-y) $(subdir-m) \
37
+ $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
4338
44
-# if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object
45
-multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
46
-multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
39
+# Handle objects in subdirs:
40
+# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
41
+# foo/modules.order
42
+# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
43
+#
44
+# Generate modules.order to determine modorder. Unfortunately, we don't have
45
+# information about ordering between -y and -m subdirs. Just put -y's first.
46
+
47
+ifdef need-modorder
48
+obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
49
+else
50
+obj-m := $(filter-out %/, $(obj-m))
51
+endif
52
+
53
+ifdef need-builtin
54
+obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
55
+else
56
+obj-y := $(filter-out %/, $(obj-y))
57
+endif
58
+
59
+# Expand $(foo-objs) $(foo-y) by calling $(call suffix-search,foo.o,-objs -y)
60
+suffix-search = $(foreach s,$(2),$($(1:.o=$s)))
61
+# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
62
+# Do this recursively to find nested composite objects.
63
+# foo-y may contain foo.o bar.o . For backwards compatibility, don't treat this
64
+# foo.o as a nested object
65
+multi-search = $(sort $(foreach m,$(1),$(if $(strip $(call suffix-search,$(m),$(2) -)),\
66
+ $(if $(filter $(m),$(strip $(call suffix-search,$(m),$(2) -))),,\
67
+ $(m) $(call multi-search,$(call suffix-search,$(m),$(2)),$(2))))))
68
+multi-used-y := $(call multi-search,$(obj-y),-objs -y)
69
+multi-used-m := $(call multi-search,$(obj-m),-objs -y -m)
4770 multi-used := $(multi-used-y) $(multi-used-m)
48
-single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
49
-
50
-# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
51
-# tell kbuild to descend
52
-subdir-obj-y := $(filter %/built-in.a, $(obj-y))
5371
5472 # Replace multi-part objects by their individual parts,
5573 # including built-in.a from subdirectories
56
-real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
57
-real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
74
+# Recursively search for real files. For backwards compatibility,
75
+# foo-y may contain foo.o bar.o . foo.o in this context is a real object, and
76
+# shouldn't be recursed into.
77
+real-search = $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)), \
78
+ $(filter $(m),$(call suffix-search,$(m),$(2))) $(call real-search,$(filter-out $(m),$(call suffix-search,$(m),$(2))),$(2)),\
79
+ $(m)))
80
+real-obj-y := $(call real-search, $(obj-y),-objs -y)
81
+real-obj-m := $(call real-search, $(obj-m),-objs -y -m)
82
+
83
+always-y += $(always-m)
84
+
85
+# hostprogs-always-y += foo
86
+# ... is a shorthand for
87
+# hostprogs += foo
88
+# always-y += foo
89
+hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
90
+always-y += $(hostprogs-always-y) $(hostprogs-always-m)
91
+
92
+# userprogs-always-y is likewise.
93
+userprogs += $(userprogs-always-y) $(userprogs-always-m)
94
+always-y += $(userprogs-always-y) $(userprogs-always-m)
5895
5996 # DTB
6097 # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
6198 extra-y += $(dtb-y)
6299 extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
63100
101
+ifneq ($(CHECK_DTBS),)
102
+extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
103
+extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
104
+endif
105
+
64106 # Add subdir path
65107
66108 extra-y := $(addprefix $(obj)/,$(extra-y))
67
-always := $(addprefix $(obj)/,$(always))
109
+always-y := $(addprefix $(obj)/,$(always-y))
68110 targets := $(addprefix $(obj)/,$(targets))
69
-modorder := $(addprefix $(obj)/,$(modorder))
70111 obj-m := $(addprefix $(obj)/,$(obj-m))
71112 lib-y := $(addprefix $(obj)/,$(lib-y))
72
-subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
73113 real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
74114 real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
75
-single-used-m := $(addprefix $(obj)/,$(single-used-m))
76115 multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
77116 subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
78117
79118 # Finds the multi-part object the current object will be linked into.
80
-# If the object belongs to two or more multi-part objects, all of them are
81
-# concatenated with a colon separator.
82
-modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
83
- $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
119
+# If the object belongs to two or more multi-part objects, list them all.
120
+modname-multi = $(sort $(foreach m,$(multi-used),\
121
+ $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
84122
85
-modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
123
+__modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
124
+
125
+modname = $(subst $(space),:,$(__modname))
126
+modfile = $(addprefix $(obj)/,$(__modname))
127
+
128
+# target with $(obj)/ and its suffix stripped
129
+target-stem = $(basename $(patsubst $(obj)/%,%,$@))
86130
87131 # These flags are needed for modversions and compiling, so we define them here
88132 # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
89133 # end up in (or would, if it gets compiled in)
90
-name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
134
+name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
135
+name-fix = $(call stringify,$(call name-fix-token,$1))
91136 basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
92
-modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
137
+modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
138
+ -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
139
+modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
93140
94
-orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
95
- $(ccflags-y) $(CFLAGS_$(basetarget).o)
96
-_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
97
-orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
98
- $(asflags-y) $(AFLAGS_$(basetarget).o)
99
-_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
100
-_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
141
+_c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
142
+ $(filter-out $(ccflags-remove-y), \
143
+ $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
144
+ $(CFLAGS_$(target-stem).o))
145
+_a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
146
+ $(filter-out $(asflags-remove-y), \
147
+ $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
148
+ $(AFLAGS_$(target-stem).o))
149
+_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
101150
102151 #
103152 # Enable gcov profiling flags for a file, directory or for all files depending
....@@ -115,9 +164,11 @@
115164 # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
116165 #
117166 ifeq ($(CONFIG_KASAN),y)
167
+ifneq ($(CONFIG_KASAN_HW_TAGS),y)
118168 _c_flags += $(if $(patsubst n%,, \
119169 $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
120170 $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
171
+endif
121172 endif
122173
123174 ifeq ($(CONFIG_UBSAN),y)
....@@ -132,43 +183,70 @@
132183 $(CFLAGS_KCOV))
133184 endif
134185
135
-# If building the kernel in a separate objtree expand all occurrences
136
-# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
137
-
138
-ifeq ($(KBUILD_SRC),)
139
-__c_flags = $(_c_flags)
140
-__a_flags = $(_a_flags)
141
-__cpp_flags = $(_cpp_flags)
142
-else
143
-
144
-# -I$(obj) locates generated .h files
145
-# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
146
-# and locates generated .h files
147
-# FIXME: Replace both with specific CFLAGS* statements in the makefiles
148
-__c_flags = $(if $(obj),$(call addtree,-I$(src)) -I$(obj)) \
149
- $(call flags,_c_flags)
150
-__a_flags = $(call flags,_a_flags)
151
-__cpp_flags = $(call flags,_cpp_flags)
186
+#
187
+# Enable KCSAN flags except some files or directories we don't want to check
188
+# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
189
+#
190
+ifeq ($(CONFIG_KCSAN),y)
191
+_c_flags += $(if $(patsubst n%,, \
192
+ $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
193
+ $(CFLAGS_KCSAN))
152194 endif
153195
154
-c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
196
+# $(srctree)/$(src) for including checkin headers from generated source files
197
+# $(objtree)/$(obj) for including generated headers from checkin source files
198
+ifeq ($(KBUILD_EXTMOD),)
199
+ifdef building_out_of_srctree
200
+_c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
201
+_a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
202
+_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
203
+endif
204
+endif
205
+
206
+part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
207
+quiet_modtag = $(if $(part-of-module),[M], )
208
+
209
+modkern_cflags = \
210
+ $(if $(part-of-module), \
211
+ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
212
+ $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
213
+
214
+modkern_aflags = $(if $(part-of-module), \
215
+ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \
216
+ $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
217
+
218
+c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
155219 -include $(srctree)/include/linux/compiler_types.h \
156
- $(__c_flags) $(modkern_cflags) \
220
+ $(_c_flags) $(modkern_cflags) \
157221 $(basename_flags) $(modname_flags)
158222
159
-a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
160
- $(__a_flags) $(modkern_aflags)
223
+a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
224
+ $(_a_flags) $(modkern_aflags)
161225
162
-cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
163
- $(__cpp_flags)
226
+cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
227
+ $(_cpp_flags)
164228
165229 ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
166230
167231 DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
168232
169
-dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
233
+dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
170234 $(addprefix -I,$(DTC_INCLUDE)) \
171235 -undef -D__DTS__
236
+
237
+# Objtool arguments are also needed for modfinal with LTO, so we define
238
+# then here to avoid duplication.
239
+objtool_args = \
240
+ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
241
+ $(if $(part-of-module), --module,) \
242
+ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
243
+ $(if $(or $(CONFIG_GCOV_KERNEL),$(CONFIG_LTO_CLANG)), \
244
+ --no-unreachable,) \
245
+ $(if $(CONFIG_RETPOLINE), --retpoline,) \
246
+ $(if $(CONFIG_RETHUNK), --rethunk,) \
247
+ $(if $(CONFIG_X86_SMAP), --uaccess,) \
248
+ $(if $(CONFIG_SLS), --sls,) \
249
+ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount,)
172250
173251 # Useful for describing the dependency of composite objects
174252 # Usage:
....@@ -179,27 +257,8 @@
179257 $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
180258 endef
181259
182
-# LEX
183
-# ---------------------------------------------------------------------------
184
-quiet_cmd_flex = LEX $@
185
- cmd_flex = $(LEX) -o$@ -L $<
186
-
187
-$(obj)/%.lex.c: $(src)/%.l FORCE
188
- $(call if_changed,flex)
189
-
190
-# YACC
191
-# ---------------------------------------------------------------------------
192
-quiet_cmd_bison = YACC $@
193
- cmd_bison = $(YACC) -o$@ -t -l $<
194
-
195
-$(obj)/%.tab.c: $(src)/%.y FORCE
196
- $(call if_changed,bison)
197
-
198
-quiet_cmd_bison_h = YACC $@
199
- cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $<
200
-
201
-$(obj)/%.tab.h: $(src)/%.y FORCE
202
- $(call if_changed,bison_h)
260
+quiet_cmd_copy = COPY $@
261
+ cmd_copy = cp $< $@
203262
204263 # Shipped files
205264 # ===========================================================================
....@@ -225,7 +284,13 @@
225284 # ---------------------------------------------------------------------------
226285
227286 quiet_cmd_ld = LD $@
228
-cmd_ld = $(LD) $(ld_flags) $(filter-out FORCE,$^) -o $@
287
+ cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
288
+
289
+# Archive
290
+# ---------------------------------------------------------------------------
291
+
292
+quiet_cmd_ar = AR $@
293
+ cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
229294
230295 # Objcopy
231296 # ---------------------------------------------------------------------------
....@@ -237,12 +302,22 @@
237302 # ---------------------------------------------------------------------------
238303
239304 quiet_cmd_gzip = GZIP $@
240
-cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
241
- (rm -f $@ ; false)
305
+ cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
242306
243307 # DTC
244308 # ---------------------------------------------------------------------------
309
+ifeq ("$(origin DTC)", "command line")
310
+PHONY += $(DTC)
311
+dtc-option = $(call try-run, $(DTC) $1 -v,$1)
312
+else
313
+# Just add the flag. DTC is compiled later as a prerequisite, so there's no dtc
314
+# to test the flag against. This is okay because we're not testing flags which
315
+# aren't supported by in-kernel dtc to begin with.
316
+dtc-option = $1
317
+endif
318
+
245319 DTC ?= $(objtree)/scripts/dtc/dtc
320
+DTC_FLAGS += $(call dtc-option,-Wno-interrupt_provider)
246321
247322 # Generation of symbols for Android
248323 ifeq ($(CONFIG_DTC_SYMBOLS),y)
....@@ -258,21 +333,21 @@
258333 endif
259334
260335 # Disable noisy checks by default
261
-ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
262
-DTC_FLAGS += -Wno-unit_address_vs_reg \
263
- -Wno-unit_address_format \
264
- -Wno-avoid_unnecessary_addr_size \
265
- -Wno-alias_paths \
266
- -Wno-graph_child_address \
267
- -Wno-graph_port \
268
- -Wno-simple_bus_reg \
269
- -Wno-unique_unit_address \
270
- -Wno-pci_device_reg
336
+ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
337
+DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg) \
338
+ $(call dtc-option,-Wno-unit_address_format) \
339
+ $(call dtc-option,-Wno-avoid_unnecessary_addr_size) \
340
+ $(call dtc-option,-Wno-alias_paths) \
341
+ $(call dtc-option,-Wno-graph_child_address) \
342
+ $(call dtc-option,-Wno-simple_bus_reg) \
343
+ $(call dtc-option,-Wno-unique_unit_address) \
344
+ $(call dtc-option,-Wno-pci_device_reg)
271345 endif
272346
273
-ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
274
-DTC_FLAGS += -Wnode_name_chars_strict \
275
- -Wproperty_name_chars_strict
347
+ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
348
+DTC_FLAGS += $(call dtc-option,-Wnode_name_chars_strict) \
349
+ $(call dtc-option,-Wproperty_name_chars_strict) \
350
+ $(call dtc-option,-Winterrupt_provider)
276351 endif
277352
278353 DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
....@@ -280,7 +355,7 @@
280355 # Generate an assembly file to wrap the output of the device tree compiler
281356 quiet_cmd_dt_S_dtb= DTB $@
282357 cmd_dt_S_dtb= \
283
-( \
358
+{ \
284359 echo '\#include <asm-generic/vmlinux.lds.h>'; \
285360 echo '.section .dtb.init.rodata,"a"'; \
286361 echo '.balign STRUCT_ALIGNMENT'; \
....@@ -290,21 +365,36 @@
290365 echo '__dtb_$(subst -,_,$(*F))_end:'; \
291366 echo '.global __dtb_$(subst -,_,$(*F))_end'; \
292367 echo '.balign STRUCT_ALIGNMENT'; \
293
-) > $@
368
+} > $@
294369
295370 $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
296371 $(call if_changed,dt_S_dtb)
297372
298373 quiet_cmd_dtc = DTC $@
299
-cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
300
- $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
301
- $(DTC) -O dtb -o $@ -b 0 \
374
+cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
375
+ $(DTC) -O $(patsubst .%,%,$(suffix $@)) -o $@ -b 0 \
302376 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
303377 -d $(depfile).dtc.tmp $(dtc-tmp) ; \
304378 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
305379
306380 $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
307381 $(call if_changed_dep,dtc)
382
+
383
+DT_CHECKER ?= dt-validate
384
+DT_BINDING_DIR := Documentation/devicetree/bindings
385
+# DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
386
+DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
387
+
388
+quiet_cmd_dtb_check = CHECK $@
389
+ cmd_dtb_check = $(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
390
+
391
+define rule_dtc
392
+ $(call cmd_and_fixdep,dtc)
393
+ $(call cmd,dtb_check)
394
+endef
395
+
396
+$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
397
+ $(call if_changed_rule,dtc,yaml)
308398
309399 dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
310400
....@@ -315,7 +405,7 @@
315405 # append the size as a 32-bit littleendian number as gzip does.
316406 size_append = printf $(shell \
317407 dec_size=0; \
318
-for F in $1; do \
408
+for F in $(real-prereqs); do \
319409 fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
320410 dec_size=$$(expr $$dec_size + $$fsize); \
321411 done; \
....@@ -329,33 +419,26 @@
329419 )
330420
331421 quiet_cmd_bzip2 = BZIP2 $@
332
-cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
333
- bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
334
- (rm -f $@ ; false)
422
+ cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
335423
336424 # Lzma
337425 # ---------------------------------------------------------------------------
338426
339427 quiet_cmd_lzma = LZMA $@
340
-cmd_lzma = (cat $(filter-out FORCE,$^) | \
341
- lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
342
- (rm -f $@ ; false)
428
+ cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
343429
344430 quiet_cmd_lzo = LZO $@
345
-cmd_lzo = (cat $(filter-out FORCE,$^) | \
346
- lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
347
- (rm -f $@ ; false)
431
+ cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
348432
349433 quiet_cmd_lz4 = LZ4 $@
350
-cmd_lz4 = (cat $(filter-out FORCE,$^) | \
351
- lz4 -l -12 --favor-decSpeed stdin stdout && \
352
- $(call size_append, $(filter-out FORCE,$^))) > $@ || \
353
- (rm -f $@ ; false)
434
+ cmd_lz4 = { cat $(real-prereqs) | \
435
+ $(LZ4) -l -12 --favor-decSpeed stdin stdout; \
436
+ $(size_append); } > $@
354437
355438 quiet_cmd_lz4c = LZ4C $@
356
-cmd_lz4c = (cat $(filter-out FORCE,$^) | \
357
- lz4c -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
358
- (rm -f $@ ; false)
439
+ cmd_lz4c = { cat $(real-prereqs) | \
440
+ $(LZ4) -12 --favor-decSpeed stdin stdout; \
441
+ $(size_append); } > $@
359442
360443 # U-Boot mkimage
361444 # ---------------------------------------------------------------------------
....@@ -371,15 +454,13 @@
371454 UIMAGE_LOADADDR ?= arch_must_set_this
372455 UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
373456 UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
374
-UIMAGE_IN ?= $<
375
-UIMAGE_OUT ?= $@
376457
377
-quiet_cmd_uimage = UIMAGE $(UIMAGE_OUT)
378
- cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
458
+quiet_cmd_uimage = UIMAGE $@
459
+ cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
379460 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
380461 -T $(UIMAGE_TYPE) \
381462 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
382
- -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
463
+ -n $(UIMAGE_NAME) -d $< $@
383464
384465 # XZ
385466 # ---------------------------------------------------------------------------
....@@ -399,15 +480,33 @@
399480 # big dictionary would increase the memory usage too much in the multi-call
400481 # decompression mode. A BCJ filter isn't used either.
401482 quiet_cmd_xzkern = XZKERN $@
402
-cmd_xzkern = (cat $(filter-out FORCE,$^) | \
403
- sh $(srctree)/scripts/xz_wrap.sh && \
404
- $(call size_append, $(filter-out FORCE,$^))) > $@ || \
405
- (rm -f $@ ; false)
483
+ cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
484
+ $(size_append); } > $@
406485
407486 quiet_cmd_xzmisc = XZMISC $@
408
-cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
409
- xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
410
- (rm -f $@ ; false)
487
+ cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
488
+
489
+# ZSTD
490
+# ---------------------------------------------------------------------------
491
+# Appends the uncompressed size of the data using size_append. The .zst
492
+# format has the size information available at the beginning of the file too,
493
+# but it's in a more complex format and it's good to avoid changing the part
494
+# of the boot code that reads the uncompressed size.
495
+#
496
+# Note that the bytes added by size_append will make the zstd tool think that
497
+# the file is corrupt. This is expected.
498
+#
499
+# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
500
+# 128 MB. zstd22 is used for kernel compression because it is decompressed in a
501
+# single pass, so zstd doesn't need to allocate a window buffer. When streaming
502
+# decompression is used, like initramfs decompression, zstd22 should likely not
503
+# be used because it would require zstd to allocate a 128 MB buffer.
504
+
505
+quiet_cmd_zstd = ZSTD $@
506
+ cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
507
+
508
+quiet_cmd_zstd22 = ZSTD22 $@
509
+ cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
411510
412511 # ASM offsets
413512 # ---------------------------------------------------------------------------
....@@ -426,7 +525,6 @@
426525 # Use filechk to avoid rebuilds when a header changes, but the resulting file
427526 # does not
428527 define filechk_offsets
429
- (set -e; \
430528 echo "#ifndef $2"; \
431529 echo "#define $2"; \
432530 echo "/*"; \
....@@ -437,5 +535,5 @@
437535 echo ""; \
438536 sed -ne $(sed-offsets) < $<; \
439537 echo ""; \
440
- echo "#endif" )
538
+ echo "#endif"
441539 endef