xref: /openbmc/linux/arch/x86/boot/compressed/Makefile (revision ccde70aa)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2db569afaSSam Ravnborg#
3db569afaSSam Ravnborg# linux/arch/x86/boot/compressed/Makefile
4db569afaSSam Ravnborg#
5db569afaSSam Ravnborg# create a compressed vmlinux image from the original vmlinux
6db569afaSSam Ravnborg#
7fb7183efSKees Cook# vmlinuz is:
8fb7183efSKees Cook#	decompression code (*.o)
9fb7183efSKees Cook#	asm globals (piggy.S), including:
10fb7183efSKees Cook#		vmlinux.bin.(gz|bz2|lzma|...)
11fb7183efSKees Cook#
12fb7183efSKees Cook# vmlinux.bin is:
13fb7183efSKees Cook#	vmlinux stripped of debugging and comments
14fb7183efSKees Cook# vmlinux.bin.all is:
15fb7183efSKees Cook#	vmlinux.bin + vmlinux.relocs
16fb7183efSKees Cook# vmlinux.bin.(gz|bz2|lzma|...) is:
17fb7183efSKees Cook#	(see scripts/Makefile.lib size_append)
18fb7183efSKees Cook#	compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
19db569afaSSam Ravnborg
2040d04110SMarco Elver# Sanitizer runtimes are unavailable and cannot be linked for early boot code.
21ef7f0d6aSAndrey RyabininKASAN_SANITIZE			:= n
2240d04110SMarco ElverKCSAN_SANITIZE			:= n
2393324e68SAlexander PotapenkoKMSAN_SANITIZE			:= n
24c0dd6716SJosh PoimboeufOBJECT_FILES_NON_STANDARD	:= y
25ef7f0d6aSAndrey Ryabinin
265c9a8750SDmitry Vyukov# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
275c9a8750SDmitry VyukovKCOV_INSTRUMENT		:= n
285c9a8750SDmitry Vyukov
29f9b493acSKyungsik Leetargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
30fb46d057SNick Terrell	vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
31db569afaSSam Ravnborg
325fe392ffSNathan Chancellor# CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
335fe392ffSNathan Chancellor# case of cross compiling, as it has the '--target=' flag, which is needed to
345fe392ffSNathan Chancellor# avoid errors with '-march=i386', and future flags may depend on the target to
355fe392ffSNathan Chancellor# be valid.
365fe392ffSNathan ChancellorKBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
37527afc21SArvind SankarKBUILD_CFLAGS += -fno-strict-aliasing -fPIE
38a554e740SNick DesaulniersKBUILD_CFLAGS += -Wundef
3995a38f34SH. Peter AnvinKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
4017a2a9b5SH. Peter Anvincflags-$(CONFIG_X86_32) := -march=i386
416ba0efa4SJoerg Roedelcflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
42db569afaSSam RavnborgKBUILD_CFLAGS += $(cflags-y)
438b3b005dSH. Peter AnvinKBUILD_CFLAGS += -mno-mmx -mno-sse
44e1ac4b24SChester LinKBUILD_CFLAGS += -ffreestanding -fshort-wchar
45893ab004SMasahiro YamadaKBUILD_CFLAGS += -fno-stack-protector
4620c6c189SMatthias KaehlckeKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
476c3b56b1SMatthias KaehlckeKBUILD_CFLAGS += $(call cc-disable-warning, gnu)
48dca5203eSNathan ChancellorKBUILD_CFLAGS += -Wno-pointer-sign
499e2276faSBruce AshfieldKBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
50003602adSArvind SankarKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
51fb46d057SNick TerrellKBUILD_CFLAGS += -D__DISABLE_EXPORTS
5209e43968SArvind Sankar# Disable relocation relaxation in case the link is not PIE.
53994f5f78SNick DesaulniersKBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
54e544ea57SArd BiesheuvelKBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
55db569afaSSam Ravnborg
56e759959fSBrijesh Singh# sev.c indirectly inludes inat-table.h which is generated during
57597cfe48SJoerg Roedel# compilation and stored in $(objtree). Add the directory to the includes so
58597cfe48SJoerg Roedel# that the compiler finds it even with out-of-tree builds (make O=/some/path).
59e759959fSBrijesh SinghCFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
60597cfe48SJoerg Roedel
61db569afaSSam RavnborgKBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
627bf99fb6SPeter OberparleiterGCOV_PROFILE := n
63c6d30853SAndrey RyabininUBSAN_SANITIZE :=n
64db569afaSSam Ravnborg
65d503ac53SMasahiro YamadaKBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
66d1c0272bSKees CookKBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
67a980ce35SH.J. Lu# Compressed kernel should be built as PIE since it may be loaded at any
68a980ce35SH.J. Lu# address by the bootloader.
69527afc21SArvind SankarLDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
7059612b24SNathan Chancellorifdef CONFIG_LD_ORPHAN_WARN
71e1789d7cSXin LiLDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
7259612b24SNathan Chancellorendif
73ffcf9c57SNick DesaulniersLDFLAGS_vmlinux += -z noexecstack
74ffcf9c57SNick Desaulniersifeq ($(CONFIG_LD_IS_BFD),y)
75ffcf9c57SNick DesaulniersLDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
76ffcf9c57SNick Desaulniersendif
77a1b87d54SArd Biesheuvelifeq ($(CONFIG_EFI_STUB),y)
78a1b87d54SArd Biesheuvel# ensure that the static EFI stub library will be pulled in, even if it is
79a1b87d54SArd Biesheuvel# never referenced explicitly from the startup code
80a1b87d54SArd BiesheuvelLDFLAGS_vmlinux += -u efi_pe_entry
81a1b87d54SArd Biesheuvelendif
823f086189SArvind SankarLDFLAGS_vmlinux += -T
83db569afaSSam Ravnborg
845f2fb52fSMasahiro Yamadahostprogs	:= mkpiggy
8512871c56SMatt FlemingHOST_EXTRACFLAGS += -I$(srctree)/tools/include
8602a884c0SH. Peter Anvin
87*ccde70aaSArd Biesheuvelsed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__start_rodata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
8867b66625SYinghai Lu
8967b66625SYinghai Luquiet_cmd_voffset = VOFFSET $@
9067b66625SYinghai Lu      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
9167b66625SYinghai Lu
9267b66625SYinghai Lutargets += ../voffset.h
9367b66625SYinghai Lu
9467b66625SYinghai Lu$(obj)/../voffset.h: vmlinux FORCE
9567b66625SYinghai Lu	$(call if_changed,voffset)
9667b66625SYinghai Lu
9767b66625SYinghai Lu$(obj)/misc.o: $(obj)/../voffset.h
9867b66625SYinghai Lu
992c33c27fSDaniel Kipervmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
1002c33c27fSDaniel Kiper	$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
1019e6abd2aSJosh Triplett	$(obj)/piggy.o $(obj)/cpuflags.o
1029e6abd2aSJosh Triplett
1033afed06aSJosh Triplettvmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
1049b238748SKees Cookvmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
1053a94707dSKees Cookifdef CONFIG_X86_64
1065f2bb016SJoerg Roedel	vmlinux-objs-y += $(obj)/ident_map_64.o
10764e68263SJoerg Roedel	vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
10861de13dfSArd Biesheuvel	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o
10908529078SKirill A. Shutemov	vmlinux-objs-y += $(obj)/pgtable_64.o
110e759959fSBrijesh Singh	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
1113a94707dSKees Cookendif
112291f3632SMatt Fleming
1133a63f70bSChao Fanvmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
11475d090fdSKirill A. Shutemovvmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o $(obj)/tdx-shared.o
115745e3ed8SKirill A. Shutemovvmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o
1163a63f70bSChao Fan
1177c4146e8SMichael Rothvmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
118cb8bda8aSArd Biesheuvelvmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
119cb8bda8aSArd Biesheuvelvmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
120291f3632SMatt Fleming
121cb8bda8aSArd Biesheuvel$(obj)/vmlinux: $(vmlinux-objs-y) FORCE
122527afc21SArvind Sankar	$(call if_changed,ld)
123db569afaSSam Ravnborg
124099e1377SIan CampbellOBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
125db569afaSSam Ravnborg$(obj)/vmlinux.bin: vmlinux FORCE
126db569afaSSam Ravnborg	$(call if_changed,objcopy)
127db569afaSSam Ravnborg
1289a1cb471SJosh Tripletttargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
129db569afaSSam Ravnborg
1309d9173e9SPetr Pavlu# vmlinux.relocs is created by the vmlinux postlink step.
1319d9173e9SPetr Pavlu$(obj)/vmlinux.relocs: vmlinux
1329d9173e9SPetr Pavlu	@true
133db569afaSSam Ravnborg
134db569afaSSam Ravnborgvmlinux.bin.all-y := $(obj)/vmlinux.bin
1355f11e020SH. Peter Anvinvmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
136db569afaSSam Ravnborg
1375f11e020SH. Peter Anvin$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
138db569afaSSam Ravnborg	$(call if_changed,gzip)
1395f11e020SH. Peter Anvin$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
1407ce7e984SMasahiro Yamada	$(call if_changed,bzip2_with_size)
1415f11e020SH. Peter Anvin$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
1427ce7e984SMasahiro Yamada	$(call if_changed,lzma_with_size)
14330314804SLasse Collin$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
1447ce7e984SMasahiro Yamada	$(call if_changed,xzkern_with_size)
14513510997SAlbin Tonnerre$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
1467ce7e984SMasahiro Yamada	$(call if_changed,lzo_with_size)
147f9b493acSKyungsik Lee$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
1487ce7e984SMasahiro Yamada	$(call if_changed,lz4_with_size)
149fb46d057SNick Terrell$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
1507ce7e984SMasahiro Yamada	$(call if_changed,zstd22_with_size)
151db569afaSSam Ravnborg
152283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_GZIP)	:= gz
153283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
154283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_LZMA)	:= lzma
15530314804SLasse Collinsuffix-$(CONFIG_KERNEL_XZ)	:= xz
15613510997SAlbin Tonnerresuffix-$(CONFIG_KERNEL_LZO) 	:= lzo
157f9b493acSKyungsik Leesuffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
158fb46d057SNick Terrellsuffix-$(CONFIG_KERNEL_ZSTD)	:= zst
159ae03c499SAlain Knaff
16002a884c0SH. Peter Anvinquiet_cmd_mkpiggy = MKPIGGY $@
161172caf19SMasahiro Yamada      cmd_mkpiggy = $(obj)/mkpiggy $< > $@
16202a884c0SH. Peter Anvin
16302a884c0SH. Peter Anvintargets += piggy.S
16402a884c0SH. Peter Anvin$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
16502a884c0SH. Peter Anvin	$(call if_changed,mkpiggy)
166