Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # Backward compatibility
0003 asflags-y  += $(EXTRA_AFLAGS)
0004 ccflags-y  += $(EXTRA_CFLAGS)
0005 cppflags-y += $(EXTRA_CPPFLAGS)
0006 ldflags-y  += $(EXTRA_LDFLAGS)
0007 
0008 # flags that take effect in current and sub directories
0009 KBUILD_AFLAGS += $(subdir-asflags-y)
0010 KBUILD_CFLAGS += $(subdir-ccflags-y)
0011 
0012 # Figure out what we need to build from the various variables
0013 # ===========================================================================
0014 
0015 # When an object is listed to be built compiled-in and modular,
0016 # only build the compiled-in version
0017 obj-m := $(filter-out $(obj-y),$(obj-m))
0018 
0019 # Libraries are always collected in one lib file.
0020 # Filter out objects already built-in
0021 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
0022 
0023 # Subdirectories we need to descend into
0024 subdir-ym := $(sort $(subdir-y) $(subdir-m) \
0025                         $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
0026 
0027 # Handle objects in subdirs:
0028 # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
0029 #   foo/modules.order
0030 # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
0031 #
0032 # Generate modules.order to determine modorder. Unfortunately, we don't have
0033 # information about ordering between -y and -m subdirs. Just put -y's first.
0034 
0035 ifdef need-modorder
0036 obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
0037 else
0038 obj-m := $(filter-out %/, $(obj-m))
0039 endif
0040 
0041 ifdef need-builtin
0042 obj-y           := $(patsubst %/, %/built-in.a, $(obj-y))
0043 else
0044 obj-y           := $(filter-out %/, $(obj-y))
0045 endif
0046 
0047 # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
0048 suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
0049 # List composite targets that are constructed by combining other targets
0050 multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
0051 # List primitive targets that are compiled from source files
0052 real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
0053 
0054 # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
0055 multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
0056 multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
0057 multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
0058 
0059 # Replace multi-part objects by their individual parts,
0060 # including built-in.a from subdirectories
0061 real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
0062 real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
0063 
0064 always-y += $(always-m)
0065 
0066 # hostprogs-always-y += foo
0067 # ... is a shorthand for
0068 # hostprogs += foo
0069 # always-y  += foo
0070 hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
0071 always-y += $(hostprogs-always-y) $(hostprogs-always-m)
0072 
0073 # userprogs-always-y is likewise.
0074 userprogs += $(userprogs-always-y) $(userprogs-always-m)
0075 always-y += $(userprogs-always-y) $(userprogs-always-m)
0076 
0077 # DTB
0078 # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
0079 dtb-$(CONFIG_OF_ALL_DTBS)       += $(dtb-)
0080 
0081 # Composite DTB (i.e. DTB constructed by overlay)
0082 multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
0083 # Primitive DTB compiled from *.dts
0084 real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
0085 # Base DTB that overlay is applied onto (each first word of $(*-dtbs) expansion)
0086 base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, .dtb, -dtbs)))
0087 
0088 always-y                        += $(dtb-y)
0089 
0090 # Add subdir path
0091 
0092 extra-y         := $(addprefix $(obj)/,$(extra-y))
0093 always-y        := $(addprefix $(obj)/,$(always-y))
0094 targets         := $(addprefix $(obj)/,$(targets))
0095 obj-m           := $(addprefix $(obj)/,$(obj-m))
0096 lib-y           := $(addprefix $(obj)/,$(lib-y))
0097 real-obj-y      := $(addprefix $(obj)/,$(real-obj-y))
0098 real-obj-m      := $(addprefix $(obj)/,$(real-obj-m))
0099 multi-obj-m     := $(addprefix $(obj)/, $(multi-obj-m))
0100 multi-dtb-y     := $(addprefix $(obj)/, $(multi-dtb-y))
0101 real-dtb-y      := $(addprefix $(obj)/, $(real-dtb-y))
0102 subdir-ym       := $(addprefix $(obj)/,$(subdir-ym))
0103 
0104 # Finds the multi-part object the current object will be linked into.
0105 # If the object belongs to two or more multi-part objects, list them all.
0106 modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
0107                 $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
0108 
0109 __modname = $(or $(modname-multi),$(basetarget))
0110 
0111 modname = $(subst $(space),:,$(__modname))
0112 modfile = $(addprefix $(obj)/,$(__modname))
0113 
0114 # target with $(obj)/ and its suffix stripped
0115 target-stem = $(basename $(patsubst $(obj)/%,%,$@))
0116 
0117 # These flags are needed for modversions and compiling, so we define them here
0118 # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
0119 # end up in (or would, if it gets compiled in)
0120 name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
0121 name-fix = $(call stringify,$(call name-fix-token,$1))
0122 basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
0123 modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
0124                  -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
0125 modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
0126 
0127 _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
0128                      $(filter-out $(ccflags-remove-y), \
0129                          $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
0130                      $(CFLAGS_$(target-stem).o))
0131 _a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
0132                      $(filter-out $(asflags-remove-y), \
0133                          $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
0134                      $(AFLAGS_$(target-stem).o))
0135 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
0136 
0137 #
0138 # Enable gcov profiling flags for a file, directory or for all files depending
0139 # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
0140 # (in this order)
0141 #
0142 ifeq ($(CONFIG_GCOV_KERNEL),y)
0143 _c_flags += $(if $(patsubst n%,, \
0144                 $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
0145                 $(CFLAGS_GCOV))
0146 endif
0147 
0148 #
0149 # Enable address sanitizer flags for kernel except some files or directories
0150 # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
0151 #
0152 ifeq ($(CONFIG_KASAN),y)
0153 ifneq ($(CONFIG_KASAN_HW_TAGS),y)
0154 _c_flags += $(if $(patsubst n%,, \
0155                 $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
0156                 $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0157 endif
0158 endif
0159 
0160 ifeq ($(CONFIG_UBSAN),y)
0161 _c_flags += $(if $(patsubst n%,, \
0162                 $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
0163                 $(CFLAGS_UBSAN))
0164 endif
0165 
0166 ifeq ($(CONFIG_KCOV),y)
0167 _c_flags += $(if $(patsubst n%,, \
0168         $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
0169         $(CFLAGS_KCOV))
0170 endif
0171 
0172 #
0173 # Enable KCSAN flags except some files or directories we don't want to check
0174 # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
0175 #
0176 ifeq ($(CONFIG_KCSAN),y)
0177 _c_flags += $(if $(patsubst n%,, \
0178         $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
0179         $(CFLAGS_KCSAN))
0180 # Some uninstrumented files provide implied barriers required to avoid false
0181 # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
0182 _c_flags += $(if $(patsubst n%,, \
0183         $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
0184         -D__KCSAN_INSTRUMENT_BARRIERS__)
0185 endif
0186 
0187 # $(srctree)/$(src) for including checkin headers from generated source files
0188 # $(objtree)/$(obj) for including generated headers from checkin source files
0189 ifeq ($(KBUILD_EXTMOD),)
0190 ifdef building_out_of_srctree
0191 _c_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
0192 _a_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
0193 _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
0194 endif
0195 endif
0196 
0197 part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
0198 quiet_modtag = $(if $(part-of-module),[M],   )
0199 
0200 modkern_cflags =                                          \
0201         $(if $(part-of-module),                           \
0202                 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
0203                 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
0204 
0205 modkern_aflags = $(if $(part-of-module),                                \
0206                         $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),       \
0207                         $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
0208 
0209 c_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0210                  -include $(srctree)/include/linux/compiler_types.h       \       
0211                  $(_c_flags) $(modkern_cflags)                           \
0212                  $(basename_flags) $(modname_flags)
0213 
0214 a_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0215                  $(_a_flags) $(modkern_aflags)
0216 
0217 cpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0218                  $(_cpp_flags)
0219 
0220 ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
0221 
0222 DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
0223 
0224 dtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
0225                  $(addprefix -I,$(DTC_INCLUDE))                          \
0226                  -undef -D__DTS__
0227 
0228 ifdef CONFIG_OBJTOOL
0229 
0230 objtool := $(objtree)/tools/objtool/objtool
0231 
0232 objtool_args =                                                          \
0233         $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label)        \
0234         $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr)              \
0235         $(if $(CONFIG_X86_KERNEL_IBT), --ibt)                           \
0236         $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)             \
0237         $(if $(CONFIG_UNWINDER_ORC), --orc)                             \
0238         $(if $(CONFIG_RETPOLINE), --retpoline)                          \
0239         $(if $(CONFIG_RETHUNK), --rethunk)                              \
0240         $(if $(CONFIG_SLS), --sls)                                      \
0241         $(if $(CONFIG_STACK_VALIDATION), --stackval)                    \
0242         $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call)          \
0243         $(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess)              \
0244         $(if $(delay-objtool), --link)                                  \
0245         $(if $(part-of-module), --module)                               \
0246         $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
0247 
0248 delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
0249 
0250 cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
0251 cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
0252 
0253 endif # CONFIG_OBJTOOL
0254 
0255 # Useful for describing the dependency of composite objects
0256 # Usage:
0257 #   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
0258 define multi_depend
0259 $(foreach m, $1, \
0260         $(eval $m: \
0261         $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
0262 endef
0263 
0264 # Copy a file
0265 # ===========================================================================
0266 # 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
0267 # the copy would be read-only as well, leading to an error when executing the
0268 # rule next time. Use 'cat' instead in order to generate a writable file.
0269 quiet_cmd_copy = COPY    $@
0270       cmd_copy = cat $< > $@
0271 
0272 $(obj)/%: $(src)/%_shipped
0273         $(call cmd,copy)
0274 
0275 # Commands useful for building a boot image
0276 # ===========================================================================
0277 #
0278 #       Use as following:
0279 #
0280 #       target: source(s) FORCE
0281 #               $(if_changed,ld/objcopy/gzip)
0282 #
0283 #       and add target to 'targets' so that we know we have to
0284 #       read in the saved command line
0285 
0286 # Linking
0287 # ---------------------------------------------------------------------------
0288 
0289 quiet_cmd_ld = LD      $@
0290       cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
0291 
0292 # Archive
0293 # ---------------------------------------------------------------------------
0294 
0295 quiet_cmd_ar = AR      $@
0296       cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
0297 
0298 # Objcopy
0299 # ---------------------------------------------------------------------------
0300 
0301 quiet_cmd_objcopy = OBJCOPY $@
0302 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
0303 
0304 # Gzip
0305 # ---------------------------------------------------------------------------
0306 
0307 quiet_cmd_gzip = GZIP    $@
0308       cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
0309 
0310 # DTC
0311 # ---------------------------------------------------------------------------
0312 DTC ?= $(objtree)/scripts/dtc/dtc
0313 DTC_FLAGS += -Wno-interrupt_provider
0314 
0315 # Disable noisy checks by default
0316 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
0317 DTC_FLAGS += -Wno-unit_address_vs_reg \
0318         -Wno-avoid_unnecessary_addr_size \
0319         -Wno-alias_paths \
0320         -Wno-graph_child_address \
0321         -Wno-simple_bus_reg \
0322         -Wno-unique_unit_address
0323 endif
0324 
0325 ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
0326 DTC_FLAGS += -Wnode_name_chars_strict \
0327         -Wproperty_name_chars_strict \
0328         -Winterrupt_provider
0329 endif
0330 
0331 DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
0332 
0333 # Set -@ if the target is a base DTB that overlay is applied onto
0334 DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
0335 
0336 # Generate an assembly file to wrap the output of the device tree compiler
0337 quiet_cmd_dt_S_dtb= DTB     $@
0338 cmd_dt_S_dtb=                                           \
0339 {                                                       \
0340         echo '\#include <asm-generic/vmlinux.lds.h>';   \
0341         echo '.section .dtb.init.rodata,"a"';           \
0342         echo '.balign STRUCT_ALIGNMENT';                \
0343         echo '.global __dtb_$(subst -,_,$(*F))_begin';  \
0344         echo '__dtb_$(subst -,_,$(*F))_begin:';         \
0345         echo '.incbin "$<" ';                           \
0346         echo '__dtb_$(subst -,_,$(*F))_end:';           \
0347         echo '.global __dtb_$(subst -,_,$(*F))_end';    \
0348         echo '.balign STRUCT_ALIGNMENT';                \
0349 } > $@
0350 
0351 $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
0352         $(call if_changed,dt_S_dtb)
0353 
0354 quiet_cmd_dtc = DTC     $@
0355 cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
0356         $(DTC) -o $@ -b 0 \
0357                 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
0358                 -d $(depfile).dtc.tmp $(dtc-tmp) ; \
0359         cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
0360 
0361 quiet_cmd_fdtoverlay = DTOVL   $@
0362       cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
0363 
0364 $(multi-dtb-y): FORCE
0365         $(call if_changed,fdtoverlay)
0366 $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
0367 
0368 ifneq ($(CHECK_DTBS)$(CHECK_DT_BINDING),)
0369 DT_CHECKER ?= dt-validate
0370 DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
0371 DT_BINDING_DIR := Documentation/devicetree/bindings
0372 DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
0373 
0374 quiet_cmd_dtb_check =   CHECK   $@
0375       cmd_dtb_check =   $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true
0376 endif
0377 
0378 define rule_dtc
0379         $(call cmd_and_fixdep,dtc)
0380         $(call cmd,dtb_check)
0381 endef
0382 
0383 $(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
0384         $(call if_changed_rule,dtc)
0385 
0386 $(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
0387         $(call if_changed_dep,dtc)
0388 
0389 dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
0390 
0391 # Bzip2
0392 # ---------------------------------------------------------------------------
0393 
0394 # Bzip2 and LZMA do not include size in file... so we have to fake that;
0395 # append the size as a 32-bit littleendian number as gzip does.
0396 size_append = printf $(shell                                            \
0397 dec_size=0;                                                             \
0398 for F in $(real-prereqs); do                                    \
0399         fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);  \
0400         dec_size=$$(expr $$dec_size + $$fsize);                         \
0401 done;                                                                   \
0402 printf "%08x\n" $$dec_size |                                            \
0403         sed 's/\(..\)/\1 /g' | {                                        \
0404                 read ch0 ch1 ch2 ch3;                                   \
0405                 for ch in $$ch3 $$ch2 $$ch1 $$ch0; do                   \
0406                         printf '%s%03o' '\\' $$((0x$$ch));              \
0407                 done;                                                   \
0408         }                                                               \
0409 )
0410 
0411 quiet_cmd_file_size = GEN     $@
0412       cmd_file_size = $(size_append) > $@
0413 
0414 quiet_cmd_bzip2 = BZIP2   $@
0415       cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
0416 
0417 quiet_cmd_bzip2_with_size = BZIP2   $@
0418       cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
0419 
0420 # Lzma
0421 # ---------------------------------------------------------------------------
0422 
0423 quiet_cmd_lzma = LZMA    $@
0424       cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
0425 
0426 quiet_cmd_lzma_with_size = LZMA    $@
0427       cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
0428 
0429 quiet_cmd_lzo = LZO     $@
0430       cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
0431 
0432 quiet_cmd_lzo_with_size = LZO     $@
0433       cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
0434 
0435 quiet_cmd_lz4 = LZ4     $@
0436       cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@
0437 
0438 quiet_cmd_lz4_with_size = LZ4     $@
0439       cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
0440                   $(size_append); } > $@
0441 
0442 # U-Boot mkimage
0443 # ---------------------------------------------------------------------------
0444 
0445 MKIMAGE := $(srctree)/scripts/mkuboot.sh
0446 
0447 # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
0448 # the number of overrides in arch makefiles
0449 UIMAGE_ARCH ?= $(SRCARCH)
0450 UIMAGE_COMPRESSION ?= $(or $(2),none)
0451 UIMAGE_OPTS-y ?=
0452 UIMAGE_TYPE ?= kernel
0453 UIMAGE_LOADADDR ?= arch_must_set_this
0454 UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
0455 UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
0456 
0457 quiet_cmd_uimage = UIMAGE  $@
0458       cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
0459                         -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
0460                         -T $(UIMAGE_TYPE) \
0461                         -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
0462                         -n $(UIMAGE_NAME) -d $< $@
0463 
0464 # XZ
0465 # ---------------------------------------------------------------------------
0466 # Use xzkern to compress the kernel image and xzmisc to compress other things.
0467 #
0468 # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
0469 # of the kernel decompressor. A BCJ filter is used if it is available for
0470 # the target architecture. xzkern also appends uncompressed size of the data
0471 # using size_append. The .xz format has the size information available at
0472 # the end of the file too, but it's in more complex format and it's good to
0473 # avoid changing the part of the boot code that reads the uncompressed size.
0474 # Note that the bytes added by size_append will make the xz tool think that
0475 # the file is corrupt. This is expected.
0476 #
0477 # xzmisc doesn't use size_append, so it can be used to create normal .xz
0478 # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
0479 # big dictionary would increase the memory usage too much in the multi-call
0480 # decompression mode. A BCJ filter isn't used either.
0481 quiet_cmd_xzkern = XZKERN  $@
0482       cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
0483 
0484 quiet_cmd_xzkern_with_size = XZKERN  $@
0485       cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
0486                      $(size_append); } > $@
0487 
0488 quiet_cmd_xzmisc = XZMISC  $@
0489       cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
0490 
0491 # ZSTD
0492 # ---------------------------------------------------------------------------
0493 # Appends the uncompressed size of the data using size_append. The .zst
0494 # format has the size information available at the beginning of the file too,
0495 # but it's in a more complex format and it's good to avoid changing the part
0496 # of the boot code that reads the uncompressed size.
0497 #
0498 # Note that the bytes added by size_append will make the zstd tool think that
0499 # the file is corrupt. This is expected.
0500 #
0501 # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
0502 # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
0503 # single pass, so zstd doesn't need to allocate a window buffer. When streaming
0504 # decompression is used, like initramfs decompression, zstd22 should likely not
0505 # be used because it would require zstd to allocate a 128 MB buffer.
0506 
0507 quiet_cmd_zstd = ZSTD    $@
0508       cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
0509 
0510 quiet_cmd_zstd22 = ZSTD22  $@
0511       cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
0512 
0513 quiet_cmd_zstd22_with_size = ZSTD22  $@
0514       cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
0515 
0516 # ASM offsets
0517 # ---------------------------------------------------------------------------
0518 
0519 # Default sed regexp - multiline due to syntax constraints
0520 #
0521 # Use [:space:] because LLVM's integrated assembler inserts <tab> around
0522 # the .ascii directive whereas GCC keeps the <space> as-is.
0523 define sed-offsets
0524         's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
0525         /^->/{s:->#\(.*\):/* \1 */:; \
0526         s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
0527         s:->::; p;}'
0528 endef
0529 
0530 # Use filechk to avoid rebuilds when a header changes, but the resulting file
0531 # does not
0532 define filechk_offsets
0533          echo "#ifndef $2"; \
0534          echo "#define $2"; \
0535          echo "/*"; \
0536          echo " * DO NOT MODIFY."; \
0537          echo " *"; \
0538          echo " * This file was generated by Kbuild"; \
0539          echo " */"; \
0540          echo ""; \
0541          sed -ne $(sed-offsets) < $<; \
0542          echo ""; \
0543          echo "#endif"
0544 endef