xref: /openbmc/linux/arch/x86/boot/compressed/Makefile (revision d1c0272b)
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
23c0dd6716SJosh PoimboeufOBJECT_FILES_NON_STANDARD	:= y
24ef7f0d6aSAndrey Ryabinin
255c9a8750SDmitry Vyukov# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
265c9a8750SDmitry VyukovKCOV_INSTRUMENT		:= n
275c9a8750SDmitry Vyukov
28f9b493acSKyungsik Leetargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
29fb46d057SNick Terrell	vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
30db569afaSSam Ravnborg
31d6289f36SCao jinKBUILD_CFLAGS := -m$(BITS) -O2
32527afc21SArvind SankarKBUILD_CFLAGS += -fno-strict-aliasing -fPIE
3395a38f34SH. Peter AnvinKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
3417a2a9b5SH. Peter Anvincflags-$(CONFIG_X86_32) := -march=i386
35db569afaSSam Ravnborgcflags-$(CONFIG_X86_64) := -mcmodel=small
36db569afaSSam RavnborgKBUILD_CFLAGS += $(cflags-y)
378b3b005dSH. Peter AnvinKBUILD_CFLAGS += -mno-mmx -mno-sse
38685969e0SMasahiro YamadaKBUILD_CFLAGS += -ffreestanding
39893ab004SMasahiro YamadaKBUILD_CFLAGS += -fno-stack-protector
4020c6c189SMatthias KaehlckeKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
416c3b56b1SMatthias KaehlckeKBUILD_CFLAGS += $(call cc-disable-warning, gnu)
42dca5203eSNathan ChancellorKBUILD_CFLAGS += -Wno-pointer-sign
439e2276faSBruce AshfieldKBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
44003602adSArvind SankarKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
45fb46d057SNick TerrellKBUILD_CFLAGS += -D__DISABLE_EXPORTS
46e544ea57SArd BiesheuvelKBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
47db569afaSSam Ravnborg
48db569afaSSam RavnborgKBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
497bf99fb6SPeter OberparleiterGCOV_PROFILE := n
50c6d30853SAndrey RyabininUBSAN_SANITIZE :=n
51db569afaSSam Ravnborg
52d503ac53SMasahiro YamadaKBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
53d1c0272bSKees CookKBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
54a980ce35SH.J. Lu# Compressed kernel should be built as PIE since it may be loaded at any
55a980ce35SH.J. Lu# address by the bootloader.
56527afc21SArvind SankarLDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
573f086189SArvind SankarLDFLAGS_vmlinux += -T
58db569afaSSam Ravnborg
595f2fb52fSMasahiro Yamadahostprogs	:= mkpiggy
6012871c56SMatt FlemingHOST_EXTRACFLAGS += -I$(srctree)/tools/include
6102a884c0SH. Peter Anvin
624abf061bSYinghai Lused-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
6367b66625SYinghai Lu
6467b66625SYinghai Luquiet_cmd_voffset = VOFFSET $@
6567b66625SYinghai Lu      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
6667b66625SYinghai Lu
6767b66625SYinghai Lutargets += ../voffset.h
6867b66625SYinghai Lu
6967b66625SYinghai Lu$(obj)/../voffset.h: vmlinux FORCE
7067b66625SYinghai Lu	$(call if_changed,voffset)
7167b66625SYinghai Lu
7267b66625SYinghai Lu$(obj)/misc.o: $(obj)/../voffset.h
7367b66625SYinghai Lu
742c33c27fSDaniel Kipervmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
752c33c27fSDaniel Kiper	$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
769e6abd2aSJosh Triplett	$(obj)/piggy.o $(obj)/cpuflags.o
779e6abd2aSJosh Triplett
783afed06aSJosh Triplettvmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
799b238748SKees Cookvmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
803a94707dSKees Cookifdef CONFIG_X86_64
817cc4eb1bSKirill A. Shutemov	vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr_64.o
821958b5fcSTom Lendacky	vmlinux-objs-y += $(obj)/mem_encrypt.o
8308529078SKirill A. Shutemov	vmlinux-objs-y += $(obj)/pgtable_64.o
843a94707dSKees Cookendif
85291f3632SMatt Fleming
863a63f70bSChao Fanvmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
873a63f70bSChao Fan
8896738c69SMatt Flemingvmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
89da05b143SArvind Sankarefi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
90291f3632SMatt Fleming
91da05b143SArvind Sankar$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
92527afc21SArvind Sankar	$(call if_changed,ld)
93db569afaSSam Ravnborg
94099e1377SIan CampbellOBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
95db569afaSSam Ravnborg$(obj)/vmlinux.bin: vmlinux FORCE
96db569afaSSam Ravnborg	$(call if_changed,objcopy)
97db569afaSSam Ravnborg
989a1cb471SJosh Tripletttargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
99db569afaSSam Ravnborg
1006520fe55SH. Peter AnvinCMD_RELOCS = arch/x86/tools/relocs
101db569afaSSam Ravnborgquiet_cmd_relocs = RELOCS  $@
1026520fe55SH. Peter Anvin      cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
1036520fe55SH. Peter Anvin$(obj)/vmlinux.relocs: vmlinux FORCE
104db569afaSSam Ravnborg	$(call if_changed,relocs)
105db569afaSSam Ravnborg
106db569afaSSam Ravnborgvmlinux.bin.all-y := $(obj)/vmlinux.bin
1075f11e020SH. Peter Anvinvmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
108db569afaSSam Ravnborg
1095f11e020SH. Peter Anvin$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
110db569afaSSam Ravnborg	$(call if_changed,gzip)
1115f11e020SH. Peter Anvin$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
112ae03c499SAlain Knaff	$(call if_changed,bzip2)
1135f11e020SH. Peter Anvin$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
114ae03c499SAlain Knaff	$(call if_changed,lzma)
11530314804SLasse Collin$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
11630314804SLasse Collin	$(call if_changed,xzkern)
11713510997SAlbin Tonnerre$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
11813510997SAlbin Tonnerre	$(call if_changed,lzo)
119f9b493acSKyungsik Lee$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
120f9b493acSKyungsik Lee	$(call if_changed,lz4)
121fb46d057SNick Terrell$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
122fb46d057SNick Terrell	$(call if_changed,zstd22)
123db569afaSSam Ravnborg
124283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_GZIP)	:= gz
125283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
126283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_LZMA)	:= lzma
12730314804SLasse Collinsuffix-$(CONFIG_KERNEL_XZ)	:= xz
12813510997SAlbin Tonnerresuffix-$(CONFIG_KERNEL_LZO) 	:= lzo
129f9b493acSKyungsik Leesuffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
130fb46d057SNick Terrellsuffix-$(CONFIG_KERNEL_ZSTD)	:= zst
131ae03c499SAlain Knaff
13202a884c0SH. Peter Anvinquiet_cmd_mkpiggy = MKPIGGY $@
133172caf19SMasahiro Yamada      cmd_mkpiggy = $(obj)/mkpiggy $< > $@
13402a884c0SH. Peter Anvin
13502a884c0SH. Peter Anvintargets += piggy.S
13602a884c0SH. Peter Anvin$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
13702a884c0SH. Peter Anvin	$(call if_changed,mkpiggy)
138