xref: /openbmc/linux/arch/x86/boot/compressed/Makefile (revision 92a2c6b2)
1#
2# linux/arch/x86/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6# vmlinuz is:
7#	decompression code (*.o)
8#	asm globals (piggy.S), including:
9#		vmlinux.bin.(gz|bz2|lzma|...)
10#
11# vmlinux.bin is:
12#	vmlinux stripped of debugging and comments
13# vmlinux.bin.all is:
14#	vmlinux.bin + vmlinux.relocs
15# vmlinux.bin.(gz|bz2|lzma|...) is:
16#	(see scripts/Makefile.lib size_append)
17#	compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
18
19KASAN_SANITIZE := n
20
21targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
22	vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
23
24KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
25KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
26KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
27cflags-$(CONFIG_X86_32) := -march=i386
28cflags-$(CONFIG_X86_64) := -mcmodel=small
29KBUILD_CFLAGS += $(cflags-y)
30KBUILD_CFLAGS += -mno-mmx -mno-sse
31KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
32KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
33
34KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35GCOV_PROFILE := n
36
37LDFLAGS := -m elf_$(UTS_MACHINE)
38LDFLAGS_vmlinux := -T
39
40hostprogs-y	:= mkpiggy
41HOST_EXTRACFLAGS += -I$(srctree)/tools/include
42
43vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
44	$(obj)/string.o $(obj)/cmdline.o \
45	$(obj)/piggy.o $(obj)/cpuflags.o
46
47vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
48vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o
49
50$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
51
52vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
53	$(objtree)/drivers/firmware/efi/libstub/lib.a
54vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
55
56$(obj)/vmlinux: $(vmlinux-objs-y) FORCE
57	$(call if_changed,ld)
58	@:
59
60OBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
61$(obj)/vmlinux.bin: vmlinux FORCE
62	$(call if_changed,objcopy)
63
64targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
65
66CMD_RELOCS = arch/x86/tools/relocs
67quiet_cmd_relocs = RELOCS  $@
68      cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
69$(obj)/vmlinux.relocs: vmlinux FORCE
70	$(call if_changed,relocs)
71
72vmlinux.bin.all-y := $(obj)/vmlinux.bin
73vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
74
75$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
76	$(call if_changed,gzip)
77$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
78	$(call if_changed,bzip2)
79$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
80	$(call if_changed,lzma)
81$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
82	$(call if_changed,xzkern)
83$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
84	$(call if_changed,lzo)
85$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
86	$(call if_changed,lz4)
87
88suffix-$(CONFIG_KERNEL_GZIP)	:= gz
89suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
90suffix-$(CONFIG_KERNEL_LZMA)	:= lzma
91suffix-$(CONFIG_KERNEL_XZ)	:= xz
92suffix-$(CONFIG_KERNEL_LZO) 	:= lzo
93suffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
94
95RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
96	     $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
97quiet_cmd_mkpiggy = MKPIGGY $@
98      cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
99
100targets += piggy.S
101$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
102	$(call if_changed,mkpiggy)
103