xref: /openbmc/u-boot/scripts/Makefile.spl (revision aa5e3e22)
1#
2# (C) Copyright 2000-2011
3# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4#
5# (C) Copyright 2011
6# Daniel Schwierzeck, daniel.schwierzeck@googlemail.com.
7#
8# (C) Copyright 2011
9# Texas Instruments Incorporated - http://www.ti.com/
10# Aneesh V <aneesh@ti.com>
11#
12# SPDX-License-Identifier:	GPL-2.0+
13#
14# Based on top-level Makefile.
15#
16
17src := $(obj)
18
19# Create output directory if not already present
20_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
21
22include $(srctree)/scripts/Kbuild.include
23
24-include include/config/auto.conf
25-include $(obj)/include/autoconf.mk
26
27KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
28ifeq ($(CONFIG_TPL_BUILD),y)
29KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
30endif
31
32ifeq ($(CONFIG_TPL_BUILD),y)
33SPL_BIN := u-boot-tpl
34else
35SPL_BIN := u-boot-spl
36endif
37
38ifdef CONFIG_SPL_BUILD
39SPL_ := SPL_
40ifeq ($(CONFIG_TPL_BUILD),y)
41SPL_TPL_ := TPL_
42else
43SPL_TPL_ := SPL_
44endif
45else
46SPL_ :=
47SPL_TPL_ :=
48endif
49
50include $(srctree)/config.mk
51include $(srctree)/arch/$(ARCH)/Makefile
52
53include $(srctree)/scripts/Makefile.lib
54
55# Enable garbage collection of un-used sections for SPL
56KBUILD_CFLAGS += -ffunction-sections -fdata-sections
57LDFLAGS_FINAL += --gc-sections
58
59# FIX ME
60cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
61							$(NOSTDINC_FLAGS)
62c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
63
64HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
65
66libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
67libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
68
69libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
70libs-y += common/init/
71
72# Special handling for a few options which support SPL/TPL
73ifeq ($(CONFIG_TPL_BUILD),y)
74libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
75libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/
76else
77libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
78libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
79endif
80
81libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
82libs-y += drivers/
83libs-$(CONFIG_SPL_USB_GADGET_SUPPORT) += drivers/usb/dwc3/
84libs-y += dts/
85libs-y += fs/
86libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
87libs-$(CONFIG_SPL_NET_SUPPORT) += net/
88
89head-y		:= $(addprefix $(obj)/,$(head-y))
90libs-y		:= $(addprefix $(obj)/,$(libs-y))
91u-boot-spl-dirs	:= $(patsubst %/,%,$(filter %/, $(libs-y)))
92
93libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
94
95# Add GCC lib
96ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
97PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
98PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
99endif
100
101u-boot-spl-init := $(head-y)
102u-boot-spl-main := $(libs-y)
103ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
104u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
105endif
106
107# Linker Script
108# First test whether there's a linker-script for the specific stage defined...
109ifneq ($(CONFIG_$(SPL_TPL_)LDSCRIPT),)
110# need to strip off double quotes
111LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_$(SPL_TPL_)LDSCRIPT:"%"=%))
112else
113# ...then fall back to the generic SPL linker-script
114ifneq ($(CONFIG_SPL_LDSCRIPT),)
115# need to strip off double quotes
116LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
117endif
118endif
119
120ifeq ($(wildcard $(LDSCRIPT)),)
121	LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds
122endif
123ifeq ($(wildcard $(LDSCRIPT)),)
124	LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds
125endif
126ifeq ($(wildcard $(LDSCRIPT)),)
127	LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds
128endif
129ifeq ($(wildcard $(LDSCRIPT)),)
130$(error could not find linker script)
131endif
132
133# Special flags for CPP when processing the linker script.
134# Pass the version down so we can handle backwards compatibility
135# on the fly.
136LDPPFLAGS += \
137	-include $(srctree)/include/u-boot/u-boot.lds.h \
138	-include $(objtree)/include/config.h \
139	-DCPUDIR=$(CPUDIR) \
140	$(shell $(LD) --version | \
141	  sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
142
143MKIMAGEOUTPUT ?= /dev/null
144
145quiet_cmd_mkimage = MKIMAGE $@
146cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
147	$(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT))
148
149MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE)
150
151MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
152
153MLO MLO.byteswap: $(obj)/u-boot-spl.bin FORCE
154	$(call if_changed,mkimage)
155
156ifeq ($(CONFIG_SYS_SOC),"at91")
157MKIMAGEFLAGS_boot.bin = -T atmelimage
158
159ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y)
160MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params)
161
162boot.bin: $(obj)/../tools/atmel_pmecc_params
163endif
164
165boot.bin: $(obj)/u-boot-spl.bin FORCE
166	$(call if_changed,mkimage)
167else
168ifdef CONFIG_ARCH_ZYNQ
169MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE)
170endif
171ifdef CONFIG_ARCH_ZYNQMP
172MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) \
173	-n $(srctree)/$(CONFIG_PMUFW_INIT_FILE)
174endif
175
176spl/boot.bin: $(obj)/u-boot-spl.bin FORCE
177	$(call if_changed,mkimage)
178endif
179
180ALL-y	+= $(obj)/$(SPL_BIN).bin
181
182ifdef CONFIG_SAMSUNG
183ALL-y	+= $(obj)/$(BOARD)-spl.bin
184endif
185
186ifdef CONFIG_ARCH_SOCFPGA
187ALL-y	+= $(obj)/$(SPL_BIN).sfp
188endif
189
190ifdef CONFIG_ARCH_SUNXI
191ALL-y	+= $(obj)/sunxi-spl.bin
192
193ifdef CONFIG_NAND_SUNXI
194ALL-y	+= $(obj)/sunxi-spl-with-ecc.bin
195endif
196endif
197
198ifeq ($(CONFIG_SYS_SOC),"at91")
199ALL-y	+= boot.bin
200endif
201
202ALL-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-16bit-spl.bin
203
204ALL-$(CONFIG_ARCH_ZYNQ)		+= $(obj)/boot.bin
205ALL-$(CONFIG_ARCH_ZYNQMP)	+= $(obj)/boot.bin
206
207all:	$(ALL-y)
208
209quiet_cmd_cat = CAT     $@
210cmd_cat = cat $(filter-out $(PHONY), $^) > $@
211
212quiet_cmd_copy = COPY    $@
213      cmd_copy = cp $< $@
214
215ifneq ($(CONFIG_SPL_MULTI_DTB_FIT),y)
216FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).dtb
217else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_LZO),y)
218FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.lzo
219else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_GZIP),y)
220FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.gz
221else
222FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit
223endif
224
225
226ifeq ($(CONFIG_$(SPL_TPL_)OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_$(SPL_TPL_)OF_PLATDATA),yy)
227$(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
228		$(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
229		$(FINAL_DTB_CONTAINER)  FORCE
230	$(call if_changed,cat)
231
232$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
233	$(call if_changed,copy)
234else
235$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE
236	$(call if_changed,copy)
237endif
238
239# Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end
240$(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN)
241	@bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
242	dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null;
243
244$(obj)/$(SPL_BIN).dtb: dts/dt-spl.dtb FORCE
245	$(call if_changed,copy)
246
247pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
248
249quiet_cmd_dtocc = DTOC C  $@
250cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
251
252quiet_cmd_dtoch = DTOC H  $@
253cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct
254
255quiet_cmd_plat = PLAT    $@
256cmd_plat = $(CC) $(c_flags) -c $< -o $@
257
258$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \
259		include/generated/dt-structs-gen.h
260	$(call if_changed,plat)
261
262PHONY += dts_dir
263dts_dir:
264	$(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
265
266include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
267	$(call if_changed,dtoch)
268
269$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
270	$(call if_changed,dtocc)
271
272ifdef CONFIG_SAMSUNG
273ifdef CONFIG_VAR_SIZE_SPL
274VAR_SIZE_PARAM = --vs
275else
276VAR_SIZE_PARAM =
277endif
278$(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
279	$(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
280	$(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
281	$(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
282endif
283
284quiet_cmd_objcopy = OBJCOPY $@
285cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
286
287OBJCOPYFLAGS_$(SPL_BIN)-nodtb.bin = $(SPL_OBJCFLAGS) -O binary \
288		$(if $(CONFIG_SPL_X86_16BIT_INIT),-R .start16 -R .resetvec)
289
290$(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE
291	$(call if_changed,objcopy)
292
293OBJCOPYFLAGS_u-boot-x86-16bit-spl.bin := -O binary -j .start16 -j .resetvec
294$(obj)/u-boot-x86-16bit-spl.bin: $(obj)/u-boot-spl FORCE
295	$(call if_changed,objcopy)
296
297LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
298
299# Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
300LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
301
302# First try the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
303ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
304LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
305else
306# And then fall back to just testing for SPL_TEXT_BASE, even if in TPL mode
307ifneq ($(CONFIG_SPL_TEXT_BASE),)
308LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
309endif
310endif
311
312MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage
313$(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
314	$(call if_changed,mkimage)
315
316quiet_cmd_mksunxiboot = MKSUNXI $@
317cmd_mksunxiboot = $(objtree)/tools/mksunxiboot \
318			--default-dt $(CONFIG_DEFAULT_DEVICE_TREE) $< $@
319$(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE
320	$(call if_changed,mksunxiboot)
321
322quiet_cmd_sunxi_spl_image_builder = SUNXI_SPL_IMAGE_BUILDER $@
323cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
324				-c $(CONFIG_NAND_SUNXI_SPL_ECC_STRENGTH)/$(CONFIG_NAND_SUNXI_SPL_ECC_SIZE) \
325				-p $(CONFIG_SYS_NAND_PAGE_SIZE) \
326				-o $(CONFIG_SYS_NAND_OOBSIZE) \
327				-u $(CONFIG_NAND_SUNXI_SPL_USABLE_PAGE_SIZE) \
328				-e $(CONFIG_SYS_NAND_BLOCK_SIZE) \
329				-s -b $< $@
330$(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin
331	$(call if_changed,sunxi_spl_image_builder)
332
333# Rule to link u-boot-spl
334# May be overridden by arch/$(ARCH)/config.mk
335quiet_cmd_u-boot-spl ?= LD      $@
336      cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
337		       $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
338		       $(patsubst $(obj)/%,%,$(u-boot-spl-main))  \
339		       $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
340		       --end-group \
341		       $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
342
343$(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
344		$(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
345	$(call if_changed,u-boot-spl)
346
347$(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
348
349PHONY += $(u-boot-spl-dirs)
350$(u-boot-spl-dirs): $(u-boot-spl-platdata)
351	$(Q)$(MAKE) $(build)=$@
352
353quiet_cmd_cpp_lds = LDS     $@
354cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
355		-D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $<
356
357$(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
358	$(call if_changed_dep,cpp_lds)
359
360# read all saved command lines
361
362targets := $(wildcard $(sort $(targets)))
363cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
364
365ifneq ($(cmd_files),)
366  $(cmd_files): ;	# Do not try to update included dependency files
367  include $(cmd_files)
368endif
369
370PHONY += FORCE
371FORCE:
372
373PHONY += dtbs
374dtbs:
375	$(Q)$(MAKE) $(build)=dts dtbs
376
377# Declare the contents of the .PHONY variable as phony.  We keep that
378# information in a variable so we can use it in if_changed and friends.
379.PHONY: $(PHONY)
380
381SHRUNK_ARCH_DTB = $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
382.SECONDEXPANSION:
383$(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, arch/$(ARCH)/dts/%, $$@)
384	$(call if_changed,fdtgrep)
385
386MKIMAGEFLAGS_$(SPL_BIN).multidtb.fit = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
387	-n "Multi DTB fit image for $(SPL_BIN)" -E \
388	$(patsubst %,-b %,$(SHRUNK_ARCH_DTB))
389
390$(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
391	$(call if_changed,mkimage)
392
393$(obj)/$(SPL_BIN).multidtb.fit.gz: $(obj)/$(SPL_BIN).multidtb.fit
394	@gzip -kf9 $< > $@
395
396$(obj)/$(SPL_BIN).multidtb.fit.lzo: $(obj)/$(SPL_BIN).multidtb.fit
397	@lzop -f9 $< > $@
398