2 # This file is subject to the terms and conditions of the GNU General Public
5 # Adapted for MIPS Pete Popov, Dan Malek
7 # Copyright (C) 1994 by Linus Torvalds
8 # Adapted for PowerPC by Gary Thomas
9 # modified by Cort (cort@cs.nmt.edu)
11 # Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University
12 # Author: Wu Zhangjin <wuzhangjin@gmail.com>
15 include $(srctree)/arch/mips/Kbuild.platforms
17 # set the default size of the mallocing area for decompressing
18 BOOT_HEAP_SIZE := 0x400000
20 # Disable Function Tracer
21 KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE), $(KBUILD_CFLAGS))
23 KBUILD_CFLAGS := $(filter-out -fstack-protector, $(KBUILD_CFLAGS))
25 # Disable lq/sq in zboot
26 ifdef CONFIG_CPU_LOONGSON64
27 KBUILD_CFLAGS := $(filter-out -march=loongson3a, $(KBUILD_CFLAGS)) -march=mips64r2
30 KBUILD_CFLAGS := $(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \
31 -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull"
33 KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ \
34 -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) \
35 -DKERNEL_ENTRY=$(VMLINUX_ENTRY_ADDRESS)
37 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
42 # decompressor objects (linked with vmlinuz)
43 vmlinuzobjs-y := $(obj)/head.o $(obj)/decompress.o $(obj)/string.o
45 ifdef CONFIG_DEBUG_ZBOOT
46 vmlinuzobjs-$(CONFIG_DEBUG_ZBOOT) += $(obj)/dbg.o
47 vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART16550) += $(obj)/uart-16550.o
48 vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART_PROM) += $(obj)/uart-prom.o
49 vmlinuzobjs-$(CONFIG_MIPS_ALCHEMY) += $(obj)/uart-alchemy.o
50 vmlinuzobjs-$(CONFIG_ATH79) += $(obj)/uart-ath79.o
53 extra-y += uart-ath79.c
54 $(obj)/uart-ath79.c: $(srctree)/arch/mips/ath79/early_printk.c
57 vmlinuzobjs-$(CONFIG_KERNEL_XZ) += $(obj)/ashldi3.o $(obj)/bswapsi.o
60 $(obj)/ashldi3.c: $(obj)/%.c: $(srctree)/lib/%.c FORCE
61 $(call if_changed,shipped)
64 $(obj)/bswapsi.c: $(obj)/%.c: $(srctree)/arch/mips/lib/%.c FORCE
65 $(call if_changed,shipped)
67 targets := $(notdir $(vmlinuzobjs-y))
69 targets += vmlinux.bin
71 OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S
73 $(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE
74 $(call if_changed,objcopy)
76 tool_$(CONFIG_KERNEL_GZIP) = gzip
77 tool_$(CONFIG_KERNEL_BZIP2) = bzip2
78 tool_$(CONFIG_KERNEL_LZ4) = lz4
79 tool_$(CONFIG_KERNEL_LZMA) = lzma
80 tool_$(CONFIG_KERNEL_LZO) = lzo
81 tool_$(CONFIG_KERNEL_XZ) = xzkern
82 tool_$(CONFIG_KERNEL_ZSTD) = zstd22
84 targets += vmlinux.bin.z
86 $(obj)/vmlinux.bin.z: $(obj)/vmlinux.bin FORCE
87 $(call if_changed,$(tool_y))
89 targets += piggy.o dummy.o
91 OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \
92 --set-section-flags=.image=contents,alloc,load,readonly,data
94 $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE
95 $(call if_changed,objcopy)
97 HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE)
99 # Calculate the load address of the compressed kernel image
100 hostprogs := calc_vmlinuz_load_addr
103 VMLINUZ_LOAD_ADDRESS := $(zload-y)
105 VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \
106 $(obj)/vmlinux.bin $(LINKER_LOAD_ADDRESS))
108 UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS)
110 vmlinuzobjs-y += $(obj)/piggy.o
112 targets += ../../../../vmlinuz
114 quiet_cmd_zld = LD $@
115 cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@
116 quiet_cmd_strip = STRIP $@
117 cmd_strip = $(STRIP) -s $@
119 $(objtree)/vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
123 objboot := $(objtree)/arch/mips/boot
125 $(objboot)/vmlinuz: $(objtree)/vmlinuz FORCE
128 # Some DECstations need all possible sections of an ECOFF executable
130 ifdef CONFIG_MACH_DECSTATION
134 # elf2ecoff can only handle 32bit image
135 hostprogs += ../elf2ecoff
138 VMLINUZ = $(objtree)/vmlinuz
140 VMLINUZ = $(objboot)/vmlinuz.32
143 targets += ../vmlinuz.32
145 quiet_cmd_32 = OBJCOPY $@
146 cmd_32 = $(OBJCOPY) -O $(32bit-bfd) $(OBJCOPYFLAGS) $< $@
148 $(objboot)/vmlinuz.32: $(objtree)/vmlinuz
151 targets += ../vmlinuz.ecoff
153 quiet_cmd_ecoff = ECOFF $@
154 cmd_ecoff = $< $(VMLINUZ) $@ $(e2eflag)
156 $(objboot)/vmlinuz.ecoff: $(objboot)/elf2ecoff $(VMLINUZ)
159 targets += ../vmlinuz.bin
161 OBJCOPYFLAGS_vmlinuz.bin := $(OBJCOPYFLAGS) -O binary
163 $(objboot)/vmlinuz.bin: $(objtree)/vmlinuz
166 targets += ../vmlinuz.srec
168 OBJCOPYFLAGS_vmlinuz.srec := $(OBJCOPYFLAGS) -S -O srec
170 $(objboot)/vmlinuz.srec: $(objtree)/vmlinuz
173 targets += ../uzImage.bin
175 $(objboot)/uzImage.bin: $(objboot)/vmlinuz.bin FORCE
176 $(call if_changed,uimage,none)
179 # Flattened Image Tree (.itb) image
182 ifeq ($(ADDR_BITS),32)
185 ifeq ($(ADDR_BITS),64)
189 targets += ../vmlinuz.its.S
191 quiet_cmd_its_cat = CAT $@
192 cmd_its_cat = cat $(real-prereqs) >$@
194 $(objboot)/vmlinuz.its.S: $(addprefix $(srctree)/arch/mips/$(PLATFORM)/,$(ITS_INPUTS)) FORCE
195 $(call if_changed,its_cat)
197 targets += ../vmlinuz.its
199 quiet_cmd_cpp_its_S = ITS $@
200 cmd_cpp_its_S = $(CPP) -P -C -o $@ $< \
201 -DKERNEL_NAME="\"Linux $(KERNELRELEASE)\"" \
202 -DVMLINUX_BINARY="\"$(2)\"" \
203 -DVMLINUX_COMPRESSION="\"none\"" \
204 -DVMLINUX_LOAD_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
205 -DVMLINUX_ENTRY_ADDRESS=$(VMLINUZ_LOAD_ADDRESS) \
206 -DADDR_BITS=$(ADDR_BITS) \
207 -DADDR_CELLS=$(itb_addr_cells)
209 $(objboot)/vmlinuz.its: $(objboot)/vmlinuz.its.S FORCE
210 $(call if_changed,cpp_its_S,vmlinuz.bin)
212 targets += ../vmlinuz.itb
214 quiet_cmd_itb-image = ITB $@
216 env PATH="$(objtree)/scripts/dtc:$(PATH)" \
218 -D "-I dts -O dtb -p 500 \
219 --include $(objtree)/arch/mips \
220 --warning no-unit_address_vs_reg" \
223 $(objboot)/vmlinuz.itb: $(objboot)/vmlinuz.its $(objboot)/vmlinuz.bin FORCE
224 $(call if_changed,itb-image,$<)