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