config.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. #
  2. # (C) Copyright 2000-2013
  3. # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0+
  6. #
  7. #########################################################################
  8. # Set shell to bash if possible, otherwise fall back to sh
  9. SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  10. else if [ -x /bin/bash ]; then echo /bin/bash; \
  11. else echo sh; fi; fi)
  12. export SHELL
  13. ifeq ($(CONFIG_TPL_BUILD),y)
  14. SPL_BIN := u-boot-tpl
  15. else
  16. SPL_BIN := u-boot-spl
  17. endif
  18. ifeq ($(CURDIR),$(SRCTREE))
  19. dir :=
  20. else
  21. dir := $(subst $(SRCTREE)/,,$(CURDIR))
  22. endif
  23. ifneq ($(OBJTREE),$(SRCTREE))
  24. # Create object files for SPL in a separate directory
  25. ifeq ($(CONFIG_SPL_BUILD),y)
  26. ifeq ($(CONFIG_TPL_BUILD),y)
  27. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  28. else
  29. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  30. endif
  31. else
  32. obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
  33. endif
  34. src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
  35. $(shell mkdir -p $(obj))
  36. else
  37. # Create object files for SPL in a separate directory
  38. ifeq ($(CONFIG_SPL_BUILD),y)
  39. ifeq ($(CONFIG_TPL_BUILD),y)
  40. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  41. else
  42. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  43. endif
  44. $(shell mkdir -p $(obj))
  45. else
  46. obj :=
  47. endif
  48. src :=
  49. endif
  50. # clean the slate ...
  51. PLATFORM_RELFLAGS =
  52. PLATFORM_CPPFLAGS =
  53. PLATFORM_LDFLAGS =
  54. #########################################################################
  55. HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
  56. $(HOSTCPPFLAGS)
  57. HOSTSTRIP = strip
  58. #
  59. # Mac OS X / Darwin's C preprocessor is Apple specific. It
  60. # generates numerous errors and warnings. We want to bypass it
  61. # and use GNU C's cpp. To do this we pass the -traditional-cpp
  62. # option to the compiler. Note that the -traditional-cpp flag
  63. # DOES NOT have the same semantics as GNU C's flag, all it does
  64. # is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
  65. #
  66. # Apple's linker is similar, thanks to the new 2 stage linking
  67. # multiple symbol definitions are treated as errors, hence the
  68. # -multiply_defined suppress option to turn off this error.
  69. #
  70. ifeq ($(HOSTOS),darwin)
  71. # get major and minor product version (e.g. '10' and '6' for Snow Leopard)
  72. DARWIN_MAJOR_VERSION = $(shell sw_vers -productVersion | cut -f 1 -d '.')
  73. DARWIN_MINOR_VERSION = $(shell sw_vers -productVersion | cut -f 2 -d '.')
  74. os_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
  75. $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
  76. # Snow Leopards build environment has no longer restrictions as described above
  77. HOSTCC = $(call os_x_before, 10, 5, "cc", "gcc")
  78. HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
  79. HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
  80. else
  81. HOSTCC = gcc
  82. endif
  83. ifeq ($(HOSTOS),cygwin)
  84. HOSTCFLAGS += -ansi
  85. endif
  86. # We build some files with extra pedantic flags to try to minimize things
  87. # that won't build on some weird host compiler -- though there are lots of
  88. # exceptions for files that aren't complaint.
  89. HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
  90. HOSTCFLAGS += -pedantic
  91. #########################################################################
  92. #
  93. # Option checker, gcc version (courtesy linux kernel) to ensure
  94. # only supported compiler options are used
  95. #
  96. CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
  97. CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
  98. -include $(CC_OPTIONS_CACHE_FILE)
  99. cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
  100. if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
  101. > /dev/null 2>&1; then \
  102. echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
  103. echo "$(1)"; fi)
  104. ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
  105. cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
  106. else
  107. cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
  108. $(if $(call cc-option-sys,$1),$1,$2)))
  109. endif
  110. # cc-version
  111. # Usage gcc-ver := $(call cc-version)
  112. cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC))
  113. binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh $(AS))
  114. dtc-version = $(shell $(SHELL) $(SRCTREE)/tools/dtc-version.sh $(DTC))
  115. #
  116. # Include the make variables (CC, etc...)
  117. #
  118. AS = $(CROSS_COMPILE)as
  119. # Always use GNU ld
  120. LD = $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
  121. then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)
  122. CC = $(CROSS_COMPILE)gcc
  123. CPP = $(CC) -E
  124. AR = $(CROSS_COMPILE)ar
  125. NM = $(CROSS_COMPILE)nm
  126. LDR = $(CROSS_COMPILE)ldr
  127. STRIP = $(CROSS_COMPILE)strip
  128. OBJCOPY = $(CROSS_COMPILE)objcopy
  129. OBJDUMP = $(CROSS_COMPILE)objdump
  130. RANLIB = $(CROSS_COMPILE)RANLIB
  131. DTC = dtc
  132. CHECK = sparse
  133. #########################################################################
  134. # Load generated board configuration
  135. ifeq ($(CONFIG_TPL_BUILD),y)
  136. # Include TPL autoconf
  137. sinclude $(OBJTREE)/include/tpl-autoconf.mk
  138. else
  139. ifeq ($(CONFIG_SPL_BUILD),y)
  140. # Include SPL autoconf
  141. sinclude $(OBJTREE)/include/spl-autoconf.mk
  142. else
  143. # Include normal autoconf
  144. sinclude $(OBJTREE)/include/autoconf.mk
  145. endif
  146. endif
  147. sinclude $(OBJTREE)/include/config.mk
  148. # Some architecture config.mk files need to know what CPUDIR is set to,
  149. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  150. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  151. # CPU-specific code.
  152. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  153. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  154. CPUDIR=arch/$(ARCH)/cpu
  155. endif
  156. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  157. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  158. ifdef SOC
  159. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  160. endif
  161. ifdef VENDOR
  162. BOARDDIR = $(VENDOR)/$(BOARD)
  163. else
  164. BOARDDIR = $(BOARD)
  165. endif
  166. ifdef BOARD
  167. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  168. endif
  169. #########################################################################
  170. # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
  171. # who are porting old code to latest mainline but not updating $(AR).
  172. ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
  173. RELFLAGS= $(PLATFORM_RELFLAGS)
  174. DBGFLAGS= -g # -DDEBUG
  175. OPTFLAGS= -Os #-fomit-frame-pointer
  176. OBJCFLAGS += --gap-fill=0xff
  177. gccincdir := $(shell $(CC) -print-file-name=include)
  178. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  179. -D__KERNEL__
  180. # Enable garbage collection of un-used sections for SPL
  181. ifeq ($(CONFIG_SPL_BUILD),y)
  182. CPPFLAGS += -ffunction-sections -fdata-sections
  183. LDFLAGS_FINAL += --gc-sections
  184. endif
  185. # TODO(sjg@chromium.org): Is this correct on Mac OS?
  186. # MXSImage needs LibSSL
  187. ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
  188. HOSTLIBS += -lssl -lcrypto
  189. # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
  190. # the mxsimage support within tools/mxsimage.c .
  191. HOSTCFLAGS += -DCONFIG_MXS
  192. endif
  193. ifdef CONFIG_FIT_SIGNATURE
  194. HOSTLIBS += -lssl -lcrypto
  195. # This affects include/image.h, but including the board config file
  196. # is tricky, so manually define this options here.
  197. HOSTCFLAGS += -DCONFIG_FIT_SIGNATURE
  198. endif
  199. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  200. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  201. endif
  202. ifeq ($(CONFIG_SPL_BUILD),y)
  203. CPPFLAGS += -DCONFIG_SPL_BUILD
  204. ifeq ($(CONFIG_TPL_BUILD),y)
  205. CPPFLAGS += -DCONFIG_TPL_BUILD
  206. endif
  207. endif
  208. # Does this architecture support generic board init?
  209. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  210. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  211. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  212. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  213. endif
  214. endif
  215. ifneq ($(OBJTREE),$(SRCTREE))
  216. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  217. endif
  218. CPPFLAGS += -I$(TOPDIR)/include
  219. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  220. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  221. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  222. ifdef BUILD_TAG
  223. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  224. endif
  225. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  226. CFLAGS += $(CFLAGS_SSP)
  227. # Some toolchains enable security related warning flags by default,
  228. # but they don't make much sense in the u-boot world, so disable them.
  229. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  230. $(call cc-option,-Wno-format-security)
  231. CFLAGS += $(CFLAGS_WARN)
  232. # Report stack usage if supported
  233. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  234. CFLAGS += $(CFLAGS_STACK)
  235. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  236. ifeq ($(findstring examples/,$(BCURDIR)),)
  237. ifeq ($(CONFIG_SPL_BUILD),)
  238. ifdef FTRACE
  239. CFLAGS += -finstrument-functions -DFTRACE
  240. endif
  241. endif
  242. endif
  243. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  244. # option to the assembler.
  245. AFLAGS_DEBUG :=
  246. # turn jbsr into jsr for m68k
  247. ifeq ($(ARCH),m68k)
  248. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  249. AFLAGS_DEBUG := -Wa,-gstabs,-S
  250. endif
  251. endif
  252. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  253. LDFLAGS += $(PLATFORM_LDFLAGS)
  254. LDFLAGS_FINAL += -Bstatic
  255. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  256. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  257. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  258. endif
  259. LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  260. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  261. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  262. endif
  263. # Linus' kernel sanity checking tool
  264. CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
  265. -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
  266. # Location of a usable BFD library, where we define "usable" as
  267. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  268. # - When cross-compiling: the root of the cross-environment
  269. # - Linux/ppc (native): /usr
  270. # - NetBSD/ppc (native): you lose ... (must extract these from the
  271. # binutils build directory, plus the native and U-Boot include
  272. # files don't like each other)
  273. #
  274. # So far, this is used only by tools/gdb/Makefile.
  275. ifeq ($(HOSTOS),darwin)
  276. BFD_ROOT_DIR = /usr/local/tools
  277. else
  278. ifeq ($(HOSTARCH),$(ARCH))
  279. # native
  280. BFD_ROOT_DIR = /usr
  281. else
  282. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  283. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  284. BFD_ROOT_DIR = /opt/powerpc
  285. endif
  286. endif
  287. #########################################################################
  288. export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
  289. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  290. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  291. #########################################################################
  292. # Allow boards to use custom optimize flags on a per dir/file basis
  293. ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
  294. ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
  295. EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
  296. ALL_CFLAGS += $(EXTRA_CPPFLAGS)
  297. # The _DEP version uses the $< file target (for dependency generation)
  298. # See rules.mk
  299. EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
  300. $(CPPFLAGS_$(BCURDIR))
  301. $(obj)%.s: %.S
  302. $(CPP) $(ALL_AFLAGS) -o $@ $<
  303. $(obj)%.o: %.S
  304. $(CC) $(ALL_AFLAGS) -o $@ $< -c
  305. $(obj)%.o: %.c
  306. ifneq ($(CHECKSRC),0)
  307. $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
  308. endif
  309. $(CC) $(ALL_CFLAGS) -o $@ $< -c
  310. $(obj)%.i: %.c
  311. $(CPP) $(ALL_CFLAGS) -o $@ $< -c
  312. $(obj)%.s: %.c
  313. $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
  314. #########################################################################
  315. # If the list of objects to link is empty, just create an empty built-in.o
  316. cmd_link_o_target = $(if $(strip $1),\
  317. $(LD) $(LDFLAGS) -r -o $@ $1,\
  318. rm -f $@; $(AR) rcs $@ )
  319. #########################################################################