2 # (C) Copyright 2000-2013
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 # SPDX-License-Identifier: GPL-2.0+
7 #########################################################################
9 ifeq ($(CURDIR
),$(SRCTREE
))
12 dir := $(subst $(SRCTREE
)/,,$(CURDIR
))
15 ifneq ($(OBJTREE
),$(SRCTREE
))
16 # Create object files for SPL in a separate directory
17 ifeq ($(CONFIG_SPL_BUILD
),y
)
18 ifeq ($(CONFIG_TPL_BUILD
),y
)
19 obj
:= $(if
$(dir),$(TPLTREE
)/$(dir)/,$(TPLTREE
)/)
21 obj
:= $(if
$(dir),$(SPLTREE
)/$(dir)/,$(SPLTREE
)/)
24 obj
:= $(if
$(dir),$(OBJTREE
)/$(dir)/,$(OBJTREE
)/)
26 src
:= $(if
$(dir),$(SRCTREE
)/$(dir)/,$(SRCTREE
)/)
28 $(shell mkdir
-p
$(obj
))
30 # Create object files for SPL in a separate directory
31 ifeq ($(CONFIG_SPL_BUILD
),y
)
32 ifeq ($(CONFIG_TPL_BUILD
),y
)
33 obj
:= $(if
$(dir),$(TPLTREE
)/$(dir)/,$(TPLTREE
)/)
35 obj
:= $(if
$(dir),$(SPLTREE
)/$(dir)/,$(SPLTREE
)/)
38 $(shell mkdir
-p
$(obj
))
50 #########################################################################
52 # Option checker, gcc version (courtesy linux kernel) to ensure
53 # only supported compiler options are used
55 CC_OPTIONS_CACHE_FILE
:= $(OBJTREE
)/include/generated
/cc_options.mk
56 CC_TEST_OFILE
:= $(OBJTREE
)/include/generated
/cc_test_file.o
58 -include $(CC_OPTIONS_CACHE_FILE
)
60 cc-option-sys
= $(shell mkdir
-p
$(dir $(CC_TEST_OFILE
)); \
61 if
$(CC
) $(CFLAGS
) $(1) -S
-xc
/dev
/null
-o
$(CC_TEST_OFILE
) \
62 > /dev
/null
2>&1; then \
63 echo
'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE
); \
66 ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE
),y
)
67 cc-option
= $(strip $(if
$(call cc-option-sys
,$1),$1,$2))
69 cc-option
= $(strip $(if
$(findstring $1,$(CC_OPTIONS
)),$1,\
70 $(if
$(call cc-option-sys
,$1),$1,$2)))
74 # Usage gcc-ver := $(call cc-version)
75 cc-version
= $(shell $(CONFIG_SHELL
) $(SRCTREE
)/scripts
/gcc-version.sh
$(CC
))
76 binutils-version
= $(shell $(CONFIG_SHELL
) $(SRCTREE
)/scripts
/binutils-version.sh
$(AS
))
77 dtc-version
= $(shell $(CONFIG_SHELL
) $(SRCTREE
)/scripts
/dtc-version.sh
$(DTC
))
79 #########################################################################
81 # Load generated board configuration
82 ifeq ($(CONFIG_TPL_BUILD
),y
)
83 # Include TPL autoconf
84 sinclude
$(OBJTREE
)/include/tpl-autoconf.mk
86 ifeq ($(CONFIG_SPL_BUILD
),y
)
87 # Include SPL autoconf
88 sinclude
$(OBJTREE
)/include/spl-autoconf.mk
90 # Include normal autoconf
91 sinclude
$(OBJTREE
)/include/autoconf.mk
94 sinclude
$(OBJTREE
)/include/config.mk
96 # Some architecture config.mk files need to know what CPUDIR is set to,
97 # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
98 # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
100 CPUDIR
=arch
/$(ARCH
)/cpu
/$(CPU
)
101 ifneq ($(SRCTREE
)/$(CPUDIR
),$(wildcard $(SRCTREE
)/$(CPUDIR
)))
102 CPUDIR
=arch
/$(ARCH
)/cpu
105 sinclude
$(TOPDIR
)/arch
/$(ARCH
)/config.mk
# include architecture dependend rules
106 sinclude
$(TOPDIR
)/$(CPUDIR
)/config.mk
# include CPU specific rules
109 sinclude
$(TOPDIR
)/$(CPUDIR
)/$(SOC
)/config.mk
# include SoC specific rules
112 BOARDDIR
= $(VENDOR
)/$(BOARD
)
117 sinclude
$(TOPDIR
)/board
/$(BOARDDIR
)/config.mk
# include board specific rules
120 #########################################################################
122 # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
123 # who are porting old code to latest mainline but not updating $(AR).
124 ARFLAGS
= $(error update your Makefile to use cmd_link_o_target and not AR
)
125 RELFLAGS
= $(PLATFORM_RELFLAGS
)
126 DBGFLAGS
= -g
# -DDEBUG
127 OPTFLAGS
= -Os
#-fomit-frame-pointer
129 OBJCFLAGS
+= --gap-fill
=0xff
131 gccincdir
:= $(shell $(CC
) -print-file-name
=include)
133 CPPFLAGS
:= $(DBGFLAGS
) $(OPTFLAGS
) $(RELFLAGS
) \
136 # Enable garbage collection of un-used sections for SPL
137 ifeq ($(CONFIG_SPL_BUILD
),y
)
138 CPPFLAGS
+= -ffunction-sections
-fdata-sections
139 LDFLAGS_FINAL
+= --gc-sections
142 ifneq ($(CONFIG_SYS_TEXT_BASE
),)
143 CPPFLAGS
+= -DCONFIG_SYS_TEXT_BASE
=$(CONFIG_SYS_TEXT_BASE
)
146 ifeq ($(CONFIG_SPL_BUILD
),y
)
147 CPPFLAGS
+= -DCONFIG_SPL_BUILD
148 ifeq ($(CONFIG_TPL_BUILD
),y
)
149 CPPFLAGS
+= -DCONFIG_TPL_BUILD
153 # Does this architecture support generic board init?
154 ifeq ($(__HAVE_ARCH_GENERIC_BOARD
),)
155 ifneq ($(CONFIG_SYS_GENERIC_BOARD
),)
156 CHECK_GENERIC_BOARD
= $(error Your architecture does not support generic board. \
157 Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file
)
161 ifneq ($(OBJTREE
),$(SRCTREE
))
162 CPPFLAGS
+= -I
$(OBJTREE
)/include
165 CPPFLAGS
+= -I
$(TOPDIR
)/include -I
$(SRCTREE
)/arch
/$(ARCH
)/include
166 CPPFLAGS
+= -fno-builtin
-ffreestanding
-nostdinc \
167 -isystem
$(gccincdir
) -pipe
$(PLATFORM_CPPFLAGS
)
169 CFLAGS
:= $(CPPFLAGS
) -Wall
-Wstrict-prototypes
172 CFLAGS
+= -DBUILD_TAG
='"$(BUILD_TAG)"'
175 CFLAGS_SSP
:= $(call cc-option
,-fno-stack-protector
)
176 CFLAGS
+= $(CFLAGS_SSP
)
177 # Some toolchains enable security related warning flags by default,
178 # but they don't make much sense in the u-boot world, so disable them.
179 CFLAGS_WARN
:= $(call cc-option
,-Wno-format-nonliteral
) \
180 $(call cc-option
,-Wno-format-security
)
181 CFLAGS
+= $(CFLAGS_WARN
)
183 # Report stack usage if supported
184 CFLAGS_STACK
:= $(call cc-option
,-fstack-usage
)
185 CFLAGS
+= $(CFLAGS_STACK
)
187 BCURDIR
= $(subst $(SRCTREE
)/,,$(CURDIR
:$(obj
)%=%))
189 ifeq ($(findstring examples
/,$(BCURDIR
)),)
190 ifeq ($(CONFIG_SPL_BUILD
),)
192 CFLAGS
+= -finstrument-functions
-DFTRACE
197 # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
198 # option to the assembler.
201 # turn jbsr into jsr for m68k
203 ifeq ($(findstring 3.4,$(shell $(CC
) --version
)),3.4)
204 AFLAGS_DEBUG
:= -Wa
,-gstabs
,-S
208 AFLAGS
:= $(AFLAGS_DEBUG
) -D__ASSEMBLY__
$(CPPFLAGS
)
210 LDFLAGS
+= $(PLATFORM_LDFLAGS
)
211 LDFLAGS_FINAL
+= -Bstatic
213 LDFLAGS_u-boot
+= -T
$(obj
)u-boot.lds
$(LDFLAGS_FINAL
)
214 ifneq ($(CONFIG_SYS_TEXT_BASE
),)
215 LDFLAGS_u-boot
+= -Ttext
$(CONFIG_SYS_TEXT_BASE
)
218 LDFLAGS_
$(SPL_BIN
) += -T
$(obj
)u-boot-spl.lds
$(LDFLAGS_FINAL
)
219 ifneq ($(CONFIG_SPL_TEXT_BASE
),)
220 LDFLAGS_
$(SPL_BIN
) += -Ttext
$(CONFIG_SPL_TEXT_BASE
)
223 # Location of a usable BFD library, where we define "usable" as
224 # "built for ${HOST}, supports ${TARGET}". Sensible values are
225 # - When cross-compiling: the root of the cross-environment
226 # - Linux/ppc (native): /usr
227 # - NetBSD/ppc (native): you lose ... (must extract these from the
228 # binutils build directory, plus the native and U-Boot include
229 # files don't like each other)
231 # So far, this is used only by tools/gdb/Makefile.
233 ifeq ($(HOSTOS
),darwin
)
234 BFD_ROOT_DIR
= /usr
/local
/tools
236 ifeq ($(HOSTARCH
),$(ARCH
))
240 #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
241 #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
242 BFD_ROOT_DIR
= /opt
/powerpc
246 #########################################################################
248 export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS