| 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | # Finds the multi-part object the current object will be linked into. |
| 4 | # If the object belongs to two or more multi-part objects, list them all. |
| 5 | modname-multi = $(sort $(foreach m,$(multi-obj-ym),\ |
| 6 | $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=)))) |
| 7 | |
| 8 | __modname = $(or $(modname-multi),$(basetarget)) |
| 9 | |
| 10 | modname = $(subst $(space),:,$(__modname)) |
| 11 | modfile = $(addprefix $(obj)/,$(__modname)) |
| 12 | |
| 13 | # target with $(obj)/ and its suffix stripped |
| 14 | target-stem = $(basename $(patsubst $(obj)/%,%,$@)) |
| 15 | |
| 16 | # These flags are needed for modversions and compiling, so we define them here |
| 17 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will |
| 18 | # end up in (or would, if it gets compiled in) |
| 19 | name-fix-token = $(subst $(comma),_,$(subst -,_,$1)) |
| 20 | name-fix = $(call stringify,$(call name-fix-token,$1)) |
| 21 | basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) |
| 22 | modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \ |
| 23 | -D__KBUILD_MODNAME=$(call name-fix-token,$(modname)) |
| 24 | modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile)) |
| 25 | |
| 26 | _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \ |
| 27 | $(filter-out $(ccflags-remove-y), \ |
| 28 | $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \ |
| 29 | $(CFLAGS_$(target-stem).o)) |
| 30 | _rust_flags = $(filter-out $(RUSTFLAGS_REMOVE_$(target-stem).o), \ |
| 31 | $(filter-out $(rustflags-remove-y), \ |
| 32 | $(KBUILD_RUSTFLAGS) $(rustflags-y)) \ |
| 33 | $(RUSTFLAGS_$(target-stem).o)) |
| 34 | _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \ |
| 35 | $(filter-out $(asflags-remove-y), \ |
| 36 | $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \ |
| 37 | $(AFLAGS_$(target-stem).o)) |
| 38 | _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) |
| 39 | |
| 40 | # |
| 41 | # Enable gcov profiling flags for a file, directory or for all files depending |
| 42 | # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL |
| 43 | # (in this order) |
| 44 | # |
| 45 | ifeq ($(CONFIG_GCOV_KERNEL),y) |
| 46 | _c_flags += $(if $(patsubst n%,, \ |
| 47 | $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(if $(is-kernel-object),$(CONFIG_GCOV_PROFILE_ALL))), \ |
| 48 | $(CFLAGS_GCOV)) |
| 49 | endif |
| 50 | |
| 51 | # |
| 52 | # Enable address sanitizer flags for kernel except some files or directories |
| 53 | # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) |
| 54 | # |
| 55 | ifeq ($(CONFIG_KASAN),y) |
| 56 | ifneq ($(CONFIG_KASAN_HW_TAGS),y) |
| 57 | _c_flags += $(if $(patsubst n%,, \ |
| 58 | $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ |
| 59 | $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) |
| 60 | _rust_flags += $(if $(patsubst n%,, \ |
| 61 | $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ |
| 62 | $(RUSTFLAGS_KASAN)) |
| 63 | endif |
| 64 | endif |
| 65 | |
| 66 | ifeq ($(CONFIG_KMSAN),y) |
| 67 | _c_flags += $(if $(patsubst n%,, \ |
| 68 | $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)$(is-kernel-object)), \ |
| 69 | $(CFLAGS_KMSAN)) |
| 70 | _c_flags += $(if $(patsubst n%,, \ |
| 71 | $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)$(is-kernel-object)), \ |
| 72 | , -mllvm -msan-disable-checks=1) |
| 73 | endif |
| 74 | |
| 75 | ifeq ($(CONFIG_UBSAN),y) |
| 76 | _c_flags += $(if $(patsubst n%,, \ |
| 77 | $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(is-kernel-object)), \ |
| 78 | $(CFLAGS_UBSAN)) |
| 79 | _c_flags += $(if $(patsubst n%,, \ |
| 80 | $(UBSAN_INTEGER_WRAP_$(target-stem).o)$(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_INTEGER_WRAP)$(UBSAN_SANITIZE)$(is-kernel-object)), \ |
| 81 | $(CFLAGS_UBSAN_INTEGER_WRAP)) |
| 82 | endif |
| 83 | |
| 84 | ifeq ($(CONFIG_KCOV),y) |
| 85 | _c_flags += $(if $(patsubst n%,, \ |
| 86 | $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \ |
| 87 | $(CFLAGS_KCOV)) |
| 88 | _rust_flags += $(if $(patsubst n%,, \ |
| 89 | $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \ |
| 90 | $(RUSTFLAGS_KCOV)) |
| 91 | endif |
| 92 | |
| 93 | # |
| 94 | # Enable KCSAN flags except some files or directories we don't want to check |
| 95 | # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE) |
| 96 | # |
| 97 | ifeq ($(CONFIG_KCSAN),y) |
| 98 | _c_flags += $(if $(patsubst n%,, \ |
| 99 | $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)$(is-kernel-object)), \ |
| 100 | $(CFLAGS_KCSAN)) |
| 101 | # Some uninstrumented files provide implied barriers required to avoid false |
| 102 | # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only. |
| 103 | _c_flags += $(if $(patsubst n%,, \ |
| 104 | $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \ |
| 105 | -D__KCSAN_INSTRUMENT_BARRIERS__) |
| 106 | endif |
| 107 | |
| 108 | # |
| 109 | # Enable context analysis flags only where explicitly opted in. |
| 110 | # (depends on variables CONTEXT_ANALYSIS_obj.o, CONTEXT_ANALYSIS) |
| 111 | # |
| 112 | ifeq ($(CONFIG_WARN_CONTEXT_ANALYSIS),y) |
| 113 | _c_flags += $(if $(patsubst n%,, \ |
| 114 | $(CONTEXT_ANALYSIS_$(target-stem).o)$(CONTEXT_ANALYSIS)$(if $(is-kernel-object),$(CONFIG_WARN_CONTEXT_ANALYSIS_ALL))), \ |
| 115 | $(CFLAGS_CONTEXT_ANALYSIS)) |
| 116 | endif |
| 117 | |
| 118 | # |
| 119 | # Enable AutoFDO build flags except some files or directories we don't want to |
| 120 | # enable (depends on variables AUTOFDO_PROFILE_obj.o and AUTOFDO_PROFILE). |
| 121 | # |
| 122 | ifeq ($(CONFIG_AUTOFDO_CLANG),y) |
| 123 | _c_flags += $(if $(patsubst n%,, \ |
| 124 | $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object)), \ |
| 125 | $(CFLAGS_AUTOFDO_CLANG)) |
| 126 | _rust_flags += $(if $(patsubst n%,, \ |
| 127 | $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object)), \ |
| 128 | $(RUSTFLAGS_AUTOFDO_CLANG)) |
| 129 | endif |
| 130 | |
| 131 | # |
| 132 | # Enable Propeller build flags except some files or directories we don't want to |
| 133 | # enable (depends on variables AUTOFDO_PROPELLER_obj.o and PROPELLER_PROFILE). |
| 134 | # |
| 135 | ifdef CONFIG_PROPELLER_CLANG |
| 136 | _c_flags += $(if $(patsubst n%,, \ |
| 137 | $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(PROPELLER_PROFILE))$(is-kernel-object), \ |
| 138 | $(CFLAGS_PROPELLER_CLANG)) |
| 139 | endif |
| 140 | |
| 141 | # $(src) for including checkin headers from generated source files |
| 142 | # $(obj) for including generated headers from checkin source files |
| 143 | ifdef building_out_of_srctree |
| 144 | _c_flags += $(addprefix -I, $(src) $(obj)) |
| 145 | _a_flags += $(addprefix -I, $(src) $(obj)) |
| 146 | _cpp_flags += $(addprefix -I, $(src) $(obj)) |
| 147 | endif |
| 148 | |
| 149 | # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules |
| 150 | is-kernel-object = $(or $(part-of-builtin),$(part-of-module)) |
| 151 | |
| 152 | part-of-builtin = $(if $(filter $(basename $@).o, $(real-obj-y) $(lib-y)),y) |
| 153 | part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) |
| 154 | quiet_modtag = $(if $(part-of-module),[M], ) |
| 155 | |
| 156 | modkern_cflags = \ |
| 157 | $(if $(part-of-module), \ |
| 158 | $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ |
| 159 | $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) |
| 160 | |
| 161 | modkern_rustflags = \ |
| 162 | $(if $(part-of-module), \ |
| 163 | $(KBUILD_RUSTFLAGS_MODULE) $(RUSTFLAGS_MODULE), \ |
| 164 | $(KBUILD_RUSTFLAGS_KERNEL) $(RUSTFLAGS_KERNEL)) |
| 165 | |
| 166 | modkern_aflags = $(if $(part-of-module), \ |
| 167 | $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ |
| 168 | $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) $(modfile_flags)) |
| 169 | |
| 170 | c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ |
| 171 | -include $(srctree)/include/linux/compiler_types.h \ |
| 172 | $(_c_flags) $(modkern_cflags) \ |
| 173 | $(basename_flags) $(modname_flags) |
| 174 | |
| 175 | rust_flags = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg |
| 176 | |
| 177 | a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ |
| 178 | $(_a_flags) $(modkern_aflags) $(modname_flags) |
| 179 | |
| 180 | cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ |
| 181 | $(_cpp_flags) |
| 182 | |
| 183 | ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) |
| 184 | |
| 185 | ifdef CONFIG_OBJTOOL |
| 186 | |
| 187 | objtool := $(objtree)/tools/objtool/objtool |
| 188 | |
| 189 | objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label |
| 190 | objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr |
| 191 | objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) += --hacks=skylake |
| 192 | objtool-args-$(CONFIG_X86_KERNEL_IBT) += --ibt |
| 193 | objtool-args-$(CONFIG_CALL_PADDING) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES) |
| 194 | ifdef CONFIG_CALL_PADDING |
| 195 | objtool-args-$(CONFIG_CFI) += --cfi |
| 196 | objtool-args-$(CONFIG_FINEIBT) += --fineibt |
| 197 | endif |
| 198 | objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) += --mcount |
| 199 | ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL |
| 200 | objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT) += --mnop |
| 201 | endif |
| 202 | objtool-args-$(CONFIG_UNWINDER_ORC) += --orc |
| 203 | objtool-args-$(CONFIG_MITIGATION_RETPOLINE) += --retpoline |
| 204 | objtool-args-$(CONFIG_MITIGATION_RETHUNK) += --rethunk |
| 205 | objtool-args-$(CONFIG_MITIGATION_SLS) += --sls |
| 206 | objtool-args-$(CONFIG_STACK_VALIDATION) += --stackval |
| 207 | objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call |
| 208 | objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess |
| 209 | objtool-args-$(or $(CONFIG_GCOV_KERNEL),$(CONFIG_KCOV)) += --no-unreachable |
| 210 | objtool-args-$(CONFIG_OBJTOOL_WERROR) += --werror |
| 211 | |
| 212 | objtool-args = $(objtool-args-y) \ |
| 213 | $(if $(delay-objtool), --link) \ |
| 214 | $(if $(part-of-module), --module) |
| 215 | |
| 216 | delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT),$(CONFIG_KLP_BUILD)) |
| 217 | |
| 218 | cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@) |
| 219 | cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) |
| 220 | |
| 221 | objtool-enabled := y |
| 222 | |
| 223 | endif # CONFIG_OBJTOOL |
| 224 | |
| 225 | # Useful for describing the dependency of composite objects |
| 226 | # Usage: |
| 227 | # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) |
| 228 | define multi_depend |
| 229 | $(foreach m, $1, \ |
| 230 | $(eval $m: \ |
| 231 | $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3)))) |
| 232 | endef |
| 233 | |
| 234 | # Remove ".." and "." from a path, without using "realpath" |
| 235 | # Usage: |
| 236 | # $(call normalize_path,path/to/../file) |
| 237 | define normalize_path |
| 238 | $(strip $(eval elements :=) \ |
| 239 | $(foreach elem,$(subst /, ,$1), \ |
| 240 | $(if $(filter-out .,$(elem)), \ |
| 241 | $(if $(filter ..,$(elem)), \ |
| 242 | $(eval elements := $(wordlist 2,$(words $(elements)),x $(elements))), \ |
| 243 | $(eval elements := $(elements) $(elem))))) \ |
| 244 | $(subst $(space),/,$(elements))) |
| 245 | endef |
| 246 | |
| 247 | # Build commands |
| 248 | # =========================================================================== |
| 249 | # These are shared by some Makefile.* files. |
| 250 | |
| 251 | ifdef CONFIG_LTO_CLANG |
| 252 | # Run $(LD) here to convert LLVM IR to ELF in the following cases: |
| 253 | # - when this object needs objtool processing, as objtool cannot process LLVM IR |
| 254 | # - when this is a single-object module, as modpost cannot process LLVM IR |
| 255 | cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) |
| 256 | endif |
| 257 | |
| 258 | ifdef CONFIG_LTO_CLANG_THIN_DIST |
| 259 | # Save the _c_flags, sliently. |
| 260 | quiet_cmd_save_c_flags = |
| 261 | saved_c_flags = $(_c_flags) $(modkern_cflags) |
| 262 | cmd_save_c_flags = printf '\n%s\n' 'saved_c_flags_$@ := $(call escsq,$(saved_c_flags))' >> $(dot-target).cmd |
| 263 | endif |
| 264 | |
| 265 | quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ |
| 266 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ |
| 267 | $(cmd_ld_single) \ |
| 268 | $(cmd_objtool) |
| 269 | |
| 270 | define rule_cc_o_c |
| 271 | $(call cmd_and_fixdep,cc_o_c) |
| 272 | $(call cmd,save_c_flags) |
| 273 | $(call cmd,checksrc) |
| 274 | $(call cmd,checkdoc) |
| 275 | $(call cmd,gen_objtooldep) |
| 276 | $(call cmd,gen_symversions_c) |
| 277 | $(call cmd,record_mcount) |
| 278 | $(call cmd,warn_shared_object) |
| 279 | endef |
| 280 | |
| 281 | quiet_cmd_as_o_S = AS $(quiet_modtag) $@ |
| 282 | cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) |
| 283 | |
| 284 | define rule_as_o_S |
| 285 | $(call cmd_and_fixdep,as_o_S) |
| 286 | $(call cmd,gen_objtooldep) |
| 287 | $(call cmd,gen_symversions_S) |
| 288 | $(call cmd,warn_shared_object) |
| 289 | endef |
| 290 | |
| 291 | # Copy a file |
| 292 | # =========================================================================== |
| 293 | # 'cp' preserves permissions. If you use it to copy a file in read-only srctree, |
| 294 | # the copy would be read-only as well, leading to an error when executing the |
| 295 | # rule next time. Use 'cat' instead in order to generate a writable file. |
| 296 | quiet_cmd_copy = COPY $@ |
| 297 | cmd_copy = cat $< > $@ |
| 298 | |
| 299 | $(obj)/%: $(src)/%_shipped |
| 300 | $(call cmd,copy) |
| 301 | |
| 302 | # Touch a file |
| 303 | # =========================================================================== |
| 304 | quiet_cmd_touch = TOUCH $(call normalize_path,$@) |
| 305 | cmd_touch = touch $@ |
| 306 | |
| 307 | # Commands useful for building a boot image |
| 308 | # =========================================================================== |
| 309 | # |
| 310 | # Use as following: |
| 311 | # |
| 312 | # target: source(s) FORCE |
| 313 | # $(if_changed,ld/objcopy/gzip) |
| 314 | # |
| 315 | # and add target to 'targets' so that we know we have to |
| 316 | # read in the saved command line |
| 317 | |
| 318 | # Linking |
| 319 | # --------------------------------------------------------------------------- |
| 320 | |
| 321 | quiet_cmd_ld = LD $@ |
| 322 | cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@ |
| 323 | |
| 324 | # Archive |
| 325 | # --------------------------------------------------------------------------- |
| 326 | |
| 327 | quiet_cmd_ar = AR $@ |
| 328 | cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs) |
| 329 | |
| 330 | # Objcopy |
| 331 | # --------------------------------------------------------------------------- |
| 332 | |
| 333 | quiet_cmd_objcopy = OBJCOPY $@ |
| 334 | cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ |
| 335 | |
| 336 | # Gzip |
| 337 | # --------------------------------------------------------------------------- |
| 338 | |
| 339 | quiet_cmd_gzip = GZIP $@ |
| 340 | cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@ |
| 341 | |
| 342 | # Bzip2 |
| 343 | # --------------------------------------------------------------------------- |
| 344 | |
| 345 | # Bzip2 and LZMA do not include size in file... so we have to fake that; |
| 346 | # append the size as a 32-bit littleendian number as gzip does. |
| 347 | size_append = printf $(shell \ |
| 348 | dec_size=0; \ |
| 349 | for F in $(real-prereqs); do \ |
| 350 | fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ |
| 351 | dec_size=$$(expr $$dec_size + $$fsize); \ |
| 352 | done; \ |
| 353 | printf "%08x\n" $$dec_size | \ |
| 354 | sed 's/\(..\)/\1 /g' | { \ |
| 355 | read ch0 ch1 ch2 ch3; \ |
| 356 | for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ |
| 357 | printf '%s%03o' '\\' $$((0x$$ch)); \ |
| 358 | done; \ |
| 359 | } \ |
| 360 | ) |
| 361 | |
| 362 | quiet_cmd_file_size = GEN $@ |
| 363 | cmd_file_size = $(size_append) > $@ |
| 364 | |
| 365 | quiet_cmd_bzip2 = BZIP2 $@ |
| 366 | cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@ |
| 367 | |
| 368 | quiet_cmd_bzip2_with_size = BZIP2 $@ |
| 369 | cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@ |
| 370 | |
| 371 | # Lzma |
| 372 | # --------------------------------------------------------------------------- |
| 373 | |
| 374 | quiet_cmd_lzma = LZMA $@ |
| 375 | cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@ |
| 376 | |
| 377 | quiet_cmd_lzma_with_size = LZMA $@ |
| 378 | cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@ |
| 379 | |
| 380 | quiet_cmd_lzo = LZO $@ |
| 381 | cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@ |
| 382 | |
| 383 | quiet_cmd_lzo_with_size = LZO $@ |
| 384 | cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@ |
| 385 | |
| 386 | quiet_cmd_lz4 = LZ4 $@ |
| 387 | cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -9 - - > $@ |
| 388 | |
| 389 | quiet_cmd_lz4_with_size = LZ4 $@ |
| 390 | cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -9 - -; \ |
| 391 | $(size_append); } > $@ |
| 392 | |
| 393 | # U-Boot mkimage |
| 394 | # --------------------------------------------------------------------------- |
| 395 | |
| 396 | MKIMAGE := $(srctree)/scripts/mkuboot.sh |
| 397 | |
| 398 | # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces |
| 399 | # the number of overrides in arch makefiles |
| 400 | UIMAGE_ARCH ?= $(SRCARCH) |
| 401 | UIMAGE_COMPRESSION ?= $(or $(2),none) |
| 402 | UIMAGE_OPTS-y ?= |
| 403 | UIMAGE_TYPE ?= kernel |
| 404 | UIMAGE_LOADADDR ?= arch_must_set_this |
| 405 | UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) |
| 406 | UIMAGE_NAME ?= Linux-$(KERNELRELEASE) |
| 407 | |
| 408 | quiet_cmd_uimage = UIMAGE $@ |
| 409 | cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ |
| 410 | -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ |
| 411 | -T $(UIMAGE_TYPE) \ |
| 412 | -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ |
| 413 | -n '$(UIMAGE_NAME)' -d $< $@ |
| 414 | |
| 415 | # Flat Image Tree (FIT) |
| 416 | # This allows for packaging of a kernel and all devicetrees files, using |
| 417 | # compression. |
| 418 | # --------------------------------------------------------------------------- |
| 419 | |
| 420 | MAKE_FIT := $(srctree)/scripts/make_fit.py |
| 421 | |
| 422 | # Use this to override the compression algorithm |
| 423 | FIT_COMPRESSION ?= gzip |
| 424 | |
| 425 | quiet_cmd_fit = FIT $@ |
| 426 | cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \ |
| 427 | --name '$(UIMAGE_NAME)' $(FIT_EXTRA_ARGS) \ |
| 428 | $(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \ |
| 429 | $(if $(FIT_DECOMPOSE_DTBS),--decompose-dtbs) \ |
| 430 | --compress $(FIT_COMPRESSION) -k $< @$(word 2,$^) |
| 431 | |
| 432 | # XZ |
| 433 | # --------------------------------------------------------------------------- |
| 434 | # Use xzkern or xzkern_with_size to compress the kernel image and xzmisc to |
| 435 | # compress other things. |
| 436 | # |
| 437 | # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage |
| 438 | # of the kernel decompressor. A BCJ filter is used if it is available for |
| 439 | # the target architecture. |
| 440 | # |
| 441 | # xzkern_with_size also appends uncompressed size of the data using |
| 442 | # size_append. The .xz format has the size information available at the end |
| 443 | # of the file too, but it's in more complex format and it's good to avoid |
| 444 | # changing the part of the boot code that reads the uncompressed size. |
| 445 | # Note that the bytes added by size_append will make the xz tool think that |
| 446 | # the file is corrupt. This is expected. |
| 447 | # |
| 448 | # xzmisc doesn't use size_append, so it can be used to create normal .xz |
| 449 | # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very |
| 450 | # big dictionary would increase the memory usage too much in the multi-call |
| 451 | # decompression mode. A BCJ filter isn't used either. |
| 452 | quiet_cmd_xzkern = XZKERN $@ |
| 453 | cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@ |
| 454 | |
| 455 | quiet_cmd_xzkern_with_size = XZKERN $@ |
| 456 | cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \ |
| 457 | $(size_append); } > $@ |
| 458 | |
| 459 | quiet_cmd_xzmisc = XZMISC $@ |
| 460 | cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@ |
| 461 | |
| 462 | # ZSTD |
| 463 | # --------------------------------------------------------------------------- |
| 464 | # Appends the uncompressed size of the data using size_append. The .zst |
| 465 | # format has the size information available at the beginning of the file too, |
| 466 | # but it's in a more complex format and it's good to avoid changing the part |
| 467 | # of the boot code that reads the uncompressed size. |
| 468 | # |
| 469 | # Note that the bytes added by size_append will make the zstd tool think that |
| 470 | # the file is corrupt. This is expected. |
| 471 | # |
| 472 | # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of |
| 473 | # 128 MB. zstd22 is used for kernel compression because it is decompressed in a |
| 474 | # single pass, so zstd doesn't need to allocate a window buffer. When streaming |
| 475 | # decompression is used, like initramfs decompression, zstd22 should likely not |
| 476 | # be used because it would require zstd to allocate a 128 MB buffer. |
| 477 | |
| 478 | quiet_cmd_zstd = ZSTD $@ |
| 479 | cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@ |
| 480 | |
| 481 | quiet_cmd_zstd22 = ZSTD22 $@ |
| 482 | cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@ |
| 483 | |
| 484 | quiet_cmd_zstd22_with_size = ZSTD22 $@ |
| 485 | cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ |
| 486 | |
| 487 | # ASM offsets |
| 488 | # --------------------------------------------------------------------------- |
| 489 | |
| 490 | # Default sed regexp - multiline due to syntax constraints |
| 491 | # |
| 492 | # Use [:space:] because LLVM's integrated assembler inserts <tab> around |
| 493 | # the .ascii directive whereas GCC keeps the <space> as-is. |
| 494 | define sed-offsets |
| 495 | 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \ |
| 496 | /^->/{s:->#\(.*\):/* \1 */:; \ |
| 497 | s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ |
| 498 | s:->::; p;}' |
| 499 | endef |
| 500 | |
| 501 | # Use filechk to avoid rebuilds when a header changes, but the resulting file |
| 502 | # does not |
| 503 | define filechk_offsets |
| 504 | echo "#ifndef $2"; \ |
| 505 | echo "#define $2"; \ |
| 506 | echo "/*"; \ |
| 507 | echo " * DO NOT MODIFY."; \ |
| 508 | echo " *"; \ |
| 509 | echo " * This file was generated by Kbuild"; \ |
| 510 | echo " */"; \ |
| 511 | echo ""; \ |
| 512 | sed -ne $(sed-offsets) < $<; \ |
| 513 | echo ""; \ |
| 514 | echo "#endif" |
| 515 | endef |