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