config.mk 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. ifeq ($(CURDIR),$(SRCTREE))
  9. dir :=
  10. else
  11. dir := $(subst $(SRCTREE)/,,$(CURDIR))
  12. endif
  13. ifneq ($(OBJTREE),$(SRCTREE))
  14. # Create object files for SPL in a separate directory
  15. ifeq ($(CONFIG_SPL_BUILD),y)
  16. ifeq ($(CONFIG_TPL_BUILD),y)
  17. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  18. else
  19. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  20. endif
  21. else
  22. obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
  23. endif
  24. src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
  25. $(shell mkdir -p $(obj))
  26. else
  27. # Create object files for SPL in a separate directory
  28. ifeq ($(CONFIG_SPL_BUILD),y)
  29. ifeq ($(CONFIG_TPL_BUILD),y)
  30. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  31. else
  32. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  33. endif
  34. $(shell mkdir -p $(obj))
  35. else
  36. obj :=
  37. endif
  38. src :=
  39. endif
  40. # clean the slate ...
  41. PLATFORM_RELFLAGS =
  42. PLATFORM_CPPFLAGS =
  43. PLATFORM_LDFLAGS =
  44. #########################################################################
  45. #
  46. # Option checker, gcc version (courtesy linux kernel) to ensure
  47. # only supported compiler options are used
  48. #
  49. CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
  50. CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
  51. -include $(CC_OPTIONS_CACHE_FILE)
  52. cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
  53. if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
  54. > /dev/null 2>&1; then \
  55. echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
  56. echo "$(1)"; fi)
  57. ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
  58. cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
  59. else
  60. cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
  61. $(if $(call cc-option-sys,$1),$1,$2)))
  62. endif
  63. # cc-version
  64. # Usage gcc-ver := $(call cc-version)
  65. cc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
  66. binutils-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
  67. dtc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
  68. #########################################################################
  69. # Load generated board configuration
  70. ifeq ($(CONFIG_TPL_BUILD),y)
  71. # Include TPL autoconf
  72. sinclude $(OBJTREE)/include/tpl-autoconf.mk
  73. else
  74. ifeq ($(CONFIG_SPL_BUILD),y)
  75. # Include SPL autoconf
  76. sinclude $(OBJTREE)/include/spl-autoconf.mk
  77. else
  78. # Include normal autoconf
  79. sinclude $(OBJTREE)/include/autoconf.mk
  80. endif
  81. endif
  82. sinclude $(OBJTREE)/include/config.mk
  83. # Some architecture config.mk files need to know what CPUDIR is set to,
  84. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  85. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  86. # CPU-specific code.
  87. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  88. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  89. CPUDIR=arch/$(ARCH)/cpu
  90. endif
  91. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  92. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  93. ifdef SOC
  94. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  95. endif
  96. ifdef VENDOR
  97. BOARDDIR = $(VENDOR)/$(BOARD)
  98. else
  99. BOARDDIR = $(BOARD)
  100. endif
  101. ifdef BOARD
  102. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  103. endif
  104. #########################################################################
  105. # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
  106. # who are porting old code to latest mainline but not updating $(AR).
  107. ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
  108. RELFLAGS= $(PLATFORM_RELFLAGS)
  109. DBGFLAGS= -g # -DDEBUG
  110. OPTFLAGS= -Os #-fomit-frame-pointer
  111. OBJCFLAGS += --gap-fill=0xff
  112. gccincdir := $(shell $(CC) -print-file-name=include)
  113. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  114. -D__KERNEL__
  115. # Enable garbage collection of un-used sections for SPL
  116. ifeq ($(CONFIG_SPL_BUILD),y)
  117. CPPFLAGS += -ffunction-sections -fdata-sections
  118. LDFLAGS_FINAL += --gc-sections
  119. endif
  120. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  121. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  122. endif
  123. ifeq ($(CONFIG_SPL_BUILD),y)
  124. CPPFLAGS += -DCONFIG_SPL_BUILD
  125. ifeq ($(CONFIG_TPL_BUILD),y)
  126. CPPFLAGS += -DCONFIG_TPL_BUILD
  127. endif
  128. endif
  129. # Does this architecture support generic board init?
  130. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  131. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  132. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  133. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  134. endif
  135. endif
  136. ifneq ($(OBJTREE),$(SRCTREE))
  137. CPPFLAGS += -I$(OBJTREE)/include
  138. endif
  139. CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include
  140. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  141. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  142. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  143. ifdef BUILD_TAG
  144. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  145. endif
  146. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  147. CFLAGS += $(CFLAGS_SSP)
  148. # Some toolchains enable security related warning flags by default,
  149. # but they don't make much sense in the u-boot world, so disable them.
  150. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  151. $(call cc-option,-Wno-format-security)
  152. CFLAGS += $(CFLAGS_WARN)
  153. # Report stack usage if supported
  154. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  155. CFLAGS += $(CFLAGS_STACK)
  156. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  157. ifeq ($(findstring examples/,$(BCURDIR)),)
  158. ifeq ($(CONFIG_SPL_BUILD),)
  159. ifdef FTRACE
  160. CFLAGS += -finstrument-functions -DFTRACE
  161. endif
  162. endif
  163. endif
  164. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  165. # option to the assembler.
  166. AFLAGS_DEBUG :=
  167. # turn jbsr into jsr for m68k
  168. ifeq ($(ARCH),m68k)
  169. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  170. AFLAGS_DEBUG := -Wa,-gstabs,-S
  171. endif
  172. endif
  173. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  174. LDFLAGS += $(PLATFORM_LDFLAGS)
  175. LDFLAGS_FINAL += -Bstatic
  176. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  177. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  178. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  179. endif
  180. LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  181. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  182. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  183. endif
  184. #########################################################################
  185. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS