6b985d1e4ac76121e1f6df99f51eff7f652a1561
[platform/kernel/u-boot.git] / spl / Makefile
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
17 src := $(obj)
18
19 # Create output directory if not already present
20 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
21
22 include $(srctree)/scripts/Kbuild.include
23
24 CONFIG_SPL_BUILD := y
25 export CONFIG_SPL_BUILD
26
27 KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
28 ifeq ($(CONFIG_TPL_BUILD),y)
29 KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
30 endif
31
32 # Enable garbage collection of un-used sections for SPL
33 KBUILD_CFLAGS += -ffunction-sections -fdata-sections
34 LDFLAGS_FINAL += --gc-sections
35
36 ifeq ($(CONFIG_TPL_BUILD),y)
37 export CONFIG_TPL_BUILD
38 SPL_BIN := u-boot-tpl
39 else
40 SPL_BIN := u-boot-spl
41 endif
42
43 include $(TOPDIR)/config.mk
44
45 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n)
46
47 ifdef   CONFIG_SPL_START_S_PATH
48 START_PATH := $(CONFIG_SPL_START_S_PATH:"%"=%)
49 else
50 START_PATH := $(CPUDIR)
51 endif
52
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
57
58 LIBS-y += arch/$(ARCH)/lib/
59
60 LIBS-y += $(CPUDIR)/
61
62 ifdef SOC
63 LIBS-y += $(CPUDIR)/$(SOC)/
64 endif
65 LIBS-y += board/$(BOARDDIR)/
66 LIBS-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
67
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/
78 LIBS-y += fs/
79 LIBS-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
80 LIBS-$(CONFIG_SPL_POWER_SUPPORT) += drivers/power/ \
81         drivers/power/pmic/
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/
97
98 ifneq (,$(CONFIG_MX23)$(CONFIG_MX35)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
99 LIBS-y += arch/$(ARCH)/imx-common/
100 endif
101
102 LIBS-$(CONFIG_ARM) += arch/arm/cpu/
103 LIBS-$(CONFIG_PPC) += arch/powerpc/cpu/
104
105 LIBS-y := $(patsubst %/, %/built-in.o, $(LIBS-y))
106
107 # Add GCC lib
108 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
109 PLATFORM_LIBS := $(SPLTREE)/arch/$(ARCH)/lib/lib.a
110 endif
111
112 LIBS-y := $(sort $(LIBS-y))
113
114 __START := $(head-y)
115 __LIBS := $(LIBS-y)
116
117 START := $(addprefix $(obj)/,$(head-y))
118 LIBS := $(addprefix $(obj)/,$(LIBS-y))
119
120 # Linker Script
121 ifdef CONFIG_SPL_LDSCRIPT
122 # need to strip off double quotes
123 LDSCRIPT := $(addprefix $(SRCTREE)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
124 endif
125
126 ifeq ($(wildcard $(LDSCRIPT)),)
127         LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-spl.lds
128 endif
129 ifeq ($(wildcard $(LDSCRIPT)),)
130         LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-spl.lds
131 endif
132 ifeq ($(wildcard $(LDSCRIPT)),)
133         LDSCRIPT := $(TOPDIR)/arch/$(ARCH)/cpu/u-boot-spl.lds
134 endif
135 ifeq ($(wildcard $(LDSCRIPT)),)
136 $(error could not find linker script)
137 endif
138
139 # Special flags for CPP when processing the linker script.
140 # Pass the version down so we can handle backwards compatibility
141 # on the fly.
142 LDPPFLAGS += \
143         -include $(TOPDIR)/include/u-boot/u-boot.lds.h \
144         -include $(OBJTREE)/include/config.h \
145         -DCPUDIR=$(CPUDIR) \
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')
148
149 $(OBJTREE)/MLO: $(obj)/u-boot-spl.bin
150         $(OBJTREE)/tools/mkimage -T omapimage \
151                 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
152
153 $(OBJTREE)/MLO.byteswap: $(obj)/u-boot-spl.bin
154         $(OBJTREE)/tools/mkimage -T omapimage -n byteswap \
155                 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
156
157 $(objtree)/SPL : $(obj)/u-boot-spl.bin
158                 $(MAKE) $(build)=spl/arch/arm/imx-common $@
159
160 ALL-y   += $(obj)/$(SPL_BIN).bin
161
162 ifdef CONFIG_SAMSUNG
163 ALL-y   += $(obj)/$(BOARD)-spl.bin
164 endif
165
166 all:    $(ALL-y)
167
168 ifdef CONFIG_SAMSUNG
169 ifdef CONFIG_VAR_SIZE_SPL
170 VAR_SIZE_PARAM = --vs
171 else
172 VAR_SIZE_PARAM =
173 endif
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) $< $@
178 endif
179
180 $(obj)/$(SPL_BIN).bin:  $(obj)/$(SPL_BIN)
181         $(OBJCOPY) $(OBJCFLAGS) $(SPL_OBJCFLAGS) -O binary $< $@
182
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)
186 endif
187
188 GEN_UBOOT = \
189         cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \
190                 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
191                 -Map $(SPL_BIN).map -o $(SPL_BIN)
192
193 $(obj)/$(SPL_BIN): $(START) $(LIBS) $(obj)/u-boot-spl.lds
194         $(GEN_UBOOT)
195
196 $(START):
197         @:
198
199 $(LIBS):
200         $(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
201
202 # FIX ME
203 cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
204
205 $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
206         $(CPP) $(cpp_flags) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@
207
208 PHONY += FORCE
209 FORCE:
210
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.
213 .PHONY: $(PHONY)