Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. src := $(obj)
  17. # Create output directory if not already present
  18. _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
  19. include $(srctree)/scripts/Kbuild.include
  20. CONFIG_SPL_BUILD := y
  21. export CONFIG_SPL_BUILD
  22. KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
  23. ifeq ($(CONFIG_TPL_BUILD),y)
  24. KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
  25. endif
  26. ifeq ($(CONFIG_TPL_BUILD),y)
  27. export CONFIG_TPL_BUILD
  28. SPL_BIN := u-boot-tpl
  29. else
  30. SPL_BIN := u-boot-spl
  31. endif
  32. include include/config.mk
  33. ifeq ($(CONFIG_TPL_BUILD),y)
  34. -include include/tpl-autoconf.mk
  35. else
  36. -include include/spl-autoconf.mk
  37. endif
  38. include $(TOPDIR)/config.mk
  39. # Enable garbage collection of un-used sections for SPL
  40. KBUILD_CFLAGS += -ffunction-sections -fdata-sections
  41. LDFLAGS_FINAL += --gc-sections
  42. # FIX ME
  43. cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  44. $(NOSTDINC_FLAGS)
  45. c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
  46. # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
  47. quiet_cmd_autoconf = GEN $@
  48. cmd_autoconf = \
  49. $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
  50. sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
  51. rm $@.tmp
  52. include/tpl-autoconf.mk: include/config.h
  53. $(call cmd,autoconf)
  54. include/spl-autoconf.mk: include/config.h
  55. $(call cmd,autoconf)
  56. HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(SRCTREE)/board/$(VENDOR)/common/Makefile),y,n)
  57. ifdef CONFIG_SPL_START_S_PATH
  58. START_PATH := $(CONFIG_SPL_START_S_PATH:"%"=%)
  59. else
  60. START_PATH := $(CPUDIR)
  61. endif
  62. head-y := $(START_PATH)/start.o
  63. head-$(CONFIG_X86) += $(START_PATH)/start16.o $(START_PATH)/resetvec.o
  64. head-$(CONFIG_4xx) += $(START_PATH)/resetvec.o
  65. head-$(CONFIG_MPC85xx) += $(START_PATH)/resetvec.o
  66. libs-y += arch/$(ARCH)/lib/
  67. libs-y += $(CPUDIR)/
  68. ifdef SOC
  69. libs-y += $(CPUDIR)/$(SOC)/
  70. endif
  71. libs-y += board/$(BOARDDIR)/
  72. libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
  73. libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
  74. libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/
  75. libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
  76. libs-$(CONFIG_SPL_I2C_SUPPORT) += drivers/i2c/
  77. libs-$(CONFIG_SPL_GPIO_SUPPORT) += drivers/gpio/
  78. libs-$(CONFIG_SPL_MMC_SUPPORT) += drivers/mmc/
  79. libs-$(CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT) += drivers/ddr/fsl/
  80. libs-$(CONFIG_SPL_SERIAL_SUPPORT) += drivers/serial/
  81. libs-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += drivers/mtd/spi/
  82. libs-$(CONFIG_SPL_SPI_SUPPORT) += drivers/spi/
  83. libs-y += fs/
  84. libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
  85. libs-$(CONFIG_SPL_POWER_SUPPORT) += drivers/power/ drivers/power/pmic/
  86. libs-$(if $(CONFIG_CMD_NAND),$(CONFIG_SPL_NAND_SUPPORT)) += drivers/mtd/nand/
  87. libs-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += drivers/misc/
  88. libs-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/
  89. libs-$(CONFIG_SPL_DMA_SUPPORT) += drivers/dma/
  90. libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
  91. libs-$(CONFIG_SPL_NET_SUPPORT) += net/
  92. libs-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/
  93. libs-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/
  94. libs-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/
  95. libs-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/
  96. libs-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/
  97. libs-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/
  98. libs-$(CONFIG_SPL_USB_HOST_SUPPORT) += drivers/usb/host/
  99. libs-$(CONFIG_OMAP_USB_PHY) += drivers/usb/phy/
  100. libs-$(CONFIG_SPL_SATA_SUPPORT) += drivers/block/
  101. ifneq (,$(CONFIG_MX23)$(CONFIG_MX35)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
  102. libs-y += arch/$(ARCH)/imx-common/
  103. endif
  104. libs-$(CONFIG_ARM) += arch/arm/cpu/
  105. libs-$(CONFIG_PPC) += arch/powerpc/cpu/
  106. head-y := $(addprefix $(obj)/,$(head-y))
  107. libs-y := $(addprefix $(obj)/,$(libs-y))
  108. u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
  109. libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
  110. # Add GCC lib
  111. ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
  112. PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
  113. PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
  114. endif
  115. u-boot-spl-init := $(head-y)
  116. u-boot-spl-main := $(libs-y)
  117. # Linker Script
  118. ifdef CONFIG_SPL_LDSCRIPT
  119. # need to strip off double quotes
  120. LDSCRIPT := $(addprefix $(SRCTREE)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
  121. endif
  122. ifeq ($(wildcard $(LDSCRIPT)),)
  123. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-spl.lds
  124. endif
  125. ifeq ($(wildcard $(LDSCRIPT)),)
  126. LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-spl.lds
  127. endif
  128. ifeq ($(wildcard $(LDSCRIPT)),)
  129. LDSCRIPT := $(TOPDIR)/arch/$(ARCH)/cpu/u-boot-spl.lds
  130. endif
  131. ifeq ($(wildcard $(LDSCRIPT)),)
  132. $(error could not find linker script)
  133. endif
  134. # Special flags for CPP when processing the linker script.
  135. # Pass the version down so we can handle backwards compatibility
  136. # on the fly.
  137. LDPPFLAGS += \
  138. -include $(TOPDIR)/include/u-boot/u-boot.lds.h \
  139. -include $(OBJTREE)/include/config.h \
  140. -DCPUDIR=$(CPUDIR) \
  141. $(shell $(LD) --version | \
  142. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  143. quiet_cmd_mkimage = UIMAGE $@
  144. cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
  145. $(if $(KBUILD_VERBOSE:1=), >/dev/null)
  146. MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE)
  147. MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
  148. MLO MLO.byteswap: $(obj)/u-boot-spl.bin
  149. $(call if_changed,mkimage)
  150. ALL-y += $(obj)/$(SPL_BIN).bin
  151. ifdef CONFIG_SAMSUNG
  152. ALL-y += $(obj)/$(BOARD)-spl.bin
  153. endif
  154. all: $(ALL-y)
  155. ifdef CONFIG_SAMSUNG
  156. ifdef CONFIG_VAR_SIZE_SPL
  157. VAR_SIZE_PARAM = --vs
  158. else
  159. VAR_SIZE_PARAM =
  160. endif
  161. $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
  162. $(if $(wildcard $(OBJTREE)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
  163. $(OBJTREE)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
  164. $(OBJTREE)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
  165. endif
  166. quiet_cmd_objcopy = OBJCOPY $@
  167. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  168. OBJCOPYFLAGS_$(SPL_BIN).bin = $(SPL_OBJCFLAGS) -O binary
  169. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN) FORCE
  170. $(call if_changed,objcopy)
  171. LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
  172. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  173. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  174. endif
  175. quiet_cmd_u-boot-spl = LD $@
  176. cmd_u-boot-spl = cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
  177. $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
  178. $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --end-group \
  179. $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)
  180. $(obj)/$(SPL_BIN): $(u-boot-spl-init) $(u-boot-spl-main) $(obj)/u-boot-spl.lds
  181. $(call cmd,u-boot-spl)
  182. $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
  183. PHONY += $(u-boot-spl-dirs)
  184. $(u-boot-spl-dirs):
  185. $(Q)$(MAKE) $(build)=$@
  186. quiet_cmd_cpp_lds = LDS $@
  187. cmd_cpp_lds = $(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ \
  188. -x assembler-with-cpp -P -o $@ $<
  189. $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
  190. $(call if_changed,cpp_lds)
  191. # read all saved command lines
  192. targets := $(wildcard $(sort $(targets)))
  193. cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  194. ifneq ($(cmd_files),)
  195. $(cmd_files): ; # Do not try to update included dependency files
  196. include $(cmd_files)
  197. endif
  198. PHONY += FORCE
  199. FORCE:
  200. # Declare the contents of the .PHONY variable as phony. We keep that
  201. # information in a variable so we can use it in if_changed and friends.
  202. .PHONY: $(PHONY)