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