Fork of the vendor (Boundary Devices) u-boot for Reform 2, with minor tweaks. The goal is to migrate to mainstream u-boot or barebox ASAP. The main impediment so far is the 4GB RAM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

410 lines
12 KiB

  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. KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
  21. ifeq ($(CONFIG_TPL_BUILD),y)
  22. KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
  23. endif
  24. ifeq ($(CONFIG_TPL_BUILD),y)
  25. SPL_BIN := u-boot-tpl
  26. else
  27. SPL_BIN := u-boot-spl
  28. endif
  29. ifdef CONFIG_SPL_BUILD
  30. SPL_ := SPL_
  31. ifeq ($(CONFIG_TPL_BUILD),y)
  32. SPL_TPL_ := TPL_
  33. else
  34. SPL_TPL_ := SPL_
  35. endif
  36. else
  37. SPL_ :=
  38. SPL_TPL_ :=
  39. endif
  40. include $(srctree)/config.mk
  41. include $(srctree)/arch/$(ARCH)/Makefile
  42. include $(srctree)/scripts/Makefile.lib
  43. # Enable garbage collection of un-used sections for SPL
  44. KBUILD_CFLAGS += -ffunction-sections -fdata-sections
  45. LDFLAGS_FINAL += --gc-sections
  46. # FIX ME
  47. cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  48. $(NOSTDINC_FLAGS)
  49. c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
  50. HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
  51. libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
  52. libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
  53. libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
  54. libs-y += common/init/
  55. # Special handling for a few options which support SPL/TPL
  56. ifeq ($(CONFIG_TPL_BUILD),y)
  57. libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
  58. libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/
  59. else
  60. libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
  61. libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
  62. endif
  63. libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
  64. libs-y += drivers/
  65. libs-$(CONFIG_SPL_USB_GADGET_SUPPORT) += drivers/usb/dwc3/
  66. libs-y += dts/
  67. libs-y += fs/
  68. libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
  69. libs-$(CONFIG_SPL_NET_SUPPORT) += net/
  70. head-y := $(addprefix $(obj)/,$(head-y))
  71. libs-y := $(addprefix $(obj)/,$(libs-y))
  72. u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
  73. libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
  74. # Add GCC lib
  75. ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
  76. PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
  77. PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
  78. endif
  79. u-boot-spl-init := $(head-y)
  80. u-boot-spl-main := $(libs-y)
  81. ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
  82. u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
  83. endif
  84. # Linker Script
  85. # First test whether there's a linker-script for the specific stage defined...
  86. ifneq ($(CONFIG_$(SPL_TPL_)LDSCRIPT),)
  87. # need to strip off double quotes
  88. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_$(SPL_TPL_)LDSCRIPT:"%"=%))
  89. else
  90. # ...then fall back to the generic SPL linker-script
  91. ifneq ($(CONFIG_SPL_LDSCRIPT),)
  92. # need to strip off double quotes
  93. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%))
  94. endif
  95. endif
  96. ifeq ($(wildcard $(LDSCRIPT)),)
  97. LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds
  98. endif
  99. ifeq ($(wildcard $(LDSCRIPT)),)
  100. LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds
  101. endif
  102. ifeq ($(wildcard $(LDSCRIPT)),)
  103. LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds
  104. endif
  105. ifeq ($(wildcard $(LDSCRIPT)),)
  106. $(error could not find linker script)
  107. endif
  108. # Special flags for CPP when processing the linker script.
  109. # Pass the version down so we can handle backwards compatibility
  110. # on the fly.
  111. LDPPFLAGS += \
  112. -include $(srctree)/include/u-boot/u-boot.lds.h \
  113. -include $(objtree)/include/config.h \
  114. -DCPUDIR=$(CPUDIR) \
  115. $(shell $(LD) --version | \
  116. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  117. MKIMAGEOUTPUT ?= /dev/null
  118. quiet_cmd_mkimage = MKIMAGE $@
  119. cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
  120. >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
  121. MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE)
  122. MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
  123. MLO MLO.byteswap: $(obj)/u-boot-spl.bin FORCE
  124. $(call if_changed,mkimage)
  125. ifeq ($(CONFIG_SYS_SOC),"at91")
  126. MKIMAGEFLAGS_boot.bin = -T atmelimage
  127. ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y)
  128. MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params)
  129. boot.bin: $(obj)/../tools/atmel_pmecc_params
  130. endif
  131. boot.bin: $(obj)/u-boot-spl.bin FORCE
  132. $(call if_changed,mkimage)
  133. else
  134. ifdef CONFIG_ARCH_ZYNQ
  135. MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE)
  136. endif
  137. ifdef CONFIG_ARCH_ZYNQMP
  138. ifneq ($(CONFIG_PMUFW_INIT_FILE),"")
  139. spl/boot.bin: zynqmp-check-pmufw
  140. zynqmp-check-pmufw: FORCE
  141. ( cd $(srctree) && test -r $(CONFIG_PMUFW_INIT_FILE) ) \
  142. || ( echo "Cannot read $(CONFIG_PMUFW_INIT_FILE)" && false )
  143. endif
  144. MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) \
  145. -n "$(shell cd $(srctree); readlink -f $(CONFIG_PMUFW_INIT_FILE))"
  146. endif
  147. spl/boot.bin: $(obj)/u-boot-spl.bin FORCE
  148. $(call if_changed,mkimage)
  149. endif
  150. ALL-y += $(obj)/$(SPL_BIN).bin
  151. ifdef CONFIG_SAMSUNG
  152. ALL-y += $(obj)/$(BOARD)-spl.bin
  153. endif
  154. ifdef CONFIG_ARCH_SOCFPGA
  155. ALL-y += $(obj)/$(SPL_BIN).sfp
  156. endif
  157. ifdef CONFIG_ARCH_SUNXI
  158. ALL-y += $(obj)/sunxi-spl.bin
  159. ifdef CONFIG_NAND_SUNXI
  160. ALL-y += $(obj)/sunxi-spl-with-ecc.bin
  161. endif
  162. endif
  163. ifeq ($(CONFIG_SYS_SOC),"at91")
  164. ALL-y += boot.bin
  165. endif
  166. ALL-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-16bit-spl.bin
  167. ALL-$(CONFIG_ARCH_ZYNQ) += $(obj)/boot.bin
  168. ALL-$(CONFIG_ARCH_ZYNQMP) += $(obj)/boot.bin
  169. all: $(ALL-y)
  170. quiet_cmd_cat = CAT $@
  171. cmd_cat = cat $(filter-out $(PHONY), $^) > $@
  172. quiet_cmd_copy = COPY $@
  173. cmd_copy = cp $< $@
  174. ifneq ($(CONFIG_SPL_MULTI_DTB_FIT),y)
  175. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).dtb
  176. else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_LZO),y)
  177. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.lzo
  178. else ifeq ($(CONFIG_SPL_MULTI_DTB_FIT_GZIP),y)
  179. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit.gz
  180. else
  181. FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit
  182. endif
  183. ifeq ($(CONFIG_$(SPL_TPL_)OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_$(SPL_TPL_)OF_PLATDATA),yy)
  184. $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
  185. $(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
  186. $(FINAL_DTB_CONTAINER) FORCE
  187. $(call if_changed,cat)
  188. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
  189. $(call if_changed,copy)
  190. else
  191. $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE
  192. $(call if_changed,copy)
  193. endif
  194. # Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end
  195. $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN)
  196. @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
  197. dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null;
  198. $(obj)/$(SPL_BIN).dtb: dts/dt-spl.dtb FORCE
  199. $(call if_changed,copy)
  200. pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
  201. quiet_cmd_dtocc = DTOC C $@
  202. cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
  203. quiet_cmd_dtoch = DTOC H $@
  204. cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct
  205. quiet_cmd_plat = PLAT $@
  206. cmd_plat = $(CC) $(c_flags) -c $< -o $@
  207. $(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \
  208. include/generated/dt-structs-gen.h
  209. $(call if_changed,plat)
  210. PHONY += dts_dir
  211. dts_dir:
  212. $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
  213. include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
  214. $(call if_changed,dtoch)
  215. $(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
  216. $(call if_changed,dtocc)
  217. ifdef CONFIG_SAMSUNG
  218. ifdef CONFIG_VAR_SIZE_SPL
  219. VAR_SIZE_PARAM = --vs
  220. else
  221. VAR_SIZE_PARAM =
  222. endif
  223. $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
  224. $(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
  225. $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
  226. $(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
  227. endif
  228. quiet_cmd_objcopy = OBJCOPY $@
  229. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  230. OBJCOPYFLAGS_$(SPL_BIN)-nodtb.bin = $(SPL_OBJCFLAGS) -O binary \
  231. $(if $(CONFIG_SPL_X86_16BIT_INIT),-R .start16 -R .resetvec)
  232. $(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE
  233. $(call if_changed,objcopy)
  234. OBJCOPYFLAGS_u-boot-x86-16bit-spl.bin := -O binary -j .start16 -j .resetvec
  235. $(obj)/u-boot-x86-16bit-spl.bin: $(obj)/u-boot-spl FORCE
  236. $(call if_changed,objcopy)
  237. LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
  238. # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
  239. LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
  240. # First try the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
  241. ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
  242. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
  243. else
  244. # And then fall back to just testing for SPL_TEXT_BASE, even if in TPL mode
  245. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  246. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  247. endif
  248. endif
  249. ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
  250. MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage_v1
  251. else
  252. MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage
  253. endif
  254. $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
  255. $(call if_changed,mkimage)
  256. quiet_cmd_mksunxiboot = MKSUNXI $@
  257. cmd_mksunxiboot = $(objtree)/tools/mksunxiboot \
  258. --default-dt $(CONFIG_DEFAULT_DEVICE_TREE) $< $@
  259. $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE
  260. $(call if_changed,mksunxiboot)
  261. quiet_cmd_sunxi_spl_image_builder = SUNXI_SPL_IMAGE_BUILDER $@
  262. cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
  263. -c $(CONFIG_NAND_SUNXI_SPL_ECC_STRENGTH)/$(CONFIG_NAND_SUNXI_SPL_ECC_SIZE) \
  264. -p $(CONFIG_SYS_NAND_PAGE_SIZE) \
  265. -o $(CONFIG_SYS_NAND_OOBSIZE) \
  266. -u $(CONFIG_NAND_SUNXI_SPL_USABLE_PAGE_SIZE) \
  267. -e $(CONFIG_SYS_NAND_BLOCK_SIZE) \
  268. -s -b $< $@
  269. $(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin
  270. $(call if_changed,sunxi_spl_image_builder)
  271. # Rule to link u-boot-spl
  272. # May be overridden by arch/$(ARCH)/config.mk
  273. quiet_cmd_u-boot-spl ?= LD $@
  274. cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
  275. $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
  276. $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
  277. $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
  278. --end-group \
  279. $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
  280. $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
  281. $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
  282. $(call if_changed,u-boot-spl)
  283. $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
  284. PHONY += $(u-boot-spl-dirs)
  285. $(u-boot-spl-dirs): $(u-boot-spl-platdata)
  286. $(Q)$(MAKE) $(build)=$@
  287. quiet_cmd_cpp_lds = LDS $@
  288. cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
  289. -D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $<
  290. $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
  291. $(call if_changed_dep,cpp_lds)
  292. # read all saved command lines
  293. targets := $(wildcard $(sort $(targets)))
  294. cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  295. ifneq ($(cmd_files),)
  296. $(cmd_files): ; # Do not try to update included dependency files
  297. include $(cmd_files)
  298. endif
  299. PHONY += FORCE
  300. FORCE:
  301. PHONY += dtbs
  302. dtbs:
  303. $(Q)$(MAKE) $(build)=dts dtbs
  304. # Declare the contents of the .PHONY variable as phony. We keep that
  305. # information in a variable so we can use it in if_changed and friends.
  306. .PHONY: $(PHONY)
  307. SHRUNK_ARCH_DTB = $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
  308. .SECONDEXPANSION:
  309. $(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, arch/$(ARCH)/dts/%, $$@)
  310. $(call if_changed,fdtgrep)
  311. MKIMAGEFLAGS_$(SPL_BIN).multidtb.fit = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
  312. -n "Multi DTB fit image for $(SPL_BIN)" -E \
  313. $(patsubst %,-b %,$(SHRUNK_ARCH_DTB))
  314. $(obj)/$(SPL_BIN).multidtb.fit: /dev/null $(SHRUNK_ARCH_DTB) FORCE
  315. $(call if_changed,mkimage)
  316. ifneq ($(SOURCE_DATE_EPOCH),)
  317. touch -d @$(SOURCE_DATE_EPOCH) $(obj)/$(SPL_BIN).multidtb.fit
  318. chmod 0600 $(obj)/$(SPL_BIN).multidtb.fit
  319. endif
  320. $(obj)/$(SPL_BIN).multidtb.fit.gz: $(obj)/$(SPL_BIN).multidtb.fit
  321. @gzip -kf9 $< > $@
  322. $(obj)/$(SPL_BIN).multidtb.fit.lzo: $(obj)/$(SPL_BIN).multidtb.fit
  323. @lzop -f9 $< > $@