Makefile.spl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. # SPDX-License-Identifier: GPL-2.0+
  2. #
  3. # (C) Copyright 2000-2011
  4. # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. #
  6. # (C) Copyright 2011
  7. # Daniel Schwierzeck, daniel.schwierzeck@googlemail.com.
  8. #
  9. # (C) Copyright 2011
  10. # Texas Instruments Incorporated - http://www.ti.com/
  11. # Aneesh V <aneesh@ti.com>
  12. # Based on top-level Makefile.
  13. #
  14. src := $(obj)
  15. # Create output directory if not already present
  16. _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
  17. include $(srctree)/scripts/Kbuild.include
  18. -include include/config/auto.conf
  19. -include $(obj)/include/autoconf.mk
  20. UBOOTINCLUDE := -I$(obj)/include $(UBOOTINCLUDE)
  21. KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
  22. ifeq ($(CONFIG_TPL_BUILD),y)
  23. KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
  24. else
  25. ifeq ($(CONFIG_VPL_BUILD),y)
  26. KBUILD_CPPFLAGS += -DCONFIG_VPL_BUILD
  27. endif
  28. endif
  29. ifeq ($(CONFIG_VPL_BUILD),y)
  30. SPL_BIN := u-boot-vpl
  31. SPL_NAME := vpl
  32. else
  33. ifeq ($(CONFIG_TPL_BUILD),y)
  34. SPL_BIN := u-boot-tpl
  35. SPL_NAME := tpl
  36. else
  37. SPL_BIN := u-boot-spl
  38. SPL_NAME := spl
  39. endif
  40. endif
  41. export SPL_NAME
  42. ifdef CONFIG_SPL_BUILD
  43. SPL_ := SPL_
  44. ifeq ($(CONFIG_VPL_BUILD),y)
  45. SPL_TPL_ := VPL_
  46. else
  47. ifeq ($(CONFIG_TPL_BUILD),y)
  48. SPL_TPL_ := TPL_
  49. else
  50. SPL_TPL_ := SPL_
  51. endif
  52. endif
  53. else
  54. SPL_ :=
  55. SPL_TPL_ :=
  56. endif
  57. ifeq ($(obj)$(CONFIG_SUPPORT_SPL),spl)
  58. $(error You cannot build SPL without enabling CONFIG_SUPPORT_SPL)
  59. endif
  60. ifeq ($(obj)$(CONFIG_SUPPORT_TPL),tpl)
  61. $(error You cannot build TPL without enabling CONFIG_SUPPORT_TPL)
  62. endif
  63. ifeq ($(obj)$(CONFIG_SUPPORT_VPL),vpl)
  64. $(error You cannot build VPL without enabling CONFIG_SUPPORT_VPL)
  65. endif
  66. include $(srctree)/config.mk
  67. include $(srctree)/arch/$(ARCH)/Makefile
  68. include $(srctree)/scripts/Makefile.lib
  69. # Enable garbage collection of un-used sections for SPL
  70. KBUILD_CFLAGS += -ffunction-sections -fdata-sections
  71. LDFLAGS_FINAL += --gc-sections
  72. ifeq ($(CONFIG_$(SPL_TPL_)STACKPROTECTOR),y)
  73. KBUILD_CFLAGS += -fstack-protector-strong
  74. else
  75. KBUILD_CFLAGS += -fno-stack-protector
  76. endif
  77. # FIX ME
  78. cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  79. $(NOSTDINC_FLAGS)
  80. c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
  81. HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
  82. libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
  83. libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
  84. ifeq ($(CONFIG_TPL_BUILD),y)
  85. libs-$(CONFIG_TPL_FRAMEWORK) += common/spl/
  86. else
  87. libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
  88. endif
  89. libs-y += common/init/
  90. # Special handling for a few options which support SPL/TPL/VPL
  91. libs-$(CONFIG_$(SPL_TPL_)LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
  92. libs-$(CONFIG_$(SPL_TPL_)LIBGENERIC_SUPPORT) += lib/
  93. ifdef CONFIG_SPL_FRAMEWORK
  94. libs-$(CONFIG_PARTITIONS) += disk/
  95. endif
  96. libs-y += drivers/
  97. libs-$(CONFIG_SPL_MEMORY) += drivers/memory/
  98. libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
  99. libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
  100. libs-y += dts/
  101. libs-y += fs/
  102. libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
  103. libs-$(CONFIG_SPL_NET) += net/
  104. libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
  105. head-y := $(addprefix $(obj)/,$(head-y))
  106. libs-y := $(addprefix $(obj)/,$(libs-y))
  107. u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
  108. libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
  109. # Add GCC lib
  110. ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
  111. PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
  112. PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
  113. endif
  114. u-boot-spl-init := $(head-y)
  115. u-boot-spl-main := $(libs-y)
  116. ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
  117. platdata-hdr := include/generated/dt-structs-gen.h include/generated/dt-decl.h
  118. platdata-inst := $(obj)/dts/dt-uclass.o $(obj)/dts/dt-device.o
  119. platdata-noinst := $(obj)/dts/dt-plat.o
  120. ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA_INST
  121. u-boot-spl-platdata := $(platdata-inst)
  122. u-boot-spl-old-platdata := $(platdata-noinst)
  123. else
  124. u-boot-spl-platdata := $(platdata-noinst)
  125. u-boot-spl-old-platdata := $(platdata-inst)
  126. endif
  127. # Files we need to generate
  128. u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
  129. # Files we won't generate and should remove
  130. u-boot-spl-old-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-old-platdata))
  131. endif # OF_PLATDATA
  132. # Linker Script
  133. # First test whether there's a linker-script for the specific stage defined...
  134. ifneq ($(CONFIG_$(SPL_TPL_)LDSCRIPT),)
  135. # need to strip off double quotes
  136. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_$(SPL_TPL_)LDSCRIPT:"%"=%))
  137. else
  138. # ...then fall back to the generic SPL linker-script
  139. ifneq ($(CONFIG_SPL_LDSCRIPT),)
  140. # need to strip off double quotes
  141. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
  142. endif
  143. endif
  144. ifeq ($(wildcard $(LDSCRIPT)),)
  145. LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds
  146. endif
  147. ifeq ($(wildcard $(LDSCRIPT)),)
  148. LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds
  149. endif
  150. ifeq ($(wildcard $(LDSCRIPT)),)
  151. LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds
  152. endif
  153. ifeq ($(wildcard $(LDSCRIPT)),)
  154. $(error could not find linker script)
  155. endif
  156. # Special flags for CPP when processing the linker script.
  157. # Pass the version down so we can handle backwards compatibility
  158. # on the fly.
  159. LDPPFLAGS += \
  160. -include $(srctree)/include/u-boot/u-boot.lds.h \
  161. -include $(objtree)/include/config.h \
  162. -DCPUDIR=$(CPUDIR) \
  163. $(shell $(LD) --version | \
  164. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  165. # Turn various CONFIG symbols into IMAGE symbols for easy reuse of
  166. # the scripts between SPL, TPL and VPL.
  167. ifneq ($(CONFIG_$(SPL_TPL_)MAX_SIZE),0x0)
  168. LDPPFLAGS += -DIMAGE_MAX_SIZE=$(CONFIG_$(SPL_TPL_)MAX_SIZE)
  169. endif
  170. ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
  171. LDPPFLAGS += -DIMAGE_TEXT_BASE=$(CONFIG_$(SPL_TPL_)TEXT_BASE)
  172. endif
  173. MKIMAGEOUTPUT ?= /dev/null
  174. quiet_cmd_mkimage = MKIMAGE $@
  175. cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
  176. >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
  177. quiet_cmd_mkfitimage = MKIMAGE $@
  178. cmd_mkfitimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -f $(SPL_ITS) -E $@ \
  179. $(if $(KBUILD_VERBOSE:1=), MKIMAGEOUTPUT)
  180. MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE)
  181. MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
  182. MLO MLO.byteswap: $(obj)/u-boot-spl.bin FORCE
  183. $(call if_changed,mkimage)
  184. ifeq ($(CONFIG_SYS_SOC),"at91")
  185. MKIMAGEFLAGS_boot.bin = -T atmelimage
  186. ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y)
  187. MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params)
  188. $(obj)/boot.bin: $(obj)/../tools/atmel_pmecc_params
  189. endif
  190. $(obj)/boot.bin: $(obj)/u-boot-spl.bin FORCE
  191. $(call if_changed,mkimage)
  192. else
  193. ifdef CONFIG_ARCH_ZYNQ
  194. MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE)
  195. endif
  196. ifdef CONFIG_ARCH_ZYNQMP
  197. ifneq ($(CONFIG_PMUFW_INIT_FILE),"")
  198. spl/boot.bin: zynqmp-check-pmufw
  199. zynqmp-check-pmufw: FORCE
  200. ( cd $(srctree) && test -r $(CONFIG_PMUFW_INIT_FILE) ) \
  201. || ( echo "Cannot read $(CONFIG_PMUFW_INIT_FILE)" && false )
  202. endif
  203. MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) \
  204. -n "$(shell cd $(srctree); readlink -f $(CONFIG_PMUFW_INIT_FILE))"
  205. endif
  206. $(obj)/$(SPL_BIN)-align.bin: $(obj)/$(SPL_BIN).bin
  207. @dd if=$< of=$@ conv=block,sync bs=4 2>/dev/null;
  208. spl/boot.bin: $(obj)/$(SPL_BIN)-align.bin FORCE
  209. $(call if_changed,mkimage)
  210. endif
  211. INPUTS-y += $(obj)/$(SPL_BIN).bin $(obj)/$(SPL_BIN).sym
  212. ifneq ($(CONFIG_ARCH_EXYNOS)$(CONFIG_ARCH_S5PC1XX),)
  213. INPUTS-y += $(obj)/$(BOARD)-spl.bin
  214. endif
  215. ifneq ($(CONFIG_TARGET_SOCFPGA_GEN5)$(CONFIG_TARGET_SOCFPGA_ARRIA10),)
  216. INPUTS-y += $(obj)/$(SPL_BIN).sfp
  217. endif
  218. INPUTS-$(CONFIG_TARGET_SOCFPGA_SOC64) += $(obj)/u-boot-spl-dtb.hex
  219. ifdef CONFIG_ARCH_SUNXI
  220. INPUTS-y += $(obj)/sunxi-spl.bin
  221. ifdef CONFIG_NAND_SUNXI
  222. INPUTS-y += $(obj)/sunxi-spl-with-ecc.bin
  223. endif
  224. endif
  225. ifeq ($(CONFIG_SYS_SOC),"at91")
  226. INPUTS-y += $(obj)/boot.bin
  227. endif
  228. ifndef CONFIG_VPL_BUILD
  229. ifdef CONFIG_TPL_BUILD
  230. INPUTS-$(CONFIG_TPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-tpl.bin \
  231. $(obj)/u-boot-x86-reset16-tpl.bin
  232. else
  233. INPUTS-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-spl.bin \
  234. $(obj)/u-boot-x86-reset16-spl.bin
  235. endif
  236. endif
  237. INPUTS-$(CONFIG_ARCH_ZYNQ) += $(obj)/boot.bin
  238. INPUTS-$(CONFIG_ARCH_ZYNQMP) += $(obj)/boot.bin
  239. INPUTS-$(CONFIG_ARCH_MEDIATEK) += $(obj)/u-boot-spl-mtk.bin
  240. all: $(INPUTS-y)
  241. quiet_cmd_cat = CAT $@
  242. cmd_cat = cat $(filter-out $(PHONY), $^) > $@
  243. quiet_cmd_copy = COPY $@
  244. cmd_copy = cp $< $@
  245. ifneq ($(CONFIG_SPL_MULTI_DTB_FIT),y)
  246. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).dtb
  247. else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_LZO),y)
  248. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.lzo
  249. else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_GZIP),y)
  250. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.gz
  251. else
  252. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit
  253. endif
  254. # Build the .dtb file if needed
  255. # - OF_REAL is enabled
  256. # - we have either OF_SEPARATE or OF_HOSTFILE
  257. build_dtb :=
  258. ifneq ($(CONFIG_$(SPL_TPL_)OF_REAL),)
  259. ifeq ($(CONFIG_OF_SEPARATE)$(CONFIG_SANDBOX),y)
  260. build_dtb := y
  261. endif
  262. endif
  263. ifneq ($(build_dtb),)
  264. $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
  265. $(if $(CONFIG_$(SPL_TPL_)SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
  266. $(FINAL_DTB_CONTAINER) FORCE
  267. $(call if_changed,cat)
  268. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
  269. $(call if_changed,copy)
  270. else
  271. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE
  272. $(call if_changed,copy)
  273. endif
  274. # Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end
  275. $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN)
  276. @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
  277. dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null;
  278. $(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE
  279. $(call if_changed,copy)
  280. pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
  281. DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
  282. -d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
  283. ifneq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA_INST),)
  284. DTOC_ARGS += -i
  285. endif
  286. quiet_cmd_dtoc = DTOC $@
  287. cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
  288. quiet_cmd_plat = PLAT $@
  289. cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@)
  290. $(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c $(platdata-hdr)
  291. $(call if_changed,plat)
  292. # Don't use dts_dir here, since it forces running this expensive rule every time
  293. $(platdata-hdr) $(u-boot-spl-platdata_c) &: $(obj)/$(SPL_BIN).dtb FORCE
  294. @[ -d $(obj)/dts ] || mkdir -p $(obj)/dts
  295. @# Remove old files since which ones we generate depends on the setting
  296. @# of OF_PLATDATA_INST and this might change between builds. Leaving old
  297. @# ones around is confusing and it is possible that switching the
  298. @# setting again will use the old one instead of regenerating it.
  299. @rm -f $(u-boot-spl-old-platdata_c) $(u-boot-spl-platdata_c) \
  300. $(u-boot-spl-old-platdata)
  301. $(call if_changed,dtoc)
  302. ifneq ($(CONFIG_ARCH_EXYNOS)$(CONFIG_ARCH_S5PC1XX),)
  303. ifeq ($(CONFIG_EXYNOS5420),y)
  304. VAR_SIZE_PARAM = --vs
  305. else
  306. VAR_SIZE_PARAM =
  307. endif
  308. $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
  309. $(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
  310. $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
  311. $(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
  312. endif
  313. quiet_cmd_objcopy = OBJCOPY $@
  314. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  315. OBJCOPYFLAGS_$(SPL_BIN)-nodtb.bin = $(SPL_OBJCFLAGS) -O binary \
  316. $(if $(CONFIG_$(SPL_TPL_)X86_16BIT_INIT),-R .start16 -R .resetvec)
  317. $(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE
  318. $(call if_changed,objcopy)
  319. OBJCOPYFLAGS_u-boot-x86-start16-spl.bin := -O binary -j .start16
  320. $(obj)/u-boot-x86-start16-spl.bin: $(obj)/u-boot-spl FORCE
  321. $(call if_changed,objcopy)
  322. OBJCOPYFLAGS_u-boot-x86-start16-tpl.bin := -O binary -j .start16
  323. $(obj)/u-boot-x86-start16-tpl.bin: $(obj)/u-boot-tpl FORCE
  324. $(call if_changed,objcopy)
  325. OBJCOPYFLAGS_u-boot-x86-reset16-spl.bin := -O binary -j .resetvec
  326. $(obj)/u-boot-x86-reset16-spl.bin: $(obj)/u-boot-spl FORCE
  327. $(call if_changed,objcopy)
  328. OBJCOPYFLAGS_u-boot-x86-reset16-tpl.bin := -O binary -j .resetvec
  329. $(obj)/u-boot-x86-reset16-tpl.bin: $(obj)/u-boot-tpl FORCE
  330. $(call if_changed,objcopy)
  331. LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
  332. # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
  333. LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
  334. LDFLAGS_$(SPL_BIN) += --build-id=none
  335. # Pick the best match (e.g. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
  336. ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
  337. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
  338. endif
  339. ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
  340. MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage_v1
  341. else
  342. MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage
  343. endif
  344. $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
  345. $(call if_changed,mkimage)
  346. MKIMAGEFLAGS_sunxi-spl.bin = \
  347. -A $(ARCH) \
  348. -T $(CONFIG_SPL_IMAGE_TYPE) \
  349. -a $(CONFIG_SPL_TEXT_BASE) \
  350. -n $(CONFIG_DEFAULT_DEVICE_TREE)
  351. OBJCOPYFLAGS_u-boot-spl-dtb.hex := -I binary -O ihex --change-address=$(CONFIG_SPL_TEXT_BASE)
  352. $(obj)/u-boot-spl-dtb.hex: $(obj)/u-boot-spl-dtb.bin FORCE
  353. $(call if_changed,objcopy)
  354. $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE
  355. $(call if_changed,mkimage)
  356. quiet_cmd_sunxi_spl_image_builder = SUNXI_SPL_IMAGE_BUILDER $@
  357. cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
  358. -c $(CONFIG_NAND_SUNXI_SPL_ECC_STRENGTH)/$(CONFIG_NAND_SUNXI_SPL_ECC_SIZE) \
  359. -p $(CONFIG_SYS_NAND_PAGE_SIZE) \
  360. -o $(CONFIG_SYS_NAND_OOBSIZE) \
  361. -u $(CONFIG_NAND_SUNXI_SPL_USABLE_PAGE_SIZE) \
  362. -e $(CONFIG_SYS_NAND_BLOCK_SIZE) \
  363. -s -b $< $@
  364. $(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin
  365. $(call if_changed,sunxi_spl_image_builder)
  366. # MediaTek's specific SPL build
  367. MKIMAGEFLAGS_u-boot-spl-mtk.bin = -T mtk_image \
  368. -a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) \
  369. -n "$(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO))"
  370. $(obj)/u-boot-spl-mtk.bin: $(obj)/u-boot-spl.bin FORCE
  371. $(call if_changed,mkimage)
  372. quiet_cmd_sym ?= SYM $@
  373. cmd_sym ?= $(OBJDUMP) -t $< > $@
  374. $(obj)/$(SPL_BIN).sym: $(obj)/$(SPL_BIN) FORCE
  375. $(call if_changed,sym)
  376. # Generate linker list symbols references to force compiler to not optimize
  377. # them away when compiling with LTO
  378. ifdef CONFIG_LTO
  379. u-boot-spl-keep-syms-lto := $(obj)/keep-syms-lto.o
  380. u-boot-spl-keep-syms-lto_c := \
  381. $(patsubst $(obj)/%.o,$(obj)/%.c,$(u-boot-spl-keep-syms-lto))
  382. quiet_cmd_keep_syms_lto = KSL $@
  383. cmd_keep_syms_lto = \
  384. $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@
  385. quiet_cmd_keep_syms_lto_cc = KSLCC $@
  386. cmd_keep_syms_lto_cc = \
  387. $(CC) $(filter-out $(LTO_CFLAGS),$(c_flags)) -c -o $@ $<
  388. $(u-boot-spl-keep-syms-lto_c): $(u-boot-spl-main) $(u-boot-spl-platdata)
  389. $(call if_changed,keep_syms_lto)
  390. $(u-boot-spl-keep-syms-lto): $(u-boot-spl-keep-syms-lto_c)
  391. $(call if_changed,keep_syms_lto_cc)
  392. else
  393. u-boot-spl-keep-syms-lto :=
  394. endif
  395. # Rule to link u-boot-spl
  396. # May be overridden by arch/$(ARCH)/config.mk
  397. ifeq ($(LTO_ENABLE),y)
  398. quiet_cmd_u-boot-spl ?= LTO $@
  399. cmd_u-boot-spl ?= \
  400. ( \
  401. cd $(obj) && \
  402. $(CC) -nostdlib -nostartfiles $(LTO_FINAL_LDFLAGS) $(c_flags) \
  403. $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_$(@F):%=-Wl,%) \
  404. $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
  405. -Wl,--whole-archive \
  406. $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
  407. $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
  408. $(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto)) \
  409. $(PLATFORM_LIBS) \
  410. -Wl,--no-whole-archive \
  411. -Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN) \
  412. )
  413. else
  414. quiet_cmd_u-boot-spl ?= LD $@
  415. cmd_u-boot-spl ?= \
  416. ( \
  417. cd $(obj) && \
  418. $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F)) \
  419. $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
  420. --whole-archive \
  421. $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
  422. $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
  423. --no-whole-archive \
  424. $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN) \
  425. )
  426. endif
  427. $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
  428. $(u-boot-spl-main) $(u-boot-spl-keep-syms-lto) \
  429. $(obj)/u-boot-spl.lds FORCE
  430. $(call if_changed,u-boot-spl)
  431. $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
  432. PHONY += $(u-boot-spl-dirs)
  433. $(u-boot-spl-dirs): $(u-boot-spl-platdata) prepare
  434. $(Q)$(MAKE) $(build)=$@
  435. PHONY += prepare
  436. prepare:
  437. $(Q)$(MAKE) $(build)=$(obj)/.
  438. quiet_cmd_cpp_lds = LDS $@
  439. cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
  440. -D__ASSEMBLY__ -x assembler-with-cpp -std=c99 -P -o $@ $<
  441. $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
  442. $(call if_changed_dep,cpp_lds)
  443. # read all saved command lines
  444. targets := $(wildcard $(sort $(targets)))
  445. cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  446. ifneq ($(cmd_files),)
  447. $(cmd_files): ; # Do not try to update included dependency files
  448. include $(cmd_files)
  449. endif
  450. PHONY += FORCE
  451. FORCE:
  452. $(obj)/dts/dt-$(SPL_NAME).dtb: dts/dt.dtb
  453. $(Q)$(MAKE) $(build)=$(obj)/dts spl_dtbs
  454. PHONY += dts_dir
  455. dts_dir:
  456. $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
  457. # Declare the contents of the .PHONY variable as phony. We keep that
  458. # information in a variable so we can use it in if_changed and friends.
  459. .PHONY: $(PHONY)
  460. SPL_OF_LIST_TARGETS = $(patsubst %,dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
  461. SHRUNK_ARCH_DTB = $(addprefix $(obj)/,$(SPL_OF_LIST_TARGETS))
  462. .SECONDEXPANSION:
  463. $(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, arch/$(ARCH)/dts/%, $$@) dts_dir
  464. $(call if_changed,fdtgrep)
  465. targets += $(SPL_OF_LIST_TARGETS)
  466. MKIMAGEFLAGS_$(SPL_BIN).multidtb.fit = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
  467. -n "Multi DTB fit image for $(SPL_BIN)" -E \
  468. $(patsubst %,-b %,$(SHRUNK_ARCH_DTB))
  469. $(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
  470. $(call if_changed,mkimage)
  471. ifneq ($(SOURCE_DATE_EPOCH),)
  472. touch -d @$(SOURCE_DATE_EPOCH) $(obj)/$(SPL_BIN).multidtb.fit
  473. chmod 0600 $(obj)/$(SPL_BIN).multidtb.fit
  474. endif
  475. $(obj)/$(SPL_BIN).multidtb.fit.gz: $(obj)/$(SPL_BIN).multidtb.fit
  476. @gzip -kf9 $< > $@
  477. $(obj)/$(SPL_BIN).multidtb.fit.lzo: $(obj)/$(SPL_BIN).multidtb.fit
  478. @lzop -f9 $< > $@
  479. ifdef CONFIG_ARCH_K3
  480. tispl.bin: $(obj)/u-boot-spl-nodtb.bin $(SHRUNK_ARCH_DTB) $(SPL_ITS) FORCE
  481. $(call if_changed,mkfitimage)
  482. endif