xref: /openbmc/u-boot/Makefile (revision 552a848e)
1da58dec8STom Rini#
2da58dec8STom Rini# SPDX-License-Identifier:	GPL-2.0+
3da58dec8STom Rini#
4da58dec8STom Rini
53cfb67d0STom RiniVERSION = 2017
6ad701b1cSTom RiniPATCHLEVEL = 07
7211e4754SWolfgang DenkSUBLEVEL =
8d85ca029STom RiniEXTRAVERSION =
95f30f3beSMasahiro YamadaNAME =
10ae6d1056SWolfgang Denk
116825a95bSMasahiro Yamada# *DOCUMENTATION*
126825a95bSMasahiro Yamada# To see a list of typical targets execute "make help"
136825a95bSMasahiro Yamada# More info can be located in ./README
146825a95bSMasahiro Yamada# Comments in this file are targeted only to the developer, do not
156825a95bSMasahiro Yamada# expect to learn how to build the kernel reading this file.
166825a95bSMasahiro Yamada
174d713be1SMasahiro Yamada# o Do not use make's built-in rules and variables
186825a95bSMasahiro Yamada#   (this increases performance and avoids hard-to-debug behaviour);
194d713be1SMasahiro Yamada# o Look for make include files relative to root of kernel src
204d713be1SMasahiro YamadaMAKEFLAGS += -rR --include-dir=$(CURDIR)
216825a95bSMasahiro Yamada
226825a95bSMasahiro Yamada# Avoid funny character set dependencies
236825a95bSMasahiro Yamadaunexport LC_ALL
246825a95bSMasahiro YamadaLC_COLLATE=C
256825a95bSMasahiro YamadaLC_NUMERIC=C
266825a95bSMasahiro Yamadaexport LC_COLLATE LC_NUMERIC
276825a95bSMasahiro Yamada
28ffe29ebcSMasahiro Yamada# Avoid interference with shell env settings
29ffe29ebcSMasahiro Yamadaunexport GREP_OPTIONS
30ffe29ebcSMasahiro Yamada
316825a95bSMasahiro Yamada# We are using a recursive build, so we need to do a little thinking
326825a95bSMasahiro Yamada# to get the ordering right.
336825a95bSMasahiro Yamada#
346825a95bSMasahiro Yamada# Most importantly: sub-Makefiles should only ever modify files in
356825a95bSMasahiro Yamada# their own directory. If in some directory we have a dependency on
366825a95bSMasahiro Yamada# a file in another dir (which doesn't happen often, but it's often
376825a95bSMasahiro Yamada# unavoidable when linking the built-in.o targets which finally
386825a95bSMasahiro Yamada# turn into vmlinux), we will call a sub make in that other dir, and
396825a95bSMasahiro Yamada# after that we are sure that everything which is in that other dir
406825a95bSMasahiro Yamada# is now up to date.
416825a95bSMasahiro Yamada#
426825a95bSMasahiro Yamada# The only cases where we need to modify files which have global
436825a95bSMasahiro Yamada# effects are thus separated out and done before the recursive
446825a95bSMasahiro Yamada# descending is started. They are now explicitly listed as the
456825a95bSMasahiro Yamada# prepare rule.
466825a95bSMasahiro Yamada
47ffe29ebcSMasahiro Yamada# Beautify output
48ffe29ebcSMasahiro Yamada# ---------------------------------------------------------------------------
49ffe29ebcSMasahiro Yamada#
50ffe29ebcSMasahiro Yamada# Normally, we echo the whole command before executing it. By making
51ffe29ebcSMasahiro Yamada# that echo $($(quiet)$(cmd)), we now have the possibility to set
52ffe29ebcSMasahiro Yamada# $(quiet) to choose other forms of output instead, e.g.
53ffe29ebcSMasahiro Yamada#
54ffe29ebcSMasahiro Yamada#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
55ffe29ebcSMasahiro Yamada#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
56ffe29ebcSMasahiro Yamada#
57ffe29ebcSMasahiro Yamada# If $(quiet) is empty, the whole command will be printed.
58ffe29ebcSMasahiro Yamada# If it is set to "quiet_", only the short version will be printed.
59ffe29ebcSMasahiro Yamada# If it is set to "silent_", nothing will be printed at all, since
60ffe29ebcSMasahiro Yamada# the variable $(silent_cmd_cc_o_c) doesn't exist.
61ffe29ebcSMasahiro Yamada#
62ffe29ebcSMasahiro Yamada# A simple variant is to prefix commands with $(Q) - that's useful
63ffe29ebcSMasahiro Yamada# for commands that shall be hidden in non-verbose mode.
64ffe29ebcSMasahiro Yamada#
65ffe29ebcSMasahiro Yamada#	$(Q)ln $@ :<
66ffe29ebcSMasahiro Yamada#
67ffe29ebcSMasahiro Yamada# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
68ffe29ebcSMasahiro Yamada# If KBUILD_VERBOSE equals 1 then the above command is displayed.
69ffe29ebcSMasahiro Yamada#
706825a95bSMasahiro Yamada# To put more focus on warnings, be less verbose as default
716825a95bSMasahiro Yamada# Use 'make V=1' to see the full commands
726825a95bSMasahiro Yamada
736825a95bSMasahiro Yamadaifeq ("$(origin V)", "command line")
746825a95bSMasahiro Yamada  KBUILD_VERBOSE = $(V)
757ebf7443Swdenkendif
766825a95bSMasahiro Yamadaifndef KBUILD_VERBOSE
776825a95bSMasahiro Yamada  KBUILD_VERBOSE = 0
786825a95bSMasahiro Yamadaendif
796825a95bSMasahiro Yamada
80ffe29ebcSMasahiro Yamadaifeq ($(KBUILD_VERBOSE),1)
81ffe29ebcSMasahiro Yamada  quiet =
82ffe29ebcSMasahiro Yamada  Q =
83ffe29ebcSMasahiro Yamadaelse
84ffe29ebcSMasahiro Yamada  quiet=quiet_
85ffe29ebcSMasahiro Yamada  Q = @
866825a95bSMasahiro Yamadaendif
876825a95bSMasahiro Yamada
88ffe29ebcSMasahiro Yamada# If the user is running make -s (silent mode), suppress echoing of
89ffe29ebcSMasahiro Yamada# commands
90ffe29ebcSMasahiro Yamada
91ffe29ebcSMasahiro Yamadaifneq ($(filter 4.%,$(MAKE_VERSION)),)	# make-4
92ffe29ebcSMasahiro Yamadaifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
93ffe29ebcSMasahiro Yamada  quiet=silent_
94ffe29ebcSMasahiro Yamadaendif
95ffe29ebcSMasahiro Yamadaelse					# make-3.8x
96ffe29ebcSMasahiro Yamadaifneq ($(filter s% -s%,$(MAKEFLAGS)),)
97ffe29ebcSMasahiro Yamada  quiet=silent_
98ffe29ebcSMasahiro Yamadaendif
996825a95bSMasahiro Yamadaendif
1006825a95bSMasahiro Yamada
101ffe29ebcSMasahiro Yamadaexport quiet Q KBUILD_VERBOSE
1026825a95bSMasahiro Yamada
1039e414032SMasahiro Yamada# kbuild supports saving output files in a separate directory.
1049e414032SMasahiro Yamada# To locate output files in a separate directory two syntaxes are supported.
1059e414032SMasahiro Yamada# In both cases the working directory must be the root of the kernel src.
1069e414032SMasahiro Yamada# 1) O=
1079e414032SMasahiro Yamada# Use "make O=dir/to/store/output/files/"
108f9328639SMarian Balakowicz#
1099e414032SMasahiro Yamada# 2) Set KBUILD_OUTPUT
1109e414032SMasahiro Yamada# Set the environment variable KBUILD_OUTPUT to point to the directory
1119e414032SMasahiro Yamada# where the output files shall be placed.
1129e414032SMasahiro Yamada# export KBUILD_OUTPUT=dir/to/store/output/files/
1139e414032SMasahiro Yamada# make
114f9328639SMarian Balakowicz#
1159e414032SMasahiro Yamada# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1169e414032SMasahiro Yamada# variable.
1177ebf7443Swdenk
1189e414032SMasahiro Yamada# KBUILD_SRC is set on invocation of make in OBJ directory
1199e414032SMasahiro Yamada# KBUILD_SRC is not intended to be used by the regular user (for now)
1209e414032SMasahiro Yamadaifeq ($(KBUILD_SRC),)
1219e414032SMasahiro Yamada
1229e414032SMasahiro Yamada# OK, Make called in directory where kernel src resides
1239e414032SMasahiro Yamada# Do we want to locate output files in a separate directory?
124f9328639SMarian Balakowiczifeq ("$(origin O)", "command line")
1259e414032SMasahiro Yamada  KBUILD_OUTPUT := $(O)
126f9328639SMarian Balakowiczendif
1277ebf7443Swdenk
1289e414032SMasahiro Yamada# That's our default target when none is given on the command line
1299e414032SMasahiro YamadaPHONY := _all
1309e414032SMasahiro Yamada_all:
1319e414032SMasahiro Yamada
1329e414032SMasahiro Yamada# Cancel implicit rules on top Makefile
1339e414032SMasahiro Yamada$(CURDIR)/Makefile Makefile: ;
1349e414032SMasahiro Yamada
1359e414032SMasahiro Yamadaifneq ($(KBUILD_OUTPUT),)
1369e414032SMasahiro Yamada# Invoke a second make in the output directory, passing relevant variables
1379e414032SMasahiro Yamada# check that the output directory actually exists
1389e414032SMasahiro Yamadasaved-output := $(KBUILD_OUTPUT)
1395a449d75SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
1405a449d75SMasahiro Yamada								&& /bin/pwd)
1419e414032SMasahiro Yamada$(if $(KBUILD_OUTPUT),, \
142598e2d33SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1439e414032SMasahiro Yamada
1449e414032SMasahiro YamadaPHONY += $(MAKECMDGOALS) sub-make
1459e414032SMasahiro Yamada
1469e414032SMasahiro Yamada$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
1479e414032SMasahiro Yamada	@:
1489e414032SMasahiro Yamada
1499e414032SMasahiro Yamadasub-make: FORCE
150ffe29ebcSMasahiro Yamada	$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
151ffe29ebcSMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1529e414032SMasahiro Yamada
1539e414032SMasahiro Yamada# Leave processing to above invocation of make
1549e414032SMasahiro Yamadaskip-makefile := 1
1559e414032SMasahiro Yamadaendif # ifneq ($(KBUILD_OUTPUT),)
1569e414032SMasahiro Yamadaendif # ifeq ($(KBUILD_SRC),)
1579e414032SMasahiro Yamada
1589e414032SMasahiro Yamada# We process the rest of the Makefile if this is the final invocation of make
1599e414032SMasahiro Yamadaifeq ($(skip-makefile),)
1609e414032SMasahiro Yamada
161ffe29ebcSMasahiro Yamada# Do not print "Entering directory ...",
162ffe29ebcSMasahiro Yamada# but we want to display it when entering to the output directory
163ffe29ebcSMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
164ffe29ebcSMasahiro YamadaMAKEFLAGS += --no-print-directory
165ffe29ebcSMasahiro Yamada
166ffe29ebcSMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
167ffe29ebcSMasahiro Yamada# C compilation.
168ffe29ebcSMasahiro Yamada#
169ffe29ebcSMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
170ffe29ebcSMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
171ffe29ebcSMasahiro Yamada# of whether they are re-compiled or not.
172ffe29ebcSMasahiro Yamada#
173ffe29ebcSMasahiro Yamada# See the file "Documentation/sparse.txt" for more details, including
174ffe29ebcSMasahiro Yamada# where to get the "sparse" utility.
175ffe29ebcSMasahiro Yamada
176ffe29ebcSMasahiro Yamadaifeq ("$(origin C)", "command line")
177ffe29ebcSMasahiro Yamada  KBUILD_CHECKSRC = $(C)
178ffe29ebcSMasahiro Yamadaendif
179ffe29ebcSMasahiro Yamadaifndef KBUILD_CHECKSRC
180ffe29ebcSMasahiro Yamada  KBUILD_CHECKSRC = 0
181ffe29ebcSMasahiro Yamadaendif
182ffe29ebcSMasahiro Yamada
183ffe29ebcSMasahiro Yamada# Use make M=dir to specify directory of external module to build
184ffe29ebcSMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
185ffe29ebcSMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
186ffe29ebcSMasahiro Yamadaifdef SUBDIRS
187ffe29ebcSMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
188ffe29ebcSMasahiro Yamadaendif
189ffe29ebcSMasahiro Yamada
190ffe29ebcSMasahiro Yamadaifeq ("$(origin M)", "command line")
191ffe29ebcSMasahiro Yamada  KBUILD_EXTMOD := $(M)
192ffe29ebcSMasahiro Yamadaendif
193ffe29ebcSMasahiro Yamada
1946825a95bSMasahiro Yamada# If building an external module we do not care about the all: rule
1956825a95bSMasahiro Yamada# but instead _all depend on modules
1969e414032SMasahiro YamadaPHONY += all
1976825a95bSMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
1989e414032SMasahiro Yamada_all: all
1996825a95bSMasahiro Yamadaelse
2006825a95bSMasahiro Yamada_all: modules
2016825a95bSMasahiro Yamadaendif
2029e414032SMasahiro Yamada
203ffe29ebcSMasahiro Yamadaifeq ($(KBUILD_SRC),)
204ffe29ebcSMasahiro Yamada        # building in the source tree
205ffe29ebcSMasahiro Yamada        srctree := .
206ffe29ebcSMasahiro Yamadaelse
207ffe29ebcSMasahiro Yamada        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
208ffe29ebcSMasahiro Yamada                # building in a subdirectory of the source tree
209ffe29ebcSMasahiro Yamada                srctree := ..
210ffe29ebcSMasahiro Yamada        else
211ffe29ebcSMasahiro Yamada                srctree := $(KBUILD_SRC)
212ffe29ebcSMasahiro Yamada        endif
213ffe29ebcSMasahiro Yamadaendif
214ffe29ebcSMasahiro Yamadaobjtree		:= .
2159e414032SMasahiro Yamadasrc		:= $(srctree)
2169e414032SMasahiro Yamadaobj		:= $(objtree)
2179e414032SMasahiro Yamada
2189e414032SMasahiro YamadaVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
2199e414032SMasahiro Yamada
2209e414032SMasahiro Yamadaexport srctree objtree VPATH
2219e414032SMasahiro Yamada
2225013c09fSWolfgang Denk# Make sure CDPATH settings don't interfere
2235013c09fSWolfgang Denkunexport CDPATH
2245013c09fSWolfgang Denk
225f9328639SMarian Balakowicz#########################################################################
226f9328639SMarian Balakowicz
2277ebf7443SwdenkHOSTARCH := $(shell uname -m | \
2287ebf7443Swdenk	sed -e s/i.86/x86/ \
2297ebf7443Swdenk	    -e s/sun4u/sparc64/ \
2307ebf7443Swdenk	    -e s/arm.*/arm/ \
2317ebf7443Swdenk	    -e s/sa110/arm/ \
2327ebf7443Swdenk	    -e s/ppc64/powerpc/ \
2337ebf7443Swdenk	    -e s/ppc/powerpc/ \
2347ebf7443Swdenk	    -e s/macppc/powerpc/\
2357ebf7443Swdenk	    -e s/sh.*/sh/)
2367ebf7443Swdenk
2377ebf7443SwdenkHOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
2387ebf7443Swdenk	    sed -e 's/\(cygwin\).*/cygwin/')
2397ebf7443Swdenk
2407ebf7443Swdenkexport	HOSTARCH HOSTOS
2417ebf7443Swdenk
2427ebf7443Swdenk#########################################################################
243f9328639SMarian Balakowicz
2441ea6bcd8SMike Frysinger# set default to nothing for native builds
245a5284efdSWolfgang Denkifeq ($(HOSTARCH),$(ARCH))
2461ea6bcd8SMike FrysingerCROSS_COMPILE ?=
2477ebf7443Swdenkendif
2487ebf7443Swdenk
24951148790SMasahiro YamadaKCONFIG_CONFIG	?= .config
25051148790SMasahiro Yamadaexport KCONFIG_CONFIG
25151148790SMasahiro Yamada
252f6322eb7SMasahiro Yamada# SHELL used by kbuild
253f6322eb7SMasahiro YamadaCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
254f6322eb7SMasahiro Yamada	  else if [ -x /bin/bash ]; then echo /bin/bash; \
255f6322eb7SMasahiro Yamada	  else echo sh; fi ; fi)
256f6322eb7SMasahiro Yamada
257b477fe44SJeroen HofsteeHOSTCC       = cc
258b477fe44SJeroen HofsteeHOSTCXX      = c++
259022885cbSSimon GlassHOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
260022885cbSSimon Glass		$(if $(CONFIG_TOOLS_DEBUG),-g)
261598e2d33SMasahiro YamadaHOSTCXXFLAGS = -O2
262598e2d33SMasahiro Yamada
263f6322eb7SMasahiro Yamadaifeq ($(HOSTOS),cygwin)
264f6322eb7SMasahiro YamadaHOSTCFLAGS	+= -ansi
265f6322eb7SMasahiro Yamadaendif
266f6322eb7SMasahiro Yamada
267f6322eb7SMasahiro Yamada# Mac OS X / Darwin's C preprocessor is Apple specific.  It
268f6322eb7SMasahiro Yamada# generates numerous errors and warnings.  We want to bypass it
269f6322eb7SMasahiro Yamada# and use GNU C's cpp.	To do this we pass the -traditional-cpp
270f6322eb7SMasahiro Yamada# option to the compiler.  Note that the -traditional-cpp flag
271f6322eb7SMasahiro Yamada# DOES NOT have the same semantics as GNU C's flag, all it does
272f6322eb7SMasahiro Yamada# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
273f6322eb7SMasahiro Yamada#
274f6322eb7SMasahiro Yamada# Apple's linker is similar, thanks to the new 2 stage linking
275f6322eb7SMasahiro Yamada# multiple symbol definitions are treated as errors, hence the
276f6322eb7SMasahiro Yamada# -multiply_defined suppress option to turn off this error.
277f6322eb7SMasahiro Yamada#
278f6322eb7SMasahiro Yamadaifeq ($(HOSTOS),darwin)
279f6322eb7SMasahiro Yamada# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
280f6322eb7SMasahiro YamadaDARWIN_MAJOR_VERSION	= $(shell sw_vers -productVersion | cut -f 1 -d '.')
281f6322eb7SMasahiro YamadaDARWIN_MINOR_VERSION	= $(shell sw_vers -productVersion | cut -f 2 -d '.')
282f6322eb7SMasahiro Yamada
283f6322eb7SMasahiro Yamadaos_x_before	= $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
284f6322eb7SMasahiro Yamada	$(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
285f6322eb7SMasahiro Yamada
286f6322eb7SMasahiro Yamada# Snow Leopards build environment has no longer restrictions as described above
287f6322eb7SMasahiro YamadaHOSTCC       = $(call os_x_before, 10, 5, "cc", "gcc")
288f6322eb7SMasahiro YamadaHOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
289f6322eb7SMasahiro YamadaHOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
2901fddd7b6SAndreas Bießmann
2911fddd7b6SAndreas Bießmann# since Lion (10.7) ASLR is on by default, but we use linker generated lists
2921fddd7b6SAndreas Bießmann# in some host tools which is a problem then ... so disable ASLR for these
2931fddd7b6SAndreas Bießmann# tools
2941fddd7b6SAndreas BießmannHOSTLDFLAGS += $(call os_x_before, 10, 7, "", "-Xlinker -no_pie")
295f6322eb7SMasahiro Yamadaendif
296f6322eb7SMasahiro Yamada
2976825a95bSMasahiro Yamada# Decide whether to build built-in, modular, or both.
2986825a95bSMasahiro Yamada# Normally, just do built-in.
2996825a95bSMasahiro Yamada
3006825a95bSMasahiro YamadaKBUILD_MODULES :=
3016825a95bSMasahiro YamadaKBUILD_BUILTIN := 1
3026825a95bSMasahiro Yamada
3036825a95bSMasahiro Yamada# If we have only "make modules", don't compile built-in objects.
3046825a95bSMasahiro Yamada# When we're building modules with modversions, we need to consider
3056825a95bSMasahiro Yamada# the built-in objects during the descend as well, in order to
3066825a95bSMasahiro Yamada# make sure the checksums are up to date before we record them.
3076825a95bSMasahiro Yamada
3086825a95bSMasahiro Yamadaifeq ($(MAKECMDGOALS),modules)
3096825a95bSMasahiro Yamada  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
3106825a95bSMasahiro Yamadaendif
3116825a95bSMasahiro Yamada
3126825a95bSMasahiro Yamada# If we have "make <whatever> modules", compile modules
3136825a95bSMasahiro Yamada# in addition to whatever we do anyway.
3146825a95bSMasahiro Yamada# Just "make" or "make all" shall build modules as well
3156825a95bSMasahiro Yamada
3166825a95bSMasahiro Yamada# U-Boot does not need modules
3176825a95bSMasahiro Yamada#ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
3186825a95bSMasahiro Yamada#  KBUILD_MODULES := 1
3196825a95bSMasahiro Yamada#endif
3206825a95bSMasahiro Yamada
3216825a95bSMasahiro Yamada#ifeq ($(MAKECMDGOALS),)
3226825a95bSMasahiro Yamada#  KBUILD_MODULES := 1
3236825a95bSMasahiro Yamada#endif
3246825a95bSMasahiro Yamada
3256825a95bSMasahiro Yamadaexport KBUILD_MODULES KBUILD_BUILTIN
3266825a95bSMasahiro Yamadaexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
3276825a95bSMasahiro Yamada
328bf4b3de1SMasahiro Yamada# We need some generic definitions (do not try to remake the file).
3294d713be1SMasahiro Yamadascripts/Kbuild.include: ;
3304d713be1SMasahiro Yamadainclude scripts/Kbuild.include
331bf4b3de1SMasahiro Yamada
332f6322eb7SMasahiro Yamada# Make variables (CC, etc...)
333f6322eb7SMasahiro Yamada
334f6322eb7SMasahiro YamadaAS		= $(CROSS_COMPILE)as
335f6322eb7SMasahiro Yamada# Always use GNU ld
336f6322eb7SMasahiro Yamadaifneq ($(shell $(CROSS_COMPILE)ld.bfd -v 2> /dev/null),)
337f6322eb7SMasahiro YamadaLD		= $(CROSS_COMPILE)ld.bfd
338f6322eb7SMasahiro Yamadaelse
339f6322eb7SMasahiro YamadaLD		= $(CROSS_COMPILE)ld
340f6322eb7SMasahiro Yamadaendif
341f6322eb7SMasahiro YamadaCC		= $(CROSS_COMPILE)gcc
342f6322eb7SMasahiro YamadaCPP		= $(CC) -E
343f6322eb7SMasahiro YamadaAR		= $(CROSS_COMPILE)ar
344f6322eb7SMasahiro YamadaNM		= $(CROSS_COMPILE)nm
345f6322eb7SMasahiro YamadaLDR		= $(CROSS_COMPILE)ldr
346f6322eb7SMasahiro YamadaSTRIP		= $(CROSS_COMPILE)strip
347f6322eb7SMasahiro YamadaOBJCOPY		= $(CROSS_COMPILE)objcopy
348f6322eb7SMasahiro YamadaOBJDUMP		= $(CROSS_COMPILE)objdump
349f6322eb7SMasahiro YamadaAWK		= awk
350f77d7096SMasahiro YamadaPERL		= perl
351b48bfc74SStefano BabicPYTHON		?= python
352f6322eb7SMasahiro YamadaDTC		= dtc
353f6322eb7SMasahiro YamadaCHECK		= sparse
354f6322eb7SMasahiro Yamada
355f6322eb7SMasahiro YamadaCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
356f6322eb7SMasahiro Yamada		  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
357f6322eb7SMasahiro Yamada
3583b612970SMasahiro YamadaKBUILD_CPPFLAGS := -D__KERNEL__ -D__UBOOT__
3592b3c9d3dSMasahiro Yamada
3602b3c9d3dSMasahiro YamadaKBUILD_CFLAGS   := -Wall -Wstrict-prototypes \
3612b3c9d3dSMasahiro Yamada		   -Wno-format-security \
3622b3c9d3dSMasahiro Yamada		   -fno-builtin -ffreestanding
3632b3c9d3dSMasahiro YamadaKBUILD_AFLAGS   := -D__ASSEMBLY__
3642b3c9d3dSMasahiro Yamada
3657424145fSMasahiro Yamada# Read UBOOTRELEASE from include/config/uboot.release (if it exists)
3667424145fSMasahiro YamadaUBOOTRELEASE = $(shell cat include/config/uboot.release 2> /dev/null)
3677424145fSMasahiro YamadaUBOOTVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
3685f30f3beSMasahiro Yamada
3697424145fSMasahiro Yamadaexport VERSION PATCHLEVEL SUBLEVEL UBOOTRELEASE UBOOTVERSION
370026f9cf2SMasahiro Yamadaexport ARCH CPU BOARD VENDOR SOC CPUDIR BOARDDIR
371f6322eb7SMasahiro Yamadaexport CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
372f6322eb7SMasahiro Yamadaexport CPP AR NM LDR STRIP OBJCOPY OBJDUMP
37351148790SMasahiro Yamadaexport MAKE AWK PERL PYTHON
3744b83f0d9SMasahiro Yamadaexport HOSTCXX HOSTCXXFLAGS CHECK CHECKFLAGS DTC DTC_FLAGS
375f6322eb7SMasahiro Yamada
376026f9cf2SMasahiro Yamadaexport KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE OBJCOPYFLAGS LDFLAGS
3772b3c9d3dSMasahiro Yamadaexport KBUILD_CFLAGS KBUILD_AFLAGS
3782b3c9d3dSMasahiro Yamada
3796825a95bSMasahiro Yamada# When compiling out-of-tree modules, put MODVERDIR in the module
3806825a95bSMasahiro Yamada# tree rather than in the kernel tree. The kernel tree might
3816825a95bSMasahiro Yamada# even be read-only.
3826825a95bSMasahiro Yamadaexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
3836825a95bSMasahiro Yamada
3846825a95bSMasahiro Yamada# Files to ignore in find ... statements
3856825a95bSMasahiro Yamada
386598e2d33SMasahiro Yamadaexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
387598e2d33SMasahiro Yamada			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
388598e2d33SMasahiro Yamada			  -prune -o
3896825a95bSMasahiro Yamadaexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
3906825a95bSMasahiro Yamada			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
3916825a95bSMasahiro Yamada
3926825a95bSMasahiro Yamada# ===========================================================================
3936825a95bSMasahiro Yamada# Rules shared between *config targets and build targets
3946825a95bSMasahiro Yamada
3956825a95bSMasahiro Yamada# Basic helpers built in scripts/
3966825a95bSMasahiro YamadaPHONY += scripts_basic
3976825a95bSMasahiro Yamadascripts_basic:
3986825a95bSMasahiro Yamada	$(Q)$(MAKE) $(build)=scripts/basic
3996825a95bSMasahiro Yamada	$(Q)rm -f .tmp_quiet_recordmcount
4006825a95bSMasahiro Yamada
4016825a95bSMasahiro Yamada# To avoid any implicit rule to kick in, define an empty command.
4026825a95bSMasahiro Yamadascripts/basic/%: scripts_basic ;
4036825a95bSMasahiro Yamada
4043341bfecSMasahiro YamadaPHONY += outputmakefile
4053341bfecSMasahiro Yamada# outputmakefile generates a Makefile in the output directory, if using a
4063341bfecSMasahiro Yamada# separate output directory. This allows convenient use of make in the
4073341bfecSMasahiro Yamada# output directory.
4083341bfecSMasahiro Yamadaoutputmakefile:
4093341bfecSMasahiro Yamadaifneq ($(KBUILD_SRC),)
4103341bfecSMasahiro Yamada	$(Q)ln -fsn $(srctree) source
4113341bfecSMasahiro Yamada	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
4123341bfecSMasahiro Yamada	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
4133341bfecSMasahiro Yamadaendif
4143341bfecSMasahiro Yamada
415433b2f1eSMasahiro Yamada# To make sure we do not include .config for any of the *config targets
416433b2f1eSMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
417433b2f1eSMasahiro Yamada# It is allowed to specify more targets when calling make, including
418433b2f1eSMasahiro Yamada# mixing *config targets and build targets.
419433b2f1eSMasahiro Yamada# For example 'make oldconfig all'.
420433b2f1eSMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
421433b2f1eSMasahiro Yamada# of make so .config is not included in this case either (for *config).
4226825a95bSMasahiro Yamada
4237424145fSMasahiro Yamadaversion_h := include/generated/version_autogenerated.h
4247424145fSMasahiro Yamadatimestamp_h := include/generated/timestamp_autogenerated.h
4257424145fSMasahiro Yamada
426433b2f1eSMasahiro Yamadano-dot-config-targets := clean clobber mrproper distclean \
42727651187SMasahiro Yamada			 help %docs check% coccicheck \
428633cc7aeSSimon Glass			 ubootversion backup tests
4292b3c9d3dSMasahiro Yamada
430433b2f1eSMasahiro Yamadaconfig-targets := 0
431433b2f1eSMasahiro Yamadamixed-targets  := 0
432433b2f1eSMasahiro Yamadadot-config     := 1
4332b3c9d3dSMasahiro Yamada
434433b2f1eSMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
435433b2f1eSMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
436433b2f1eSMasahiro Yamada		dot-config := 0
4372b3c9d3dSMasahiro Yamada	endif
4382b3c9d3dSMasahiro Yamadaendif
4392b3c9d3dSMasahiro Yamada
440433b2f1eSMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
441433b2f1eSMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
442433b2f1eSMasahiro Yamada                config-targets := 1
44398bd0e0dSMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
444433b2f1eSMasahiro Yamada                        mixed-targets := 1
445433b2f1eSMasahiro Yamada                endif
446433b2f1eSMasahiro Yamada        endif
447433b2f1eSMasahiro Yamadaendif
448433b2f1eSMasahiro Yamada
449433b2f1eSMasahiro Yamadaifeq ($(mixed-targets),1)
450433b2f1eSMasahiro Yamada# ===========================================================================
451433b2f1eSMasahiro Yamada# We're called with mixed targets (*config and build targets).
452433b2f1eSMasahiro Yamada# Handle them one by one.
453433b2f1eSMasahiro Yamada
454e7734404SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
45553bca5abSMasahiro Yamada
456e7734404SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
45753bca5abSMasahiro Yamada	@:
45853bca5abSMasahiro Yamada
459e7734404SMasahiro Yamada__build_one_by_one:
46053bca5abSMasahiro Yamada	$(Q)set -e; \
46153bca5abSMasahiro Yamada	for i in $(MAKECMDGOALS); do \
46253bca5abSMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
46353bca5abSMasahiro Yamada	done
464433b2f1eSMasahiro Yamada
465433b2f1eSMasahiro Yamadaelse
466433b2f1eSMasahiro Yamadaifeq ($(config-targets),1)
467433b2f1eSMasahiro Yamada# ===========================================================================
468433b2f1eSMasahiro Yamada# *config targets only - make sure prerequisites are updated, and descend
469433b2f1eSMasahiro Yamada# in scripts/kconfig to make the *config target
470433b2f1eSMasahiro Yamada
47151148790SMasahiro YamadaKBUILD_DEFCONFIG := sandbox_defconfig
47251148790SMasahiro Yamadaexport KBUILD_DEFCONFIG KBUILD_KCONFIG
473433b2f1eSMasahiro Yamada
47451148790SMasahiro Yamadaconfig: scripts_basic outputmakefile FORCE
4755f9eb220SMasahiro Yamada	$(Q)$(MAKE) $(build)=scripts/kconfig $@
47651148790SMasahiro Yamada
47751148790SMasahiro Yamada%config: scripts_basic outputmakefile FORCE
4785f9eb220SMasahiro Yamada	$(Q)$(MAKE) $(build)=scripts/kconfig $@
479433b2f1eSMasahiro Yamada
480433b2f1eSMasahiro Yamadaelse
481433b2f1eSMasahiro Yamada# ===========================================================================
482433b2f1eSMasahiro Yamada# Build targets only - this includes vmlinux, arch specific targets, clean
483433b2f1eSMasahiro Yamada# targets and others. In general all targets except *config targets.
484433b2f1eSMasahiro Yamada
48561304dbeSMasahiro Yamada# Additional helpers built in scripts/
48661304dbeSMasahiro Yamada# Carefully list dependencies so we do not try to build scripts twice
48761304dbeSMasahiro Yamada# in parallel
48861304dbeSMasahiro YamadaPHONY += scripts
48961304dbeSMasahiro Yamadascripts: scripts_basic include/config/auto.conf
49061304dbeSMasahiro Yamada	$(Q)$(MAKE) $(build)=$(@)
49161304dbeSMasahiro Yamada
492433b2f1eSMasahiro Yamadaifeq ($(dot-config),1)
493433b2f1eSMasahiro Yamada# Read in config
49451148790SMasahiro Yamada-include include/config/auto.conf
49551148790SMasahiro Yamada
49651148790SMasahiro Yamada# Read in dependencies to all Kconfig* files, make sure to run
49751148790SMasahiro Yamada# oldconfig if changes are detected.
49851148790SMasahiro Yamada-include include/config/auto.conf.cmd
49951148790SMasahiro Yamada
50051148790SMasahiro Yamada# To avoid any implicit rule to kick in, define an empty command
50151148790SMasahiro Yamada$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
50251148790SMasahiro Yamada
50351148790SMasahiro Yamada# If .config is newer than include/config/auto.conf, someone tinkered
50451148790SMasahiro Yamada# with it and forgot to run make oldconfig.
50551148790SMasahiro Yamada# if auto.conf.cmd is missing then we are probably in a cleaned tree so
50651148790SMasahiro Yamada# we execute the config step to be sure to catch updated Kconfig files
50751148790SMasahiro Yamadainclude/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
50851148790SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
5095f9eb220SMasahiro Yamada	@# If the following part fails, include/config/auto.conf should be
5105f9eb220SMasahiro Yamada	@# deleted so "make silentoldconfig" will be re-run on the next build.
5115f9eb220SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.autoconf || \
5125f9eb220SMasahiro Yamada		{ rm -f include/config/auto.conf; false; }
5135f9eb220SMasahiro Yamada	@# include/config.h has been updated after "make silentoldconfig".
5145f9eb220SMasahiro Yamada	@# We need to touch include/config/auto.conf so it gets newer
5155f9eb220SMasahiro Yamada	@# than include/config.h.
5165f9eb220SMasahiro Yamada	@# Otherwise, 'make silentoldconfig' would be invoked twice.
5175f9eb220SMasahiro Yamada	$(Q)touch include/config/auto.conf
51851148790SMasahiro Yamada
519433b2f1eSMasahiro Yamada-include include/autoconf.mk
520433b2f1eSMasahiro Yamada-include include/autoconf.mk.dep
521433b2f1eSMasahiro Yamada
52251148790SMasahiro Yamada# We want to include arch/$(ARCH)/config.mk only when include/config/auto.conf
52351148790SMasahiro Yamada# is up-to-date. When we switch to a different board configuration, old CONFIG
52451148790SMasahiro Yamada# macros are still remaining in include/config/auto.conf. Without the following
52551148790SMasahiro Yamada# gimmick, wrong config.mk would be included leading nasty warnings/errors.
526cffcd286SMasahiro Yamadaifneq ($(wildcard $(KCONFIG_CONFIG)),)
527cffcd286SMasahiro Yamadaifneq ($(wildcard include/config/auto.conf),)
528cffcd286SMasahiro Yamadaautoconf_is_old := $(shell find . -path ./$(KCONFIG_CONFIG) -newer \
529cffcd286SMasahiro Yamada						include/config/auto.conf)
530cffcd286SMasahiro Yamadaifeq ($(autoconf_is_old),)
5314d713be1SMasahiro Yamadainclude config.mk
5324d713be1SMasahiro Yamadainclude arch/$(ARCH)/Makefile
533ced0715dSMasahiro Yamadaendif
534cffcd286SMasahiro Yamadaendif
535cffcd286SMasahiro Yamadaendif
536fada9e20SSimon Glass
537bb1ae559SSimon Glass# These are set by the arch-specific config.mk. Make sure they are exported
538bb1ae559SSimon Glass# so they can be used when building an EFI application.
539bb1ae559SSimon Glassexport EFI_LDS		# Filename of EFI link script in arch/$(ARCH)/lib
540bb1ae559SSimon Glassexport EFI_CRT0		# Filename of EFI CRT0 in arch/$(ARCH)/lib
541bb1ae559SSimon Glassexport EFI_RELOC	# Filename of EFU relocation code in arch/$(ARCH)/lib
542bb1ae559SSimon Glassexport CFLAGS_EFI	# Compiler flags to add when building EFI app
543bb1ae559SSimon Glassexport CFLAGS_NON_EFI	# Compiler flags to remove when building EFI app
544bb1ae559SSimon Glassexport EFI_TARGET	# binutils target if EFI is natively supported
545bb1ae559SSimon Glass
546d51dfff7SIlya Yanok# If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
547d51dfff7SIlya Yanok# that (or fail if absent).  Otherwise, search for a linker script in a
548d51dfff7SIlya Yanok# standard location.
549d51dfff7SIlya Yanok
550d51dfff7SIlya Yanokifndef LDSCRIPT
5514379ac61SMasahiro Yamada	#LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot.lds.debug
552d51dfff7SIlya Yanok	ifdef CONFIG_SYS_LDSCRIPT
553d51dfff7SIlya Yanok		# need to strip off double quotes
5544a377552SMasahiro Yamada		LDSCRIPT := $(srctree)/$(CONFIG_SYS_LDSCRIPT:"%"=%)
555d51dfff7SIlya Yanok	endif
556d51dfff7SIlya Yanokendif
557d51dfff7SIlya Yanok
558ee60197eSSimon Glass# If there is no specified link script, we look in a number of places for it
559d51dfff7SIlya Yanokifndef LDSCRIPT
560d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
5614379ac61SMasahiro Yamada		LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot.lds
562d51dfff7SIlya Yanok	endif
563d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
5644379ac61SMasahiro Yamada		LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot.lds
565d51dfff7SIlya Yanok	endif
566d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
5674379ac61SMasahiro Yamada		LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot.lds
568ee60197eSSimon Glass	endif
569d51dfff7SIlya Yanokendif
570d51dfff7SIlya Yanok
571433b2f1eSMasahiro Yamadaelse
57251148790SMasahiro Yamada# Dummy target needed, because used as prerequisite
57351148790SMasahiro Yamadainclude/config/auto.conf: ;
574433b2f1eSMasahiro Yamadaendif # $(dot-config)
575433b2f1eSMasahiro Yamada
576de5e5ceaSChris Zankel#
577de5e5ceaSChris Zankel# Xtensa linker script cannot be preprocessed with -ansi because of
578de5e5ceaSChris Zankel# preprocessor operations on strings that don't make C identifiers.
579de5e5ceaSChris Zankel#
580de5e5ceaSChris Zankelifeq ($(CONFIG_XTENSA),)
581de5e5ceaSChris ZankelLDPPFLAGS	+= -ansi
582de5e5ceaSChris Zankelendif
583de5e5ceaSChris Zankel
5844a8ed8e2SMasahiro Yamadaifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
5854a8ed8e2SMasahiro YamadaKBUILD_CFLAGS	+= -Os
5864a8ed8e2SMasahiro Yamadaelse
5874a8ed8e2SMasahiro YamadaKBUILD_CFLAGS	+= -O2
5884a8ed8e2SMasahiro Yamadaendif
589433b2f1eSMasahiro Yamada
590433b2f1eSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
591687a7518SPrabhakar KushwahaKBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
592433b2f1eSMasahiro Yamada
593433b2f1eSMasahiro YamadaKBUILD_CFLAGS	+= -g
594433b2f1eSMasahiro Yamada# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
595433b2f1eSMasahiro Yamada# option to the assembler.
596433b2f1eSMasahiro YamadaKBUILD_AFLAGS	+= -g
597433b2f1eSMasahiro Yamada
598433b2f1eSMasahiro Yamada# Report stack usage if supported
5995b1f1f4aSMasahiro Yamadaifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-stack-usage.sh $(CC)),y)
6005b1f1f4aSMasahiro Yamada	KBUILD_CFLAGS += -fstack-usage
6015b1f1f4aSMasahiro Yamadaendif
602433b2f1eSMasahiro Yamada
603433b2f1eSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
604433b2f1eSMasahiro Yamada
605433b2f1eSMasahiro Yamada# turn jbsr into jsr for m68k
606433b2f1eSMasahiro Yamadaifeq ($(ARCH),m68k)
607433b2f1eSMasahiro Yamadaifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
608433b2f1eSMasahiro YamadaKBUILD_AFLAGS += -Wa,-gstabs,-S
609433b2f1eSMasahiro Yamadaendif
610433b2f1eSMasahiro Yamadaendif
611433b2f1eSMasahiro Yamada
61265bb6d8dSMasahiro Yamada# Prohibit date/time macros, which would make the build non-deterministic
61365bb6d8dSMasahiro YamadaKBUILD_CFLAGS   += $(call cc-option,-Werror=date-time)
61465bb6d8dSMasahiro Yamada
6154d713be1SMasahiro Yamadainclude scripts/Makefile.extrawarn
6166419e144SMasahiro Yamada
6170e6256d0SMasahiro Yamada# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
6180e6256d0SMasahiro YamadaKBUILD_CPPFLAGS += $(KCPPFLAGS)
6190e6256d0SMasahiro YamadaKBUILD_AFLAGS += $(KAFLAGS)
6200e6256d0SMasahiro YamadaKBUILD_CFLAGS += $(KCFLAGS)
6210e6256d0SMasahiro Yamada
622433b2f1eSMasahiro Yamada# Use UBOOTINCLUDE when you must reference the include/ directory.
623433b2f1eSMasahiro Yamada# Needed to be compatible with the O= option
624f5c66bdbSMasahiro YamadaUBOOTINCLUDE    := \
625f5c66bdbSMasahiro Yamada		-Iinclude \
626f5c66bdbSMasahiro Yamada		$(if $(KBUILD_SRC), -I$(srctree)/include) \
6273a649407STom Rini		$(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \
6283a649407STom Rini			$(if $(CONFIG_HAS_THUMB2),, \
62962e92077SAlbert ARIBAUD				-I$(srctree)/arch/$(ARCH)/thumb1/include),) \
63051148790SMasahiro Yamada		-I$(srctree)/arch/$(ARCH)/include \
63151148790SMasahiro Yamada		-include $(srctree)/include/linux/kconfig.h
632433b2f1eSMasahiro Yamada
633433b2f1eSMasahiro YamadaNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
634433b2f1eSMasahiro YamadaCHECKFLAGS     += $(NOSTDINC_FLAGS)
635433b2f1eSMasahiro Yamada
636433b2f1eSMasahiro Yamada# FIX ME
637026f9cf2SMasahiro Yamadacpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
638026f9cf2SMasahiro Yamada							$(NOSTDINC_FLAGS)
639433b2f1eSMasahiro Yamadac_flags := $(KBUILD_CFLAGS) $(cpp_flags)
640433b2f1eSMasahiro Yamada
6417ebf7443Swdenk#########################################################################
6427ebf7443Swdenk# U-Boot objects....order is important (i.e. start must be first)
6437ebf7443Swdenk
6449e414032SMasahiro YamadaHAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
645f9328639SMarian Balakowicz
646656de6b8SMasahiro Yamadalibs-y += lib/
647656de6b8SMasahiro Yamadalibs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
648656de6b8SMasahiro Yamadalibs-$(CONFIG_OF_EMBED) += dts/
649656de6b8SMasahiro Yamadalibs-y += fs/
650656de6b8SMasahiro Yamadalibs-y += net/
651656de6b8SMasahiro Yamadalibs-y += disk/
652656de6b8SMasahiro Yamadalibs-y += drivers/
653656de6b8SMasahiro Yamadalibs-y += drivers/dma/
654656de6b8SMasahiro Yamadalibs-y += drivers/gpio/
655656de6b8SMasahiro Yamadalibs-y += drivers/i2c/
656656de6b8SMasahiro Yamadalibs-y += drivers/mtd/
657656de6b8SMasahiro Yamadalibs-$(CONFIG_CMD_NAND) += drivers/mtd/nand/
658656de6b8SMasahiro Yamadalibs-y += drivers/mtd/onenand/
659656de6b8SMasahiro Yamadalibs-$(CONFIG_CMD_UBI) += drivers/mtd/ubi/
660656de6b8SMasahiro Yamadalibs-y += drivers/mtd/spi/
661656de6b8SMasahiro Yamadalibs-y += drivers/net/
662656de6b8SMasahiro Yamadalibs-y += drivers/net/phy/
663656de6b8SMasahiro Yamadalibs-y += drivers/pci/
664656de6b8SMasahiro Yamadalibs-y += drivers/power/ \
66561f5ddcbSStephen Warren	drivers/power/domain/ \
666e2906a59SMasahiro Yamada	drivers/power/fuel_gauge/ \
667e2906a59SMasahiro Yamada	drivers/power/mfd/ \
668e2906a59SMasahiro Yamada	drivers/power/pmic/ \
669af41e8dbSPrzemyslaw Marczak	drivers/power/battery/ \
670af41e8dbSPrzemyslaw Marczak	drivers/power/regulator/
671656de6b8SMasahiro Yamadalibs-y += drivers/spi/
672656de6b8SMasahiro Yamadalibs-$(CONFIG_FMAN_ENET) += drivers/net/fm/
673656de6b8SMasahiro Yamadalibs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
674b9e745bbSShengzhou Liulibs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
6759bbd2132SDinh Nguyenlibs-$(CONFIG_ALTERA_SDRAM) += drivers/ddr/altera/
676656de6b8SMasahiro Yamadalibs-y += drivers/serial/
6775b9ce0e2SKishon Vijay Abraham Ilibs-y += drivers/usb/dwc3/
67893eb8f39SSriram Dashlibs-y += drivers/usb/common/
679019808f9SSimon Glasslibs-y += drivers/usb/emul/
680656de6b8SMasahiro Yamadalibs-y += drivers/usb/eth/
681656de6b8SMasahiro Yamadalibs-y += drivers/usb/gadget/
6825b9ce0e2SKishon Vijay Abraham Ilibs-y += drivers/usb/gadget/udc/
683656de6b8SMasahiro Yamadalibs-y += drivers/usb/host/
684656de6b8SMasahiro Yamadalibs-y += drivers/usb/musb/
685656de6b8SMasahiro Yamadalibs-y += drivers/usb/musb-new/
686656de6b8SMasahiro Yamadalibs-y += drivers/usb/phy/
687656de6b8SMasahiro Yamadalibs-y += drivers/usb/ulpi/
68872a8cf8dSSimon Glasslibs-y += cmd/
689656de6b8SMasahiro Yamadalibs-y += common/
690656de6b8SMasahiro Yamadalibs-$(CONFIG_API) += api/
691656de6b8SMasahiro Yamadalibs-$(CONFIG_HAS_POST) += post/
692656de6b8SMasahiro Yamadalibs-y += test/
6932e7d35d2SSimon Glasslibs-y += test/dm/
694421f86f3SJoe Hershbergerlibs-$(CONFIG_UT_ENV) += test/env/
695f2a9942fSMaxime Ripardlibs-$(CONFIG_UT_OVERLAY) += test/overlay/
696f9328639SMarian Balakowicz
69733a02da0SMasahiro Yamadalibs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
69808e39a84SMasahiro Yamada
699656de6b8SMasahiro Yamadalibs-y := $(sort $(libs-y))
700656de6b8SMasahiro Yamada
701656de6b8SMasahiro Yamadau-boot-dirs	:= $(patsubst %/,%,$(filter %/, $(libs-y))) tools examples
702656de6b8SMasahiro Yamada
703656de6b8SMasahiro Yamadau-boot-alldirs	:= $(sort $(u-boot-dirs) $(patsubst %/,%,$(filter %/, $(libs-))))
704656de6b8SMasahiro Yamada
705656de6b8SMasahiro Yamadalibs-y		:= $(patsubst %/, %/built-in.o, $(libs-y))
706656de6b8SMasahiro Yamada
707656de6b8SMasahiro Yamadau-boot-init := $(head-y)
708656de6b8SMasahiro Yamadau-boot-main := $(libs-y)
709656de6b8SMasahiro Yamada
710a8c7c708Swdenk
7114f7cb08eSwdenk# Add GCC lib
712cd2e46cbSMasahiro Yamadaifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
713a86cf89cSMasahiro YamadaPLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
71452b1bf2cSWolfgang Denkelse
7156825a95bSMasahiro YamadaPLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc
71652b1bf2cSWolfgang Denkendif
71752b1bf2cSWolfgang DenkPLATFORM_LIBS += $(PLATFORM_LIBGCC)
71852b1bf2cSWolfgang Denkexport PLATFORM_LIBS
719e75e73ddSAlexey Brodkinexport PLATFORM_LIBGCC
7203d3befa7Swdenk
7216ac9f479SMike Frysinger# Special flags for CPP when processing the linker script.
7226ac9f479SMike Frysinger# Pass the version down so we can handle backwards compatibility
7236ac9f479SMike Frysinger# on the fly.
7246ac9f479SMike FrysingerLDPPFLAGS += \
7254379ac61SMasahiro Yamada	-include $(srctree)/include/u-boot/u-boot.lds.h \
7267e6403a6SSimon Glass	-DCPUDIR=$(CPUDIR) \
7276ac9f479SMike Frysinger	$(shell $(LD) --version | \
7286ac9f479SMike Frysinger	  sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
7296ac9f479SMike Frysinger
7307ebf7443Swdenk#########################################################################
731bdccc4feSwdenk#########################################################################
7327ebf7443Swdenk
733f3a14d37SMike Frysingerifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
734f3a14d37SMike FrysingerBOARD_SIZE_CHECK = \
735f3a14d37SMike Frysinger	@actual=`wc -c $@ | awk '{print $$1}'`; \
736d060e6f4SJoe Hershberger	limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
737f3a14d37SMike Frysinger	if test $$actual -gt $$limit; then \
738d060e6f4SJoe Hershberger		echo "$@ exceeds file size limit:" >&2 ; \
739d060e6f4SJoe Hershberger		echo "  limit:  $$limit bytes" >&2 ; \
740d060e6f4SJoe Hershberger		echo "  actual: $$actual bytes" >&2 ; \
741d060e6f4SJoe Hershberger		echo "  excess: $$((actual - limit)) bytes" >&2; \
742f3a14d37SMike Frysinger		exit 1; \
743f3a14d37SMike Frysinger	fi
744f3a14d37SMike Frysingerelse
745f3a14d37SMike FrysingerBOARD_SIZE_CHECK =
746f3a14d37SMike Frysingerendif
747f3a14d37SMike Frysinger
7488137af19SScott Wood# Statically apply RELA-style relocations (currently arm64 only)
749d57259b9SÁlvaro Fernández Rojas# This is useful for arm64 where static relocation needs to be performed on
750d57259b9SÁlvaro Fernández Rojas# the raw binary, but certain simulators only accept an ELF file (but don't
751d57259b9SÁlvaro Fernández Rojas# do the relocation).
7528137af19SScott Woodifneq ($(CONFIG_STATIC_RELA),)
7538137af19SScott Wood# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base
7548137af19SScott WoodDO_STATIC_RELA = \
7558137af19SScott Wood	start=$$($(NM) $(1) | grep __rel_dyn_start | cut -f 1 -d ' '); \
7568137af19SScott Wood	end=$$($(NM) $(1) | grep __rel_dyn_end | cut -f 1 -d ' '); \
7579e414032SMasahiro Yamada	tools/relocate-rela $(2) $(3) $$start $$end
7588137af19SScott Woodelse
7598137af19SScott WoodDO_STATIC_RELA =
7608137af19SScott Woodendif
7618137af19SScott Wood
7623e88337bSMike Frysinger# Always append ALL so that arch config.mk's can add custom ones
763e19b0fb4SMasahiro YamadaALL-y += u-boot.srec u-boot.bin u-boot.sym System.map binary_size_check
764e935a374SHaiying Wang
7659e414032SMasahiro YamadaALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin
76689ad7be8SPrabhakar Kushwahaifeq ($(CONFIG_SPL_FSL_PBL),y)
76789ad7be8SPrabhakar KushwahaALL-$(CONFIG_RAMBOOT_PBL) += u-boot-with-spl-pbl.bin
76889ad7be8SPrabhakar Kushwahaelse
769467a40dfSAneesh Bansalifneq ($(CONFIG_SECURE_BOOT), y)
770467a40dfSAneesh Bansal# For Secure Boot The Image needs to be signed and Header must also
771467a40dfSAneesh Bansal# be included. So The image has to be built explicitly
7729e414032SMasahiro YamadaALL-$(CONFIG_RAMBOOT_PBL) += u-boot.pbl
77389ad7be8SPrabhakar Kushwahaendif
774467a40dfSAneesh Bansalendif
7759e414032SMasahiro YamadaALL-$(CONFIG_SPL) += spl/u-boot-spl.bin
776d21bd69bSSven Ebenfeldifeq ($(CONFIG_MX6)$(CONFIG_SECURE_BOOT), yy)
777d21bd69bSSven EbenfeldALL-$(CONFIG_SPL_FRAMEWORK) += u-boot-ivt.img
778d21bd69bSSven Ebenfeldelse
7799e414032SMasahiro YamadaALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
780d21bd69bSSven Ebenfeldendif
7819e414032SMasahiro YamadaALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
782ad1ecd20SSimon GlassALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb
7832405d09cSMasahiro Yamadaifeq ($(CONFIG_SPL_FRAMEWORK),y)
7842405d09cSMasahiro YamadaALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
7852405d09cSMasahiro Yamadaendif
786714a5621SSimon GlassALL-$(CONFIG_OF_HOSTFILE) += u-boot.dtb
787b343bbb5SVadim Bendeburyifneq ($(CONFIG_SPL_TARGET),)
7889e414032SMasahiro YamadaALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
789b343bbb5SVadim Bendeburyendif
7909e414032SMasahiro YamadaALL-$(CONFIG_REMAKE_ELF) += u-boot.elf
79108aeb8b5SSimon GlassALL-$(CONFIG_EFI_APP) += u-boot-app.efi
792476476e7SSimon GlassALL-$(CONFIG_EFI_STUB) += u-boot-payload.efi
7937ebf7443Swdenk
794eea0f112SSimon Glassifneq ($(BUILD_ROM),)
795eea0f112SSimon GlassALL-$(CONFIG_X86_RESET_VECTOR) += u-boot.rom
796eea0f112SSimon Glassendif
797fce7b276SSimon Glass
79812b7b70cSAllen Martin# enable combined SPL/u-boot/dtb rules for tegra
799580cc033SSimon Glassifeq ($(CONFIG_TEGRA)$(CONFIG_SPL),yy)
800a9d78260SSimon GlassALL-y += u-boot-tegra.bin u-boot-nodtb-tegra.bin
801580cc033SSimon GlassALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb-tegra.bin
8027dcd3a21SVidya Sagarendif
80312b7b70cSAllen Martin
804b2b8a696SStefan Roese# Add optional build target if defined in board/cpu/soc headers
805b2b8a696SStefan Roeseifneq ($(CONFIG_BUILD_TARGET),)
806b2b8a696SStefan RoeseALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
807b2b8a696SStefan Roeseendif
808b2b8a696SStefan Roese
809ad0fed46SMasahiro YamadaLDFLAGS_u-boot += $(LDFLAGS_FINAL)
810e391b1e6SJoel Stanley
811e391b1e6SJoel Stanley# Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
812e391b1e6SJoel StanleyLDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker)
813e391b1e6SJoel Stanley
814433b2f1eSMasahiro Yamadaifneq ($(CONFIG_SYS_TEXT_BASE),)
815433b2f1eSMasahiro YamadaLDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
816433b2f1eSMasahiro Yamadaendif
81771f84ef0SMasahiro Yamada
818e020c88aSSimon Glass# Normally we fill empty space with 0xff
819f9c235fdSMasahiro Yamadaquiet_cmd_objcopy = OBJCOPY $@
820e020c88aSSimon Glasscmd_objcopy = $(OBJCOPY) --gap-fill=0xff $(OBJCOPYFLAGS) \
821e020c88aSSimon Glass	$(OBJCOPYFLAGS_$(@F)) $< $@
822e020c88aSSimon Glass
823e020c88aSSimon Glass# Provide a version which does not do this, for use by EFI
824e020c88aSSimon Glassquiet_cmd_zobjcopy = OBJCOPY $@
825e020c88aSSimon Glasscmd_zobjcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
826f9c235fdSMasahiro Yamada
827476476e7SSimon Glassquiet_cmd_efipayload = OBJCOPY $@
828476476e7SSimon Glasscmd_efipayload = $(OBJCOPY) -I binary -O $(EFIPAYLOAD_BFDTARGET) -B $(EFIPAYLOAD_BFDARCH) $< $@
829476476e7SSimon Glass
8301f6a6648SSven EbenfeldMKIMAGEOUTPUT ?= /dev/null
8311f6a6648SSven Ebenfeld
832b97241b3SMarek Vasutquiet_cmd_mkimage = MKIMAGE $@
8339bf215b0SMasahiro Yamadacmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
8341f6a6648SSven Ebenfeld	$(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT))
8359bf215b0SMasahiro Yamada
8361a12fdc4SAndre Przywaraquiet_cmd_mkfitimage = MKIMAGE $@
8371a12fdc4SAndre Przywaracmd_mkfitimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -f $(U_BOOT_ITS) -E $@ \
8381a12fdc4SAndre Przywara	$(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT))
8391a12fdc4SAndre Przywara
840ee0acfa2SMasahiro Yamadaquiet_cmd_cat = CAT     $@
841ee0acfa2SMasahiro Yamadacmd_cat = cat $(filter-out $(PHONY), $^) > $@
842ee0acfa2SMasahiro Yamada
843982a1199SMasahiro Yamadaappend = cat $(filter-out $< $(PHONY), $^) >> $@
844982a1199SMasahiro Yamada
845982a1199SMasahiro Yamadaquiet_cmd_pad_cat = CAT     $@
846982a1199SMasahiro Yamadacmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
847982a1199SMasahiro Yamada
8481bd87630SSimon Glasscfg: u-boot.cfg
8491bd87630SSimon Glass
8501bdd942bSMasahiro Yamadaquiet_cmd_cfgcheck = CFGCHK  $2
8511bdd942bSMasahiro Yamadacmd_cfgcheck = $(srctree)/scripts/check-config.sh $2 \
8521bdd942bSMasahiro Yamada		$(srctree)/scripts/config_whitelist.txt $(srctree)
8531bdd942bSMasahiro Yamada
854656de6b8SMasahiro Yamadaall:		$(ALL-y)
8557fcdac0eSSimon Glassifeq ($(CONFIG_DM_I2C_COMPAT)$(CONFIG_SANDBOX),y)
85673845350SSimon Glass	@echo "===================== WARNING ======================"
85773845350SSimon Glass	@echo "This board uses CONFIG_DM_I2C_COMPAT. Please remove"
85873845350SSimon Glass	@echo "(possibly in a subsequent patch in your series)"
85973845350SSimon Glass	@echo "before sending patches to the mailing list."
86073845350SSimon Glass	@echo "===================================================="
86173845350SSimon Glassendif
8624bf06d11SMasahiro Yamada	@# Check that this build does not use CONFIG options that we do not
8634bf06d11SMasahiro Yamada	@# know about unless they are in Kconfig. All the existing CONFIG
8644bf06d11SMasahiro Yamada	@# options are whitelisted, so new ones should not be added.
8651bdd942bSMasahiro Yamada	$(call cmd,cfgcheck,u-boot.cfg)
8667ebf7443Swdenk
8676ab6b2afSMasahiro YamadaPHONY += dtbs
8684141e85bSMasahiro Yamadadtbs: dts/dt.dtb
8694141e85bSMasahiro Yamada	@:
8704141e85bSMasahiro Yamadadts/dt.dtb: checkdtc u-boot
8716ab6b2afSMasahiro Yamada	$(Q)$(MAKE) $(build)=dts dtbs
8722c0f79e4SSimon Glass
873ad1ecd20SSimon Glassquiet_cmd_copy = COPY    $@
874ad1ecd20SSimon Glass      cmd_copy = cp $< $@
875ad1ecd20SSimon Glass
8766f59fb07SCooper Jr., Franklinifeq ($(CONFIG_FIT_EMBED),y)
8776f59fb07SCooper Jr., Franklin
8786f59fb07SCooper Jr., Franklinfit-dtb.blob: dts/dt.dtb FORCE
8796f59fb07SCooper Jr., Franklin	$(call if_changed,mkimage)
8806f59fb07SCooper Jr., Franklin
8816f59fb07SCooper Jr., FranklinMKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
8826f59fb07SCooper Jr., Franklin	-a 0 -e 0 -E \
8836f59fb07SCooper Jr., Franklin	$(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null
8846f59fb07SCooper Jr., Franklin
8856f59fb07SCooper Jr., Franklinu-boot-fit-dtb.bin: u-boot-nodtb.bin fit-dtb.blob
8866f59fb07SCooper Jr., Franklin	$(call if_changed,cat)
8876f59fb07SCooper Jr., Franklin
8886f59fb07SCooper Jr., Franklinu-boot.bin: u-boot-fit-dtb.bin FORCE
8896f59fb07SCooper Jr., Franklin	$(call if_changed,copy)
8906f59fb07SCooper Jr., Franklinelse ifeq ($(CONFIG_OF_SEPARATE),y)
891ad1ecd20SSimon Glassu-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
892ee0acfa2SMasahiro Yamada	$(call if_changed,cat)
8932c0f79e4SSimon Glass
894ad1ecd20SSimon Glassu-boot.bin: u-boot-dtb.bin FORCE
895ad1ecd20SSimon Glass	$(call if_changed,copy)
896ad1ecd20SSimon Glasselse
897ad1ecd20SSimon Glassu-boot.bin: u-boot-nodtb.bin FORCE
898ad1ecd20SSimon Glass	$(call if_changed,copy)
899ad1ecd20SSimon Glassendif
900ad1ecd20SSimon Glass
901e64348f5SStefano Babic%.imx: %.bin
902*552a848eSStefano Babic	$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
903e64348f5SStefano Babic
904ed0c2c0aSAlbert ARIBAUD \(3ADEV\)%.vyb: %.imx
905ed0c2c0aSAlbert ARIBAUD \(3ADEV\)	$(Q)$(MAKE) $(build)=arch/arm/cpu/armv7/vf610 $@
906ed0c2c0aSAlbert ARIBAUD \(3ADEV\)
907ed0c2c0aSAlbert ARIBAUD \(3ADEV\)quiet_cmd_copy = COPY    $@
908ed0c2c0aSAlbert ARIBAUD \(3ADEV\)      cmd_copy = cp $< $@
909ed0c2c0aSAlbert ARIBAUD \(3ADEV\)
9100d1e8aacSMasahiro Yamadau-boot.dtb: dts/dt.dtb
9110d1e8aacSMasahiro Yamada	$(call cmd,copy)
9120d1e8aacSMasahiro Yamada
913f9c235fdSMasahiro YamadaOBJCOPYFLAGS_u-boot.hex := -O ihex
9146310eb9dSwdenk
915f9c235fdSMasahiro YamadaOBJCOPYFLAGS_u-boot.srec := -O srec
9167ebf7443Swdenk
917f9c235fdSMasahiro Yamadau-boot.hex u-boot.srec: u-boot FORCE
918f9c235fdSMasahiro Yamada	$(call if_changed,objcopy)
919f9c235fdSMasahiro Yamada
920ad1ecd20SSimon GlassOBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \
921972188b3SSimon Glass		$(if $(CONFIG_X86_16BIT_INIT),-R .start16 -R .resetvec)
922f9c235fdSMasahiro Yamada
923ad1ecd20SSimon Glassbinary_size_check: u-boot-nodtb.bin FORCE
924ad1ecd20SSimon Glass	@file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \
9253ce7a4feSChris Packham	map_size=$(shell cat u-boot.map | \
9260b308f14SSimon Glass		awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \
9273ce7a4feSChris Packham		| sed 's/0X//g' \
9280b308f14SSimon Glass		| bc); \
92989742924SSimon Glass	if [ "" != "$$map_size" ]; then \
93089742924SSimon Glass		if test $$map_size -ne $$file_size; then \
9313ce7a4feSChris Packham			echo "u-boot.map shows a binary size of $$map_size" >&2 ; \
932ad1ecd20SSimon Glass			echo "  but u-boot-nodtb.bin shows $$file_size" >&2 ; \
93389742924SSimon Glass			exit 1; \
93489742924SSimon Glass		fi \
93589742924SSimon Glass	fi
93689742924SSimon Glass
937ad1ecd20SSimon Glassu-boot-nodtb.bin: u-boot FORCE
938f9c235fdSMasahiro Yamada	$(call if_changed,objcopy)
9398137af19SScott Wood	$(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
940f3a14d37SMike Frysinger	$(BOARD_SIZE_CHECK)
9417ebf7443Swdenk
9429e414032SMasahiro Yamadau-boot.ldr:	u-boot
94376d82187SMike Frysinger		$(CREATE_LDR_ENV)
944240182d5SSonic Zhang		$(LDR) -T $(CONFIG_CPU) -c $@ $< $(LDR_FLAGS)
945f3a14d37SMike Frysinger		$(BOARD_SIZE_CHECK)
94694a91e24SMike Frysinger
94717a944b6SSimon Glass# binman
94817a944b6SSimon Glass# ---------------------------------------------------------------------------
94917a944b6SSimon Glassquiet_cmd_binman = BINMAN  $@
95017a944b6SSimon Glasscmd_binman = $(srctree)/tools/binman/binman -d u-boot.dtb -O . \
95117a944b6SSimon Glass		-I . -I $(srctree)/board/$(BOARDDIR) $<
95217a944b6SSimon Glass
953f9c235fdSMasahiro YamadaOBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
95494a91e24SMike Frysinger
955f9c235fdSMasahiro YamadaOBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
956f9c235fdSMasahiro Yamada
957f9c235fdSMasahiro Yamadau-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE
958f9c235fdSMasahiro Yamada	$(call if_changed,objcopy)
95994a91e24SMike Frysinger
960b40bda6bSStefan Roese#
961b40bda6bSStefan Roese# U-Boot entry point, needed for booting of full-blown U-Boot
962b40bda6bSStefan Roese# from the SPL U-Boot version.
963b40bda6bSStefan Roese#
964b40bda6bSStefan Roeseifndef CONFIG_SYS_UBOOT_START
965b40bda6bSStefan RoeseCONFIG_SYS_UBOOT_START := 0
966b40bda6bSStefan Roeseendif
967b40bda6bSStefan Roese
968741e58e0SSimon Glass# Create a file containing the configuration options the image was built with
969741e58e0SSimon Glassquiet_cmd_cpp_cfg = CFG     $@
970741e58e0SSimon Glasscmd_cpp_cfg = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
9713113471fSMasahiro Yamada	-DDO_DEPS_ONLY -D__ASSEMBLY__ -x assembler-with-cpp -P -dM -E -o $@ $<
972741e58e0SSimon Glass
9731a12fdc4SAndre Przywara# Boards with more complex image requirments can provide an .its source file
9741a12fdc4SAndre Przywara# or a generator script
9751a12fdc4SAndre Przywaraifneq ($(CONFIG_SPL_FIT_SOURCE),"")
9761a12fdc4SAndre PrzywaraU_BOOT_ITS = $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
9771a12fdc4SAndre Przywaraelse
9781a12fdc4SAndre Przywaraifneq ($(CONFIG_SPL_FIT_GENERATOR),"")
9791a12fdc4SAndre PrzywaraU_BOOT_ITS := u-boot.its
9801a12fdc4SAndre Przywara$(U_BOOT_ITS): FORCE
9811a12fdc4SAndre Przywara	$(srctree)/$(CONFIG_SPL_FIT_GENERATOR) \
9821a12fdc4SAndre Przywara	$(patsubst %,arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) > $@
9831a12fdc4SAndre Przywaraendif
9841a12fdc4SAndre Przywaraendif
9851a12fdc4SAndre Przywara
986cdf17246SSimon Glassifdef CONFIG_SPL_LOAD_FIT
987cdf17246SSimon GlassMKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
988cdf17246SSimon Glass	-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
989cdf17246SSimon Glass	-n "U-Boot $(UBOOTRELEASE) for $(BOARD) board" -E \
9907a439cadSAndreas Bießmann	$(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST)))
991cdf17246SSimon Glasselse
9929bf215b0SMasahiro YamadaMKIMAGEFLAGS_u-boot.img = -A $(ARCH) -T firmware -C none -O u-boot \
9939bf215b0SMasahiro Yamada	-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
9949bf215b0SMasahiro Yamada	-n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
995d21bd69bSSven EbenfeldMKIMAGEFLAGS_u-boot-ivt.img = -A $(ARCH) -T firmware_ivt -C none -O u-boot \
996d21bd69bSSven Ebenfeld	-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
997d21bd69bSSven Ebenfeld	-n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
9981f6a6648SSven Ebenfeldu-boot-ivt.img: MKIMAGEOUTPUT = u-boot-ivt.img.log
9991f6a6648SSven EbenfeldCLEAN_FILES += u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log
1000cdf17246SSimon Glassendif
10019bf215b0SMasahiro Yamada
1002dae6e7bfSSimon GlassMKIMAGEFLAGS_u-boot-dtb.img = $(MKIMAGEFLAGS_u-boot.img)
1003dae6e7bfSSimon Glass
10044ab3fc5eSMasahiro YamadaMKIMAGEFLAGS_u-boot.kwb = -n $(srctree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%) \
10054ab3fc5eSMasahiro Yamada	-T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
10069bf215b0SMasahiro Yamada
1007a90ffb56SStefan RoeseMKIMAGEFLAGS_u-boot-spl.kwb = -n $(srctree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%) \
1008a1b6b0a9SMario Six	-T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
1009a1b6b0a9SMario Six	$(if $(KEYDIR),-k $(KEYDIR))
1010a90ffb56SStefan Roese
1011e4536f8eSMasahiro YamadaMKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
1012e4536f8eSMasahiro Yamada		-R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -T pblimage
10139bf215b0SMasahiro Yamada
1014d21bd69bSSven Ebenfeldu-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
1015cdf17246SSimon Glass		$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin dts/dt.dtb,u-boot.bin) FORCE
10169bf215b0SMasahiro Yamada	$(call if_changed,mkimage)
1017bdccc4feSwdenk
10181a12fdc4SAndre Przywarau-boot.itb: u-boot-nodtb.bin dts/dt.dtb $(U_BOOT_ITS) FORCE
10191a12fdc4SAndre Przywara	$(call if_changed,mkfitimage)
10201a12fdc4SAndre Przywara
102173c5c399SSimon Glassu-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE
1022a90ffb56SStefan Roese	$(call if_changed,mkimage)
1023a90ffb56SStefan Roese
10249e414032SMasahiro Yamadau-boot.sha1:	u-boot.bin
10259e414032SMasahiro Yamada		tools/ubsha1 u-boot.bin
1026566a494fSHeiko Schocher
10279e414032SMasahiro Yamadau-boot.dis:	u-boot
10287ebf7443Swdenk		$(OBJDUMP) -d $< > $@
10297ebf7443Swdenk
10303aa29de0SYing Zhangifdef CONFIG_TPL
10319e414032SMasahiro YamadaSPL_PAYLOAD := tpl/u-boot-with-tpl.bin
10323aa29de0SYing Zhangelse
10339e414032SMasahiro YamadaSPL_PAYLOAD := u-boot.bin
10343aa29de0SYing Zhangendif
103574752baaSScott Wood
1036982a1199SMasahiro YamadaOBJCOPYFLAGS_u-boot-with-spl.bin = -I binary -O binary \
1037982a1199SMasahiro Yamada				   --pad-to=$(CONFIG_SPL_PAD_TO)
1038982a1199SMasahiro Yamadau-boot-with-spl.bin: spl/u-boot-spl.bin $(SPL_PAYLOAD) FORCE
1039982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
10403aa29de0SYing Zhang
1041412ae53aSAlbert ARIBAUD \(3ADEV\)MKIMAGEFLAGS_lpc32xx-spl.img = -T lpc32xximage -a $(CONFIG_SPL_TEXT_BASE)
1042412ae53aSAlbert ARIBAUD \(3ADEV\)
1043412ae53aSAlbert ARIBAUD \(3ADEV\)lpc32xx-spl.img: spl/u-boot-spl.bin FORCE
1044412ae53aSAlbert ARIBAUD \(3ADEV\)	$(call if_changed,mkimage)
1045412ae53aSAlbert ARIBAUD \(3ADEV\)
1046412ae53aSAlbert ARIBAUD \(3ADEV\)OBJCOPYFLAGS_lpc32xx-boot-0.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1047412ae53aSAlbert ARIBAUD \(3ADEV\)
1048514ec438SMasahiro Yamadalpc32xx-boot-0.bin: lpc32xx-spl.img FORCE
1049412ae53aSAlbert ARIBAUD \(3ADEV\)	$(call if_changed,objcopy)
1050412ae53aSAlbert ARIBAUD \(3ADEV\)
1051412ae53aSAlbert ARIBAUD \(3ADEV\)OBJCOPYFLAGS_lpc32xx-boot-1.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1052412ae53aSAlbert ARIBAUD \(3ADEV\)
1053514ec438SMasahiro Yamadalpc32xx-boot-1.bin: lpc32xx-spl.img FORCE
1054412ae53aSAlbert ARIBAUD \(3ADEV\)	$(call if_changed,objcopy)
1055412ae53aSAlbert ARIBAUD \(3ADEV\)
1056514ec438SMasahiro Yamadalpc32xx-full.bin: lpc32xx-boot-0.bin lpc32xx-boot-1.bin u-boot.img FORCE
1057412ae53aSAlbert ARIBAUD \(3ADEV\)	$(call if_changed,cat)
1058412ae53aSAlbert ARIBAUD \(3ADEV\)
1059412ae53aSAlbert ARIBAUD \(3ADEV\)CLEAN_FILES += lpc32xx-*
1060412ae53aSAlbert ARIBAUD \(3ADEV\)
1061982a1199SMasahiro YamadaOBJCOPYFLAGS_u-boot-with-tpl.bin = -I binary -O binary \
1062982a1199SMasahiro Yamada				   --pad-to=$(CONFIG_TPL_PAD_TO)
1063982a1199SMasahiro Yamadatpl/u-boot-with-tpl.bin: tpl/u-boot-tpl.bin u-boot.bin FORCE
1064982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
10657816f2cfSHeiko Schocher
1066630d2345SMasahiro YamadaSPL: spl/u-boot-spl.bin FORCE
1067*552a848eSStefano Babic	$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1068630d2345SMasahiro Yamada
1069630d2345SMasahiro Yamadau-boot-with-spl.imx u-boot-with-nand-spl.imx: SPL u-boot.bin FORCE
1070*552a848eSStefano Babic	$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
10717d5a5c79SBenoît Thébaudeau
10729bf215b0SMasahiro YamadaMKIMAGEFLAGS_u-boot.ubl = -n $(UBL_CONFIG) -T ublimage -e $(CONFIG_SYS_TEXT_BASE)
10739bf215b0SMasahiro Yamada
10749bf215b0SMasahiro Yamadau-boot.ubl: u-boot-with-spl.bin FORCE
10759bf215b0SMasahiro Yamada	$(call if_changed,mkimage)
1076277f00f5SJosé Miguel Gonçalves
1077982a1199SMasahiro YamadaMKIMAGEFLAGS_u-boot-spl.ais = -s -n $(if $(CONFIG_AIS_CONFIG_FILE), \
1078982a1199SMasahiro Yamada	$(srctree)/$(CONFIG_AIS_CONFIG_FILE:"%"=%),"/dev/null") \
1079982a1199SMasahiro Yamada	-T aisimage -e $(CONFIG_SPL_TEXT_BASE)
1080982a1199SMasahiro Yamadaspl/u-boot-spl.ais: spl/u-boot-spl.bin FORCE
1081982a1199SMasahiro Yamada	$(call if_changed,mkimage)
1082d36d8859SChristian Riesch
1083532d5318SChristian RieschOBJCOPYFLAGS_u-boot.ais = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1084982a1199SMasahiro Yamadau-boot.ais: spl/u-boot-spl.ais u-boot.img FORCE
1085982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
1086a5453555SOtavio Salvador
10871a9df13dSMarek Vasutu-boot-signed.sb: u-boot.bin spl/u-boot-spl.bin
10881a9df13dSMarek Vasut	$(Q)$(MAKE) $(build)=arch/arm/cpu/arm926ejs/mxs u-boot-signed.sb
10899e414032SMasahiro Yamadau-boot.sb: u-boot.bin spl/u-boot-spl.bin
109007e27ce0SMasahiro Yamada	$(Q)$(MAKE) $(build)=arch/arm/cpu/arm926ejs/mxs u-boot.sb
109130b9b932SMarek Vasut
109294aebe6cSStefan Roese# On x600 (SPEAr600) U-Boot is appended to U-Boot SPL.
109394aebe6cSStefan Roese# Both images are created using mkimage (crc etc), so that the ROM
109494aebe6cSStefan Roese# bootloader can check its integrity. Padding needs to be done to the
109594aebe6cSStefan Roese# SPL image (with mkimage header) and not the binary. Otherwise the resulting image
109694aebe6cSStefan Roese# which is loaded/copied by the ROM bootloader to SRAM doesn't fit.
109794aebe6cSStefan Roese# The resulting image containing both U-Boot images is called u-boot.spr
1098982a1199SMasahiro YamadaMKIMAGEFLAGS_u-boot-spl.img = -A $(ARCH) -T firmware -C none \
1099982a1199SMasahiro Yamada	-a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) -n XLOADER
1100982a1199SMasahiro Yamadaspl/u-boot-spl.img: spl/u-boot-spl.bin FORCE
1101982a1199SMasahiro Yamada	$(call if_changed,mkimage)
1102982a1199SMasahiro Yamada
1103982a1199SMasahiro YamadaOBJCOPYFLAGS_u-boot.spr = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
1104982a1199SMasahiro Yamada			  --gap-fill=0xff
1105982a1199SMasahiro Yamadau-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
1106982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
110794aebe6cSStefan Roese
1108333b7209SMarek Vasutifneq ($(CONFIG_ARCH_SOCFPGA),)
1109333b7209SMarek Vasutquiet_cmd_socboot = SOCBOOT $@
1110bd7dc388SSimon Glasscmd_socboot = cat	spl/u-boot-spl.sfp spl/u-boot-spl.sfp	\
1111bd7dc388SSimon Glass			spl/u-boot-spl.sfp spl/u-boot-spl.sfp	\
1112bd7dc388SSimon Glass			u-boot.img > $@ || rm -f $@
1113bd7dc388SSimon Glassu-boot-with-spl.sfp: spl/u-boot-spl.sfp u-boot.img FORCE
1114333b7209SMarek Vasut	$(call if_changed,socboot)
1115333b7209SMarek Vasutendif
1116333b7209SMarek Vasut
1117fce7b276SSimon Glass# x86 uses a large ROM. We fill it with 0xff, put the 16-bit stuff (including
1118fce7b276SSimon Glass# reset vector) at the top, Intel ME descriptor at the bottom, and U-Boot in
1119b215fbd8SSimon Glass# the middle. This is handled by binman based on an image description in the
1120b215fbd8SSimon Glass# board's device tree.
1121fce7b276SSimon Glassifneq ($(CONFIG_X86_RESET_VECTOR),)
1122fce7b276SSimon Glassrom: u-boot.rom FORCE
1123fce7b276SSimon Glass
11240adf8d35SSimon Glassrefcode.bin: $(srctree)/board/$(BOARDDIR)/refcode.bin FORCE
11250adf8d35SSimon Glass	$(call if_changed,copy)
11260adf8d35SSimon Glass
11270adf8d35SSimon Glassquiet_cmd_ldr = LD      $@
11280adf8d35SSimon Glasscmd_ldr = $(LD) $(LDFLAGS_$(@F)) \
11290adf8d35SSimon Glass	       $(filter-out FORCE,$^) -o $@
11300adf8d35SSimon Glass
1131972188b3SSimon Glassu-boot.rom: u-boot-x86-16bit.bin u-boot.bin \
1132972188b3SSimon Glass		$(if $(CONFIG_SPL_X86_16BIT_INIT),spl/u-boot-spl.bin) \
1133e38ffc42SSimon Glass		$(if $(CONFIG_HAVE_REFCODE),refcode.bin) checkbinman FORCE
1134b215fbd8SSimon Glass	$(call if_changed,binman)
1135fce7b276SSimon Glass
1136fce7b276SSimon GlassOBJCOPYFLAGS_u-boot-x86-16bit.bin := -O binary -j .start16 -j .resetvec
1137fce7b276SSimon Glassu-boot-x86-16bit.bin: u-boot FORCE
1138fce7b276SSimon Glass	$(call if_changed,objcopy)
1139fce7b276SSimon Glassendif
1140fce7b276SSimon Glass
1141aec9a0f1SJagan Tekiifneq ($(CONFIG_ARCH_SUNXI),)
1142e38ffc42SSimon Glassu-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb \
1143e38ffc42SSimon Glass		checkbinman FORCE
114461b994a3SSimon Glass	$(call if_changed,binman)
114550827a59SIan Campbellendif
114650827a59SIan Campbell
11476d6c0baeSTom Warrenifneq ($(CONFIG_TEGRA),)
1148982a1199SMasahiro YamadaOBJCOPYFLAGS_u-boot-nodtb-tegra.bin = -O binary --pad-to=$(CONFIG_SYS_TEXT_BASE)
1149ad1ecd20SSimon Glassu-boot-nodtb-tegra.bin: spl/u-boot-spl u-boot-nodtb.bin FORCE
1150982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
11519972db5cSStephen Warren
1152a9d78260SSimon GlassOBJCOPYFLAGS_u-boot-tegra.bin = -O binary --pad-to=$(CONFIG_SYS_TEXT_BASE)
115373c5c399SSimon Glassu-boot-tegra.bin: spl/u-boot-spl u-boot.bin FORCE
1154580cc033SSimon Glass	$(call if_changed,pad_cat)
1155a9d78260SSimon Glass
1156a9d78260SSimon Glassu-boot-dtb-tegra.bin: u-boot-tegra.bin FORCE
1157a9d78260SSimon Glass	$(call if_changed,copy)
1158984df4ecSAllen Martinendif
1159984df4ecSAllen Martin
116008aeb8b5SSimon GlassOBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
116108aeb8b5SSimon Glassu-boot-app.efi: u-boot FORCE
116208aeb8b5SSimon Glass	$(call if_changed,zobjcopy)
116308aeb8b5SSimon Glass
116473c5c399SSimon Glassu-boot.bin.o: u-boot.bin FORCE
1165476476e7SSimon Glass	$(call if_changed,efipayload)
1166476476e7SSimon Glass
1167476476e7SSimon Glassu-boot-payload.lds: $(LDSCRIPT_EFI) FORCE
1168476476e7SSimon Glass	$(call if_changed_dep,cpp_lds)
1169476476e7SSimon Glass
1170476476e7SSimon Glass# Rule to link the EFI payload which contains a stub and a U-Boot binary
1171476476e7SSimon Glassquiet_cmd_u-boot_payload ?= LD      $@
1172476476e7SSimon Glass      cmd_u-boot_payload ?= $(LD) $(LDFLAGS_EFI_PAYLOAD) -o $@ \
117396a8d409SSimon Glass      -T u-boot-payload.lds arch/x86/cpu/call32.o \
117473c5c399SSimon Glass      lib/efi/efi.o lib/efi/efi_stub.o u-boot.bin.o \
11752dcd4e9eSSimon Glass      $(addprefix arch/$(ARCH)/lib/,$(EFISTUB))
1176476476e7SSimon Glass
117773c5c399SSimon Glassu-boot-payload: u-boot.bin.o u-boot-payload.lds FORCE
1178476476e7SSimon Glass	$(call if_changed,u-boot_payload)
1179476476e7SSimon Glass
1180476476e7SSimon GlassOBJCOPYFLAGS_u-boot-payload.efi := $(OBJCOPYFLAGS_EFI)
1181476476e7SSimon Glassu-boot-payload.efi: u-boot-payload FORCE
1182476476e7SSimon Glass	$(call if_changed,zobjcopy)
1183476476e7SSimon Glass
1184ee0acfa2SMasahiro Yamadau-boot-img.bin: spl/u-boot-spl.bin u-boot.img FORCE
1185ee0acfa2SMasahiro Yamada	$(call if_changed,cat)
1186fb3d2b8aSStefan Roese
118789ad7be8SPrabhakar Kushwaha#Add a target to create boot binary having SPL binary in PBI format
118889ad7be8SPrabhakar Kushwaha#concatenated with u-boot binary. It is need by PowerPC SoC having
118989ad7be8SPrabhakar Kushwaha#internal SRAM <= 512KB.
119089ad7be8SPrabhakar KushwahaMKIMAGEFLAGS_u-boot-spl.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
119194cb17d0SAlison Wang		-R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -T pblimage \
119294cb17d0SAlison Wang		-A $(ARCH) -a $(CONFIG_SPL_TEXT_BASE)
119389ad7be8SPrabhakar Kushwaha
119489ad7be8SPrabhakar Kushwahaspl/u-boot-spl.pbl: spl/u-boot-spl.bin FORCE
119589ad7be8SPrabhakar Kushwaha	$(call if_changed,mkimage)
119689ad7be8SPrabhakar Kushwaha
119745c2e480SAlison Wangifeq ($(ARCH),arm)
119845c2e480SAlison WangUBOOT_BINLOAD := u-boot.img
119945c2e480SAlison Wangelse
120045c2e480SAlison WangUBOOT_BINLOAD := u-boot.bin
120145c2e480SAlison Wangendif
120245c2e480SAlison Wang
120389ad7be8SPrabhakar KushwahaOBJCOPYFLAGS_u-boot-with-spl-pbl.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
120489ad7be8SPrabhakar Kushwaha			  --gap-fill=0xff
120589ad7be8SPrabhakar Kushwaha
120645c2e480SAlison Wangu-boot-with-spl-pbl.bin: spl/u-boot-spl.pbl $(UBOOT_BINLOAD) FORCE
120789ad7be8SPrabhakar Kushwaha	$(call if_changed,pad_cat)
120889ad7be8SPrabhakar Kushwaha
1209ecddccd0SStefan Roese# PPC4xx needs the SPL at the end of the image, since the reset vector
1210ecddccd0SStefan Roese# is located at 0xfffffffc. So we can't use the "u-boot-img.bin" target
1211ecddccd0SStefan Roese# and need to introduce a new build target with the full blown U-Boot
1212ecddccd0SStefan Roese# at the start padded up to the start of the SPL image. And then concat
1213ecddccd0SStefan Roese# the SPL image to the end.
1214982a1199SMasahiro Yamada
1215982a1199SMasahiro YamadaOBJCOPYFLAGS_u-boot-img-spl-at-end.bin := -I binary -O binary \
1216982a1199SMasahiro Yamada	--pad-to=$(CONFIG_UBOOT_PAD_TO) --gap-fill=0xff
1217982a1199SMasahiro Yamadau-boot-img-spl-at-end.bin: u-boot.img spl/u-boot-spl.bin FORCE
1218982a1199SMasahiro Yamada	$(call if_changed,pad_cat)
1219ecddccd0SStefan Roese
1220d57259b9SÁlvaro Fernández Rojas# Create a new ELF from a raw binary file.
122196ee1adaSÁlvaro Fernández Rojasifndef PLATFORM_ELFENTRY
122296ee1adaSÁlvaro Fernández Rojas  PLATFORM_ELFENTRY = "_start"
122396ee1adaSÁlvaro Fernández Rojasendif
1224e69945eeSÁlvaro Fernández Rojasquiet_cmd_u-boot-elf ?= LD      $@
1225e69945eeSÁlvaro Fernández Rojas	cmd_u-boot-elf ?= $(LD) u-boot-elf.o -o $@ \
122696ee1adaSÁlvaro Fernández Rojas	--defsym=$(PLATFORM_ELFENTRY)=$(CONFIG_SYS_TEXT_BASE) \
1227f4dc714aSScott Wood	-Ttext=$(CONFIG_SYS_TEXT_BASE)
1228e69945eeSÁlvaro Fernández Rojasu-boot.elf: u-boot.bin
1229e69945eeSÁlvaro Fernández Rojas	$(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o
1230e69945eeSÁlvaro Fernández Rojas	$(call if_changed,u-boot-elf)
1231f4dc714aSScott Wood
1232ad0fed46SMasahiro Yamada# Rule to link u-boot
1233ad0fed46SMasahiro Yamada# May be overridden by arch/$(ARCH)/config.mk
1234ad0fed46SMasahiro Yamadaquiet_cmd_u-boot__ ?= LD      $@
1235ad0fed46SMasahiro Yamada      cmd_u-boot__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
1236ad0fed46SMasahiro Yamada      -T u-boot.lds $(u-boot-init)                             \
1237ad0fed46SMasahiro Yamada      --start-group $(u-boot-main) --end-group                 \
1238ad0fed46SMasahiro Yamada      $(PLATFORM_LIBS) -Map u-boot.map
123986eb49b3SSimon Glass
1240cac8f38aSVasili Galkaquiet_cmd_smap = GEN     common/system_map.o
1241cac8f38aSVasili Galkacmd_smap = \
12429e414032SMasahiro Yamada	smap=`$(call SYSTEM_MAP,u-boot) | \
12431aada9cdSWolfgang Denk		awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
12446825a95bSMasahiro Yamada	$(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
12459e414032SMasahiro Yamada		-c $(srctree)/common/system_map.c -o common/system_map.o
1246cac8f38aSVasili Galka
1247514ec438SMasahiro Yamadau-boot:	$(u-boot-init) $(u-boot-main) u-boot.lds FORCE
1248cac8f38aSVasili Galka	$(call if_changed,u-boot__)
1249cac8f38aSVasili Galkaifeq ($(CONFIG_KALLSYMS),y)
1250cac8f38aSVasili Galka	$(call cmd,smap)
1251ad0fed46SMasahiro Yamada	$(call cmd,u-boot__) common/system_map.o
1252ecb1dc89SMike Frysingerendif
12537ebf7443Swdenk
12547ed4848bSStephen Warrenquiet_cmd_sym ?= SYM     $@
12557ed4848bSStephen Warren      cmd_sym ?= $(OBJDUMP) -t $< > $@
12567ed4848bSStephen Warrenu-boot.sym: u-boot FORCE
12577ed4848bSStephen Warren	$(call if_changed,sym)
12587ed4848bSStephen Warren
1259656de6b8SMasahiro Yamada# The actual objects are generated when descending,
1260656de6b8SMasahiro Yamada# make sure no implicit rule kicks in
1261656de6b8SMasahiro Yamada$(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;
1262f9328639SMarian Balakowicz
1263656de6b8SMasahiro Yamada# Handle descending into subdirectories listed in $(vmlinux-dirs)
1264656de6b8SMasahiro Yamada# Preset locale variables to speed up the build process. Limit locale
1265656de6b8SMasahiro Yamada# tweaks to this spot to avoid wrong language settings when running
1266656de6b8SMasahiro Yamada# make menuconfig etc.
1267656de6b8SMasahiro Yamada# Error messages still appears in the original language
1268a8c7c708Swdenk
1269656de6b8SMasahiro YamadaPHONY += $(u-boot-dirs)
12706378008aSMasahiro Yamada$(u-boot-dirs): prepare scripts
12716825a95bSMasahiro Yamada	$(Q)$(MAKE) $(build)=$@
1272940db16dSMasahiro Yamada
12737424145fSMasahiro Yamadatools: prepare
1274656de6b8SMasahiro Yamada# The "tools" are needed early
1275656de6b8SMasahiro Yamada$(filter-out tools, $(u-boot-dirs)): tools
1276656de6b8SMasahiro Yamada# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
1277656de6b8SMasahiro Yamada# is "yes"), so compile examples after U-Boot is compiled.
1278656de6b8SMasahiro Yamadaexamples: $(filter-out examples, $(u-boot-dirs))
1279656de6b8SMasahiro Yamada
12807424145fSMasahiro Yamadadefine filechk_uboot.release
12817424145fSMasahiro Yamada	echo "$(UBOOTVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
12827424145fSMasahiro Yamadaendef
12837424145fSMasahiro Yamada
12847424145fSMasahiro Yamada# Store (new) UBOOTRELEASE string in include/config/uboot.release
128551148790SMasahiro Yamadainclude/config/uboot.release: include/config/auto.conf FORCE
12867424145fSMasahiro Yamada	$(call filechk,uboot.release)
12877424145fSMasahiro Yamada
12887424145fSMasahiro Yamada
12893341bfecSMasahiro Yamada# Things we need to do before we recursively start building the kernel
12903341bfecSMasahiro Yamada# or the modules are listed in "prepare".
12913341bfecSMasahiro Yamada# A multi level approach is used. prepareN is processed before prepareN-1.
12923341bfecSMasahiro Yamada# archprepare is used in arch Makefiles and when processed asm symlink,
12933341bfecSMasahiro Yamada# version.h and scripts_basic is processed / created.
12943341bfecSMasahiro Yamada
12953341bfecSMasahiro Yamada# Listed in dependency order
12963341bfecSMasahiro YamadaPHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
12973341bfecSMasahiro Yamada
12983341bfecSMasahiro Yamada# prepare3 is used to check if we are building in a separate output directory,
12993341bfecSMasahiro Yamada# and if so do:
13003341bfecSMasahiro Yamada# 1) Check that make has not been executed in the kernel src $(srctree)
13017424145fSMasahiro Yamadaprepare3: include/config/uboot.release
13023341bfecSMasahiro Yamadaifneq ($(KBUILD_SRC),)
130351148790SMasahiro Yamada	@$(kecho) '  Using $(srctree) as source for U-Boot'
130451148790SMasahiro Yamada	$(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
13053341bfecSMasahiro Yamada		echo >&2 "  $(srctree) is not clean, please run 'make mrproper'"; \
13063341bfecSMasahiro Yamada		echo >&2 "  in the '$(srctree)' directory.";\
13073341bfecSMasahiro Yamada		/bin/false; \
13083341bfecSMasahiro Yamada	fi;
13093341bfecSMasahiro Yamadaendif
13103341bfecSMasahiro Yamada
13113341bfecSMasahiro Yamada# prepare2 creates a makefile if using a separate output directory
13123341bfecSMasahiro Yamadaprepare2: prepare3 outputmakefile
13133341bfecSMasahiro Yamada
131451148790SMasahiro Yamadaprepare1: prepare2 $(version_h) $(timestamp_h) \
131551148790SMasahiro Yamada                   include/config/auto.conf
13164a377552SMasahiro Yamadaifeq ($(wildcard $(LDSCRIPT)),)
13174a377552SMasahiro Yamada	@echo >&2 "  Could not find linker script."
13184a377552SMasahiro Yamada	@/bin/false
13194a377552SMasahiro Yamadaendif
13207ebf7443Swdenk
13213341bfecSMasahiro Yamadaarchprepare: prepare1 scripts_basic
1322a8c7c708Swdenk
13236a44d806SMasahiro Yamadaprepare0: archprepare FORCE
13246a44d806SMasahiro Yamada	$(Q)$(MAKE) $(build)=.
13257ebf7443Swdenk
13263341bfecSMasahiro Yamada# All the preparing..
13273341bfecSMasahiro Yamadaprepare: prepare0
1328349e83f0SChe-liang Chiou
13297424145fSMasahiro Yamada# Generate some files
13307424145fSMasahiro Yamada# ---------------------------------------------------------------------------
13317424145fSMasahiro Yamada
13327424145fSMasahiro Yamadadefine filechk_version.h
13337424145fSMasahiro Yamada	(echo \#define PLAIN_VERSION \"$(UBOOTRELEASE)\"; \
13347424145fSMasahiro Yamada	echo \#define U_BOOT_VERSION \"U-Boot \" PLAIN_VERSION; \
133542ffa51fSVagrant Cascadian	echo \#define CC_VERSION_STRING \"$$(LC_ALL=C $(CC) --version | head -n 1)\"; \
133642ffa51fSVagrant Cascadian	echo \#define LD_VERSION_STRING \"$$(LC_ALL=C $(LD) --version | head -n 1)\"; )
13377424145fSMasahiro Yamadaendef
13387424145fSMasahiro Yamada
13392d9efa12SAndreas Bießmann# The SOURCE_DATE_EPOCH mechanism requires a date that behaves like GNU date.
13402d9efa12SAndreas Bießmann# The BSD date on the other hand behaves different and would produce errors
13412d9efa12SAndreas Bießmann# with the misused '-d' switch.  Respect that and search a working date with
13422d9efa12SAndreas Bießmann# well known pre- and suffixes for the GNU variant of date.
13437424145fSMasahiro Yamadadefine filechk_timestamp.h
134470d39f57SChris Packham	(if test -n "$${SOURCE_DATE_EPOCH}"; then \
134570d39f57SChris Packham		SOURCE_DATE="@$${SOURCE_DATE_EPOCH}"; \
13462d9efa12SAndreas Bießmann		DATE=""; \
13472d9efa12SAndreas Bießmann		for date in gdate date.gnu date; do \
13482d9efa12SAndreas Bießmann			$${date} -u -d "$${SOURCE_DATE}" >/dev/null 2>&1 && DATE="$${date}"; \
13492d9efa12SAndreas Bießmann		done; \
13502d9efa12SAndreas Bießmann		if test -n "$${DATE}"; then \
13512d9efa12SAndreas Bießmann			LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DATE "%b %d %C%y"'; \
13522d9efa12SAndreas Bießmann			LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TIME "%T"'; \
13532d9efa12SAndreas Bießmann			LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TZ "%z"'; \
1354a34b4676SBin Meng			LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; \
13552d9efa12SAndreas Bießmann		else \
13562d9efa12SAndreas Bießmann			return 42; \
13572d9efa12SAndreas Bießmann		fi; \
135870d39f57SChris Packham	else \
135970d39f57SChris Packham		LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"'; \
136070d39f57SChris Packham		LC_ALL=C date +'#define U_BOOT_TIME "%T"'; \
136170d39f57SChris Packham		LC_ALL=C date +'#define U_BOOT_TZ "%z"'; \
1362a34b4676SBin Meng		LC_ALL=C date +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; \
136370d39f57SChris Packham	fi)
13647424145fSMasahiro Yamadaendef
13657424145fSMasahiro Yamada
13662e6b2f6aSMasahiro Yamada$(version_h): include/config/uboot.release FORCE
13677424145fSMasahiro Yamada	$(call filechk,version.h)
13687424145fSMasahiro Yamada
13697424145fSMasahiro Yamada$(timestamp_h): $(srctree)/Makefile FORCE
13707424145fSMasahiro Yamada	$(call filechk,timestamp.h)
13717424145fSMasahiro Yamada
1372e38ffc42SSimon Glasscheckbinman: tools
1373e38ffc42SSimon Glass	@if ! ( echo 'import libfdt' | ( PYTHONPATH=tools python )); then \
1374e38ffc42SSimon Glass		echo >&2; \
1375e38ffc42SSimon Glass		echo >&2 '*** binman needs the Python libfdt library.'; \
1376e38ffc42SSimon Glass		echo >&2 '*** Either install it on your system, or try:'; \
1377e38ffc42SSimon Glass		echo >&2 '***'; \
1378e38ffc42SSimon Glass		echo >&2 '*** sudo apt-get install swig libpython-dev'; \
1379e38ffc42SSimon Glass		echo >&2 '***'; \
1380e38ffc42SSimon Glass		echo >&2 '*** to have U-Boot build its own version.'; \
1381e38ffc42SSimon Glass		false; \
1382e38ffc42SSimon Glass	fi
1383e38ffc42SSimon Glass
13846378008aSMasahiro Yamada# ---------------------------------------------------------------------------
138504a34c96SMasahiro Yamadaquiet_cmd_cpp_lds = LDS     $@
1386de5e5ceaSChris Zankelcmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \
1387395e60cdSMasahiro Yamada		-D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $<
13886378008aSMasahiro Yamada
138904a34c96SMasahiro Yamadau-boot.lds: $(LDSCRIPT) prepare FORCE
1390395e60cdSMasahiro Yamada	$(call if_changed_dep,cpp_lds)
13911aada9cdSWolfgang Denk
1392982a1199SMasahiro Yamadaspl/u-boot-spl.bin: spl/u-boot-spl
1393982a1199SMasahiro Yamada	@:
1394054b3a1eSSimon Glassspl/u-boot-spl: tools prepare \
1395054b3a1eSSimon Glass		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
1396c7163083SMasahiro Yamada	$(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all
13975df2ee27SDaniel Schwierzeck
139850827a59SIan Campbellspl/sunxi-spl.bin: spl/u-boot-spl
139950827a59SIan Campbell	@:
140050827a59SIan Campbell
1401d2fdcc76SMaxime Ripardspl/sunxi-spl-with-ecc.bin: spl/sunxi-spl.bin
1402d2fdcc76SMaxime Ripard	@:
1403d2fdcc76SMaxime Ripard
1404bd7dc388SSimon Glassspl/u-boot-spl.sfp: spl/u-boot-spl
1405333b7209SMarek Vasut	@:
1406333b7209SMarek Vasut
140708598d6eSNathan Rossispl/boot.bin: spl/u-boot-spl
140808598d6eSNathan Rossi	@:
140908598d6eSNathan Rossi
14103c00a2c8SSimon Glasstpl/u-boot-tpl.bin: tools prepare \
14113c00a2c8SSimon Glass		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
141251148790SMasahiro Yamada	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
14133aa29de0SYing Zhang
14148d819ab5SIgor GrinbergTAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
1415a340c325SJean-Christophe PLAGNIOL-VILLARD
1416857d9ea6SHorst KronstorferFIND := find
1417857d9ea6SHorst KronstorferFINDFLAGS := -L
1418857d9ea6SHorst Kronstorfer
1419f9328639SMarian Balakowicztags ctags:
14209e414032SMasahiro Yamada		ctags -w -o ctags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
1421e5e4e705SLi Yang						-name '*.[chS]' -print`
142274d339beSDu Huanpeng		ln -s ctags tags
14237ebf7443Swdenk
14247ebf7443Swdenketags:
14258d819ab5SIgor Grinberg		etags -a -o etags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
1426e5e4e705SLi Yang						-name '*.[chS]' -print`
1427ffda586fSLi Yangcscope:
1428857d9ea6SHorst Kronstorfer		$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
1429857d9ea6SHorst Kronstorfer						cscope.files
1430ffda586fSLi Yang		cscope -b -q -k
14317ebf7443Swdenk
1432ecb1dc89SMike FrysingerSYSTEM_MAP = \
1433ecb1dc89SMike Frysinger		$(NM) $1 | \
14347ebf7443Swdenk		grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
1435ecb1dc89SMike Frysinger		LC_ALL=C sort
14369e414032SMasahiro YamadaSystem.map:	u-boot
1437bc8bb6ecSMasahiro Yamada		@$(call SYSTEM_MAP,$<) > $@
14387ebf7443Swdenk
1439501ebdf2SStephen Warrencheckdtc:
1440501ebdf2SStephen Warren	@if test $(call dtc-version) -lt 0104; then \
1441501ebdf2SStephen Warren		echo '*** Your dtc is too old, please upgrade to dtc 1.4 or newer'; \
1442501ebdf2SStephen Warren		false; \
1443501ebdf2SStephen Warren	fi
1444501ebdf2SStephen Warren
14457ebf7443Swdenk#########################################################################
14467ebf7443Swdenk
144754799e45SScott Wood# ARM relocations should all be R_ARM_RELATIVE (32-bit) or
144854799e45SScott Wood# R_AARCH64_RELATIVE (64-bit).
14499e414032SMasahiro Yamadacheckarmreloc: u-boot
145054799e45SScott Wood	@RELOC="`$(CROSS_COMPILE)readelf -r -W $< | cut -d ' ' -f 4 | \
145154799e45SScott Wood		grep R_A | sort -u`"; \
145254799e45SScott Wood	if test "$$RELOC" != "R_ARM_RELATIVE" -a \
145354799e45SScott Wood		 "$$RELOC" != "R_AARCH64_RELATIVE"; then \
145454799e45SScott Wood		echo "$< contains unexpected relocations: $$RELOC"; \
145554799e45SScott Wood		false; \
145654799e45SScott Wood	fi
1457c37980c3SAlbert ARIBAUD
14587424145fSMasahiro Yamadaenv: scripts_basic
14593f76e984SMasahiro Yamada	$(Q)$(MAKE) $(build)=tools/$@
14600358df42SMike Frysinger
14614642e002SMasahiro Yamadatools-only: scripts_basic $(version_h) $(timestamp_h)
14624642e002SMasahiro Yamada	$(Q)$(MAKE) $(build)=tools
14634642e002SMasahiro Yamada
14641ec8b4efSMasahiro Yamadatools-all: export HOST_TOOLS_ALL=y
14652887c473SMasahiro Yamadatools-all: env tools ;
14660358df42SMike Frysinger
1467db5b339cSMasahiro Yamadacross_tools: export CROSS_BUILD_TOOLS=y
1468db5b339cSMasahiro Yamadacross_tools: tools ;
1469db5b339cSMasahiro Yamada
14704e53a258SWolfgang Denk.PHONY : CHANGELOG
14714e53a258SWolfgang DenkCHANGELOG:
1472b985b5d6SBen Warren	git log --no-merges U-Boot-1_1_5.. | \
1473b985b5d6SBen Warren	unexpand -a | sed -e 's/\s\s*$$//' > $@
14744e53a258SWolfgang Denk
14757ebf7443Swdenk#########################################################################
14767ebf7443Swdenk
1477efcf8619SMasahiro Yamada###
1478efcf8619SMasahiro Yamada# Cleaning is done on three levels.
1479efcf8619SMasahiro Yamada# make clean     Delete most generated files
1480efcf8619SMasahiro Yamada#                Leave enough to build external modules
1481efcf8619SMasahiro Yamada# make mrproper  Delete the current configuration, and all generated files
1482efcf8619SMasahiro Yamada# make distclean Remove editor backup files, patch leftover files and the like
14837ebf7443Swdenk
1484efcf8619SMasahiro Yamada# Directories & files removed with 'make clean'
148548aa812dSMasahiro YamadaCLEAN_DIRS  += $(MODVERDIR) \
148648aa812dSMasahiro Yamada	       $(foreach d, spl tpl, $(patsubst %,$d/%, \
148751148790SMasahiro Yamada			$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
148848aa812dSMasahiro Yamada
1489d726f225SMasahiro YamadaCLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h \
14906f59fb07SCooper Jr., Franklin	       boot* u-boot* MLO* SPL System.map fit-dtb.blob
14919f4a4206SMike Frysinger
1492efcf8619SMasahiro Yamada# Directories & files removed with 'make mrproper'
149351148790SMasahiro YamadaMRPROPER_DIRS  += include/config include/generated spl tpl \
1494598e2d33SMasahiro Yamada		  .tmp_objdiff
149551148790SMasahiro YamadaMRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
149668a2fd43SVignesh R		  ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
14977ebf7443Swdenk
1498efcf8619SMasahiro Yamada# clean - Delete most, but leave enough to build external modules
1499efcf8619SMasahiro Yamada#
1500efcf8619SMasahiro Yamadaclean: rm-dirs  := $(CLEAN_DIRS)
1501efcf8619SMasahiro Yamadaclean: rm-files := $(CLEAN_FILES)
15027ebf7443Swdenk
15036bd04bb4SMasahiro Yamadaclean-dirs	:= $(foreach f,$(u-boot-alldirs),$(if $(wildcard $(srctree)/$f/Makefile),$f))
1504734329f9SAndy Fleming
1505efcf8619SMasahiro Yamadaclean-dirs      := $(addprefix _clean_, $(clean-dirs) doc/DocBook)
15067ebf7443Swdenk
1507efcf8619SMasahiro YamadaPHONY += $(clean-dirs) clean archclean
1508efcf8619SMasahiro Yamada$(clean-dirs):
1509efcf8619SMasahiro Yamada	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1510efcf8619SMasahiro Yamada
1511efcf8619SMasahiro Yamada# TODO: Do not use *.cfgtmp
1512efcf8619SMasahiro Yamadaclean: $(clean-dirs)
1513efcf8619SMasahiro Yamada	$(call cmd,rmdirs)
1514efcf8619SMasahiro Yamada	$(call cmd,rmfiles)
1515efcf8619SMasahiro Yamada	@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1516efcf8619SMasahiro Yamada		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1517efcf8619SMasahiro Yamada		-o -name '*.ko.*' -o -name '*.su' -o -name '*.cfgtmp' \
1518efcf8619SMasahiro Yamada		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1519efcf8619SMasahiro Yamada		-o -name '*.symtypes' -o -name 'modules.order' \
1520efcf8619SMasahiro Yamada		-o -name modules.builtin -o -name '.tmp_*.o.*' \
15210fbdaa0eSBin Meng		-o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \
1522efcf8619SMasahiro Yamada		-o -name '*.gcno' \) -type f -print | xargs rm -f
1523efcf8619SMasahiro Yamada
1524efcf8619SMasahiro Yamada# mrproper - Delete all generated files, including .config
1525efcf8619SMasahiro Yamada#
1526efcf8619SMasahiro Yamadamrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
1527efcf8619SMasahiro Yamadamrproper: rm-files := $(wildcard $(MRPROPER_FILES))
1528efcf8619SMasahiro Yamadamrproper-dirs      := $(addprefix _mrproper_,scripts)
1529efcf8619SMasahiro Yamada
1530efcf8619SMasahiro YamadaPHONY += $(mrproper-dirs) mrproper archmrproper
1531efcf8619SMasahiro Yamada$(mrproper-dirs):
1532efcf8619SMasahiro Yamada	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1533efcf8619SMasahiro Yamada
153448aa812dSMasahiro Yamadamrproper: clean $(mrproper-dirs)
1535efcf8619SMasahiro Yamada	$(call cmd,rmdirs)
1536efcf8619SMasahiro Yamada	$(call cmd,rmfiles)
1537e9c16a80SMasahiro Yamada	@rm -f arch/*/include/asm/arch
1538efcf8619SMasahiro Yamada
1539efcf8619SMasahiro Yamada# distclean
1540efcf8619SMasahiro Yamada#
1541efcf8619SMasahiro YamadaPHONY += distclean
1542efcf8619SMasahiro Yamada
1543433b2f1eSMasahiro Yamadadistclean: mrproper
1544efcf8619SMasahiro Yamada	@find $(srctree) $(RCS_FIND_IGNORE) \
1545efcf8619SMasahiro Yamada		\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1546efcf8619SMasahiro Yamada		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
1547598e2d33SMasahiro Yamada		-o -name '.*.rej' -o -name '*%' -o -name 'core' \
1548598e2d33SMasahiro Yamada		-o -name '*.pyc' \) \
1549efcf8619SMasahiro Yamada		-type f -print | xargs rm -f
1550fd18a89eSRoger Meier	@rm -f boards.cfg
15517ebf7443Swdenk
15527ebf7443Swdenkbackup:
15534379ac61SMasahiro Yamada	F=`basename $(srctree)` ; cd .. ; \
1554d6b93714SIlya Yanok	gtar --force-local -zcvf `LC_ALL=C date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
15557ebf7443Swdenk
1556ed1ca528SMasahiro Yamadahelp:
1557ed1ca528SMasahiro Yamada	@echo  'Cleaning targets:'
155848aa812dSMasahiro Yamada	@echo  '  clean		  - Remove most generated files but keep the config'
1559ed1ca528SMasahiro Yamada	@echo  '  mrproper	  - Remove all generated files + config + various backup files'
1560ed1ca528SMasahiro Yamada	@echo  '  distclean	  - mrproper + remove editor backup and patch files'
1561ed1ca528SMasahiro Yamada	@echo  ''
156251148790SMasahiro Yamada	@echo  'Configuration targets:'
156351148790SMasahiro Yamada	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
156451148790SMasahiro Yamada	@echo  ''
1565ed1ca528SMasahiro Yamada	@echo  'Other generic targets:'
1566ed1ca528SMasahiro Yamada	@echo  '  all		  - Build all necessary images depending on configuration'
1567633cc7aeSSimon Glass	@echo  '  tests		  - Build U-Boot for sandbox and run tests'
1568ffe29ebcSMasahiro Yamada	@echo  '* u-boot	  - Build the bare u-boot'
1569ed1ca528SMasahiro Yamada	@echo  '  dir/            - Build all files in dir and below'
1570ed1ca528SMasahiro Yamada	@echo  '  dir/file.[oisS] - Build specified target only'
1571ed1ca528SMasahiro Yamada	@echo  '  dir/file.lst    - Build specified mixed source/assembly target only'
1572ed1ca528SMasahiro Yamada	@echo  '                    (requires a recent binutils and recent build (System.map))'
15735fc2f924SIgor Grinberg	@echo  '  tags/ctags	  - Generate ctags file for editors'
15745fc2f924SIgor Grinberg	@echo  '  etags		  - Generate etags file for editors'
1575ed1ca528SMasahiro Yamada	@echo  '  cscope	  - Generate cscope index'
1576ffe29ebcSMasahiro Yamada	@echo  '  ubootrelease	  - Output the release version string (use with make -s)'
1577ffe29ebcSMasahiro Yamada	@echo  '  ubootversion	  - Output the version stored in Makefile (use with make -s)'
15781bd87630SSimon Glass	@echo  "  cfg		  - Don't build, just create the .cfg files"
1579ed1ca528SMasahiro Yamada	@echo  ''
1580ed1ca528SMasahiro Yamada	@echo  'Static analysers'
1581ed1ca528SMasahiro Yamada	@echo  '  checkstack      - Generate a list of stack hogs'
1582ed1ca528SMasahiro Yamada	@echo  ''
1583ed1ca528SMasahiro Yamada	@echo  'Documentation targets:'
1584ed1ca528SMasahiro Yamada	@$(MAKE) -f $(srctree)/doc/DocBook/Makefile dochelp
1585ed1ca528SMasahiro Yamada	@echo  ''
1586ed1ca528SMasahiro Yamada	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
1587ed1ca528SMasahiro Yamada	@echo  '  make V=2   [targets] 2 => give reason for rebuild of target'
1588ed1ca528SMasahiro Yamada	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
1589ed1ca528SMasahiro Yamada	@echo  '  make C=1   [targets] Check all c source with $$CHECK (sparse by default)'
1590ed1ca528SMasahiro Yamada	@echo  '  make C=2   [targets] Force check of all c source with $$CHECK'
1591ed1ca528SMasahiro Yamada	@echo  '  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
1592ed1ca528SMasahiro Yamada	@echo  '  make W=n   [targets] Enable extra gcc checks, n=1,2,3 where'
1593ed1ca528SMasahiro Yamada	@echo  '		1: warnings which may be relevant and do not occur too often'
1594ed1ca528SMasahiro Yamada	@echo  '		2: warnings which occur quite often but may still be relevant'
1595ed1ca528SMasahiro Yamada	@echo  '		3: more obscure warnings, can most likely be ignored'
1596ed1ca528SMasahiro Yamada	@echo  '		Multiple levels can be combined with W=12 or W=123'
1597ed1ca528SMasahiro Yamada	@echo  ''
1598ed1ca528SMasahiro Yamada	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
1599ed1ca528SMasahiro Yamada	@echo  'For further info see the ./README file'
1600ed1ca528SMasahiro Yamada
1601633cc7aeSSimon Glasstests:
1602633cc7aeSSimon Glass	$(srctree)/test/run
16038fac9c7bSMasahiro Yamada
16048fac9c7bSMasahiro Yamada# Documentation targets
16058fac9c7bSMasahiro Yamada# ---------------------------------------------------------------------------
16068fac9c7bSMasahiro Yamada%docs: scripts_basic FORCE
16078fac9c7bSMasahiro Yamada	$(Q)$(MAKE) $(build)=scripts build_docproc
16088fac9c7bSMasahiro Yamada	$(Q)$(MAKE) $(build)=doc/DocBook $@
16098fac9c7bSMasahiro Yamada
1610433b2f1eSMasahiro Yamadaendif #ifeq ($(config-targets),1)
1611433b2f1eSMasahiro Yamadaendif #ifeq ($(mixed-targets),1)
1612433b2f1eSMasahiro Yamada
1613ed1ca528SMasahiro YamadaPHONY += checkstack ubootrelease ubootversion
1614ed1ca528SMasahiro Yamada
1615ed1ca528SMasahiro Yamadacheckstack:
1616ed1ca528SMasahiro Yamada	$(OBJDUMP) -d u-boot $$(find . -name u-boot-spl) | \
1617ed1ca528SMasahiro Yamada	$(PERL) $(src)/scripts/checkstack.pl $(ARCH)
1618ed1ca528SMasahiro Yamada
1619ed1ca528SMasahiro Yamadaubootrelease:
1620ed1ca528SMasahiro Yamada	@echo "$(UBOOTVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
1621ed1ca528SMasahiro Yamada
1622ed1ca528SMasahiro Yamadaubootversion:
1623ed1ca528SMasahiro Yamada	@echo $(UBOOTVERSION)
1624ed1ca528SMasahiro Yamada
1625886d86e8SMasahiro Yamada# Single targets
1626886d86e8SMasahiro Yamada# ---------------------------------------------------------------------------
1627886d86e8SMasahiro Yamada# Single targets are compatible with:
1628886d86e8SMasahiro Yamada# - build with mixed source and output
1629886d86e8SMasahiro Yamada# - build with separate output dir 'make O=...'
1630886d86e8SMasahiro Yamada# - external modules
1631886d86e8SMasahiro Yamada#
1632886d86e8SMasahiro Yamada#  target-dir => where to store outputfile
1633886d86e8SMasahiro Yamada#  build-dir  => directory in kernel source tree to use
1634886d86e8SMasahiro Yamada
1635886d86e8SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
1636886d86e8SMasahiro Yamada        build-dir  = $(patsubst %/,%,$(dir $@))
1637886d86e8SMasahiro Yamada        target-dir = $(dir $@)
1638886d86e8SMasahiro Yamadaelse
1639886d86e8SMasahiro Yamada        zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
1640886d86e8SMasahiro Yamada        build-dir  = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
1641886d86e8SMasahiro Yamada        target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
1642886d86e8SMasahiro Yamadaendif
1643886d86e8SMasahiro Yamada
1644886d86e8SMasahiro Yamada%.s: %.c prepare scripts FORCE
1645886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1646886d86e8SMasahiro Yamada%.i: %.c prepare scripts FORCE
1647886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1648886d86e8SMasahiro Yamada%.o: %.c prepare scripts FORCE
1649886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1650886d86e8SMasahiro Yamada%.lst: %.c prepare scripts FORCE
1651886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1652886d86e8SMasahiro Yamada%.s: %.S prepare scripts FORCE
1653886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1654886d86e8SMasahiro Yamada%.o: %.S prepare scripts FORCE
1655886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1656886d86e8SMasahiro Yamada%.symtypes: %.c prepare scripts FORCE
1657886d86e8SMasahiro Yamada	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1658886d86e8SMasahiro Yamada
1659886d86e8SMasahiro Yamada# Modules
1660886d86e8SMasahiro Yamada/: prepare scripts FORCE
1661886d86e8SMasahiro Yamada	$(cmd_crmodverdir)
1662886d86e8SMasahiro Yamada	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1663886d86e8SMasahiro Yamada	$(build)=$(build-dir)
1664886d86e8SMasahiro Yamada%/: prepare scripts FORCE
1665886d86e8SMasahiro Yamada	$(cmd_crmodverdir)
1666886d86e8SMasahiro Yamada	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1667886d86e8SMasahiro Yamada	$(build)=$(build-dir)
1668886d86e8SMasahiro Yamada%.ko: prepare scripts FORCE
1669886d86e8SMasahiro Yamada	$(cmd_crmodverdir)
1670886d86e8SMasahiro Yamada	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \
1671886d86e8SMasahiro Yamada	$(build)=$(build-dir) $(@:.ko=.o)
1672886d86e8SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1673886d86e8SMasahiro Yamada
1674886d86e8SMasahiro Yamada# FIXME Should go into a make.lib or something
1675886d86e8SMasahiro Yamada# ===========================================================================
1676886d86e8SMasahiro Yamada
1677efcf8619SMasahiro Yamadaquiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
1678efcf8619SMasahiro Yamada      cmd_rmdirs = rm -rf $(rm-dirs)
1679efcf8619SMasahiro Yamada
1680efcf8619SMasahiro Yamadaquiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
1681efcf8619SMasahiro Yamada      cmd_rmfiles = rm -f $(rm-files)
1682efcf8619SMasahiro Yamada
1683f9c235fdSMasahiro Yamada# read all saved command lines
1684f9c235fdSMasahiro Yamada
1685f9c235fdSMasahiro Yamadatargets := $(wildcard $(sort $(targets)))
1686f9c235fdSMasahiro Yamadacmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1687f9c235fdSMasahiro Yamada
1688f9c235fdSMasahiro Yamadaifneq ($(cmd_files),)
1689f9c235fdSMasahiro Yamada  $(cmd_files): ;	# Do not try to update included dependency files
1690f9c235fdSMasahiro Yamada  include $(cmd_files)
1691f9c235fdSMasahiro Yamadaendif
1692f9c235fdSMasahiro Yamada
16939e414032SMasahiro Yamadaendif	# skip-makefile
16949e414032SMasahiro Yamada
16959e414032SMasahiro YamadaPHONY += FORCE
16969e414032SMasahiro YamadaFORCE:
16979e414032SMasahiro Yamada
16989e414032SMasahiro Yamada# Declare the contents of the .PHONY variable as phony.  We keep that
16999e414032SMasahiro Yamada# information in a variable so we can use it in if_changed and friends.
17009e414032SMasahiro Yamada.PHONY: $(PHONY)
1701