18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci# 38c2ecf20Sopenharmony_ci# linux/arch/x86/boot/compressed/Makefile 48c2ecf20Sopenharmony_ci# 58c2ecf20Sopenharmony_ci# create a compressed vmlinux image from the original vmlinux 68c2ecf20Sopenharmony_ci# 78c2ecf20Sopenharmony_ci# vmlinuz is: 88c2ecf20Sopenharmony_ci# decompression code (*.o) 98c2ecf20Sopenharmony_ci# asm globals (piggy.S), including: 108c2ecf20Sopenharmony_ci# vmlinux.bin.(gz|bz2|lzma|...) 118c2ecf20Sopenharmony_ci# 128c2ecf20Sopenharmony_ci# vmlinux.bin is: 138c2ecf20Sopenharmony_ci# vmlinux stripped of debugging and comments 148c2ecf20Sopenharmony_ci# vmlinux.bin.all is: 158c2ecf20Sopenharmony_ci# vmlinux.bin + vmlinux.relocs 168c2ecf20Sopenharmony_ci# vmlinux.bin.(gz|bz2|lzma|...) is: 178c2ecf20Sopenharmony_ci# (see scripts/Makefile.lib size_append) 188c2ecf20Sopenharmony_ci# compressed vmlinux.bin.all + u32 size of vmlinux.bin.all 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci# Sanitizer runtimes are unavailable and cannot be linked for early boot code. 218c2ecf20Sopenharmony_ciKASAN_SANITIZE := n 228c2ecf20Sopenharmony_ciKCSAN_SANITIZE := n 238c2ecf20Sopenharmony_ciOBJECT_FILES_NON_STANDARD := y 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. 268c2ecf20Sopenharmony_ciKCOV_INSTRUMENT := n 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_citargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ 298c2ecf20Sopenharmony_ci vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci# CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in 328c2ecf20Sopenharmony_ci# case of cross compiling, as it has the '--target=' flag, which is needed to 338c2ecf20Sopenharmony_ci# avoid errors with '-march=i386', and future flags may depend on the target to 348c2ecf20Sopenharmony_ci# be valid. 358c2ecf20Sopenharmony_ciKBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS) 368c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -fno-strict-aliasing -fPIE 378c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING 388c2ecf20Sopenharmony_cicflags-$(CONFIG_X86_32) := -march=i386 398c2ecf20Sopenharmony_cicflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone 408c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(cflags-y) 418c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -mno-mmx -mno-sse 428c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -ffreestanding 438c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -fno-stack-protector 448c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 458c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(call cc-disable-warning, gnu) 468c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -Wno-pointer-sign 478c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) 488c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -fno-asynchronous-unwind-tables 498c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -D__DISABLE_EXPORTS 508c2ecf20Sopenharmony_ci# Disable relocation relaxation in case the link is not PIE. 518c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 528c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci# sev-es.c indirectly inludes inat-table.h which is generated during 558c2ecf20Sopenharmony_ci# compilation and stored in $(objtree). Add the directory to the includes so 568c2ecf20Sopenharmony_ci# that the compiler finds it even with out-of-tree builds (make O=/some/path). 578c2ecf20Sopenharmony_ciCFLAGS_sev-es.o += -I$(objtree)/arch/x86/lib/ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciKBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 608c2ecf20Sopenharmony_ciGCOV_PROFILE := n 618c2ecf20Sopenharmony_ciUBSAN_SANITIZE :=n 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciKBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) 648c2ecf20Sopenharmony_ciKBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info) 658c2ecf20Sopenharmony_ci# Compressed kernel should be built as PIE since it may be loaded at any 668c2ecf20Sopenharmony_ci# address by the bootloader. 678c2ecf20Sopenharmony_ciLDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker) 688c2ecf20Sopenharmony_ciifdef CONFIG_LD_ORPHAN_WARN 698c2ecf20Sopenharmony_ciLDFLAGS_vmlinux += --orphan-handling=warn 708c2ecf20Sopenharmony_ciendif 718c2ecf20Sopenharmony_ciLDFLAGS_vmlinux += -z noexecstack 728c2ecf20Sopenharmony_ciLDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments) 738c2ecf20Sopenharmony_ciLDFLAGS_vmlinux += -T 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cihostprogs := mkpiggy 768c2ecf20Sopenharmony_ciHOST_EXTRACFLAGS += -I$(srctree)/tools/include 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cised-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciquiet_cmd_voffset = VOFFSET $@ 818c2ecf20Sopenharmony_ci cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_citargets += ../voffset.h 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci$(obj)/../voffset.h: vmlinux FORCE 868c2ecf20Sopenharmony_ci $(call if_changed,voffset) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci$(obj)/misc.o: $(obj)/../voffset.h 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_civmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \ 918c2ecf20Sopenharmony_ci $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \ 928c2ecf20Sopenharmony_ci $(obj)/piggy.o $(obj)/cpuflags.o 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_civmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o 958c2ecf20Sopenharmony_civmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o 968c2ecf20Sopenharmony_ciifdef CONFIG_X86_64 978c2ecf20Sopenharmony_ci vmlinux-objs-y += $(obj)/ident_map_64.o 988c2ecf20Sopenharmony_ci vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o 998c2ecf20Sopenharmony_ci vmlinux-objs-y += $(obj)/mem_encrypt.o 1008c2ecf20Sopenharmony_ci vmlinux-objs-y += $(obj)/pgtable_64.o 1018c2ecf20Sopenharmony_ci vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev-es.o 1028c2ecf20Sopenharmony_ciendif 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_civmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_civmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o 1078c2ecf20Sopenharmony_ciefi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE 1108c2ecf20Sopenharmony_ci $(call if_changed,ld) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciOBJCOPYFLAGS_vmlinux.bin := -R .comment -S 1138c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin: vmlinux FORCE 1148c2ecf20Sopenharmony_ci $(call if_changed,objcopy) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_citargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciCMD_RELOCS = arch/x86/tools/relocs 1198c2ecf20Sopenharmony_ciquiet_cmd_relocs = RELOCS $@ 1208c2ecf20Sopenharmony_ci cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< 1218c2ecf20Sopenharmony_ci$(obj)/vmlinux.relocs: vmlinux FORCE 1228c2ecf20Sopenharmony_ci $(call if_changed,relocs) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_civmlinux.bin.all-y := $(obj)/vmlinux.bin 1258c2ecf20Sopenharmony_civmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 1288c2ecf20Sopenharmony_ci $(call if_changed,gzip) 1298c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 1308c2ecf20Sopenharmony_ci $(call if_changed,bzip2) 1318c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 1328c2ecf20Sopenharmony_ci $(call if_changed,lzma) 1338c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 1348c2ecf20Sopenharmony_ci $(call if_changed,xzkern) 1358c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 1368c2ecf20Sopenharmony_ci $(call if_changed,lzo) 1378c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE 1388c2ecf20Sopenharmony_ci $(call if_changed,lz4) 1398c2ecf20Sopenharmony_ci$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE 1408c2ecf20Sopenharmony_ci $(call if_changed,zstd22) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_GZIP) := gz 1438c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_BZIP2) := bz2 1448c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZMA) := lzma 1458c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_XZ) := xz 1468c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZO) := lzo 1478c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_LZ4) := lz4 1488c2ecf20Sopenharmony_cisuffix-$(CONFIG_KERNEL_ZSTD) := zst 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ciquiet_cmd_mkpiggy = MKPIGGY $@ 1518c2ecf20Sopenharmony_ci cmd_mkpiggy = $(obj)/mkpiggy $< > $@ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_citargets += piggy.S 1548c2ecf20Sopenharmony_ci$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE 1558c2ecf20Sopenharmony_ci $(call if_changed,mkpiggy) 156