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