2 # (C) Copyright 2000-2011
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 # Daniel Schwierzeck, daniel.schwierzeck@googlemail.com.
9 # Texas Instruments Incorporated - http://www.ti.com/
10 # Aneesh V <aneesh@ti.com>
12 # SPDX-License-Identifier: GPL-2.0+
14 # Based on top-level Makefile.
19 # Create output directory if not already present
20 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
22 include $(srctree)/scripts/Kbuild.include
25 export CONFIG_SPL_BUILD
27 KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
28 ifeq ($(CONFIG_TPL_BUILD),y)
29 KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
32 # Enable garbage collection of un-used sections for SPL
33 KBUILD_CFLAGS += -ffunction-sections -fdata-sections
34 LDFLAGS_FINAL += --gc-sections
36 ifeq ($(CONFIG_TPL_BUILD),y)
37 export CONFIG_TPL_BUILD
43 include $(TOPDIR)/config.mk
45 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n)
47 ifdef CONFIG_SPL_START_S_PATH
48 START_PATH := $(CONFIG_SPL_START_S_PATH:"%"=%)
50 START_PATH := $(CPUDIR)
53 head-y := $(START_PATH)/start.o
54 head-$(CONFIG_X86) += $(START_PATH)/start16.o $(START_PATH)/resetvec.o
55 head-$(CONFIG_4xx) += $(START_PATH)/resetvec.o
56 head-$(CONFIG_MPC85xx) += $(START_PATH)/resetvec.o
58 LIBS-y += arch/$(ARCH)/lib/
63 LIBS-y += $(CPUDIR)/$(SOC)/
65 LIBS-y += board/$(BOARDDIR)/
66 LIBS-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
68 LIBS-$(CONFIG_SPL_FRAMEWORK) += common/spl/
69 LIBS-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/
70 LIBS-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
71 LIBS-$(CONFIG_SPL_I2C_SUPPORT) += drivers/i2c/
72 LIBS-$(CONFIG_SPL_GPIO_SUPPORT) += drivers/gpio/
73 LIBS-$(CONFIG_SPL_MMC_SUPPORT) += drivers/mmc/
74 LIBS-$(CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT) += drivers/ddr/fsl/
75 LIBS-$(CONFIG_SPL_SERIAL_SUPPORT) += drivers/serial/
76 LIBS-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += drivers/mtd/spi/
77 LIBS-$(CONFIG_SPL_SPI_SUPPORT) += drivers/spi/
79 LIBS-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
80 LIBS-$(CONFIG_SPL_POWER_SUPPORT) += drivers/power/ \
82 LIBS-$(if $(CONFIG_CMD_NAND),$(CONFIG_SPL_NAND_SUPPORT)) += drivers/mtd/nand/
83 LIBS-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += drivers/misc/
84 LIBS-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/
85 LIBS-$(CONFIG_SPL_DMA_SUPPORT) += drivers/dma/
86 LIBS-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
87 LIBS-$(CONFIG_SPL_NET_SUPPORT) += net/
88 LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/
89 LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/
90 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/
91 LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/
92 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/
93 LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/
94 LIBS-$(CONFIG_SPL_USB_HOST_SUPPORT) += drivers/usb/host/
95 LIBS-$(CONFIG_OMAP_USB_PHY) += drivers/usb/phy/
96 LIBS-$(CONFIG_SPL_SATA_SUPPORT) += drivers/block/
98 ifneq (,$(CONFIG_MX23)$(CONFIG_MX35)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
99 LIBS-y += arch/$(ARCH)/imx-common/
102 LIBS-$(CONFIG_ARM) += arch/arm/cpu/
103 LIBS-$(CONFIG_PPC) += arch/powerpc/cpu/
105 LIBS-y := $(patsubst %/, %/built-in.o, $(LIBS-y))
108 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
109 PLATFORM_LIBS := $(SPLTREE)/arch/$(ARCH)/lib/lib.a
112 LIBS-y := $(sort $(LIBS-y))
117 START := $(addprefix $(obj)/,$(head-y))
118 LIBS := $(addprefix $(obj)/,$(LIBS-y))
121 ifdef CONFIG_SPL_LDSCRIPT
122 # need to strip off double quotes
123 LDSCRIPT := $(addprefix $(SRCTREE)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
126 ifeq ($(wildcard $(LDSCRIPT)),)
127 LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-spl.lds
129 ifeq ($(wildcard $(LDSCRIPT)),)
130 LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-spl.lds
132 ifeq ($(wildcard $(LDSCRIPT)),)
133 LDSCRIPT := $(TOPDIR)/arch/$(ARCH)/cpu/u-boot-spl.lds
135 ifeq ($(wildcard $(LDSCRIPT)),)
136 $(error could not find linker script)
139 # Special flags for CPP when processing the linker script.
140 # Pass the version down so we can handle backwards compatibility
143 -include $(TOPDIR)/include/u-boot/u-boot.lds.h \
144 -include $(OBJTREE)/include/config.h \
146 $(shell $(LD) --version | \
147 sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
149 $(OBJTREE)/MLO: $(obj)/u-boot-spl.bin
150 $(OBJTREE)/tools/mkimage -T omapimage \
151 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
153 $(OBJTREE)/MLO.byteswap: $(obj)/u-boot-spl.bin
154 $(OBJTREE)/tools/mkimage -T omapimage -n byteswap \
155 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
157 $(objtree)/SPL : $(obj)/u-boot-spl.bin
158 $(MAKE) $(build)=spl/arch/arm/imx-common $@
160 ALL-y += $(obj)/$(SPL_BIN).bin
163 ALL-y += $(obj)/$(BOARD)-spl.bin
169 ifdef CONFIG_VAR_SIZE_SPL
170 VAR_SIZE_PARAM = --vs
174 $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
175 $(if $(wildcard $(OBJTREE)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
176 $(OBJTREE)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
177 $(OBJTREE)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
180 $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)
181 $(OBJCOPY) $(OBJCFLAGS) $(SPL_OBJCFLAGS) -O binary $< $@
183 LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
184 ifneq ($(CONFIG_SPL_TEXT_BASE),)
185 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
189 cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \
190 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
191 -Map $(SPL_BIN).map -o $(SPL_BIN)
193 $(obj)/$(SPL_BIN): $(START) $(LIBS) $(obj)/u-boot-spl.lds
200 $(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
203 cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
205 $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
206 $(CPP) $(cpp_flags) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@
211 # Declare the contents of the .PHONY variable as phony. We keep that
212 # information in a variable so we can use it in if_changed and friends.