162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci#
362306a36Sopenharmony_ci# linux/arch/x86/boot/compressed/Makefile
462306a36Sopenharmony_ci#
562306a36Sopenharmony_ci# create a compressed vmlinux image from the original vmlinux
662306a36Sopenharmony_ci#
762306a36Sopenharmony_ci# vmlinuz is:
862306a36Sopenharmony_ci#	decompression code (*.o)
962306a36Sopenharmony_ci#	asm globals (piggy.S), including:
1062306a36Sopenharmony_ci#		vmlinux.bin.(gz|bz2|lzma|...)
1162306a36Sopenharmony_ci#
1262306a36Sopenharmony_ci# vmlinux.bin is:
1362306a36Sopenharmony_ci#	vmlinux stripped of debugging and comments
1462306a36Sopenharmony_ci# vmlinux.bin.all is:
1562306a36Sopenharmony_ci#	vmlinux.bin + vmlinux.relocs
1662306a36Sopenharmony_ci# vmlinux.bin.(gz|bz2|lzma|...) is:
1762306a36Sopenharmony_ci#	(see scripts/Makefile.lib size_append)
1862306a36Sopenharmony_ci#	compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci# Sanitizer runtimes are unavailable and cannot be linked for early boot code.
2162306a36Sopenharmony_ciKASAN_SANITIZE			:= n
2262306a36Sopenharmony_ciKCSAN_SANITIZE			:= n
2362306a36Sopenharmony_ciKMSAN_SANITIZE			:= n
2462306a36Sopenharmony_ciOBJECT_FILES_NON_STANDARD	:= y
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
2762306a36Sopenharmony_ciKCOV_INSTRUMENT		:= n
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_citargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
3062306a36Sopenharmony_ci	vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci# CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
3362306a36Sopenharmony_ci# case of cross compiling, as it has the '--target=' flag, which is needed to
3462306a36Sopenharmony_ci# avoid errors with '-march=i386', and future flags may depend on the target to
3562306a36Sopenharmony_ci# be valid.
3662306a36Sopenharmony_ciKBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
3762306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-strict-aliasing -fPIE
3862306a36Sopenharmony_ciKBUILD_CFLAGS += -Wundef
3962306a36Sopenharmony_ciKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
4062306a36Sopenharmony_cicflags-$(CONFIG_X86_32) := -march=i386
4162306a36Sopenharmony_cicflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
4262306a36Sopenharmony_ciKBUILD_CFLAGS += $(cflags-y)
4362306a36Sopenharmony_ciKBUILD_CFLAGS += -mno-mmx -mno-sse
4462306a36Sopenharmony_ciKBUILD_CFLAGS += -ffreestanding -fshort-wchar
4562306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-stack-protector
4662306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
4762306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-disable-warning, gnu)
4862306a36Sopenharmony_ciKBUILD_CFLAGS += -Wno-pointer-sign
4962306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
5062306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
5162306a36Sopenharmony_ciKBUILD_CFLAGS += -D__DISABLE_EXPORTS
5262306a36Sopenharmony_ci# Disable relocation relaxation in case the link is not PIE.
5362306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
5462306a36Sopenharmony_ciKBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci# sev.c indirectly inludes inat-table.h which is generated during
5762306a36Sopenharmony_ci# compilation and stored in $(objtree). Add the directory to the includes so
5862306a36Sopenharmony_ci# that the compiler finds it even with out-of-tree builds (make O=/some/path).
5962306a36Sopenharmony_ciCFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ciKBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6262306a36Sopenharmony_ciGCOV_PROFILE := n
6362306a36Sopenharmony_ciUBSAN_SANITIZE :=n
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciKBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
6662306a36Sopenharmony_ciKBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
6762306a36Sopenharmony_ci# Compressed kernel should be built as PIE since it may be loaded at any
6862306a36Sopenharmony_ci# address by the bootloader.
6962306a36Sopenharmony_ciLDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
7062306a36Sopenharmony_ciifdef CONFIG_LD_ORPHAN_WARN
7162306a36Sopenharmony_ciLDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
7262306a36Sopenharmony_ciendif
7362306a36Sopenharmony_ciLDFLAGS_vmlinux += -z noexecstack
7462306a36Sopenharmony_ciifeq ($(CONFIG_LD_IS_BFD),y)
7562306a36Sopenharmony_ciLDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
7662306a36Sopenharmony_ciendif
7762306a36Sopenharmony_ciifeq ($(CONFIG_EFI_STUB),y)
7862306a36Sopenharmony_ci# ensure that the static EFI stub library will be pulled in, even if it is
7962306a36Sopenharmony_ci# never referenced explicitly from the startup code
8062306a36Sopenharmony_ciLDFLAGS_vmlinux += -u efi_pe_entry
8162306a36Sopenharmony_ciendif
8262306a36Sopenharmony_ciLDFLAGS_vmlinux += -T
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cihostprogs	:= mkpiggy
8562306a36Sopenharmony_ciHOST_EXTRACFLAGS += -I$(srctree)/tools/include
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cised-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciquiet_cmd_voffset = VOFFSET $@
9062306a36Sopenharmony_ci      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_citargets += ../voffset.h
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci$(obj)/../voffset.h: vmlinux FORCE
9562306a36Sopenharmony_ci	$(call if_changed,voffset)
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci$(obj)/misc.o: $(obj)/../voffset.h
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_civmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
10062306a36Sopenharmony_ci	$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
10162306a36Sopenharmony_ci	$(obj)/piggy.o $(obj)/cpuflags.o
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_civmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
10462306a36Sopenharmony_civmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
10562306a36Sopenharmony_ciifdef CONFIG_X86_64
10662306a36Sopenharmony_ci	vmlinux-objs-y += $(obj)/ident_map_64.o
10762306a36Sopenharmony_ci	vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
10862306a36Sopenharmony_ci	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o
10962306a36Sopenharmony_ci	vmlinux-objs-y += $(obj)/pgtable_64.o
11062306a36Sopenharmony_ci	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
11162306a36Sopenharmony_ciendif
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_civmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
11462306a36Sopenharmony_civmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o $(obj)/tdx-shared.o
11562306a36Sopenharmony_civmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_civmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
11862306a36Sopenharmony_civmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
11962306a36Sopenharmony_civmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci$(obj)/vmlinux: $(vmlinux-objs-y) FORCE
12262306a36Sopenharmony_ci	$(call if_changed,ld)
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciOBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
12562306a36Sopenharmony_ci$(obj)/vmlinux.bin: vmlinux FORCE
12662306a36Sopenharmony_ci	$(call if_changed,objcopy)
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_citargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci# vmlinux.relocs is created by the vmlinux postlink step.
13162306a36Sopenharmony_ci$(obj)/vmlinux.relocs: vmlinux
13262306a36Sopenharmony_ci	@true
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_civmlinux.bin.all-y := $(obj)/vmlinux.bin
13562306a36Sopenharmony_civmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
13862306a36Sopenharmony_ci	$(call if_changed,gzip)
13962306a36Sopenharmony_ci$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
14062306a36Sopenharmony_ci	$(call if_changed,bzip2_with_size)
14162306a36Sopenharmony_ci$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
14262306a36Sopenharmony_ci	$(call if_changed,lzma_with_size)
14362306a36Sopenharmony_ci$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
14462306a36Sopenharmony_ci	$(call if_changed,xzkern_with_size)
14562306a36Sopenharmony_ci$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
14662306a36Sopenharmony_ci	$(call if_changed,lzo_with_size)
14762306a36Sopenharmony_ci$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
14862306a36Sopenharmony_ci	$(call if_changed,lz4_with_size)
14962306a36Sopenharmony_ci$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
15062306a36Sopenharmony_ci	$(call if_changed,zstd22_with_size)
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_GZIP)	:= gz
15362306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
15462306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZMA)	:= lzma
15562306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_XZ)	:= xz
15662306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZO) 	:= lzo
15762306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
15862306a36Sopenharmony_cisuffix-$(CONFIG_KERNEL_ZSTD)	:= zst
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ciquiet_cmd_mkpiggy = MKPIGGY $@
16162306a36Sopenharmony_ci      cmd_mkpiggy = $(obj)/mkpiggy $< > $@
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_citargets += piggy.S
16462306a36Sopenharmony_ci$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
16562306a36Sopenharmony_ci	$(call if_changed,mkpiggy)
166