]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - spl/Makefile
ARM: imx-common: convert makefiles to Kbuild style
[karo-tx-uboot.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 CONFIG_SPL_BUILD := y
18 export CONFIG_SPL_BUILD
19
20 ifeq ($(CONFIG_TPL_BUILD),y)
21 export CONFIG_TPL_BUILD
22 SPL_BIN := u-boot-tpl
23 else
24 SPL_BIN := u-boot-spl
25 endif
26
27 include $(TOPDIR)/config.mk
28
29 # We want the final binaries in this directory
30 ifeq ($(CONFIG_TPL_BUILD),y)
31 obj := $(OBJTREE)/tpl/
32 SPLTREE := $(TPLTREE)
33 else
34 obj := $(OBJTREE)/spl/
35 endif
36
37 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n)
38
39 ifdef   CONFIG_SPL_START_S_PATH
40 START_PATH := $(subst ",,$(CONFIG_SPL_START_S_PATH))
41 else
42 START_PATH := $(CPUDIR)
43 endif
44
45 START := $(START_PATH)/start.o
46 ifeq ($(CPU),x86)
47 START += $(START_PATH)/start16.o
48 START += $(START_PATH)/resetvec.o
49 endif
50 ifeq ($(CPU),ppc4xx)
51 START += $(START_PATH)/resetvec.o
52 endif
53 ifeq ($(CPU),mpc85xx)
54 START += $(START_PATH)/resetvec.o
55 endif
56
57 LIBS-y += arch/$(ARCH)/lib/lib$(ARCH).o
58
59 LIBS-y += $(CPUDIR)/lib$(CPU).o
60 ifeq ($(CPU),mpc83xx)
61 LIBS-y += arch/powerpc/cpu/mpc8xxx/lib8xxx.o
62 endif
63 ifeq ($(CPU),mpc85xx)
64 LIBS-y += arch/powerpc/cpu/mpc8xxx/lib8xxx.o
65 ifdef CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT
66 LIBS-y += arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
67 endif
68 endif
69 ifeq ($(CPU),mpc86xx)
70 LIBS-y += arch/powerpc/cpu/mpc8xxx/lib8xxx.o
71 endif
72
73 ifdef SOC
74 LIBS-y += $(CPUDIR)/$(SOC)/lib$(SOC).o
75 endif
76 LIBS-y += board/$(BOARDDIR)/lib$(BOARD).o
77 LIBS-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/lib$(VENDOR).o
78
79 LIBS-$(CONFIG_SPL_FRAMEWORK) += common/spl/libspl.o
80 LIBS-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/libcommon.o
81 LIBS-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/libdisk.o
82 LIBS-$(CONFIG_SPL_I2C_SUPPORT) += drivers/i2c/libi2c.o
83 LIBS-$(CONFIG_SPL_GPIO_SUPPORT) += drivers/gpio/libgpio.o
84 LIBS-$(CONFIG_SPL_MMC_SUPPORT) += drivers/mmc/libmmc.o
85 LIBS-$(CONFIG_SPL_SERIAL_SUPPORT) += drivers/serial/libserial.o
86 LIBS-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += drivers/mtd/spi/libspi_flash.o
87 LIBS-$(CONFIG_SPL_SPI_SUPPORT) += drivers/spi/libspi.o
88 LIBS-$(CONFIG_SPL_FAT_SUPPORT) += fs/fat/libfat.o
89 LIBS-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/libgeneric.o
90 LIBS-$(CONFIG_SPL_POWER_SUPPORT) += drivers/power/libpower.o \
91         drivers/power/pmic/libpmic.o
92 LIBS-$(CONFIG_SPL_NAND_SUPPORT) += drivers/mtd/nand/libnand.o
93 LIBS-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/libonenand.o
94 LIBS-$(CONFIG_SPL_DMA_SUPPORT) += drivers/dma/libdma.o
95 LIBS-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/memory.o
96 LIBS-$(CONFIG_SPL_NET_SUPPORT) += net/libnet.o
97 LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/libnet.o
98 LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/libphy.o
99 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/libphy.o
100 LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/libusb_musb-new.o
101 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/libusb_gadget.o
102 LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/libwatchdog.o
103
104 ifneq ($(CONFIG_OMAP_COMMON),)
105 LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
106 endif
107
108 ifneq (,$(CONFIG_MX23)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
109 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
110 endif
111
112 ifneq ($(CONFIG_TEGRA),)
113 LIBS-y += arch/$(ARCH)/cpu/$(SOC)-common/lib$(SOC)-common.o
114 LIBS-y += arch/$(ARCH)/cpu/tegra-common/libcputegra-common.o
115 LIBS-y += $(CPUDIR)/tegra-common/libtegra-common.o
116 endif
117
118 ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
119 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
120 endif
121
122 ifeq ($(SOC),exynos)
123 LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
124 endif
125
126 # Add GCC lib
127 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
128 PLATFORM_LIBGCC = $(SPLTREE)/arch/$(ARCH)/lib/libgcc.o
129 PLATFORM_LIBS := $(filter-out %/libgcc.o, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
130 endif
131
132 START := $(addprefix $(SPLTREE)/,$(START))
133 LIBS := $(addprefix $(SPLTREE)/,$(sort $(LIBS-y)))
134
135 __START := $(subst $(obj),,$(START))
136 __LIBS := $(subst $(obj),,$(LIBS))
137
138 # Linker Script
139 ifdef CONFIG_SPL_LDSCRIPT
140 # need to strip off double quotes
141 LDSCRIPT := $(addprefix $(SRCTREE)/,$(subst ",,$(CONFIG_SPL_LDSCRIPT)))
142 endif
143
144 ifeq ($(wildcard $(LDSCRIPT)),)
145         LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-spl.lds
146 endif
147 ifeq ($(wildcard $(LDSCRIPT)),)
148         LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-spl.lds
149 endif
150 ifeq ($(wildcard $(LDSCRIPT)),)
151         LDSCRIPT := $(TOPDIR)/arch/$(ARCH)/cpu/u-boot-spl.lds
152 endif
153 ifeq ($(wildcard $(LDSCRIPT)),)
154 $(error could not find linker script)
155 endif
156
157 build := -f $(TOPDIR)/scripts/Makefile.build -C
158
159 # Special flags for CPP when processing the linker script.
160 # Pass the version down so we can handle backwards compatibility
161 # on the fly.
162 LDPPFLAGS += \
163         -include $(TOPDIR)/include/u-boot/u-boot.lds.h \
164         -include $(OBJTREE)/include/config.h \
165         -DCPUDIR=$(CPUDIR) \
166         $(shell $(LD) --version | \
167           sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
168
169 $(OBJTREE)/MLO: $(obj)u-boot-spl.bin
170         $(OBJTREE)/tools/mkimage -T omapimage \
171                 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
172
173 $(OBJTREE)/MLO.byteswap: $(obj)u-boot-spl.bin
174         $(OBJTREE)/tools/mkimage -T omapimage -n byteswap \
175                 -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
176
177 $(OBJTREE)/SPL : $(obj)u-boot-spl.bin depend
178                 $(MAKE) $(build) $(SRCTREE)/arch/arm/imx-common $@
179
180 ALL-y   += $(obj)$(SPL_BIN).bin
181
182 ifdef CONFIG_SAMSUNG
183 ALL-y   += $(obj)$(BOARD)-spl.bin
184 endif
185
186 all:    $(ALL-y)
187
188 ifdef CONFIG_SAMSUNG
189 $(obj)$(BOARD)-spl.bin: $(obj)u-boot-spl.bin
190         $(OBJTREE)/tools/mk$(BOARD)spl \
191                 $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin
192 endif
193
194 $(obj)$(SPL_BIN).bin:   $(obj)$(SPL_BIN)
195         $(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
196
197 GEN_UBOOT = \
198         cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \
199                 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
200                 -Map $(SPL_BIN).map -o $(SPL_BIN)
201
202 $(obj)$(SPL_BIN):       depend $(START) $(LIBS) $(obj)u-boot-spl.lds
203         $(GEN_UBOOT)
204
205 # Tentative step for Kbuild-style makefiles coexist with conventional U-Boot style makefiles
206 #  U-Boot conventional sub makefiles always include some other makefiles.
207 #  So, the build system searches a line beginning with "include" before entering into the sub makefile
208 #  in order to distinguish which style it is.
209 #  If the Makefile include a "include" line, we assume it is an U-Boot style makefile.
210 #  Otherwise, it is treated as a Kbuild-style makefile.
211 select_makefile = \
212         if grep -q "^include" $1/Makefile; then                         \
213                 $(MAKE) -C $1;                                          \
214         else                                                            \
215                 $(MAKE) -C $1 -f $(TOPDIR)/scripts/Makefile.build;      \
216                 mv $(dir $@)built-in.o $@;                              \
217         fi
218
219 # We do not need to build $(START) explicitly.
220 # It is built while we are at $(CPUDIR)/lib$(CPU).o build.
221 $(START):       depend
222         if grep -q "^include" $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))Makefile; then \
223                 $(MAKE) -C $(SRCTREE)/$(START_PATH) $@; \
224         fi
225
226 $(LIBS):        depend
227         +$(call select_makefile, $(SRCTREE)$(dir $(subst $(SPLTREE),,$@)))
228
229 $(obj)u-boot-spl.lds: $(LDSCRIPT) depend
230         $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@
231
232 depend: $(obj).depend
233 .PHONY: depend
234
235 # defines $(obj).depend target
236 include $(SRCTREE)/rules.mk