Makefile.spl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 $(srctree)/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 += $(if $(BOARDDIR),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-$(CONFIG_SPL_MTD_SUPPORT) += drivers/mtd/
  87. libs-$(if $(CONFIG_CMD_NAND),$(CONFIG_SPL_NAND_SUPPORT)) += drivers/mtd/nand/
  88. libs-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += drivers/misc/
  89. libs-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/
  90. libs-$(CONFIG_SPL_DMA_SUPPORT) += drivers/dma/
  91. libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
  92. libs-$(CONFIG_SPL_NET_SUPPORT) += net/
  93. libs-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/
  94. libs-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/
  95. libs-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/
  96. libs-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/
  97. libs-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/
  98. libs-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/
  99. libs-$(CONFIG_SPL_USB_HOST_SUPPORT) += drivers/usb/host/
  100. libs-$(CONFIG_OMAP_USB_PHY) += drivers/usb/phy/
  101. libs-$(CONFIG_SPL_SATA_SUPPORT) += drivers/block/
  102. ifneq (,$(CONFIG_MX23)$(CONFIG_MX35)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
  103. libs-y += arch/$(ARCH)/imx-common/
  104. endif
  105. libs-$(CONFIG_ARM) += arch/arm/cpu/
  106. libs-$(CONFIG_PPC) += arch/powerpc/cpu/
  107. head-y := $(addprefix $(obj)/,$(head-y))
  108. libs-y := $(addprefix $(obj)/,$(libs-y))
  109. u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
  110. libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
  111. # Add GCC lib
  112. ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
  113. PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
  114. PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
  115. endif
  116. u-boot-spl-init := $(head-y)
  117. u-boot-spl-main := $(libs-y)
  118. # Linker Script
  119. ifdef CONFIG_SPL_LDSCRIPT
  120. # need to strip off double quotes
  121. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
  122. endif
  123. ifeq ($(wildcard $(LDSCRIPT)),)
  124. LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds
  125. endif
  126. ifeq ($(wildcard $(LDSCRIPT)),)
  127. LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds
  128. endif
  129. ifeq ($(wildcard $(LDSCRIPT)),)
  130. LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds
  131. endif
  132. ifeq ($(wildcard $(LDSCRIPT)),)
  133. $(error could not find linker script)
  134. endif
  135. # Special flags for CPP when processing the linker script.
  136. # Pass the version down so we can handle backwards compatibility
  137. # on the fly.
  138. LDPPFLAGS += \
  139. -include $(srctree)/include/u-boot/u-boot.lds.h \
  140. -include $(objtree)/include/config.h \
  141. -DCPUDIR=$(CPUDIR) \
  142. $(shell $(LD) --version | \
  143. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  144. quiet_cmd_mkimage = MKIMAGE $@
  145. cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
  146. $(if $(KBUILD_VERBOSE:1=), >/dev/null)
  147. MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE)
  148. MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
  149. MLO MLO.byteswap: $(obj)/u-boot-spl.bin
  150. $(call if_changed,mkimage)
  151. MKIMAGEFLAGS_boot.bin = -T atmelimage
  152. ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y)
  153. MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params)
  154. boot.bin: $(obj)/../tools/atmel_pmecc_params
  155. endif
  156. boot.bin: $(obj)/u-boot-spl.bin
  157. $(call if_changed,mkimage)
  158. ALL-y += $(obj)/$(SPL_BIN).bin
  159. ifdef CONFIG_SAMSUNG
  160. ALL-y += $(obj)/$(BOARD)-spl.bin
  161. endif
  162. ifdef CONFIG_SUNXI
  163. ifndef CONFIG_SPL_FEL
  164. ALL-y += $(obj)/sunxi-spl.bin
  165. endif
  166. endif
  167. all: $(ALL-y)
  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. quiet_cmd_objcopy = OBJCOPY $@
  180. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  181. OBJCOPYFLAGS_$(SPL_BIN).bin = $(SPL_OBJCFLAGS) -O binary
  182. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN) FORCE
  183. $(call if_changed,objcopy)
  184. LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
  185. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  186. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  187. endif
  188. ifdef CONFIG_SUNXI
  189. quiet_cmd_mksunxiboot = MKSUNXI $@
  190. cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@
  191. $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin
  192. $(call if_changed,mksunxiboot)
  193. endif
  194. quiet_cmd_u-boot-spl = LD $@
  195. cmd_u-boot-spl = cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
  196. $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
  197. $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --end-group \
  198. $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)
  199. $(obj)/$(SPL_BIN): $(u-boot-spl-init) $(u-boot-spl-main) $(obj)/u-boot-spl.lds
  200. $(call cmd,u-boot-spl)
  201. $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
  202. PHONY += $(u-boot-spl-dirs)
  203. $(u-boot-spl-dirs):
  204. $(Q)$(MAKE) $(build)=$@
  205. quiet_cmd_cpp_lds = LDS $@
  206. cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
  207. -D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $<
  208. $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
  209. $(call if_changed_dep,cpp_lds)
  210. # read all saved command lines
  211. targets := $(wildcard $(sort $(targets)))
  212. cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  213. ifneq ($(cmd_files),)
  214. $(cmd_files): ; # Do not try to update included dependency files
  215. include $(cmd_files)
  216. endif
  217. PHONY += FORCE
  218. FORCE:
  219. # Declare the contents of the .PHONY variable as phony. We keep that
  220. # information in a variable so we can use it in if_changed and friends.
  221. .PHONY: $(PHONY)