xref: /openbmc/u-boot/Makefile (revision 5f30f3be7394e66a84de501803cab2fe9392ed8b)
17ebf7443Swdenk#
2eca3aeb3SWolfgang Denk# (C) Copyright 2000-2013
37ebf7443Swdenk# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
47ebf7443Swdenk#
5eca3aeb3SWolfgang Denk# SPDX-License-Identifier:	GPL-2.0+
67ebf7443Swdenk#
77ebf7443Swdenk
8d19ad726STom RiniVERSION = 2014
9d19ad726STom RiniPATCHLEVEL = 01
10211e4754SWolfgang DenkSUBLEVEL =
11b44bd2c7STom RiniEXTRAVERSION =
12*5f30f3beSMasahiro YamadaNAME =
13ae6d1056SWolfgang Denk
146825a95bSMasahiro Yamada# *DOCUMENTATION*
156825a95bSMasahiro Yamada# To see a list of typical targets execute "make help"
166825a95bSMasahiro Yamada# More info can be located in ./README
176825a95bSMasahiro Yamada# Comments in this file are targeted only to the developer, do not
186825a95bSMasahiro Yamada# expect to learn how to build the kernel reading this file.
196825a95bSMasahiro Yamada
206825a95bSMasahiro Yamada# Do not:
216825a95bSMasahiro Yamada# o  use make's built-in rules and variables
226825a95bSMasahiro Yamada#    (this increases performance and avoids hard-to-debug behaviour);
236825a95bSMasahiro Yamada# o  print "Entering directory ...";
246825a95bSMasahiro YamadaMAKEFLAGS += -rR --no-print-directory
256825a95bSMasahiro Yamada
266825a95bSMasahiro Yamada# Avoid funny character set dependencies
276825a95bSMasahiro Yamadaunexport LC_ALL
286825a95bSMasahiro YamadaLC_COLLATE=C
296825a95bSMasahiro YamadaLC_NUMERIC=C
306825a95bSMasahiro Yamadaexport LC_COLLATE LC_NUMERIC
316825a95bSMasahiro Yamada
326825a95bSMasahiro Yamada# We are using a recursive build, so we need to do a little thinking
336825a95bSMasahiro Yamada# to get the ordering right.
346825a95bSMasahiro Yamada#
356825a95bSMasahiro Yamada# Most importantly: sub-Makefiles should only ever modify files in
366825a95bSMasahiro Yamada# their own directory. If in some directory we have a dependency on
376825a95bSMasahiro Yamada# a file in another dir (which doesn't happen often, but it's often
386825a95bSMasahiro Yamada# unavoidable when linking the built-in.o targets which finally
396825a95bSMasahiro Yamada# turn into vmlinux), we will call a sub make in that other dir, and
406825a95bSMasahiro Yamada# after that we are sure that everything which is in that other dir
416825a95bSMasahiro Yamada# is now up to date.
426825a95bSMasahiro Yamada#
436825a95bSMasahiro Yamada# The only cases where we need to modify files which have global
446825a95bSMasahiro Yamada# effects are thus separated out and done before the recursive
456825a95bSMasahiro Yamada# descending is started. They are now explicitly listed as the
466825a95bSMasahiro Yamada# prepare rule.
476825a95bSMasahiro Yamada
486825a95bSMasahiro Yamada# To put more focus on warnings, be less verbose as default
496825a95bSMasahiro Yamada# Use 'make V=1' to see the full commands
506825a95bSMasahiro Yamada
516825a95bSMasahiro Yamadaifeq ("$(origin V)", "command line")
526825a95bSMasahiro Yamada  KBUILD_VERBOSE = $(V)
536825a95bSMasahiro Yamadaendif
546825a95bSMasahiro Yamadaifndef KBUILD_VERBOSE
556825a95bSMasahiro Yamada  KBUILD_VERBOSE = 0
566825a95bSMasahiro Yamadaendif
576825a95bSMasahiro Yamada
586825a95bSMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
596825a95bSMasahiro Yamada# C compilation.
606825a95bSMasahiro Yamada#
616825a95bSMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
626825a95bSMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
636825a95bSMasahiro Yamada# of whether they are re-compiled or not.
646825a95bSMasahiro Yamada#
656825a95bSMasahiro Yamada# See the file "Documentation/sparse.txt" for more details, including
666825a95bSMasahiro Yamada# where to get the "sparse" utility.
676825a95bSMasahiro Yamada
686825a95bSMasahiro Yamadaifeq ("$(origin C)", "command line")
696825a95bSMasahiro Yamada  KBUILD_CHECKSRC = $(C)
706825a95bSMasahiro Yamadaendif
716825a95bSMasahiro Yamadaifndef KBUILD_CHECKSRC
726825a95bSMasahiro Yamada  KBUILD_CHECKSRC = 0
736825a95bSMasahiro Yamadaendif
746825a95bSMasahiro Yamada
756825a95bSMasahiro Yamada# Use make M=dir to specify directory of external module to build
766825a95bSMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
776825a95bSMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
786825a95bSMasahiro Yamadaifdef SUBDIRS
796825a95bSMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
806825a95bSMasahiro Yamadaendif
816825a95bSMasahiro Yamada
826825a95bSMasahiro Yamadaifeq ("$(origin M)", "command line")
836825a95bSMasahiro Yamada  KBUILD_EXTMOD := $(M)
846825a95bSMasahiro Yamadaendif
856825a95bSMasahiro Yamada
869e414032SMasahiro Yamada# kbuild supports saving output files in a separate directory.
879e414032SMasahiro Yamada# To locate output files in a separate directory two syntaxes are supported.
889e414032SMasahiro Yamada# In both cases the working directory must be the root of the kernel src.
899e414032SMasahiro Yamada# 1) O=
909e414032SMasahiro Yamada# Use "make O=dir/to/store/output/files/"
91f9328639SMarian Balakowicz#
929e414032SMasahiro Yamada# 2) Set KBUILD_OUTPUT
939e414032SMasahiro Yamada# Set the environment variable KBUILD_OUTPUT to point to the directory
949e414032SMasahiro Yamada# where the output files shall be placed.
959e414032SMasahiro Yamada# export KBUILD_OUTPUT=dir/to/store/output/files/
969e414032SMasahiro Yamada# make
97f9328639SMarian Balakowicz#
989e414032SMasahiro Yamada# The O= assignment takes precedence over the KBUILD_OUTPUT environment
999e414032SMasahiro Yamada# variable.
1007ebf7443Swdenk
1019e414032SMasahiro Yamada
1029e414032SMasahiro Yamada# KBUILD_SRC is set on invocation of make in OBJ directory
1039e414032SMasahiro Yamada# KBUILD_SRC is not intended to be used by the regular user (for now)
1049e414032SMasahiro Yamadaifeq ($(KBUILD_SRC),)
1059e414032SMasahiro Yamada
1069e414032SMasahiro Yamada# OK, Make called in directory where kernel src resides
1079e414032SMasahiro Yamada# Do we want to locate output files in a separate directory?
108f9328639SMarian Balakowiczifeq ("$(origin O)", "command line")
1099e414032SMasahiro Yamada  KBUILD_OUTPUT := $(O)
110f9328639SMarian Balakowiczendif
1117ebf7443Swdenk
1129e414032SMasahiro Yamadaifeq ("$(origin W)", "command line")
1139e414032SMasahiro Yamada  export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
1149e414032SMasahiro Yamadaendif
1159e414032SMasahiro Yamada
1169e414032SMasahiro Yamada# That's our default target when none is given on the command line
1179e414032SMasahiro YamadaPHONY := _all
1189e414032SMasahiro Yamada_all:
1199e414032SMasahiro Yamada
1209e414032SMasahiro Yamada# Cancel implicit rules on top Makefile
1219e414032SMasahiro Yamada$(CURDIR)/Makefile Makefile: ;
1229e414032SMasahiro Yamada
1239e414032SMasahiro Yamadaifneq ($(KBUILD_OUTPUT),)
1249e414032SMasahiro Yamada# Invoke a second make in the output directory, passing relevant variables
1259e414032SMasahiro Yamada# check that the output directory actually exists
1269e414032SMasahiro Yamadasaved-output := $(KBUILD_OUTPUT)
1279e414032SMasahiro YamadaKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1289e414032SMasahiro Yamada$(if $(KBUILD_OUTPUT),, \
1299e414032SMasahiro Yamada     $(error output directory "$(saved-output)" does not exist))
1309e414032SMasahiro Yamada
1319e414032SMasahiro YamadaPHONY += $(MAKECMDGOALS) sub-make
1329e414032SMasahiro Yamada
1339e414032SMasahiro Yamada$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
1349e414032SMasahiro Yamada	@:
1359e414032SMasahiro Yamada
1369e414032SMasahiro Yamadasub-make: FORCE
1379e414032SMasahiro Yamada	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
1389e414032SMasahiro Yamada	KBUILD_SRC=$(CURDIR) \
1399e414032SMasahiro Yamada	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
1409e414032SMasahiro Yamada	$(filter-out _all sub-make,$(MAKECMDGOALS))
1419e414032SMasahiro Yamada
1429e414032SMasahiro Yamada# Leave processing to above invocation of make
1439e414032SMasahiro Yamadaskip-makefile := 1
1449e414032SMasahiro Yamadaendif # ifneq ($(KBUILD_OUTPUT),)
1459e414032SMasahiro Yamadaendif # ifeq ($(KBUILD_SRC),)
1469e414032SMasahiro Yamada
1479e414032SMasahiro Yamada# We process the rest of the Makefile if this is the final invocation of make
1489e414032SMasahiro Yamadaifeq ($(skip-makefile),)
1499e414032SMasahiro Yamada
1506825a95bSMasahiro Yamada# If building an external module we do not care about the all: rule
1516825a95bSMasahiro Yamada# but instead _all depend on modules
1529e414032SMasahiro YamadaPHONY += all
1536825a95bSMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
1549e414032SMasahiro Yamada_all: all
1556825a95bSMasahiro Yamadaelse
1566825a95bSMasahiro Yamada_all: modules
1576825a95bSMasahiro Yamadaendif
1589e414032SMasahiro Yamada
1599e414032SMasahiro Yamadasrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
1609e414032SMasahiro Yamadaobjtree		:= $(CURDIR)
1619e414032SMasahiro Yamadasrc		:= $(srctree)
1629e414032SMasahiro Yamadaobj		:= $(objtree)
1639e414032SMasahiro Yamada
1649e414032SMasahiro YamadaVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
1659e414032SMasahiro Yamada
1669e414032SMasahiro Yamadaexport srctree objtree VPATH
1679e414032SMasahiro Yamada
1689e414032SMasahiro YamadaOBJTREE		:= $(objtree)
169c8f9c302SDaniel SchwierzeckSPLTREE		:= $(OBJTREE)/spl
1703aa29de0SYing ZhangTPLTREE		:= $(OBJTREE)/tpl
1719e414032SMasahiro YamadaSRCTREE		:= $(srctree)
172f9328639SMarian BalakowiczTOPDIR		:= $(SRCTREE)
1739e414032SMasahiro Yamadaexport	TOPDIR SRCTREE OBJTREE SPLTREE TPLTREE
174f9328639SMarian Balakowicz
175f9328639SMarian BalakowiczMKCONFIG	:= $(SRCTREE)/mkconfig
176f9328639SMarian Balakowiczexport MKCONFIG
177f9328639SMarian Balakowicz
1785013c09fSWolfgang Denk# Make sure CDPATH settings don't interfere
1795013c09fSWolfgang Denkunexport CDPATH
1805013c09fSWolfgang Denk
181f9328639SMarian Balakowicz#########################################################################
182f9328639SMarian Balakowicz
183*5f30f3beSMasahiro YamadaTIMESTAMP_FILE = include/generated/timestamp_autogenerated.h
184*5f30f3beSMasahiro YamadaVERSION_FILE = include/generated/version_autogenerated.h
185*5f30f3beSMasahiro Yamada
186*5f30f3beSMasahiro YamadaHOSTARCH := $(shell uname -m | \
187*5f30f3beSMasahiro Yamada	sed -e s/i.86/x86/ \
188*5f30f3beSMasahiro Yamada	    -e s/sun4u/sparc64/ \
189*5f30f3beSMasahiro Yamada	    -e s/arm.*/arm/ \
190*5f30f3beSMasahiro Yamada	    -e s/sa110/arm/ \
191*5f30f3beSMasahiro Yamada	    -e s/ppc64/powerpc/ \
192*5f30f3beSMasahiro Yamada	    -e s/ppc/powerpc/ \
193*5f30f3beSMasahiro Yamada	    -e s/macppc/powerpc/\
194*5f30f3beSMasahiro Yamada	    -e s/sh.*/sh/)
195*5f30f3beSMasahiro Yamada
196*5f30f3beSMasahiro YamadaHOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
197*5f30f3beSMasahiro Yamada	    sed -e 's/\(cygwin\).*/cygwin/')
198*5f30f3beSMasahiro Yamada
199*5f30f3beSMasahiro Yamadaexport	HOSTARCH HOSTOS
200*5f30f3beSMasahiro Yamada
201*5f30f3beSMasahiro Yamada# Deal with colliding definitions from tcsh etc.
202*5f30f3beSMasahiro YamadaVENDOR=
203*5f30f3beSMasahiro Yamada
204*5f30f3beSMasahiro Yamada#########################################################################
205*5f30f3beSMasahiro Yamada# Allow for silent builds
206*5f30f3beSMasahiro Yamadaifeq (,$(findstring s,$(MAKEFLAGS)))
207*5f30f3beSMasahiro YamadaXECHO = echo
208*5f30f3beSMasahiro Yamadaelse
209*5f30f3beSMasahiro YamadaXECHO = :
210*5f30f3beSMasahiro Yamadaendif
211*5f30f3beSMasahiro Yamada
2126d1ce387SMike Frysinger# The "tools" are needed early, so put this first
2136d1ce387SMike Frysinger# Don't include stuff already done in $(LIBS)
214349e83f0SChe-liang Chiou# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
215349e83f0SChe-liang Chiou# is "yes"), so compile examples after U-Boot is compiled.
216349e83f0SChe-liang ChiouSUBDIR_TOOLS = tools
217349e83f0SChe-liang ChiouSUBDIRS = $(SUBDIR_TOOLS)
2186d1ce387SMike Frysinger
219249b53a6SLoïc Minier.PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE)
2206d1ce387SMike Frysinger
2219e414032SMasahiro Yamadaifeq (include/config.mk,$(wildcard include/config.mk))
222f9328639SMarian Balakowicz
2232632c008SMike Frysinger# Include autoconf.mk before config.mk so that the config options are available
2242632c008SMike Frysinger# to all top level build files.  We need the dummy all: target to prevent the
2252632c008SMike Frysinger# dependency target in autoconf.mk.dep from being the default.
2262632c008SMike Frysingerall:
2279e414032SMasahiro Yamadasinclude include/autoconf.mk.dep
2289e414032SMasahiro Yamadasinclude include/autoconf.mk
2292632c008SMike Frysinger
2308a7e7d56SMasahiro YamadaSUBDIR_EXAMPLES-y := examples/standalone
2318a7e7d56SMasahiro YamadaSUBDIR_EXAMPLES-$(CONFIG_API) += examples/api
232b5728756SSimon Glassifndef CONFIG_SANDBOX
2338a7e7d56SMasahiro YamadaSUBDIRS += $(SUBDIR_EXAMPLES-y)
234b5728756SSimon Glassendif
235b5728756SSimon Glass
2367ebf7443Swdenk# load ARCH, BOARD, and CPU configuration
2379e414032SMasahiro Yamadainclude include/config.mk
2381d9f4105Swdenkexport	ARCH CPU BOARD VENDOR SOC
239f9328639SMarian Balakowicz
2401ea6bcd8SMike Frysinger# set default to nothing for native builds
241a5284efdSWolfgang Denkifeq ($(HOSTARCH),$(ARCH))
2421ea6bcd8SMike FrysingerCROSS_COMPILE ?=
2437ebf7443Swdenkendif
2447ebf7443Swdenk
245f6322eb7SMasahiro Yamada# SHELL used by kbuild
246f6322eb7SMasahiro YamadaCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
247f6322eb7SMasahiro Yamada	  else if [ -x /bin/bash ]; then echo /bin/bash; \
248f6322eb7SMasahiro Yamada	  else echo sh; fi ; fi)
249f6322eb7SMasahiro Yamada
250f6322eb7SMasahiro YamadaHOSTCC       = gcc
251f6322eb7SMasahiro YamadaHOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
252f6322eb7SMasahiro Yamada
253f6322eb7SMasahiro Yamadaifeq ($(HOSTOS),cygwin)
254f6322eb7SMasahiro YamadaHOSTCFLAGS	+= -ansi
255f6322eb7SMasahiro Yamadaendif
256f6322eb7SMasahiro Yamada
257f6322eb7SMasahiro Yamada# Mac OS X / Darwin's C preprocessor is Apple specific.  It
258f6322eb7SMasahiro Yamada# generates numerous errors and warnings.  We want to bypass it
259f6322eb7SMasahiro Yamada# and use GNU C's cpp.	To do this we pass the -traditional-cpp
260f6322eb7SMasahiro Yamada# option to the compiler.  Note that the -traditional-cpp flag
261f6322eb7SMasahiro Yamada# DOES NOT have the same semantics as GNU C's flag, all it does
262f6322eb7SMasahiro Yamada# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
263f6322eb7SMasahiro Yamada#
264f6322eb7SMasahiro Yamada# Apple's linker is similar, thanks to the new 2 stage linking
265f6322eb7SMasahiro Yamada# multiple symbol definitions are treated as errors, hence the
266f6322eb7SMasahiro Yamada# -multiply_defined suppress option to turn off this error.
267f6322eb7SMasahiro Yamada#
268f6322eb7SMasahiro Yamadaifeq ($(HOSTOS),darwin)
269f6322eb7SMasahiro Yamada# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
270f6322eb7SMasahiro YamadaDARWIN_MAJOR_VERSION	= $(shell sw_vers -productVersion | cut -f 1 -d '.')
271f6322eb7SMasahiro YamadaDARWIN_MINOR_VERSION	= $(shell sw_vers -productVersion | cut -f 2 -d '.')
272f6322eb7SMasahiro Yamada
273f6322eb7SMasahiro Yamadaos_x_before	= $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
274f6322eb7SMasahiro Yamada	$(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
275f6322eb7SMasahiro Yamada
276f6322eb7SMasahiro Yamada# Snow Leopards build environment has no longer restrictions as described above
277f6322eb7SMasahiro YamadaHOSTCC       = $(call os_x_before, 10, 5, "cc", "gcc")
278f6322eb7SMasahiro YamadaHOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
279f6322eb7SMasahiro YamadaHOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
280f6322eb7SMasahiro Yamadaendif
281f6322eb7SMasahiro Yamada
2826825a95bSMasahiro Yamada# Decide whether to build built-in, modular, or both.
2836825a95bSMasahiro Yamada# Normally, just do built-in.
2846825a95bSMasahiro Yamada
2856825a95bSMasahiro YamadaKBUILD_MODULES :=
2866825a95bSMasahiro YamadaKBUILD_BUILTIN := 1
2876825a95bSMasahiro Yamada
2886825a95bSMasahiro Yamada#	If we have only "make modules", don't compile built-in objects.
2896825a95bSMasahiro Yamada#	When we're building modules with modversions, we need to consider
2906825a95bSMasahiro Yamada#	the built-in objects during the descend as well, in order to
2916825a95bSMasahiro Yamada#	make sure the checksums are up to date before we record them.
2926825a95bSMasahiro Yamada
2936825a95bSMasahiro Yamadaifeq ($(MAKECMDGOALS),modules)
2946825a95bSMasahiro Yamada  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2956825a95bSMasahiro Yamadaendif
2966825a95bSMasahiro Yamada
2976825a95bSMasahiro Yamada#	If we have "make <whatever> modules", compile modules
2986825a95bSMasahiro Yamada#	in addition to whatever we do anyway.
2996825a95bSMasahiro Yamada#	Just "make" or "make all" shall build modules as well
3006825a95bSMasahiro Yamada
3016825a95bSMasahiro Yamada# U-Boot does not need modules
3026825a95bSMasahiro Yamada#ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
3036825a95bSMasahiro Yamada#  KBUILD_MODULES := 1
3046825a95bSMasahiro Yamada#endif
3056825a95bSMasahiro Yamada
3066825a95bSMasahiro Yamada#ifeq ($(MAKECMDGOALS),)
3076825a95bSMasahiro Yamada#  KBUILD_MODULES := 1
3086825a95bSMasahiro Yamada#endif
3096825a95bSMasahiro Yamada
3106825a95bSMasahiro Yamadaexport KBUILD_MODULES KBUILD_BUILTIN
3116825a95bSMasahiro Yamadaexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
3126825a95bSMasahiro Yamada
3136825a95bSMasahiro Yamada# Beautify output
3146825a95bSMasahiro Yamada# ---------------------------------------------------------------------------
3156825a95bSMasahiro Yamada#
3166825a95bSMasahiro Yamada# Normally, we echo the whole command before executing it. By making
3176825a95bSMasahiro Yamada# that echo $($(quiet)$(cmd)), we now have the possibility to set
3186825a95bSMasahiro Yamada# $(quiet) to choose other forms of output instead, e.g.
3196825a95bSMasahiro Yamada#
3206825a95bSMasahiro Yamada#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
3216825a95bSMasahiro Yamada#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
3226825a95bSMasahiro Yamada#
3236825a95bSMasahiro Yamada# If $(quiet) is empty, the whole command will be printed.
3246825a95bSMasahiro Yamada# If it is set to "quiet_", only the short version will be printed.
3256825a95bSMasahiro Yamada# If it is set to "silent_", nothing will be printed at all, since
3266825a95bSMasahiro Yamada# the variable $(silent_cmd_cc_o_c) doesn't exist.
3276825a95bSMasahiro Yamada#
3286825a95bSMasahiro Yamada# A simple variant is to prefix commands with $(Q) - that's useful
3296825a95bSMasahiro Yamada# for commands that shall be hidden in non-verbose mode.
3306825a95bSMasahiro Yamada#
3316825a95bSMasahiro Yamada#	$(Q)ln $@ :<
3326825a95bSMasahiro Yamada#
3336825a95bSMasahiro Yamada# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
3346825a95bSMasahiro Yamada# If KBUILD_VERBOSE equals 1 then the above command is displayed.
3356825a95bSMasahiro Yamada
3366825a95bSMasahiro Yamadaifeq ($(KBUILD_VERBOSE),1)
3376825a95bSMasahiro Yamada  quiet =
3386825a95bSMasahiro Yamada  Q =
3396825a95bSMasahiro Yamadaelse
3406825a95bSMasahiro Yamada  quiet=quiet_
3416825a95bSMasahiro Yamada  Q = @
3426825a95bSMasahiro Yamadaendif
3436825a95bSMasahiro Yamada
3446825a95bSMasahiro Yamada# If the user is running make -s (silent mode), suppress echoing of
3456825a95bSMasahiro Yamada# commands
3466825a95bSMasahiro Yamada
3476825a95bSMasahiro Yamadaifneq ($(filter s% -s%,$(MAKEFLAGS)),)
3486825a95bSMasahiro Yamada  quiet=silent_
3496825a95bSMasahiro Yamadaendif
3506825a95bSMasahiro Yamada
3516825a95bSMasahiro Yamadaexport quiet Q KBUILD_VERBOSE
3526825a95bSMasahiro Yamada
3536825a95bSMasahiro Yamada
3549e414032SMasahiro Yamada# Look for make include files relative to root of kernel src
3559e414032SMasahiro YamadaMAKEFLAGS += --include-dir=$(srctree)
3569e414032SMasahiro Yamada
357bf4b3de1SMasahiro Yamada# We need some generic definitions (do not try to remake the file).
358bf4b3de1SMasahiro Yamada$(srctree)/scripts/Kbuild.include: ;
359bf4b3de1SMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include
360bf4b3de1SMasahiro Yamada
361f6322eb7SMasahiro Yamada# Make variables (CC, etc...)
362f6322eb7SMasahiro Yamada
363f6322eb7SMasahiro YamadaAS		= $(CROSS_COMPILE)as
364f6322eb7SMasahiro Yamada# Always use GNU ld
365f6322eb7SMasahiro Yamadaifneq ($(shell $(CROSS_COMPILE)ld.bfd -v 2> /dev/null),)
366f6322eb7SMasahiro YamadaLD		= $(CROSS_COMPILE)ld.bfd
367f6322eb7SMasahiro Yamadaelse
368f6322eb7SMasahiro YamadaLD		= $(CROSS_COMPILE)ld
369f6322eb7SMasahiro Yamadaendif
370f6322eb7SMasahiro YamadaCC		= $(CROSS_COMPILE)gcc
371f6322eb7SMasahiro YamadaCPP		= $(CC) -E
372f6322eb7SMasahiro YamadaAR		= $(CROSS_COMPILE)ar
373f6322eb7SMasahiro YamadaNM		= $(CROSS_COMPILE)nm
374f6322eb7SMasahiro YamadaLDR		= $(CROSS_COMPILE)ldr
375f6322eb7SMasahiro YamadaSTRIP		= $(CROSS_COMPILE)strip
376f6322eb7SMasahiro YamadaOBJCOPY		= $(CROSS_COMPILE)objcopy
377f6322eb7SMasahiro YamadaOBJDUMP		= $(CROSS_COMPILE)objdump
378f6322eb7SMasahiro YamadaAWK		= awk
379f6322eb7SMasahiro YamadaRANLIB		= $(CROSS_COMPILE)RANLIB
380f6322eb7SMasahiro YamadaDTC		= dtc
381f6322eb7SMasahiro YamadaCHECK		= sparse
382f6322eb7SMasahiro Yamada
383f6322eb7SMasahiro YamadaCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
384f6322eb7SMasahiro Yamada		  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
385f6322eb7SMasahiro Yamada
386fea1ca8eSMasahiro Yamada# Use UBOOTINCLUDE when you must reference the include/ directory.
387fea1ca8eSMasahiro Yamada# Needed to be compatible with the O= option
388fea1ca8eSMasahiro YamadaUBOOTINCLUDE    :=
389fea1ca8eSMasahiro Yamadaifneq ($(OBJTREE),$(SRCTREE))
390fea1ca8eSMasahiro YamadaUBOOTINCLUDE	+= -I$(OBJTREE)/include
391fea1ca8eSMasahiro Yamadaendif
392fea1ca8eSMasahiro YamadaUBOOTINCLUDE	+= -I$(srctree)/include \
393fea1ca8eSMasahiro Yamada		-I$(srctree)/arch/$(ARCH)/include
394fea1ca8eSMasahiro Yamada
3952b3c9d3dSMasahiro YamadaKBUILD_CPPFLAGS := -D__KERNEL__
3962b3c9d3dSMasahiro Yamada
3972b3c9d3dSMasahiro YamadaKBUILD_CFLAGS   := -Wall -Wstrict-prototypes \
3982b3c9d3dSMasahiro Yamada		   -Wno-format-security \
3992b3c9d3dSMasahiro Yamada		   -fno-builtin -ffreestanding
4002b3c9d3dSMasahiro YamadaKBUILD_AFLAGS   := -D__ASSEMBLY__
4012b3c9d3dSMasahiro Yamada
402*5f30f3beSMasahiro YamadaU_BOOT_VERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
403*5f30f3beSMasahiro Yamada
404*5f30f3beSMasahiro Yamadaexport VERSION PATCHLEVEL SUBLEVEL U_BOOT_VERSION
405f6322eb7SMasahiro Yamadaexport CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
406f6322eb7SMasahiro Yamadaexport CPP AR NM LDR STRIP OBJCOPY OBJDUMP
407f6322eb7SMasahiro Yamadaexport MAKE AWK
408f6322eb7SMasahiro Yamadaexport DTC CHECK CHECKFLAGS
409f6322eb7SMasahiro Yamada
410fea1ca8eSMasahiro Yamadaexport KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE
4112b3c9d3dSMasahiro Yamadaexport KBUILD_CFLAGS KBUILD_AFLAGS
4122b3c9d3dSMasahiro Yamada
4136825a95bSMasahiro Yamada# When compiling out-of-tree modules, put MODVERDIR in the module
4146825a95bSMasahiro Yamada# tree rather than in the kernel tree. The kernel tree might
4156825a95bSMasahiro Yamada# even be read-only.
4166825a95bSMasahiro Yamadaexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4176825a95bSMasahiro Yamada
4186825a95bSMasahiro Yamada# Files to ignore in find ... statements
4196825a95bSMasahiro Yamada
4206825a95bSMasahiro YamadaRCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \
4216825a95bSMasahiro Yamada		   -o -name .pc -o -name .hg -o -name .git \) -prune -o
4226825a95bSMasahiro Yamadaexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
4236825a95bSMasahiro Yamada			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
4246825a95bSMasahiro Yamada
4256825a95bSMasahiro Yamada# ===========================================================================
4266825a95bSMasahiro Yamada# Rules shared between *config targets and build targets
4276825a95bSMasahiro Yamada
4286825a95bSMasahiro Yamada# Basic helpers built in scripts/
4296825a95bSMasahiro YamadaPHONY += scripts_basic
4306825a95bSMasahiro Yamadascripts_basic:
4316825a95bSMasahiro Yamada	$(Q)$(MAKE) $(build)=scripts/basic
4326825a95bSMasahiro Yamada	$(Q)rm -f .tmp_quiet_recordmcount
4336825a95bSMasahiro Yamada
4346825a95bSMasahiro Yamada# To avoid any implicit rule to kick in, define an empty command.
4356825a95bSMasahiro Yamadascripts/basic/%: scripts_basic ;
4366825a95bSMasahiro Yamada
4376825a95bSMasahiro Yamada
4382b3c9d3dSMasahiro YamadaKBUILD_CFLAGS += -Os #-fomit-frame-pointer
4392b3c9d3dSMasahiro Yamada
4402b3c9d3dSMasahiro Yamadaifdef BUILD_TAG
4412b3c9d3dSMasahiro YamadaKBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
4422b3c9d3dSMasahiro Yamadaendif
4432b3c9d3dSMasahiro Yamada
4442b3c9d3dSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
4452b3c9d3dSMasahiro Yamada
4462b3c9d3dSMasahiro YamadaKBUILD_CFLAGS	+= -g
4472b3c9d3dSMasahiro Yamada# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
4482b3c9d3dSMasahiro Yamada# option to the assembler.
4492b3c9d3dSMasahiro YamadaKBUILD_AFLAGS	+= -g
4502b3c9d3dSMasahiro Yamada
451fea1ca8eSMasahiro YamadaNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
452fea1ca8eSMasahiro YamadaCHECKFLAGS     += $(NOSTDINC_FLAGS)
453fea1ca8eSMasahiro Yamada
4542b3c9d3dSMasahiro Yamada# Report stack usage if supported
4552b3c9d3dSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option,-fstack-usage)
4562b3c9d3dSMasahiro Yamada
4572b3c9d3dSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
4582b3c9d3dSMasahiro Yamada
4592b3c9d3dSMasahiro Yamada# turn jbsr into jsr for m68k
4602b3c9d3dSMasahiro Yamadaifeq ($(ARCH),m68k)
4612b3c9d3dSMasahiro Yamadaifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
4622b3c9d3dSMasahiro YamadaKBUILD_AFLAGS += -Wa,-gstabs,-S
4632b3c9d3dSMasahiro Yamadaendif
4642b3c9d3dSMasahiro Yamadaendif
4652b3c9d3dSMasahiro Yamada
46692b197f0SWolfgang Denk# load other configuration
46792b197f0SWolfgang Denkinclude $(TOPDIR)/config.mk
46892b197f0SWolfgang Denk
469ced0715dSMasahiro Yamadaifneq ($(CONFIG_SYS_TEXT_BASE),)
470ced0715dSMasahiro YamadaKBUILD_CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
471ced0715dSMasahiro Yamadaendif
472ced0715dSMasahiro Yamada
473ced0715dSMasahiro Yamadaexport CONFIG_SYS_TEXT_BASE
474ced0715dSMasahiro Yamada
4759e414032SMasahiro YamadaLDFLAGS_u-boot += -T u-boot.lds $(LDFLAGS_FINAL)
476ced0715dSMasahiro Yamadaifneq ($(CONFIG_SYS_TEXT_BASE),)
477ced0715dSMasahiro YamadaLDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
478ced0715dSMasahiro Yamadaendif
479ced0715dSMasahiro Yamada
480fada9e20SSimon Glass# Targets which don't build the source code
481ced0715dSMasahiro YamadaNON_BUILD_TARGETS = backup clean clobber distclean mrproper tidy unconfig %_config
482fada9e20SSimon Glass
483fada9e20SSimon Glass# Only do the generic board check when actually building, not configuring
484fada9e20SSimon Glassifeq ($(filter $(NON_BUILD_TARGETS),$(MAKECMDGOALS)),)
485ced0715dSMasahiro Yamadaifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
486ced0715dSMasahiro Yamadaifneq ($(CONFIG_SYS_GENERIC_BOARD),)
487ced0715dSMasahiro YamadaCHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
488ced0715dSMasahiro YamadaPlease undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
489ced0715dSMasahiro Yamadaendif
490fada9e20SSimon Glassendif
491fada9e20SSimon Glassendif
492fada9e20SSimon Glass
4936825a95bSMasahiro Yamada# FIX ME
4946825a95bSMasahiro Yamadacpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
4956825a95bSMasahiro Yamadac_flags := $(KBUILD_CFLAGS) $(cpp_flags)
4966825a95bSMasahiro Yamada
497d51dfff7SIlya Yanok# If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
498d51dfff7SIlya Yanok# that (or fail if absent).  Otherwise, search for a linker script in a
499d51dfff7SIlya Yanok# standard location.
500d51dfff7SIlya Yanok
501ee60197eSSimon GlassLDSCRIPT_MAKEFILE_DIR = $(dir $(LDSCRIPT))
502ee60197eSSimon Glass
503d51dfff7SIlya Yanokifndef LDSCRIPT
504d51dfff7SIlya Yanok	#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
505d51dfff7SIlya Yanok	ifdef CONFIG_SYS_LDSCRIPT
506d51dfff7SIlya Yanok		# need to strip off double quotes
507a8c07541SMasahiro Yamada		LDSCRIPT := $(CONFIG_SYS_LDSCRIPT:"%"=%)
508d51dfff7SIlya Yanok	endif
509d51dfff7SIlya Yanokendif
510d51dfff7SIlya Yanok
511ee60197eSSimon Glass# If there is no specified link script, we look in a number of places for it
512d51dfff7SIlya Yanokifndef LDSCRIPT
513d51dfff7SIlya Yanok	ifeq ($(CONFIG_NAND_U_BOOT),y)
514d51dfff7SIlya Yanok		LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
515d51dfff7SIlya Yanok		ifeq ($(wildcard $(LDSCRIPT)),)
516d51dfff7SIlya Yanok			LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-nand.lds
517d51dfff7SIlya Yanok		endif
518d51dfff7SIlya Yanok	endif
519d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
520d51dfff7SIlya Yanok		LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
521d51dfff7SIlya Yanok	endif
522d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
523d51dfff7SIlya Yanok		LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot.lds
524d51dfff7SIlya Yanok	endif
525d51dfff7SIlya Yanok	ifeq ($(wildcard $(LDSCRIPT)),)
526ee60197eSSimon Glass		LDSCRIPT := $(TOPDIR)/arch/$(ARCH)/cpu/u-boot.lds
527ee60197eSSimon Glass		# We don't expect a Makefile here
528ee60197eSSimon Glass		LDSCRIPT_MAKEFILE_DIR =
529ee60197eSSimon Glass	endif
530ee60197eSSimon Glass	ifeq ($(wildcard $(LDSCRIPT)),)
531d51dfff7SIlya Yanok$(error could not find linker script)
532d51dfff7SIlya Yanok	endif
533d51dfff7SIlya Yanokendif
534d51dfff7SIlya Yanok
5357ebf7443Swdenk#########################################################################
5367ebf7443Swdenk# U-Boot objects....order is important (i.e. start must be first)
5377ebf7443Swdenk
538e8a8b824SMasahiro Yamadahead-y := $(CPUDIR)/start.o
539e8a8b824SMasahiro Yamadahead-$(CONFIG_4xx) += arch/powerpc/cpu/ppc4xx/resetvec.o
540e8a8b824SMasahiro Yamadahead-$(CONFIG_MPC85xx) += arch/powerpc/cpu/mpc85xx/resetvec.o
5417ebf7443Swdenk
5429e414032SMasahiro YamadaOBJS := $(head-y)
543f9328639SMarian Balakowicz
5449e414032SMasahiro YamadaHAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
5458b5a0264SDaniel Schwierzeck
546e2906a59SMasahiro YamadaLIBS-y += lib/
547e2906a59SMasahiro YamadaLIBS-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
548e2906a59SMasahiro YamadaLIBS-y += $(CPUDIR)/
5491d9f4105Swdenkifdef SOC
550e2906a59SMasahiro YamadaLIBS-y += $(CPUDIR)/$(SOC)/
5511d9f4105Swdenkendif
552e2906a59SMasahiro YamadaLIBS-$(CONFIG_IXP4XX_NPE) += drivers/net/npe/
553e2906a59SMasahiro YamadaLIBS-$(CONFIG_OF_EMBED) += dts/
554e2906a59SMasahiro YamadaLIBS-y += arch/$(ARCH)/lib/
55557c3e5fcSMasahiro YamadaLIBS-y += fs/
556e2906a59SMasahiro YamadaLIBS-y += net/
557e2906a59SMasahiro YamadaLIBS-y += disk/
558e2906a59SMasahiro YamadaLIBS-y += drivers/
559e2906a59SMasahiro YamadaLIBS-y += drivers/dma/
560e2906a59SMasahiro YamadaLIBS-y += drivers/gpio/
561e2906a59SMasahiro YamadaLIBS-y += drivers/i2c/
562e2906a59SMasahiro YamadaLIBS-y += drivers/input/
563e2906a59SMasahiro YamadaLIBS-y += drivers/mmc/
564e2906a59SMasahiro YamadaLIBS-y += drivers/mtd/
565392ba525SMasahiro YamadaLIBS-$(CONFIG_CMD_NAND) += drivers/mtd/nand/
566e2906a59SMasahiro YamadaLIBS-y += drivers/mtd/onenand/
567392ba525SMasahiro YamadaLIBS-$(CONFIG_CMD_UBI) += drivers/mtd/ubi/
568e2906a59SMasahiro YamadaLIBS-y += drivers/mtd/spi/
569e2906a59SMasahiro YamadaLIBS-y += drivers/net/
570e2906a59SMasahiro YamadaLIBS-y += drivers/net/phy/
571e2906a59SMasahiro YamadaLIBS-y += drivers/pci/
572e2906a59SMasahiro YamadaLIBS-y += drivers/power/ \
573e2906a59SMasahiro Yamada	drivers/power/fuel_gauge/ \
574e2906a59SMasahiro Yamada	drivers/power/mfd/ \
575e2906a59SMasahiro Yamada	drivers/power/pmic/ \
576e2906a59SMasahiro Yamada	drivers/power/battery/
577e2906a59SMasahiro YamadaLIBS-y += drivers/spi/
578e2906a59SMasahiro YamadaLIBS-$(CONFIG_FMAN_ENET) += drivers/net/fm/
5795614e71bSYork SunLIBS-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
580e2906a59SMasahiro YamadaLIBS-y += drivers/serial/
581e2906a59SMasahiro YamadaLIBS-y += drivers/usb/eth/
582e2906a59SMasahiro YamadaLIBS-y += drivers/usb/gadget/
583e2906a59SMasahiro YamadaLIBS-y += drivers/usb/host/
584e2906a59SMasahiro YamadaLIBS-y += drivers/usb/musb/
585e2906a59SMasahiro YamadaLIBS-y += drivers/usb/musb-new/
586e2906a59SMasahiro YamadaLIBS-y += drivers/usb/phy/
587e2906a59SMasahiro YamadaLIBS-y += drivers/usb/ulpi/
588e2906a59SMasahiro YamadaLIBS-y += common/
589e2906a59SMasahiro YamadaLIBS-y += lib/libfdt/
5908a7e7d56SMasahiro YamadaLIBS-$(CONFIG_API) += api/
591755e08f0SMasahiro YamadaLIBS-$(CONFIG_HAS_POST) += post/
592e2906a59SMasahiro YamadaLIBS-y += test/
593f9328639SMarian Balakowicz
59424e8bee5SAlison Wangifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
595e2906a59SMasahiro YamadaLIBS-y += arch/$(ARCH)/imx-common/
59618936ee2SJason Liuendif
59718936ee2SJason Liu
598e2906a59SMasahiro YamadaLIBS-$(CONFIG_ARM) += arch/arm/cpu/
599e2906a59SMasahiro YamadaLIBS-$(CONFIG_PPC) += arch/powerpc/cpu/
600852bd07cSMinkyu Kang
601e2906a59SMasahiro YamadaLIBS-y += board/$(BOARDDIR)/
60208e39a84SMasahiro Yamada
603e2906a59SMasahiro YamadaLIBS-y := $(patsubst %/, %/built-in.o, $(LIBS-y))
6049e414032SMasahiro YamadaLIBS := $(sort $(LIBS-y))
605249b53a6SLoïc Minier.PHONY : $(LIBS)
606a8c7c708Swdenk
6074f7cb08eSwdenk# Add GCC lib
60852b1bf2cSWolfgang Denkifdef USE_PRIVATE_LIBGCC
60952b1bf2cSWolfgang Denkifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
6106825a95bSMasahiro YamadaPLATFORM_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/lib.a
61152b1bf2cSWolfgang Denkelse
61252b1bf2cSWolfgang DenkPLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
61352b1bf2cSWolfgang Denkendif
61452b1bf2cSWolfgang Denkelse
6156825a95bSMasahiro YamadaPLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc
61652b1bf2cSWolfgang Denkendif
61752b1bf2cSWolfgang DenkPLATFORM_LIBS += $(PLATFORM_LIBGCC)
61852b1bf2cSWolfgang Denkexport PLATFORM_LIBS
6193d3befa7Swdenk
6206ac9f479SMike Frysinger# Special flags for CPP when processing the linker script.
6216ac9f479SMike Frysinger# Pass the version down so we can handle backwards compatibility
6226ac9f479SMike Frysinger# on the fly.
6236ac9f479SMike FrysingerLDPPFLAGS += \
6246ac9f479SMike Frysinger	-include $(TOPDIR)/include/u-boot/u-boot.lds.h \
6257e6403a6SSimon Glass	-DCPUDIR=$(CPUDIR) \
6266ac9f479SMike Frysinger	$(shell $(LD) --version | \
6276ac9f479SMike Frysinger	  sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
6286ac9f479SMike Frysinger
6297ebf7443Swdenk#########################################################################
630bdccc4feSwdenk#########################################################################
6317ebf7443Swdenk
632f3a14d37SMike Frysingerifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
633f3a14d37SMike FrysingerBOARD_SIZE_CHECK = \
634f3a14d37SMike Frysinger	@actual=`wc -c $@ | awk '{print $$1}'`; \
635d060e6f4SJoe Hershberger	limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
636f3a14d37SMike Frysinger	if test $$actual -gt $$limit; then \
637d060e6f4SJoe Hershberger		echo "$@ exceeds file size limit:" >&2 ; \
638d060e6f4SJoe Hershberger		echo "  limit:  $$limit bytes" >&2 ; \
639d060e6f4SJoe Hershberger		echo "  actual: $$actual bytes" >&2 ; \
640d060e6f4SJoe Hershberger		echo "  excess: $$((actual - limit)) bytes" >&2; \
641f3a14d37SMike Frysinger		exit 1; \
642f3a14d37SMike Frysinger	fi
643f3a14d37SMike Frysingerelse
644f3a14d37SMike FrysingerBOARD_SIZE_CHECK =
645f3a14d37SMike Frysingerendif
646f3a14d37SMike Frysinger
6478137af19SScott Wood# Statically apply RELA-style relocations (currently arm64 only)
6488137af19SScott Woodifneq ($(CONFIG_STATIC_RELA),)
6498137af19SScott Wood# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base
6508137af19SScott WoodDO_STATIC_RELA = \
6518137af19SScott Wood	start=$$($(NM) $(1) | grep __rel_dyn_start | cut -f 1 -d ' '); \
6528137af19SScott Wood	end=$$($(NM) $(1) | grep __rel_dyn_end | cut -f 1 -d ' '); \
6539e414032SMasahiro Yamada	tools/relocate-rela $(2) $(3) $$start $$end
6548137af19SScott Woodelse
6558137af19SScott WoodDO_STATIC_RELA =
6568137af19SScott Woodendif
6578137af19SScott Wood
6583e88337bSMike Frysinger# Always append ALL so that arch config.mk's can add custom ones
6599e414032SMasahiro YamadaALL-y += u-boot.srec u-boot.bin System.map
660e935a374SHaiying Wang
6619e414032SMasahiro YamadaALL-$(CONFIG_NAND_U_BOOT) += u-boot-nand.bin
6629e414032SMasahiro YamadaALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin
6639e414032SMasahiro YamadaALL-$(CONFIG_RAMBOOT_PBL) += u-boot.pbl
6649e414032SMasahiro YamadaALL-$(CONFIG_SPL) += spl/u-boot-spl.bin
6659e414032SMasahiro YamadaALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
6669e414032SMasahiro YamadaALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
6679e414032SMasahiro YamadaALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb u-boot-dtb.bin
668b343bbb5SVadim Bendeburyifneq ($(CONFIG_SPL_TARGET),)
6699e414032SMasahiro YamadaALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
670b343bbb5SVadim Bendeburyendif
6719e414032SMasahiro YamadaALL-$(CONFIG_REMAKE_ELF) += u-boot.elf
6727ebf7443Swdenk
67312b7b70cSAllen Martin# enable combined SPL/u-boot/dtb rules for tegra
6746d6c0baeSTom Warrenifneq ($(CONFIG_TEGRA),)
6757dcd3a21SVidya Sagarifeq ($(CONFIG_SPL),y)
67612b7b70cSAllen Martinifeq ($(CONFIG_OF_SEPARATE),y)
6779e414032SMasahiro YamadaALL-y += u-boot-dtb-tegra.bin
67812b7b70cSAllen Martinelse
6799e414032SMasahiro YamadaALL-y += u-boot-nodtb-tegra.bin
68012b7b70cSAllen Martinendif
68112b7b70cSAllen Martinendif
6827dcd3a21SVidya Sagarendif
68312b7b70cSAllen Martin
6848a7e7d56SMasahiro Yamadaall:		$(ALL-y) $(SUBDIR_EXAMPLES-y)
6857ebf7443Swdenk
6869e414032SMasahiro Yamadau-boot.dtb:	checkdtc u-boot
6879e414032SMasahiro Yamada		$(MAKE) $(build)=dts binary
6889e414032SMasahiro Yamada		mv dts/dt.dtb $@
6892c0f79e4SSimon Glass
6909e414032SMasahiro Yamadau-boot-dtb.bin:	u-boot.bin u-boot.dtb
6912c0f79e4SSimon Glass		cat $^ >$@
6922c0f79e4SSimon Glass
6939e414032SMasahiro Yamadau-boot.hex:	u-boot
6946310eb9dSwdenk		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
6956310eb9dSwdenk
6969e414032SMasahiro Yamadau-boot.srec:	u-boot
69747ed5dd0SAlbert ARIBAUD		$(OBJCOPY) ${OBJCFLAGS} -O srec $< $@
6987ebf7443Swdenk
6999e414032SMasahiro Yamadau-boot.bin:	u-boot
7007ebf7443Swdenk		$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
7018137af19SScott Wood		$(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
702f3a14d37SMike Frysinger		$(BOARD_SIZE_CHECK)
7037ebf7443Swdenk
7049e414032SMasahiro Yamadau-boot.ldr:	u-boot
70576d82187SMike Frysinger		$(CREATE_LDR_ENV)
70668e56324SMike Frysinger		$(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS)
707f3a14d37SMike Frysinger		$(BOARD_SIZE_CHECK)
70894a91e24SMike Frysinger
7099e414032SMasahiro Yamadau-boot.ldr.hex:	u-boot.ldr
71094a91e24SMike Frysinger		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary
71194a91e24SMike Frysinger
7129e414032SMasahiro Yamadau-boot.ldr.srec:	u-boot.ldr
71394a91e24SMike Frysinger		$(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ -I binary
71494a91e24SMike Frysinger
715b40bda6bSStefan Roese#
716b40bda6bSStefan Roese# U-Boot entry point, needed for booting of full-blown U-Boot
717b40bda6bSStefan Roese# from the SPL U-Boot version.
718b40bda6bSStefan Roese#
719b40bda6bSStefan Roeseifndef CONFIG_SYS_UBOOT_START
720b40bda6bSStefan RoeseCONFIG_SYS_UBOOT_START := 0
721b40bda6bSStefan Roeseendif
722b40bda6bSStefan Roese
7239e414032SMasahiro Yamadau-boot.img:	u-boot.bin
7249e414032SMasahiro Yamada		tools/mkimage -A $(ARCH) -T firmware -C none \
725b40bda6bSStefan Roese		-O u-boot -a $(CONFIG_SYS_TEXT_BASE) \
726b40bda6bSStefan Roese		-e $(CONFIG_SYS_UBOOT_START) \
727881a87ecSWolfgang Denk		-n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
728bdccc4feSwdenk			sed -e 's/"[	 ]*$$/ for $(BOARD) board"/') \
729bdccc4feSwdenk		-d $< $@
730bdccc4feSwdenk
7319e414032SMasahiro Yamadau-boot.imx: u-boot.bin depend
7329e414032SMasahiro Yamada		$(MAKE) $(build)=arch/arm/imx-common $(objtree)/u-boot.imx
7338edcde5eSStefano Babic
7349e414032SMasahiro Yamadau-boot.kwb:       u-boot.bin
7359e414032SMasahiro Yamada		tools/mkimage -n $(CONFIG_SYS_KWD_CONFIG) -T kwbimage \
7362ea88b06SEric Cooper		-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) -d $< $@
737aa0c7a86SPrafulla Wadaskar
7389e414032SMasahiro Yamadau-boot.pbl:	u-boot.bin
7399e414032SMasahiro Yamada		tools/mkimage -n $(CONFIG_SYS_FSL_PBL_RCW) \
740690e4258SPrabhakar Kushwaha		-R $(CONFIG_SYS_FSL_PBL_PBI) -T pblimage \
7415d898a00SShaohui Xie		-d $< $@
7425d898a00SShaohui Xie
7439e414032SMasahiro Yamadau-boot.sha1:	u-boot.bin
7449e414032SMasahiro Yamada		tools/ubsha1 u-boot.bin
745566a494fSHeiko Schocher
7469e414032SMasahiro Yamadau-boot.dis:	u-boot
7477ebf7443Swdenk		$(OBJDUMP) -d $< > $@
7487ebf7443Swdenk
7493aa29de0SYing Zhang# $@ is output, $(1) and $(2) are inputs, $(3) is padded intermediate,
7503aa29de0SYing Zhang# $(4) is pad-to
7513aa29de0SYing ZhangSPL_PAD_APPEND = \
7523aa29de0SYing Zhang		$(OBJCOPY) ${OBJCFLAGS} --pad-to=$(4) -I binary -O binary \
7539e414032SMasahiro Yamada		$(1) $(3); \
7549e414032SMasahiro Yamada		cat $(3) $(2) > $@; \
7559e414032SMasahiro Yamada		rm $(3)
75674752baaSScott Wood
7573aa29de0SYing Zhangifdef CONFIG_TPL
7589e414032SMasahiro YamadaSPL_PAYLOAD := tpl/u-boot-with-tpl.bin
7593aa29de0SYing Zhangelse
7609e414032SMasahiro YamadaSPL_PAYLOAD := u-boot.bin
7613aa29de0SYing Zhangendif
76274752baaSScott Wood
7639e414032SMasahiro Yamadau-boot-with-spl.bin: spl/u-boot-spl.bin $(SPL_PAYLOAD)
7643aa29de0SYing Zhang		$(call SPL_PAD_APPEND,$<,$(SPL_PAYLOAD),spl/u-boot-spl-pad.bin,$(CONFIG_SPL_PAD_TO))
7653aa29de0SYing Zhang
7669e414032SMasahiro Yamadatpl/u-boot-with-tpl.bin: tpl/u-boot-tpl.bin u-boot.bin
7679e414032SMasahiro Yamada		$(call SPL_PAD_APPEND,$<,u-boot.bin,tpl/u-boot-tpl-pad.bin,$(CONFIG_TPL_PAD_TO))
7687816f2cfSHeiko Schocher
7699e414032SMasahiro Yamadau-boot-with-spl.imx: spl/u-boot-spl.bin u-boot.bin
7709e414032SMasahiro Yamada		$(MAKE) $(build)=arch/arm/imx-common \
771ba597609SBenoît Thébaudeau			$(OBJTREE)/u-boot-with-spl.imx
772ba597609SBenoît Thébaudeau
7739e414032SMasahiro Yamadau-boot-with-nand-spl.imx: spl/u-boot-spl.bin u-boot.bin
7749e414032SMasahiro Yamada		$(MAKE) $(build)=arch/arm/imx-common \
7757d5a5c79SBenoît Thébaudeau			$(OBJTREE)/u-boot-with-nand-spl.imx
7767d5a5c79SBenoît Thébaudeau
7779e414032SMasahiro Yamadau-boot.ubl:       u-boot-with-spl.bin
7789e414032SMasahiro Yamada		tools/mkimage -n $(UBL_CONFIG) -T ublimage \
7799e414032SMasahiro Yamada		-e $(CONFIG_SYS_TEXT_BASE) -d $< u-boot.ubl
780277f00f5SJosé Miguel Gonçalves
7819e414032SMasahiro Yamadau-boot.ais:       spl/u-boot-spl.bin u-boot.img
7829e414032SMasahiro Yamada		tools/mkimage -s -n $(if $(CONFIG_AIS_CONFIG_FILE),$(srctree)/$(CONFIG_AIS_CONFIG_FILE:"%"=%),"/dev/null") \
7836d660e77SSughosh Ganu			-T aisimage \
784d36d8859SChristian Riesch			-e $(CONFIG_SPL_TEXT_BASE) \
7859e414032SMasahiro Yamada			-d spl/u-boot-spl.bin \
7869e414032SMasahiro Yamada			spl/u-boot-spl.ais
787d36d8859SChristian Riesch		$(OBJCOPY) ${OBJCFLAGS} -I binary \
788d36d8859SChristian Riesch			--pad-to=$(CONFIG_SPL_MAX_SIZE) -O binary \
7899e414032SMasahiro Yamada			spl/u-boot-spl.ais spl/u-boot-spl-pad.ais
7909e414032SMasahiro Yamada		cat spl/u-boot-spl-pad.ais u-boot.img > u-boot.ais
791d36d8859SChristian Riesch
792a5453555SOtavio Salvador
7939e414032SMasahiro Yamadau-boot.sb:       u-boot.bin spl/u-boot-spl.bin
7949e414032SMasahiro Yamada		$(MAKE) $(build)=$(CPUDIR)/$(SOC)/ $(OBJTREE)/u-boot.sb
79530b9b932SMarek Vasut
79694aebe6cSStefan Roese# On x600 (SPEAr600) U-Boot is appended to U-Boot SPL.
79794aebe6cSStefan Roese# Both images are created using mkimage (crc etc), so that the ROM
79894aebe6cSStefan Roese# bootloader can check its integrity. Padding needs to be done to the
79994aebe6cSStefan Roese# SPL image (with mkimage header) and not the binary. Otherwise the resulting image
80094aebe6cSStefan Roese# which is loaded/copied by the ROM bootloader to SRAM doesn't fit.
80194aebe6cSStefan Roese# The resulting image containing both U-Boot images is called u-boot.spr
8029e414032SMasahiro Yamadau-boot.spr:	u-boot.img spl/u-boot-spl.bin
8039e414032SMasahiro Yamada		tools/mkimage -A $(ARCH) -T firmware -C none \
80494aebe6cSStefan Roese		-a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) -n XLOADER \
8059e414032SMasahiro Yamada		-d spl/u-boot-spl.bin $@
80657270260SMasahiro Yamada		$(OBJCOPY) -I binary -O binary \
80757270260SMasahiro Yamada			--pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff $@
8089e414032SMasahiro Yamada		cat u-boot.img >> $@
80994aebe6cSStefan Roese
8106d6c0baeSTom Warrenifneq ($(CONFIG_TEGRA),)
8119e414032SMasahiro Yamadau-boot-nodtb-tegra.bin: spl/u-boot-spl.bin u-boot.bin
8129e414032SMasahiro Yamada		$(OBJCOPY) ${OBJCFLAGS} --pad-to=$(CONFIG_SYS_TEXT_BASE) -O binary spl/u-boot-spl spl/u-boot-spl-pad.bin
8139e414032SMasahiro Yamada		cat spl/u-boot-spl-pad.bin u-boot.bin > $@
8149e414032SMasahiro Yamada		rm spl/u-boot-spl-pad.bin
8159972db5cSStephen Warren
8169972db5cSStephen Warrenifeq ($(CONFIG_OF_SEPARATE),y)
8179e414032SMasahiro Yamadau-boot-dtb-tegra.bin: u-boot-nodtb-tegra.bin u-boot.dtb
8189e414032SMasahiro Yamada		cat u-boot-nodtb-tegra.bin u-boot.dtb > $@
8199972db5cSStephen Warrenendif
820984df4ecSAllen Martinendif
821984df4ecSAllen Martin
8229e414032SMasahiro Yamadau-boot-img.bin: spl/u-boot-spl.bin u-boot.img
8239e414032SMasahiro Yamada		cat spl/u-boot-spl.bin u-boot.img > $@
824fb3d2b8aSStefan Roese
825ecddccd0SStefan Roese# PPC4xx needs the SPL at the end of the image, since the reset vector
826ecddccd0SStefan Roese# is located at 0xfffffffc. So we can't use the "u-boot-img.bin" target
827ecddccd0SStefan Roese# and need to introduce a new build target with the full blown U-Boot
828ecddccd0SStefan Roese# at the start padded up to the start of the SPL image. And then concat
829ecddccd0SStefan Roese# the SPL image to the end.
8309e414032SMasahiro Yamadau-boot-img-spl-at-end.bin: spl/u-boot-spl.bin u-boot.img
83157270260SMasahiro Yamada		$(OBJCOPY) -I binary -O binary --pad-to=$(CONFIG_UBOOT_PAD_TO) \
8329e414032SMasahiro Yamada			 --gap-fill=0xff u-boot.img $@
8339e414032SMasahiro Yamada		cat spl/u-boot-spl.bin >> $@
834ecddccd0SStefan Roese
835f4dc714aSScott Wood# Create a new ELF from a raw binary file.  This is useful for arm64
836f4dc714aSScott Wood# where static relocation needs to be performed on the raw binary,
837f4dc714aSScott Wood# but certain simulators only accept an ELF file (but don't do the
838f4dc714aSScott Wood# relocation).
839f4dc714aSScott Wood# FIXME refactor dts/Makefile to share target/arch detection
8409e414032SMasahiro Yamadau-boot.elf: u-boot.bin
841f4dc714aSScott Wood	@$(OBJCOPY)  -B aarch64 -I binary -O elf64-littleaarch64 \
8429e414032SMasahiro Yamada		$< u-boot-elf.o
8439e414032SMasahiro Yamada	@$(LD) u-boot-elf.o -o $@ \
844f4dc714aSScott Wood		--defsym=_start=$(CONFIG_SYS_TEXT_BASE) \
845f4dc714aSScott Wood		-Ttext=$(CONFIG_SYS_TEXT_BASE)
846f4dc714aSScott Wood
84786eb49b3SSimon Glassifeq ($(CONFIG_SANDBOX),y)
84886eb49b3SSimon GlassGEN_UBOOT = \
8499e414032SMasahiro Yamada		$(CC) $(SYMS) -T u-boot.lds \
8509e414032SMasahiro Yamada			-Wl,--start-group $(LIBS) -Wl,--end-group \
85186eb49b3SSimon Glass			$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map -o u-boot
85286eb49b3SSimon Glasselse
853ecb1dc89SMike FrysingerGEN_UBOOT = \
8549e414032SMasahiro Yamada		$(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
8559e414032SMasahiro Yamada			$(OBJS) \
8569e414032SMasahiro Yamada			--start-group $(LIBS) --end-group $(PLATFORM_LIBS) \
857b2184c31Swdenk			-Map u-boot.map -o u-boot
85886eb49b3SSimon Glassendif
85986eb49b3SSimon Glass
8609e414032SMasahiro Yamadau-boot:	depend $(SUBDIR_TOOLS) $(OBJS) $(LIBS) u-boot.lds
861ecb1dc89SMike Frysinger		$(GEN_UBOOT)
862ecb1dc89SMike Frysingerifeq ($(CONFIG_KALLSYMS),y)
8639e414032SMasahiro Yamada		smap=`$(call SYSTEM_MAP,u-boot) | \
8641aada9cdSWolfgang Denk			awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
8656825a95bSMasahiro Yamada		$(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
8669e414032SMasahiro Yamada			-c $(srctree)/common/system_map.c -o common/system_map.o
8679e414032SMasahiro Yamada		$(GEN_UBOOT) common/system_map.o
868ecb1dc89SMike Frysingerendif
8697ebf7443Swdenk
8703bddafaaSMasahiro Yamada$(OBJS):
8713bddafaaSMasahiro Yamada	@:
872f9328639SMarian Balakowicz
8736825a95bSMasahiro Yamada$(LIBS):	depend $(SUBDIR_TOOLS) scripts_basic
8746825a95bSMasahiro Yamada		$(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
875a8c7c708Swdenk
8766825a95bSMasahiro Yamada$(SUBDIRS):	depend scripts_basic
8776825a95bSMasahiro Yamada		$(Q)$(MAKE) $(build)=$@
878940db16dSMasahiro Yamada
8799e414032SMasahiro Yamada$(SUBDIR_EXAMPLES-y): u-boot
880349e83f0SChe-liang Chiou
8819e414032SMasahiro Yamadau-boot.lds: $(LDSCRIPT) depend
8826825a95bSMasahiro Yamada		$(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$< >$@
8831aada9cdSWolfgang Denk
8846825a95bSMasahiro Yamadanand_spl:	$(TIMESTAMP_FILE) $(VERSION_FILE) depend scripts_basic
8859e414032SMasahiro Yamada		$(MAKE) $(build)=nand_spl/board/$(BOARDDIR) all
886887e2ec9SStefan Roese
8879e414032SMasahiro Yamadau-boot-nand.bin:	nand_spl u-boot.bin
8889e414032SMasahiro Yamada		cat nand_spl/u-boot-spl-16k.bin u-boot.bin > u-boot-nand.bin
889887e2ec9SStefan Roese
8906825a95bSMasahiro Yamadaspl/u-boot-spl.bin:	$(SUBDIR_TOOLS) depend scripts_basic
8919e414032SMasahiro Yamada		$(MAKE) obj=spl -f $(srctree)/spl/Makefile all
8925df2ee27SDaniel Schwierzeck
8936825a95bSMasahiro Yamadatpl/u-boot-tpl.bin:	$(SUBDIR_TOOLS) depend scripts_basic
8949e414032SMasahiro Yamada		$(MAKE) obj=tpl -f $(srctree)/spl/Makefile all CONFIG_TPL_BUILD=y
8953aa29de0SYing Zhang
8962a998793SDaniel Hobi# Explicitly make _depend in subdirs containing multiple targets to prevent
8972a998793SDaniel Hobi# parallel sub-makes creating .depend files simultaneously.
89816a354f9SWolfgang Denkdepend dep:	$(TIMESTAMP_FILE) $(VERSION_FILE) \
8999e414032SMasahiro Yamada		include/spl-autoconf.mk \
9009e414032SMasahiro Yamada		include/tpl-autoconf.mk \
9019e414032SMasahiro Yamada		include/autoconf.mk \
9029e414032SMasahiro Yamada		include/generated/generic-asm-offsets.h \
9039e414032SMasahiro Yamada		include/generated/asm-offsets.h
9047ebf7443Swdenk
905e5e4e705SLi YangTAG_SUBDIRS = $(SUBDIRS)
9069e414032SMasahiro YamadaTAG_SUBDIRS += $(dir $(LIBS))
907a340c325SJean-Christophe PLAGNIOL-VILLARDTAG_SUBDIRS += include
908a340c325SJean-Christophe PLAGNIOL-VILLARD
909857d9ea6SHorst KronstorferFIND := find
910857d9ea6SHorst KronstorferFINDFLAGS := -L
911857d9ea6SHorst Kronstorfer
9121064d980STom Rinicheckstack:
9139e414032SMasahiro Yamada		$(CROSS_COMPILE)objdump -d u-boot \
9149e414032SMasahiro Yamada			`$(FIND) . -name u-boot-spl -print` | \
9159e414032SMasahiro Yamada			perl $(src)/scripts/checkstack.pl $(ARCH)
9161064d980STom Rini
917f9328639SMarian Balakowicztags ctags:
9189e414032SMasahiro Yamada		ctags -w -o ctags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
919e5e4e705SLi Yang						-name '*.[chS]' -print`
9207ebf7443Swdenk
9217ebf7443Swdenketags:
922857d9ea6SHorst Kronstorfer		etags -a -o $(obj)etags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
923e5e4e705SLi Yang						-name '*.[chS]' -print`
924ffda586fSLi Yangcscope:
925857d9ea6SHorst Kronstorfer		$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
926857d9ea6SHorst Kronstorfer						cscope.files
927ffda586fSLi Yang		cscope -b -q -k
9287ebf7443Swdenk
929ecb1dc89SMike FrysingerSYSTEM_MAP = \
930ecb1dc89SMike Frysinger		$(NM) $1 | \
9317ebf7443Swdenk		grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
932ecb1dc89SMike Frysinger		LC_ALL=C sort
9339e414032SMasahiro YamadaSystem.map:	u-boot
934bc8bb6ecSMasahiro Yamada		@$(call SYSTEM_MAP,$<) > $@
9357ebf7443Swdenk
93606a119a0STom Rinicheckthumb:
93706a119a0STom Rini	@if test $(call cc-version) -lt 0404; then \
93806a119a0STom Rini		echo -n '*** Your GCC does not produce working '; \
93906a119a0STom Rini		echo 'binaries in THUMB mode.'; \
94006a119a0STom Rini		echo '*** Your board is configured for THUMB mode.'; \
94106a119a0STom Rini		false; \
94206a119a0STom Rini	fi
9436ec63f41SScott Wood
9446ec63f41SScott Wood# GCC 3.x is reported to have problems generating the type of relocation
9456ec63f41SScott Wood# that U-Boot wants.
9466ec63f41SScott Wood# See http://lists.denx.de/pipermail/u-boot/2012-September/135156.html
9476ec63f41SScott Woodcheckgcc4:
9486ec63f41SScott Wood	@if test $(call cc-version) -lt 0400; then \
9496ec63f41SScott Wood		echo -n '*** Your GCC is too old, please upgrade to GCC 4.x or newer'; \
9506ec63f41SScott Wood		false; \
9516ec63f41SScott Wood	fi
9526ec63f41SScott Wood
953501ebdf2SStephen Warrencheckdtc:
954501ebdf2SStephen Warren	@if test $(call dtc-version) -lt 0104; then \
955501ebdf2SStephen Warren		echo '*** Your dtc is too old, please upgrade to dtc 1.4 or newer'; \
956501ebdf2SStephen Warren		false; \
957501ebdf2SStephen Warren	fi
958501ebdf2SStephen Warren
9592f155f6cSGrant Likely#
9602f155f6cSGrant Likely# Auto-generate the autoconf.mk file (which is included by all makefiles)
9612f155f6cSGrant Likely#
9622f155f6cSGrant Likely# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
9632f155f6cSGrant Likely# the dep file is only include in this top level makefile to determine when
9642f155f6cSGrant Likely# to regenerate the autoconf.mk file.
9659e414032SMasahiro Yamadainclude/autoconf.mk.dep: include/config.h include/common.h
9661510b82dSWolfgang Denk	@$(XECHO) Generating $@ ; \
967ae6d1056SWolfgang Denk	: Generate the dependancies ; \
9686825a95bSMasahiro Yamada	$(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \
9699e414032SMasahiro Yamada		-MQ include/autoconf.mk $(srctree)/include/common.h > $@ || \
97065947ab4SMasahiro Yamada		rm $@
9711510b82dSWolfgang Denk
9729e414032SMasahiro Yamadainclude/autoconf.mk: include/config.h
9731510b82dSWolfgang Denk	@$(XECHO) Generating $@ ; \
974ae6d1056SWolfgang Denk	: Extract the config macros ; \
9756825a95bSMasahiro Yamada	$(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
9769e414032SMasahiro Yamada		sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
97765947ab4SMasahiro Yamada	rm $@.tmp
9782f155f6cSGrant Likely
97939bc12ddSJoel Fernandes# Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
9809e414032SMasahiro Yamadainclude/tpl-autoconf.mk: include/config.h
9813aa29de0SYing Zhang	@$(XECHO) Generating $@ ; \
9823aa29de0SYing Zhang	: Extract the config macros ; \
9836825a95bSMasahiro Yamada	$(CPP) $(c_flags) -DCONFIG_TPL_BUILD  -DCONFIG_SPL_BUILD\
9849e414032SMasahiro Yamada			-DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
9859e414032SMasahiro Yamada		sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
98665947ab4SMasahiro Yamada	rm $@.tmp
9873aa29de0SYing Zhang
9889e414032SMasahiro Yamadainclude/spl-autoconf.mk: include/config.h
98939bc12ddSJoel Fernandes	@$(XECHO) Generating $@ ; \
99039bc12ddSJoel Fernandes	: Extract the config macros ; \
9916825a95bSMasahiro Yamada	$(CPP) $(c_flags) -DCONFIG_SPL_BUILD -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
9929e414032SMasahiro Yamada		sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
99365947ab4SMasahiro Yamada	rm $@.tmp
99439bc12ddSJoel Fernandes
9959e414032SMasahiro Yamadainclude/generated/generic-asm-offsets.h: lib/asm-offsets.s
99616a354f9SWolfgang Denk	@$(XECHO) Generating $@
9979e414032SMasahiro Yamada	$(srctree)/tools/scripts/make-asm-offsets lib/asm-offsets.s $@
99816a354f9SWolfgang Denk
9999e414032SMasahiro Yamadalib/asm-offsets.s: include/config.h $(srctree)/lib/asm-offsets.c
10009e414032SMasahiro Yamada	@mkdir -p lib
100116a354f9SWolfgang Denk	$(CC) -DDO_DEPS_ONLY \
10026825a95bSMasahiro Yamada		$(c_flags) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
10039e414032SMasahiro Yamada		-o $@ $(srctree)/lib/asm-offsets.c -c -S
100416a354f9SWolfgang Denk
10059e414032SMasahiro Yamadainclude/generated/asm-offsets.h: $(CPUDIR)/$(SOC)/asm-offsets.s
1006b12734eeSWolfgang Denk	@$(XECHO) Generating $@
10079e414032SMasahiro Yamada	$(srctree)/tools/scripts/make-asm-offsets $(CPUDIR)/$(SOC)/asm-offsets.s $@
1008a4814a69SStefano Babic
10099e414032SMasahiro Yamada$(CPUDIR)/$(SOC)/asm-offsets.s:	include/config.h
10109e414032SMasahiro Yamada	@mkdir -p $(CPUDIR)/$(SOC)
10119e414032SMasahiro Yamada	if [ -f $(srctree)/$(CPUDIR)/$(SOC)/asm-offsets.c ];then \
1012a4814a69SStefano Babic		$(CC) -DDO_DEPS_ONLY \
10136825a95bSMasahiro Yamada		$(c_flags) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
10149e414032SMasahiro Yamada			-o $@ $(srctree)/$(CPUDIR)/$(SOC)/asm-offsets.c -c -S; \
1015a4814a69SStefano Babic	else \
1016a4814a69SStefano Babic		touch $@; \
1017a4814a69SStefano Babic	fi
1018a4814a69SStefano Babic
10197ebf7443Swdenk#########################################################################
1020ae6d1056SWolfgang Denkelse	# !config.mk
10219e414032SMasahiro Yamadaall u-boot.hex u-boot.srec u-boot.bin \
10229e414032SMasahiro Yamadau-boot.img u-boot.dis u-boot \
1023249b53a6SLoïc Minier$(filter-out tools,$(SUBDIRS)) \
10249e414032SMasahiro Yamadadepend dep tags ctags etags cscope System.map:
10257ebf7443Swdenk	@echo "System not configured - see README" >&2
10267ebf7443Swdenk	@ exit 1
1027c7c0d542SMike Frysinger
1028249b53a6SLoïc Miniertools: $(VERSION_FILE) $(TIMESTAMP_FILE)
10299e414032SMasahiro Yamada	$(MAKE) $(build)=$@ all
1030ae6d1056SWolfgang Denkendif	# config.mk
10317ebf7443Swdenk
103254799e45SScott Wood# ARM relocations should all be R_ARM_RELATIVE (32-bit) or
103354799e45SScott Wood# R_AARCH64_RELATIVE (64-bit).
10349e414032SMasahiro Yamadacheckarmreloc: u-boot
103554799e45SScott Wood	@RELOC="`$(CROSS_COMPILE)readelf -r -W $< | cut -d ' ' -f 4 | \
103654799e45SScott Wood		grep R_A | sort -u`"; \
103754799e45SScott Wood	if test "$$RELOC" != "R_ARM_RELATIVE" -a \
103854799e45SScott Wood		 "$$RELOC" != "R_AARCH64_RELATIVE"; then \
103954799e45SScott Wood		echo "$< contains unexpected relocations: $$RELOC"; \
104054799e45SScott Wood		false; \
104154799e45SScott Wood	fi
1042c37980c3SAlbert ARIBAUD
104328abd48fSIlya Yanok$(VERSION_FILE):
104414ce91b1SMike Frysinger		@mkdir -p $(dir $(VERSION_FILE))
1045dd88ab32SMasahiro Yamada		@( localvers='$(shell $(TOPDIR)/scripts/setlocalversion $(TOPDIR))' ; \
104628abd48fSIlya Yanok		   printf '#define PLAIN_VERSION "%s%s"\n' \
104728abd48fSIlya Yanok			"$(U_BOOT_VERSION)" "$${localvers}" ; \
104828abd48fSIlya Yanok		   printf '#define U_BOOT_VERSION "U-Boot %s%s"\n' \
104928abd48fSIlya Yanok			"$(U_BOOT_VERSION)" "$${localvers}" ; \
105028abd48fSIlya Yanok		) > $@.tmp
105128abd48fSIlya Yanok		@( printf '#define CC_VERSION_STRING "%s"\n' \
105228abd48fSIlya Yanok		 '$(shell $(CC) --version | head -n 1)' )>>  $@.tmp
105328abd48fSIlya Yanok		@( printf '#define LD_VERSION_STRING "%s"\n' \
105428abd48fSIlya Yanok		 '$(shell $(LD) -v | head -n 1)' )>>  $@.tmp
105528abd48fSIlya Yanok		@cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@
105628abd48fSIlya Yanok
1057249b53a6SLoïc Minier$(TIMESTAMP_FILE):
1058249b53a6SLoïc Minier		@mkdir -p $(dir $(TIMESTAMP_FILE))
1059a76406fbSLoïc Minier		@LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"' > $@.tmp
1060a76406fbSLoïc Minier		@LC_ALL=C date +'#define U_BOOT_TIME "%T"' >> $@.tmp
1061a76406fbSLoïc Minier		@cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@
1062249b53a6SLoïc Minier
10630358df42SMike Frysingereasylogo env gdb:
10646825a95bSMasahiro Yamada	$(Q)$(MAKE) $(build)=tools/$@ MTD_VERSION=${MTD_VERSION}
1065940db16dSMasahiro Yamada
10660358df42SMike Frysingergdbtools: gdb
10670358df42SMike Frysinger
106830ff8918SMarek Vasutxmldocs pdfdocs psdocs htmldocs mandocs: tools/kernel-doc/docproc
10696825a95bSMasahiro Yamada	$(Q)$(MAKE) U_BOOT_VERSION=$(U_BOOT_VERSION) $(build)=doc/DocBook $@
107030ff8918SMarek Vasut
1071249b53a6SLoïc Miniertools-all: easylogo env gdb $(VERSION_FILE) $(TIMESTAMP_FILE)
10726825a95bSMasahiro Yamada	$(Q)$(MAKE) $(build)=tools HOST_TOOLS_ALL=y
10730358df42SMike Frysinger
10744e53a258SWolfgang Denk.PHONY : CHANGELOG
10754e53a258SWolfgang DenkCHANGELOG:
1076b985b5d6SBen Warren	git log --no-merges U-Boot-1_1_5.. | \
1077b985b5d6SBen Warren	unexpand -a | sed -e 's/\s\s*$$//' > $@
10784e53a258SWolfgang Denk
10790a823aa2SHarald Welteinclude/license.h: tools/bin2header COPYING
10800a823aa2SHarald Welte	cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h
10817ebf7443Swdenk#########################################################################
10827ebf7443Swdenk
10837ebf7443Swdenkunconfig:
10849e414032SMasahiro Yamada	@rm -f include/config.h include/config.mk \
10859e414032SMasahiro Yamada		board/*/config.tmp board/*/*/config.tmp \
10869e414032SMasahiro Yamada		include/autoconf.mk include/autoconf.mk.dep \
10879e414032SMasahiro Yamada		include/spl-autoconf.mk \
10889e414032SMasahiro Yamada		include/tpl-autoconf.mk
10897ebf7443Swdenk
1090a6862bc1SWolfgang Denk%_config::	unconfig
1091a6862bc1SWolfgang Denk	@$(MKCONFIG) -A $(@:_config=)
1092a6862bc1SWolfgang Denk
10933e38691eSwdenk#########################################################################
10947ebf7443Swdenk
10957ebf7443Swdenkclean:
10969e414032SMasahiro Yamada	@rm -f examples/standalone/atmel_df_pow2			  \
10979e414032SMasahiro Yamada	       examples/standalone/hello_world				  \
10989e414032SMasahiro Yamada	       examples/standalone/interrupt				  \
10999e414032SMasahiro Yamada	       examples/standalone/mem_to_mem_idma2intr			  \
11009e414032SMasahiro Yamada	       examples/standalone/sched				  \
11019e414032SMasahiro Yamada	       $(addprefix examples/standalone/, smc91111_eeprom smc911x_eeprom) \
11029e414032SMasahiro Yamada	       examples/standalone/test_burst				  \
11039e414032SMasahiro Yamada	       examples/standalone/timer
11049e414032SMasahiro Yamada	@rm -f $(addprefix examples/api/, demo demo.bin)
11059e414032SMasahiro Yamada	@rm -f tools/bmp_logo	   tools/easylogo/easylogo		  \
11069e414032SMasahiro Yamada	       tools/env/fw_printenv					  \
11079e414032SMasahiro Yamada	       tools/envcrc						  \
11089e414032SMasahiro Yamada	       $(addprefix tools/gdb/, gdbcont gdbsend)			  \
11099e414032SMasahiro Yamada	       tools/gen_eth_addr    tools/img2srec			  \
11109e414032SMasahiro Yamada	       tools/dumpimage						  \
11119e414032SMasahiro Yamada	       $(addprefix tools/, mkenvimage mkimage)			  \
11129e414032SMasahiro Yamada	       tools/mpc86x_clk						  \
11139e414032SMasahiro Yamada	       $(addprefix tools/, mk$(BOARD)spl mkexynosspl)		  \
11149e414032SMasahiro Yamada	       tools/mxsboot						  \
11159e414032SMasahiro Yamada	       tools/ncb		   tools/ubsha1			  \
11169e414032SMasahiro Yamada	       tools/kernel-doc/docproc					  \
11179e414032SMasahiro Yamada	       tools/proftool
11189e414032SMasahiro Yamada	@rm -f $(addprefix board/cray/L1/, bootscript.c bootscript.image) \
11199e414032SMasahiro Yamada	       board/matrix_vision/*/bootscript.img			  \
11209e414032SMasahiro Yamada	       spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl		  \
11219e414032SMasahiro Yamada	       u-boot.lds						  \
11229e414032SMasahiro Yamada	       $(addprefix arch/blackfin/cpu/, init.lds init.elf)
11239e414032SMasahiro Yamada	@rm -f include/bmp_logo.h
11249e414032SMasahiro Yamada	@rm -f include/bmp_logo_data.h
11259e414032SMasahiro Yamada	@rm -f lib/asm-offsets.s
11269e414032SMasahiro Yamada	@rm -f include/generated/asm-offsets.h
11279e414032SMasahiro Yamada	@rm -f $(CPUDIR)/$(SOC)/asm-offsets.s
1128d4abc757SPeter Tyser	@rm -f $(TIMESTAMP_FILE) $(VERSION_FILE)
11299e414032SMasahiro Yamada	@$(MAKE) -f $(srctree)/doc/DocBook/Makefile cleandocs
1130ae6d1056SWolfgang Denk	@find $(OBJTREE) -type f \
11314a30f1e8STom Rini		\( -name 'core' -o -name '*.bak' -o -name '*~' -o -name '*.su' \
11326825a95bSMasahiro Yamada		-o -name '*.o'	-o -name '*.a' -o -name '*.exe' -o -name '*.cmd' \
113371a988aaSTroy Kisky		-o -name '*.cfgtmp' \) -print \
11347ebf7443Swdenk		| xargs rm -f
11357ebf7443Swdenk
1136734329f9SAndy Fleming# Removes everything not needed for testing u-boot
1137734329f9SAndy Flemingtidy:	clean
1138734329f9SAndy Fleming	@find $(OBJTREE) -type f \( -name '*.depend*' \) -print | xargs rm -f
1139734329f9SAndy Fleming
1140734329f9SAndy Flemingclobber:	tidy
1141734329f9SAndy Fleming	@find $(OBJTREE) -type f \( -name '*.srec' \
1142734329f9SAndy Fleming		-o -name '*.bin' -o -name u-boot.img \) \
1143734329f9SAndy Fleming		-print0 | xargs -0 rm -f
11449e414032SMasahiro Yamada	@rm -f $(OBJS) *.bak ctags etags TAGS \
11459e414032SMasahiro Yamada		cscope.* *.*~
11469e414032SMasahiro Yamada	@rm -f u-boot u-boot.map u-boot.hex $(ALL-y)
11479e414032SMasahiro Yamada	@rm -f u-boot.kwb
11489e414032SMasahiro Yamada	@rm -f u-boot.pbl
11499e414032SMasahiro Yamada	@rm -f u-boot.imx
11509e414032SMasahiro Yamada	@rm -f u-boot-with-spl.imx
11519e414032SMasahiro Yamada	@rm -f u-boot-with-nand-spl.imx
11529e414032SMasahiro Yamada	@rm -f u-boot.ubl
11539e414032SMasahiro Yamada	@rm -f u-boot.ais
11549e414032SMasahiro Yamada	@rm -f u-boot.dtb
11559e414032SMasahiro Yamada	@rm -f u-boot.sb
11569e414032SMasahiro Yamada	@rm -f u-boot.spr
11579e414032SMasahiro Yamada	@rm -f $(addprefix nand_spl/, u-boot.lds u-boot.lst System.map)
11589e414032SMasahiro Yamada	@rm -f $(addprefix nand_spl/, u-boot-nand_spl.lds u-boot-spl u-boot-spl.map)
11599e414032SMasahiro Yamada	@rm -f $(addprefix spl/, u-boot-spl u-boot-spl.bin u-boot-spl.map)
11609e414032SMasahiro Yamada	@rm -f spl/u-boot-spl.lds
11619e414032SMasahiro Yamada	@rm -f $(addprefix tpl/, u-boot-tpl u-boot-tpl.bin u-boot-tpl.map)
11629e414032SMasahiro Yamada	@rm -f tpl/u-boot-spl.lds
11639e414032SMasahiro Yamada	@rm -f MLO MLO.byteswap
11649e414032SMasahiro Yamada	@rm -f SPL
11659e414032SMasahiro Yamada	@rm -f tools/xway-swap-bytes
11669e414032SMasahiro Yamada	@rm -fr include/asm/proc include/asm/arch include/asm
11679e414032SMasahiro Yamada	@rm -fr include/generated
11689e414032SMasahiro Yamada	@[ ! -d nand_spl ] || find nand_spl -name "*" -type l -print | xargs rm -f
11699e414032SMasahiro Yamada	@rm -f dts/*.tmp
11709e414032SMasahiro Yamada	@rm -f $(addprefix spl/, u-boot-spl.ais, u-boot-spl-pad.ais)
11717ebf7443Swdenk
11727ebf7443Swdenkmrproper \
11737ebf7443Swdenkdistclean:	clobber unconfig
1174afd077bdSMike Frysingerifneq ($(OBJTREE),$(SRCTREE))
11759e414032SMasahiro Yamada	rm -rf *
1176f9328639SMarian Balakowiczendif
11777ebf7443Swdenk
11787ebf7443Swdenkbackup:
11797ebf7443Swdenk	F=`basename $(TOPDIR)` ; cd .. ; \
1180d6b93714SIlya Yanok	gtar --force-local -zcvf `LC_ALL=C date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
11817ebf7443Swdenk
11827ebf7443Swdenk#########################################################################
11839e414032SMasahiro Yamada
11849e414032SMasahiro Yamadaendif	# skip-makefile
11859e414032SMasahiro Yamada
11869e414032SMasahiro YamadaPHONY += FORCE
11879e414032SMasahiro YamadaFORCE:
11889e414032SMasahiro Yamada
11899e414032SMasahiro Yamada# Declare the contents of the .PHONY variable as phony.  We keep that
11909e414032SMasahiro Yamada# information in a variable so we can use it in if_changed and friends.
11919e414032SMasahiro Yamada.PHONY: $(PHONY)
1192