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