xref: /OK3568_Linux_fs/kernel/arch/x86/boot/compressed/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# linux/arch/x86/boot/compressed/Makefile
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# create a compressed vmlinux image from the original vmlinux
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun# vmlinuz is:
8*4882a593Smuzhiyun#	decompression code (*.o)
9*4882a593Smuzhiyun#	asm globals (piggy.S), including:
10*4882a593Smuzhiyun#		vmlinux.bin.(gz|bz2|lzma|...)
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# vmlinux.bin is:
13*4882a593Smuzhiyun#	vmlinux stripped of debugging and comments
14*4882a593Smuzhiyun# vmlinux.bin.all is:
15*4882a593Smuzhiyun#	vmlinux.bin + vmlinux.relocs
16*4882a593Smuzhiyun# vmlinux.bin.(gz|bz2|lzma|...) is:
17*4882a593Smuzhiyun#	(see scripts/Makefile.lib size_append)
18*4882a593Smuzhiyun#	compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun# Sanitizer runtimes are unavailable and cannot be linked for early boot code.
21*4882a593SmuzhiyunKASAN_SANITIZE			:= n
22*4882a593SmuzhiyunKCSAN_SANITIZE			:= n
23*4882a593SmuzhiyunOBJECT_FILES_NON_STANDARD	:= y
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
26*4882a593SmuzhiyunKCOV_INSTRUMENT		:= n
27*4882a593Smuzhiyun
28*4882a593Smuzhiyuntargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
29*4882a593Smuzhiyun	vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun# CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
32*4882a593Smuzhiyun# case of cross compiling, as it has the '--target=' flag, which is needed to
33*4882a593Smuzhiyun# avoid errors with '-march=i386', and future flags may depend on the target to
34*4882a593Smuzhiyun# be valid.
35*4882a593SmuzhiyunKBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
36*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-strict-aliasing -fPIE
37*4882a593SmuzhiyunKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
38*4882a593Smuzhiyuncflags-$(CONFIG_X86_32) := -march=i386
39*4882a593Smuzhiyuncflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
40*4882a593SmuzhiyunKBUILD_CFLAGS += $(cflags-y)
41*4882a593SmuzhiyunKBUILD_CFLAGS += -mno-mmx -mno-sse
42*4882a593SmuzhiyunKBUILD_CFLAGS += -ffreestanding
43*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-stack-protector
44*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
45*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, gnu)
46*4882a593SmuzhiyunKBUILD_CFLAGS += -Wno-pointer-sign
47*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
48*4882a593SmuzhiyunKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
49*4882a593SmuzhiyunKBUILD_CFLAGS += -D__DISABLE_EXPORTS
50*4882a593Smuzhiyun# Disable relocation relaxation in case the link is not PIE.
51*4882a593SmuzhiyunKBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
52*4882a593SmuzhiyunKBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun# sev-es.c indirectly inludes inat-table.h which is generated during
55*4882a593Smuzhiyun# compilation and stored in $(objtree). Add the directory to the includes so
56*4882a593Smuzhiyun# that the compiler finds it even with out-of-tree builds (make O=/some/path).
57*4882a593SmuzhiyunCFLAGS_sev-es.o += -I$(objtree)/arch/x86/lib/
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunKBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
60*4882a593SmuzhiyunGCOV_PROFILE := n
61*4882a593SmuzhiyunUBSAN_SANITIZE :=n
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunKBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
64*4882a593SmuzhiyunKBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
65*4882a593Smuzhiyun# Compressed kernel should be built as PIE since it may be loaded at any
66*4882a593Smuzhiyun# address by the bootloader.
67*4882a593SmuzhiyunLDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
68*4882a593Smuzhiyunifdef CONFIG_LD_ORPHAN_WARN
69*4882a593SmuzhiyunLDFLAGS_vmlinux += --orphan-handling=warn
70*4882a593Smuzhiyunendif
71*4882a593SmuzhiyunLDFLAGS_vmlinux += -z noexecstack
72*4882a593SmuzhiyunLDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
73*4882a593SmuzhiyunLDFLAGS_vmlinux += -T
74*4882a593Smuzhiyun
75*4882a593Smuzhiyunhostprogs	:= mkpiggy
76*4882a593SmuzhiyunHOST_EXTRACFLAGS += -I$(srctree)/tools/include
77*4882a593Smuzhiyun
78*4882a593Smuzhiyunsed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
79*4882a593Smuzhiyun
80*4882a593Smuzhiyunquiet_cmd_voffset = VOFFSET $@
81*4882a593Smuzhiyun      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
82*4882a593Smuzhiyun
83*4882a593Smuzhiyuntargets += ../voffset.h
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun$(obj)/../voffset.h: vmlinux FORCE
86*4882a593Smuzhiyun	$(call if_changed,voffset)
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun$(obj)/misc.o: $(obj)/../voffset.h
89*4882a593Smuzhiyun
90*4882a593Smuzhiyunvmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
91*4882a593Smuzhiyun	$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
92*4882a593Smuzhiyun	$(obj)/piggy.o $(obj)/cpuflags.o
93*4882a593Smuzhiyun
94*4882a593Smuzhiyunvmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
95*4882a593Smuzhiyunvmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
96*4882a593Smuzhiyunifdef CONFIG_X86_64
97*4882a593Smuzhiyun	vmlinux-objs-y += $(obj)/ident_map_64.o
98*4882a593Smuzhiyun	vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
99*4882a593Smuzhiyun	vmlinux-objs-y += $(obj)/mem_encrypt.o
100*4882a593Smuzhiyun	vmlinux-objs-y += $(obj)/pgtable_64.o
101*4882a593Smuzhiyun	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev-es.o
102*4882a593Smuzhiyunendif
103*4882a593Smuzhiyun
104*4882a593Smuzhiyunvmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
105*4882a593Smuzhiyun
106*4882a593Smuzhiyunvmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
107*4882a593Smuzhiyunefi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
110*4882a593Smuzhiyun	$(call if_changed,ld)
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunOBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
113*4882a593Smuzhiyun$(obj)/vmlinux.bin: vmlinux FORCE
114*4882a593Smuzhiyun	$(call if_changed,objcopy)
115*4882a593Smuzhiyun
116*4882a593Smuzhiyuntargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
117*4882a593Smuzhiyun
118*4882a593SmuzhiyunCMD_RELOCS = arch/x86/tools/relocs
119*4882a593Smuzhiyunquiet_cmd_relocs = RELOCS  $@
120*4882a593Smuzhiyun      cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
121*4882a593Smuzhiyun$(obj)/vmlinux.relocs: vmlinux FORCE
122*4882a593Smuzhiyun	$(call if_changed,relocs)
123*4882a593Smuzhiyun
124*4882a593Smuzhiyunvmlinux.bin.all-y := $(obj)/vmlinux.bin
125*4882a593Smuzhiyunvmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
128*4882a593Smuzhiyun	$(call if_changed,gzip)
129*4882a593Smuzhiyun$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
130*4882a593Smuzhiyun	$(call if_changed,bzip2)
131*4882a593Smuzhiyun$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
132*4882a593Smuzhiyun	$(call if_changed,lzma)
133*4882a593Smuzhiyun$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
134*4882a593Smuzhiyun	$(call if_changed,xzkern)
135*4882a593Smuzhiyun$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
136*4882a593Smuzhiyun	$(call if_changed,lzo)
137*4882a593Smuzhiyun$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
138*4882a593Smuzhiyun	$(call if_changed,lz4)
139*4882a593Smuzhiyun$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
140*4882a593Smuzhiyun	$(call if_changed,zstd22)
141*4882a593Smuzhiyun
142*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_GZIP)	:= gz
143*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
144*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_LZMA)	:= lzma
145*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_XZ)	:= xz
146*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_LZO) 	:= lzo
147*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
148*4882a593Smuzhiyunsuffix-$(CONFIG_KERNEL_ZSTD)	:= zst
149*4882a593Smuzhiyun
150*4882a593Smuzhiyunquiet_cmd_mkpiggy = MKPIGGY $@
151*4882a593Smuzhiyun      cmd_mkpiggy = $(obj)/mkpiggy $< > $@
152*4882a593Smuzhiyun
153*4882a593Smuzhiyuntargets += piggy.S
154*4882a593Smuzhiyun$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
155*4882a593Smuzhiyun	$(call if_changed,mkpiggy)
156