xref: /openbmc/linux/arch/mips/boot/compressed/Makefile (revision 0526b56c)
1#
2# This file is subject to the terms and conditions of the GNU General Public
3# License.
4#
5# Adapted for MIPS Pete Popov, Dan Malek
6#
7# Copyright (C) 1994 by Linus Torvalds
8# Adapted for PowerPC by Gary Thomas
9# modified by Cort (cort@cs.nmt.edu)
10#
11# Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University
12# Author: Wu Zhangjin <wuzhangjin@gmail.com>
13#
14
15include $(srctree)/arch/mips/Kbuild.platforms
16
17# set the default size of the mallocing area for decompressing
18BOOT_HEAP_SIZE := 0x400000
19
20# Disable Function Tracer
21KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE), $(KBUILD_CFLAGS))
22
23KBUILD_CFLAGS := $(filter-out -fstack-protector, $(KBUILD_CFLAGS))
24
25# Disable lq/sq in zboot
26ifdef CONFIG_CPU_LOONGSON64
27KBUILD_CFLAGS := $(filter-out -march=loongson3a, $(KBUILD_CFLAGS)) -march=mips64r2
28endif
29
30KBUILD_CFLAGS := $(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \
31	-DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull"
32
33KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ \
34	-DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) \
35	-DKERNEL_ENTRY=$(VMLINUX_ENTRY_ADDRESS)
36
37# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
38KCOV_INSTRUMENT		:= n
39GCOV_PROFILE := n
40UBSAN_SANITIZE := n
41KCSAN_SANITIZE			:= n
42
43# decompressor objects (linked with vmlinuz)
44vmlinuzobjs-y := $(obj)/head.o $(obj)/decompress.o $(obj)/string.o $(obj)/bswapsi.o
45
46ifdef CONFIG_DEBUG_ZBOOT
47vmlinuzobjs-$(CONFIG_DEBUG_ZBOOT)		   += $(obj)/dbg.o
48vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART16550) += $(obj)/uart-16550.o
49vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART_PROM) += $(obj)/uart-prom.o
50vmlinuzobjs-$(CONFIG_MIPS_ALCHEMY)		   += $(obj)/uart-alchemy.o
51vmlinuzobjs-$(CONFIG_ATH79)			   += $(obj)/uart-ath79.o
52endif
53
54vmlinuzobjs-$(CONFIG_KERNEL_XZ) += $(obj)/ashldi3.o
55
56vmlinuzobjs-$(CONFIG_KERNEL_ZSTD) += $(obj)/bswapdi.o $(obj)/ashldi3.o $(obj)/clz_ctz.o
57
58targets := $(notdir $(vmlinuzobjs-y))
59
60targets += vmlinux.bin
61
62OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S
63
64$(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE
65	$(call if_changed,objcopy)
66
67tool_$(CONFIG_KERNEL_GZIP)    = gzip
68tool_$(CONFIG_KERNEL_BZIP2)   = bzip2_with_size
69tool_$(CONFIG_KERNEL_LZ4)     = lz4_with_size
70tool_$(CONFIG_KERNEL_LZMA)    = lzma_with_size
71tool_$(CONFIG_KERNEL_LZO)     = lzo_with_size
72tool_$(CONFIG_KERNEL_XZ)      = xzkern_with_size
73tool_$(CONFIG_KERNEL_ZSTD)    = zstd22_with_size
74
75targets += vmlinux.bin.z
76
77$(obj)/vmlinux.bin.z: $(obj)/vmlinux.bin FORCE
78	$(call if_changed,$(tool_y))
79
80targets += piggy.o dummy.o
81
82OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \
83			--set-section-flags=.image=contents,alloc,load,readonly,data
84
85$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE
86	$(call if_changed,objcopy)
87
88HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE)
89
90# Calculate the load address of the compressed kernel image
91hostprogs := calc_vmlinuz_load_addr
92
93ifneq (0x0,$(CONFIG_ZBOOT_LOAD_ADDRESS))
94zload-y	= $(CONFIG_ZBOOT_LOAD_ADDRESS)
95endif
96
97ifneq ($(zload-y),)
98VMLINUZ_LOAD_ADDRESS := $(zload-y)
99else
100VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \
101		$(obj)/vmlinux.bin $(LINKER_LOAD_ADDRESS))
102endif
103UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS)
104
105vmlinuzobjs-y += $(obj)/piggy.o
106
107targets += ../../../../vmlinuz
108
109quiet_cmd_zld = LD      $@
110      cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@
111quiet_cmd_strip = STRIP   $@
112      cmd_strip = $(STRIP) -s $@
113
114$(objtree)/vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
115	$(call cmd,zld)
116	$(call cmd,strip)
117
118objboot := $(objtree)/arch/mips/boot
119
120$(objboot)/vmlinuz: $(objtree)/vmlinuz FORCE
121
122#
123# Some DECstations need all possible sections of an ECOFF executable
124#
125ifdef CONFIG_MACH_DECSTATION
126  e2eflag := -a
127endif
128
129# elf2ecoff can only handle 32bit image
130hostprogs += ../elf2ecoff
131
132ifdef CONFIG_32BIT
133	VMLINUZ = $(objtree)/vmlinuz
134else
135	VMLINUZ = $(objboot)/vmlinuz.32
136endif
137
138targets += ../vmlinuz.32
139
140quiet_cmd_32 = OBJCOPY $@
141      cmd_32 = $(OBJCOPY) -O $(32bit-bfd) $(OBJCOPYFLAGS) $< $@
142
143$(objboot)/vmlinuz.32: $(objtree)/vmlinuz
144	$(call cmd,32)
145
146targets += ../vmlinuz.ecoff
147
148quiet_cmd_ecoff = ECOFF	  $@
149      cmd_ecoff = $< $(VMLINUZ) $@ $(e2eflag)
150
151$(objboot)/vmlinuz.ecoff: $(objboot)/elf2ecoff $(VMLINUZ)
152	$(call cmd,ecoff)
153
154targets += ../vmlinuz.bin
155
156OBJCOPYFLAGS_vmlinuz.bin := $(OBJCOPYFLAGS) -O binary
157
158$(objboot)/vmlinuz.bin: $(objtree)/vmlinuz
159	$(call cmd,objcopy)
160
161targets += ../vmlinuz.srec
162
163OBJCOPYFLAGS_vmlinuz.srec := $(OBJCOPYFLAGS) -S -O srec
164
165$(objboot)/vmlinuz.srec: $(objtree)/vmlinuz
166	$(call cmd,objcopy)
167
168targets += ../uzImage.bin
169
170$(objboot)/uzImage.bin: $(objboot)/vmlinuz.bin FORCE
171	$(call if_changed,uimage,none)
172
173#
174# Flattened Image Tree (.itb) image
175#
176
177ifeq ($(ADDR_BITS),32)
178itb_addr_cells = 1
179endif
180ifeq ($(ADDR_BITS),64)
181itb_addr_cells = 2
182endif
183
184targets += ../vmlinuz.its.S
185
186quiet_cmd_its_cat = CAT     $@
187      cmd_its_cat = cat $(real-prereqs) >$@
188
189$(objboot)/vmlinuz.its.S: $(addprefix $(srctree)/arch/mips/$(PLATFORM)/,$(ITS_INPUTS)) FORCE
190	$(call if_changed,its_cat)
191
192targets += ../vmlinuz.its
193
194quiet_cmd_cpp_its_S = ITS     $@
195      cmd_cpp_its_S = $(CPP) -P -C -o $@ $< \
196		        -DKERNEL_NAME="\"Linux $(KERNELRELEASE)\"" \
197			-DVMLINUX_BINARY="\"$(2)\"" \
198			-DVMLINUX_COMPRESSION="\"none\"" \
199			-DVMLINUX_LOAD_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
200			-DVMLINUX_ENTRY_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
201			-DADDR_BITS=$(ADDR_BITS) \
202			-DADDR_CELLS=$(itb_addr_cells)
203
204$(objboot)/vmlinuz.its: $(objboot)/vmlinuz.its.S FORCE
205	$(call if_changed,cpp_its_S,vmlinuz.bin)
206
207targets += ../vmlinuz.itb
208
209quiet_cmd_itb-image = ITB     $@
210      cmd_itb-image = \
211		env PATH="$(objtree)/scripts/dtc:$(PATH)" \
212		$(BASH) $(MKIMAGE) \
213		-D "-I dts -O dtb -p 500 \
214			--include $(objtree)/arch/mips \
215			--warning no-unit_address_vs_reg" \
216		-f $(2) $@
217
218$(objboot)/vmlinuz.itb: $(objboot)/vmlinuz.its $(objboot)/vmlinuz.bin FORCE
219	$(call if_changed,itb-image,$<)
220