xref: /openbmc/linux/arch/mips/boot/compressed/Makefile (revision 8e74a48d)
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
41
42# decompressor objects (linked with vmlinuz)
43vmlinuzobjs-y := $(obj)/head.o $(obj)/decompress.o $(obj)/string.o $(obj)/bswapsi.o
44
45ifdef CONFIG_DEBUG_ZBOOT
46vmlinuzobjs-$(CONFIG_DEBUG_ZBOOT)		   += $(obj)/dbg.o
47vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART16550) += $(obj)/uart-16550.o
48vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART_PROM) += $(obj)/uart-prom.o
49vmlinuzobjs-$(CONFIG_MIPS_ALCHEMY)		   += $(obj)/uart-alchemy.o
50vmlinuzobjs-$(CONFIG_ATH79)			   += $(obj)/uart-ath79.o
51endif
52
53vmlinuzobjs-$(CONFIG_KERNEL_XZ) += $(obj)/ashldi3.o
54
55vmlinuzobjs-$(CONFIG_KERNEL_ZSTD) += $(obj)/bswapdi.o $(obj)/ashldi3.o $(obj)/clz_ctz.o
56
57targets := $(notdir $(vmlinuzobjs-y))
58
59targets += vmlinux.bin
60
61OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S
62
63$(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE
64	$(call if_changed,objcopy)
65
66tool_$(CONFIG_KERNEL_GZIP)    = gzip
67tool_$(CONFIG_KERNEL_BZIP2)   = bzip2_with_size
68tool_$(CONFIG_KERNEL_LZ4)     = lz4_with_size
69tool_$(CONFIG_KERNEL_LZMA)    = lzma_with_size
70tool_$(CONFIG_KERNEL_LZO)     = lzo_with_size
71tool_$(CONFIG_KERNEL_XZ)      = xzkern_with_size
72tool_$(CONFIG_KERNEL_ZSTD)    = zstd22_with_size
73
74targets += vmlinux.bin.z
75
76$(obj)/vmlinux.bin.z: $(obj)/vmlinux.bin FORCE
77	$(call if_changed,$(tool_y))
78
79targets += piggy.o dummy.o
80
81OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \
82			--set-section-flags=.image=contents,alloc,load,readonly,data
83
84$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE
85	$(call if_changed,objcopy)
86
87HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE)
88
89# Calculate the load address of the compressed kernel image
90hostprogs := calc_vmlinuz_load_addr
91
92ifneq (0x0,$(CONFIG_ZBOOT_LOAD_ADDRESS))
93zload-y	= $(CONFIG_ZBOOT_LOAD_ADDRESS)
94endif
95
96ifneq ($(zload-y),)
97VMLINUZ_LOAD_ADDRESS := $(zload-y)
98else
99VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \
100		$(obj)/vmlinux.bin $(LINKER_LOAD_ADDRESS))
101endif
102UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS)
103
104vmlinuzobjs-y += $(obj)/piggy.o
105
106targets += ../../../../vmlinuz
107
108quiet_cmd_zld = LD      $@
109      cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@
110quiet_cmd_strip = STRIP   $@
111      cmd_strip = $(STRIP) -s $@
112
113$(objtree)/vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
114	$(call cmd,zld)
115	$(call cmd,strip)
116
117objboot := $(objtree)/arch/mips/boot
118
119$(objboot)/vmlinuz: $(objtree)/vmlinuz FORCE
120
121#
122# Some DECstations need all possible sections of an ECOFF executable
123#
124ifdef CONFIG_MACH_DECSTATION
125  e2eflag := -a
126endif
127
128# elf2ecoff can only handle 32bit image
129hostprogs += ../elf2ecoff
130
131ifdef CONFIG_32BIT
132	VMLINUZ = $(objtree)/vmlinuz
133else
134	VMLINUZ = $(objboot)/vmlinuz.32
135endif
136
137targets += ../vmlinuz.32
138
139quiet_cmd_32 = OBJCOPY $@
140      cmd_32 = $(OBJCOPY) -O $(32bit-bfd) $(OBJCOPYFLAGS) $< $@
141
142$(objboot)/vmlinuz.32: $(objtree)/vmlinuz
143	$(call cmd,32)
144
145targets += ../vmlinuz.ecoff
146
147quiet_cmd_ecoff = ECOFF	  $@
148      cmd_ecoff = $< $(VMLINUZ) $@ $(e2eflag)
149
150$(objboot)/vmlinuz.ecoff: $(objboot)/elf2ecoff $(VMLINUZ)
151	$(call cmd,ecoff)
152
153targets += ../vmlinuz.bin
154
155OBJCOPYFLAGS_vmlinuz.bin := $(OBJCOPYFLAGS) -O binary
156
157$(objboot)/vmlinuz.bin: $(objtree)/vmlinuz
158	$(call cmd,objcopy)
159
160targets += ../vmlinuz.srec
161
162OBJCOPYFLAGS_vmlinuz.srec := $(OBJCOPYFLAGS) -S -O srec
163
164$(objboot)/vmlinuz.srec: $(objtree)/vmlinuz
165	$(call cmd,objcopy)
166
167targets += ../uzImage.bin
168
169$(objboot)/uzImage.bin: $(objboot)/vmlinuz.bin FORCE
170	$(call if_changed,uimage,none)
171
172#
173# Flattened Image Tree (.itb) image
174#
175
176ifeq ($(ADDR_BITS),32)
177itb_addr_cells = 1
178endif
179ifeq ($(ADDR_BITS),64)
180itb_addr_cells = 2
181endif
182
183targets += ../vmlinuz.its.S
184
185quiet_cmd_its_cat = CAT     $@
186      cmd_its_cat = cat $(real-prereqs) >$@
187
188$(objboot)/vmlinuz.its.S: $(addprefix $(srctree)/arch/mips/$(PLATFORM)/,$(ITS_INPUTS)) FORCE
189	$(call if_changed,its_cat)
190
191targets += ../vmlinuz.its
192
193quiet_cmd_cpp_its_S = ITS     $@
194      cmd_cpp_its_S = $(CPP) -P -C -o $@ $< \
195		        -DKERNEL_NAME="\"Linux $(KERNELRELEASE)\"" \
196			-DVMLINUX_BINARY="\"$(2)\"" \
197			-DVMLINUX_COMPRESSION="\"none\"" \
198			-DVMLINUX_LOAD_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
199			-DVMLINUX_ENTRY_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
200			-DADDR_BITS=$(ADDR_BITS) \
201			-DADDR_CELLS=$(itb_addr_cells)
202
203$(objboot)/vmlinuz.its: $(objboot)/vmlinuz.its.S FORCE
204	$(call if_changed,cpp_its_S,vmlinuz.bin)
205
206targets += ../vmlinuz.itb
207
208quiet_cmd_itb-image = ITB     $@
209      cmd_itb-image = \
210		env PATH="$(objtree)/scripts/dtc:$(PATH)" \
211		$(BASH) $(MKIMAGE) \
212		-D "-I dts -O dtb -p 500 \
213			--include $(objtree)/arch/mips \
214			--warning no-unit_address_vs_reg" \
215		-f $(2) $@
216
217$(objboot)/vmlinuz.itb: $(objboot)/vmlinuz.its $(objboot)/vmlinuz.bin FORCE
218	$(call if_changed,itb-image,$<)
219