xref: /rk3399_ARM-atf/Makefile (revision b7124ea7f6fe1e1e73a0975cfb0fa34cabd73b2a)
14f6ad66aSAchin Gupta#
2e83b0cadSDan Handley# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta#
44f6ad66aSAchin Gupta# Redistribution and use in source and binary forms, with or without
54f6ad66aSAchin Gupta# modification, are permitted provided that the following conditions are met:
64f6ad66aSAchin Gupta#
74f6ad66aSAchin Gupta# Redistributions of source code must retain the above copyright notice, this
84f6ad66aSAchin Gupta# list of conditions and the following disclaimer.
94f6ad66aSAchin Gupta#
104f6ad66aSAchin Gupta# Redistributions in binary form must reproduce the above copyright notice,
114f6ad66aSAchin Gupta# this list of conditions and the following disclaimer in the documentation
124f6ad66aSAchin Gupta# and/or other materials provided with the distribution.
134f6ad66aSAchin Gupta#
144f6ad66aSAchin Gupta# Neither the name of ARM nor the names of its contributors may be used
154f6ad66aSAchin Gupta# to endorse or promote products derived from this software without specific
164f6ad66aSAchin Gupta# prior written permission.
174f6ad66aSAchin Gupta#
184f6ad66aSAchin Gupta# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
194f6ad66aSAchin Gupta# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204f6ad66aSAchin Gupta# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214f6ad66aSAchin Gupta# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
224f6ad66aSAchin Gupta# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
234f6ad66aSAchin Gupta# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
244f6ad66aSAchin Gupta# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
254f6ad66aSAchin Gupta# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
264f6ad66aSAchin Gupta# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
274f6ad66aSAchin Gupta# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284f6ad66aSAchin Gupta# POSSIBILITY OF SUCH DAMAGE.
294f6ad66aSAchin Gupta#
304f6ad66aSAchin Gupta
31e35c4045SJeenu Viswambharan#
32aaa3e722SJuan Castillo# Trusted Firmware Version
33aaa3e722SJuan Castillo#
34c6249aaaSDan HandleyVERSION_MAJOR		:= 1
35c6249aaaSDan HandleyVERSION_MINOR		:= 0
36aaa3e722SJuan Castillo
37aaa3e722SJuan Castillo#
38e35c4045SJeenu Viswambharan# Default values for build configurations
39e35c4045SJeenu Viswambharan#
40e35c4045SJeenu Viswambharan
41e35c4045SJeenu Viswambharan# Build verbosity
42e35c4045SJeenu ViswambharanV			:= 0
43e35c4045SJeenu Viswambharan# Debug build
44e35c4045SJeenu ViswambharanDEBUG			:= 0
45e35c4045SJeenu Viswambharan# Build architecture
46e35c4045SJeenu ViswambharanARCH 			:= aarch64
47e35c4045SJeenu Viswambharan# Build platform
48e35c4045SJeenu ViswambharanDEFAULT_PLAT		:= fvp
49e35c4045SJeenu ViswambharanPLAT			:= ${DEFAULT_PLAT}
50e35c4045SJeenu Viswambharan# SPD choice
51e35c4045SJeenu ViswambharanSPD			:= none
52e35c4045SJeenu Viswambharan# Base commit to perform code check on
53e35c4045SJeenu ViswambharanBASE_COMMIT		:= origin/master
542da8d8bfSJeenu Viswambharan# NS timer register save and restore
552da8d8bfSJeenu ViswambharanNS_TIMER_SWITCH		:= 0
56dbad1bacSVikram Kanigiri# By default, Bl1 acts as the reset handler, not BL31
57dbad1bacSVikram KanigiriRESET_TO_BL31		:= 0
580f21c547SJuan Castillo# Include FP registers in cpu context
590f21c547SJuan CastilloCTX_INCLUDE_FPREGS		:= 0
602b98e789SSandrine Bailleux# Determine the version of ARM GIC architecture to use for interrupt management
612b98e789SSandrine Bailleux# in EL3. The platform port can change this value if needed.
622b98e789SSandrine BailleuxARM_GIC_ARCH		:=	2
63bc920128SSoby Mathew# Flag used to indicate if ASM_ASSERTION should be enabled for the build.
64bc920128SSoby Mathew# This defaults to being present in DEBUG builds only.
65bc920128SSoby MathewASM_ASSERTION		:=	${DEBUG}
668c5fe0b5SSoby Mathew# Build option to choose whether Trusted firmware uses Coherent memory or not.
678c5fe0b5SSoby MathewUSE_COHERENT_MEM	:=	1
687f48fab9SJuan Castillo# Default FIP file name
697f48fab9SJuan CastilloFIP_NAME		:= fip.bin
706f971622SJuan Castillo# Flags to generate the Chain of Trust
716f971622SJuan CastilloGENERATE_COT		:= 0
726f971622SJuan CastilloCREATE_KEYS		:= 1
734f6ad66aSAchin Gupta
747421b465SAchin Gupta# Checkpatch ignores
757421b465SAchin GuptaCHECK_IGNORE		=	--ignore COMPLEX_MACRO
767421b465SAchin Gupta
777421b465SAchin GuptaCHECKPATCH_ARGS		=	--no-tree --no-signoff ${CHECK_IGNORE}
787421b465SAchin GuptaCHECKCODE_ARGS		=	--no-patch --no-tree --no-signoff ${CHECK_IGNORE}
7936eaaf37SIan Spray
80e35c4045SJeenu Viswambharanifeq (${V},0)
814f6ad66aSAchin Gupta	Q=@
8236eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
834f6ad66aSAchin Guptaelse
844f6ad66aSAchin Gupta	Q=
854f6ad66aSAchin Guptaendif
862f2cef46SJeenu Viswambharanexport Q
872f2cef46SJeenu Viswambharan
88eaaeece2SJames Morrisseyifneq (${DEBUG}, 0)
89eaaeece2SJames Morrissey	BUILD_TYPE	:=	debug
90289c28a8SDan Handley	# Use LOG_LEVEL_INFO by default for debug builds
91289c28a8SDan Handley	LOG_LEVEL	:=	40
92eaaeece2SJames Morrisseyelse
93eaaeece2SJames Morrissey	BUILD_TYPE	:=	release
94289c28a8SDan Handley	# Use LOG_LEVEL_NOTICE by default for release builds
95289c28a8SDan Handley	LOG_LEVEL	:=	20
96eaaeece2SJames Morrisseyendif
97eaaeece2SJames Morrissey
98aaa3e722SJuan Castillo# Default build string (git branch and commit)
99aaa3e722SJuan Castilloifeq (${BUILD_STRING},)
100aaa3e722SJuan Castillo	BUILD_STRING	:=	$(shell git log -n 1 --pretty=format:"%h")
101aaa3e722SJuan Castilloendif
102aaa3e722SJuan Castillo
103aaa3e722SJuan CastilloVERSION_STRING		:=	v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
104aaa3e722SJuan Castillo
105bee82417SDan HandleyBL_COMMON_SOURCES	:=	common/bl_common.c			\
106b79af934SSoby Mathew				common/tf_printf.c			\
107626ed510SSoby Mathew				common/aarch64/debug.S			\
108bee82417SDan Handley				lib/aarch64/cache_helpers.S		\
109bee82417SDan Handley				lib/aarch64/misc_helpers.S		\
110bee82417SDan Handley				lib/aarch64/xlat_helpers.c		\
111bee82417SDan Handley				lib/stdlib/std.c			\
112bee82417SDan Handley				plat/common/aarch64/platform_helpers.S
113d7a6b0f8SRyan Harkin
114eaaeece2SJames MorrisseyBUILD_BASE		:=	./build
11525cff83eSRyan HarkinBUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
1164f6ad66aSAchin Gupta
11725cff83eSRyan HarkinPLATFORMS		:=	$(shell ls -I common plat/)
118375f538aSAchin GuptaSPDS			:=	$(shell ls -I none services/spd)
11972ee3314SRyan HarkinHELP_PLATFORMS		:=	$(shell echo ${PLATFORMS} | sed 's/ /|/g')
12072ee3314SRyan Harkin
121289e0dadSJeenu Viswambharan# Convenience function for adding build definitions
122289e0dadSJeenu Viswambharan# $(eval $(call add_define,FOO)) will have:
123289e0dadSJeenu Viswambharan# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
124289e0dadSJeenu Viswambharandefine add_define
125289e0dadSJeenu ViswambharanDEFINES			+=	-D$(1)$(if $(value $(1)),=$(value $(1)),)
126289e0dadSJeenu Viswambharanendef
127289e0dadSJeenu Viswambharan
128289e0dadSJeenu Viswambharan# Convenience function for verifying option has a boolean value
129289e0dadSJeenu Viswambharan# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
130289e0dadSJeenu Viswambharandefine assert_boolean
131289e0dadSJeenu Viswambharan$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
132289e0dadSJeenu Viswambharanendef
133289e0dadSJeenu Viswambharan
13425cff83eSRyan Harkinifeq (${PLAT},)
13525cff83eSRyan Harkin  $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
13625cff83eSRyan Harkinendif
1374bfc2d21SJon Medhurstifeq ($(findstring ${PLAT},${PLATFORMS}),)
13825cff83eSRyan Harkin  $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
13925cff83eSRyan Harkinendif
1404f6ad66aSAchin Gupta
1414bfc2d21SJon Medhurstall: msg_start
14225cff83eSRyan Harkin
14325cff83eSRyan Harkinmsg_start:
14425cff83eSRyan Harkin	@echo "Building ${PLAT}"
14525cff83eSRyan Harkin
14625cff83eSRyan Harkininclude plat/${PLAT}/platform.mk
1474bfc2d21SJon Medhurst
1485541bb3fSSoby Mathew# Include the CPU specific operations makefile. By default all CPU errata
1495541bb3fSSoby Mathew# workarounds and CPU specifc optimisations are disabled. This can be
150d9bdaf2dSSoby Mathew# overridden by the platform.
1515541bb3fSSoby Mathewinclude lib/cpus/cpu-ops.mk
152d9bdaf2dSSoby Mathew
1534bfc2d21SJon Medhurstifdef BL1_SOURCES
1544bfc2d21SJon MedhurstNEED_BL1 := yes
1554f6ad66aSAchin Guptainclude bl1/bl1.mk
1564bfc2d21SJon Medhurstendif
1574bfc2d21SJon Medhurst
1584bfc2d21SJon Medhurstifdef BL2_SOURCES
1594bfc2d21SJon MedhurstNEED_BL2 := yes
1604f6ad66aSAchin Guptainclude bl2/bl2.mk
16127713fb4SSoby Mathew# Using the ARM Trusted Firmware BL2 implies that a BL3-3 image also need to be supplied for the FIP.
16227713fb4SSoby Mathew# This flag can be overridden by the platform.
16327713fb4SSoby MathewNEED_BL33 ?= yes
1644bfc2d21SJon Medhurstendif
1654bfc2d21SJon Medhurst
1664bfc2d21SJon Medhurstifdef BL31_SOURCES
1674bfc2d21SJon MedhurstNEED_BL31 := yes
1684f6ad66aSAchin Guptainclude bl31/bl31.mk
16925cff83eSRyan Harkinendif
1704f6ad66aSAchin Gupta
171375f538aSAchin Gupta# Include SPD Makefile if one has been specified
172375f538aSAchin Guptaifneq (${SPD},none)
173375f538aSAchin Gupta  # We expect to locate an spd.mk under the specified SPD directory
174375f538aSAchin Gupta  SPD_MAKE		:=	$(shell m="services/spd/${SPD}/${SPD}.mk"; [ -f "$$m" ] && echo "$$m")
175375f538aSAchin Gupta
176375f538aSAchin Gupta  ifeq (${SPD_MAKE},)
177375f538aSAchin Gupta    $(error Error: No services/spd/${SPD}/${SPD}.mk located)
178375f538aSAchin Gupta  endif
179375f538aSAchin Gupta  $(info Including ${SPD_MAKE})
180375f538aSAchin Gupta  include ${SPD_MAKE}
181375f538aSAchin Gupta
18227713fb4SSoby Mathew  # If there's BL3-2 companion for the chosen SPD, and the SPD wants to build the
18327713fb4SSoby Mathew  # BL3-2 from source, we expect that the SPD's Makefile would set NEED_BL32
18427713fb4SSoby Mathew  # variable to "yes". In case the BL3-2 is a binary which needs to be included in
18527713fb4SSoby Mathew  # fip, then the NEED_BL32 needs to be set and BL3-2 would need to point to the bin.
186375f538aSAchin Guptaendif
187375f538aSAchin Gupta
1886f971622SJuan Castillo.PHONY:			all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip certtool
189eaaeece2SJames Morrissey.SUFFIXES:
190eaaeece2SJames Morrissey
191a0df63efSSandrine BailleuxINCLUDES		+=	-Iinclude/bl31			\
1924ecca339SDan Handley				-Iinclude/bl31/services		\
1934ecca339SDan Handley				-Iinclude/common		\
1944ecca339SDan Handley				-Iinclude/drivers		\
1954ecca339SDan Handley				-Iinclude/drivers/arm		\
196935db693SDan Handley				-Iinclude/drivers/io		\
1974ecca339SDan Handley				-Iinclude/lib			\
1984ecca339SDan Handley				-Iinclude/lib/aarch64		\
199add40351SSoby Mathew				-Iinclude/lib/cpus/aarch64	\
2005f0cdb05SDan Handley				-Iinclude/plat/common		\
201d7a6b0f8SRyan Harkin				-Iinclude/stdlib		\
202d7a6b0f8SRyan Harkin				-Iinclude/stdlib/sys		\
203375f538aSAchin Gupta				${PLAT_INCLUDES}		\
204375f538aSAchin Gupta				${SPD_INCLUDES}
2054f6ad66aSAchin Gupta
206e35c4045SJeenu Viswambharan# Process DEBUG flag
207e35c4045SJeenu Viswambharan$(eval $(call assert_boolean,DEBUG))
208e35c4045SJeenu Viswambharan$(eval $(call add_define,DEBUG))
209e35c4045SJeenu Viswambharanifeq (${DEBUG},0)
210e35c4045SJeenu Viswambharan  $(eval $(call add_define,NDEBUG))
211e35c4045SJeenu Viswambharanelse
212e35c4045SJeenu ViswambharanCFLAGS			+= 	-g
213e35c4045SJeenu ViswambharanASFLAGS			+= 	-g -Wa,--gdwarf-2
214e35c4045SJeenu Viswambharanendif
215e35c4045SJeenu Viswambharan
2162da8d8bfSJeenu Viswambharan# Process NS_TIMER_SWITCH flag
2172da8d8bfSJeenu Viswambharan$(eval $(call assert_boolean,NS_TIMER_SWITCH))
2182da8d8bfSJeenu Viswambharan$(eval $(call add_define,NS_TIMER_SWITCH))
2192da8d8bfSJeenu Viswambharan
220dbad1bacSVikram Kanigiri# Process RESET_TO_BL31 flag
221dbad1bacSVikram Kanigiri$(eval $(call assert_boolean,RESET_TO_BL31))
222dbad1bacSVikram Kanigiri$(eval $(call add_define,RESET_TO_BL31))
223dbad1bacSVikram Kanigiri
2240f21c547SJuan Castillo# Process CTX_INCLUDE_FPREGS flag
2250f21c547SJuan Castillo$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
2260f21c547SJuan Castillo$(eval $(call add_define,CTX_INCLUDE_FPREGS))
2270f21c547SJuan Castillo
2282b98e789SSandrine Bailleux# Process ARM_GIC_ARCH flag
2292b98e789SSandrine Bailleux$(eval $(call add_define,ARM_GIC_ARCH))
2302b98e789SSandrine Bailleux
231bc920128SSoby Mathew# Process ASM_ASSERTION flag
232bc920128SSoby Mathew$(eval $(call assert_boolean,ASM_ASSERTION))
233bc920128SSoby Mathew$(eval $(call add_define,ASM_ASSERTION))
2342b98e789SSandrine Bailleux
235289c28a8SDan Handley# Process LOG_LEVEL flag
236289c28a8SDan Handley$(eval $(call add_define,LOG_LEVEL))
237289c28a8SDan Handley
2388c5fe0b5SSoby Mathew# Process USE_COHERENT_MEM flag
2398c5fe0b5SSoby Mathew$(eval $(call assert_boolean,USE_COHERENT_MEM))
2408c5fe0b5SSoby Mathew$(eval $(call add_define,USE_COHERENT_MEM))
2418c5fe0b5SSoby Mathew
2426f971622SJuan Castillo# Process Generate CoT flags
2436f971622SJuan Castillo$(eval $(call assert_boolean,GENERATE_COT))
2446f971622SJuan Castillo$(eval $(call assert_boolean,CREATE_KEYS))
2456f971622SJuan Castillo
2460af6d64dSHarry LiebelASFLAGS			+= 	-nostdinc -ffreestanding -Wa,--fatal-warnings	\
247a0df63efSSandrine Bailleux				-Werror -Wmissing-include-dirs			\
248e35c4045SJeenu Viswambharan				-mgeneral-regs-only -D__ASSEMBLY__		\
249e35c4045SJeenu Viswambharan				${DEFINES} ${INCLUDES}
250e35c4045SJeenu ViswambharanCFLAGS			+= 	-nostdinc -pedantic -ffreestanding -Wall	\
251a0df63efSSandrine Bailleux				-Werror -Wmissing-include-dirs			\
252a0df63efSSandrine Bailleux				-mgeneral-regs-only -std=c99 -c -Os		\
253e35c4045SJeenu Viswambharan				${DEFINES} ${INCLUDES}
254dccc537aSAndrew ThoelkeCFLAGS			+=	-ffunction-sections -fdata-sections
2554f6ad66aSAchin Gupta
2563e850a84SSandrine BailleuxLDFLAGS			+=	--fatal-warnings -O1
257dccc537aSAndrew ThoelkeLDFLAGS			+=	--gc-sections
2584f6ad66aSAchin Gupta
2594f6ad66aSAchin Gupta
260eaaeece2SJames MorrisseyCC			:=	${CROSS_COMPILE}gcc
261eaaeece2SJames MorrisseyCPP			:=	${CROSS_COMPILE}cpp
262eaaeece2SJames MorrisseyAS			:=	${CROSS_COMPILE}gcc
263eaaeece2SJames MorrisseyAR			:=	${CROSS_COMPILE}ar
264eaaeece2SJames MorrisseyLD			:=	${CROSS_COMPILE}ld
265eaaeece2SJames MorrisseyOC			:=	${CROSS_COMPILE}objcopy
266eaaeece2SJames MorrisseyOD			:=	${CROSS_COMPILE}objdump
267eaaeece2SJames MorrisseyNM			:=	${CROSS_COMPILE}nm
268eaaeece2SJames MorrisseyPP			:=	${CROSS_COMPILE}gcc -E ${CFLAGS}
2694f6ad66aSAchin Gupta
270f58ad36fSHarry Liebel# Variables for use with Firmware Image Package
271f58ad36fSHarry LiebelFIPTOOLPATH		?=	tools/fip_create
272f58ad36fSHarry LiebelFIPTOOL			?=	${FIPTOOLPATH}/fip_create
273f58ad36fSHarry Liebelfiptool:		${FIPTOOL}
2747f48fab9SJuan Castillofip:			${BUILD_PLAT}/${FIP_NAME}
275f58ad36fSHarry Liebel
2766f971622SJuan Castillo# Variables for use with Certificate Generation Tool
2776f971622SJuan CastilloCRTTOOLPATH		?=	tools/cert_create
2786f971622SJuan CastilloCRTTOOL			?=	${CRTTOOLPATH}/cert_create
2796f971622SJuan Castillocerttool:		${CRTTOOL}
2806f971622SJuan Castillo
2816f971622SJuan Castillo# CoT generation tool default parameters
2826f971622SJuan CastilloTRUSTED_KEY_CERT	:=	${BUILD_PLAT}/trusted_key.crt
2836f971622SJuan Castillo
2846f971622SJuan Castillo# Pass the private keys to the CoT generation tool in the command line
2856f971622SJuan Castillo# If CREATE_KEYS is set, the '-n' option will be added, indicating the tool to create new keys
2866f971622SJuan Castilloifneq (${GENERATE_COT},0)
2876f971622SJuan Castillo    $(eval CERTS := yes)
2886f971622SJuan Castillo
289*b7124ea7SJuan Castillo    $(eval FIP_DEPS += certificates)
290*b7124ea7SJuan Castillo    $(eval FIP_ARGS += --trusted-key-cert ${TRUSTED_KEY_CERT})
291*b7124ea7SJuan Castillo
2926f971622SJuan Castillo    ifneq (${CREATE_KEYS},0)
2936f971622SJuan Castillo        $(eval CRT_ARGS += -n)
2946f971622SJuan Castillo    endif
2956f971622SJuan Castillo    $(eval CRT_ARGS += $(if ${ROT_KEY}, --rot-key ${ROT_KEY}))
2966f971622SJuan Castillo    $(eval CRT_ARGS += $(if ${TRUSTED_WORLD_KEY}, --trusted-world-key ${TRUSTED_WORLD_KEY}))
2976f971622SJuan Castillo    $(eval CRT_ARGS += $(if ${NON_TRUSTED_WORLD_KEY}, --non-trusted-world-key ${NON_TRUSTED_WORLD_KEY}))
2986f971622SJuan Castillo    $(eval CRT_ARGS += --trusted-key-cert ${TRUSTED_KEY_CERT})
2996f971622SJuan Castilloendif
3006f971622SJuan Castillo
30136eaaf37SIan Spraylocate-checkpatch:
30236eaaf37SIan Sprayifndef CHECKPATCH
30336eaaf37SIan Spray	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
30436eaaf37SIan Sprayelse
30536eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
30636eaaf37SIan Spray	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
30736eaaf37SIan Sprayendif
30836eaaf37SIan Sprayendif
30936eaaf37SIan Spray
3104f6ad66aSAchin Guptaclean:
3114f6ad66aSAchin Gupta			@echo "  CLEAN"
31225cff83eSRyan Harkin			${Q}rm -rf ${BUILD_PLAT}
3132f2cef46SJeenu Viswambharan			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
3146f971622SJuan Castillo			${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
3154f6ad66aSAchin Gupta
316eaaeece2SJames Morrisseyrealclean distclean:
317eaaeece2SJames Morrissey			@echo "  REALCLEAN"
318eaaeece2SJames Morrissey			${Q}rm -rf ${BUILD_BASE}
31935fab8c9SJoakim Bech			${Q}rm -f ${CURDIR}/cscope.*
3202f2cef46SJeenu Viswambharan			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
3216f971622SJuan Castillo			${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
3224f6ad66aSAchin Gupta
32336eaaf37SIan Spraycheckcodebase:		locate-checkpatch
32436eaaf37SIan Spray			@echo "  CHECKING STYLE"
32536eaaf37SIan Spray			@if test -d .git ; then	\
3264f2104ffSJuan Castillo				git ls-files | grep -v stdlib | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ;	\
32736eaaf37SIan Spray			 else			\
3284f2104ffSJuan Castillo				 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -not -iwholename "*stdlib*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
32936eaaf37SIan Spray			 fi
33036eaaf37SIan Spray
33136eaaf37SIan Spraycheckpatch:		locate-checkpatch
33236eaaf37SIan Spray			@echo "  CHECKING STYLE"
33336eaaf37SIan Spray			@git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true
33436eaaf37SIan Spray
3356f971622SJuan Castillo.PHONY: ${CRTTOOL}
3366f971622SJuan Castillo${CRTTOOL}:
3376f971622SJuan Castillo			${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH}
3386f971622SJuan Castillo			@echo
3396f971622SJuan Castillo			@echo "Built $@ successfully"
3406f971622SJuan Castillo			@echo
3416f971622SJuan Castillo
34207deed40SSandrine Bailleux.PHONY: ${FIPTOOL}
343f58ad36fSHarry Liebel${FIPTOOL}:
3442f2cef46SJeenu Viswambharan			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH}
345f58ad36fSHarry Liebel
3466d55d109SJon Medhurstdefine match_goals
3476d55d109SJon Medhurst$(strip $(foreach goal,$(1),$(filter $(goal),$(MAKECMDGOALS))))
3486d55d109SJon Medhurstendef
349eaaeece2SJames Morrissey
3508d2296f3SSandrine Bailleux# List of rules that involve building things
3518d2296f3SSandrine BailleuxBUILD_TARGETS := all bl1 bl2 bl31 bl32 fip
352eaaeece2SJames Morrissey
3538d2296f3SSandrine Bailleux# Does the list of goals specified on the command line include a build target?
3548d2296f3SSandrine Bailleuxifneq ($(call match_goals,${BUILD_TARGETS}),)
3558d2296f3SSandrine BailleuxIS_ANYTHING_TO_BUILD := 1
3568d2296f3SSandrine Bailleuxendif
3574f6ad66aSAchin Gupta
3586d55d109SJon Medhurstdefine MAKE_C
359eaaeece2SJames Morrissey
3606d55d109SJon Medhurst$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
3616d55d109SJon Medhurst$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ)))
362eaaeece2SJames Morrissey
3636d55d109SJon Medhurst$(OBJ) : $(2)
3646d55d109SJon Medhurst	@echo "  CC      $$<"
36527905d0aSSoby Mathew	$$(Q)$$(CC) $$(CFLAGS) -DIMAGE_BL$(3) -c $$< -o $$@
366eaaeece2SJames Morrissey
3676d55d109SJon Medhurst
3686d55d109SJon Medhurst$(PREREQUISITES) : $(2)
3696d55d109SJon Medhurst	@echo "  DEPS    $$@"
3706d55d109SJon Medhurst	@mkdir -p $(1)
3716d55d109SJon Medhurst	$$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$<
3726d55d109SJon Medhurst
3738d2296f3SSandrine Bailleuxifdef IS_ANYTHING_TO_BUILD
3746d55d109SJon Medhurst-include $(PREREQUISITES)
3756d55d109SJon Medhurstendif
3766d55d109SJon Medhurst
3776d55d109SJon Medhurstendef
3786d55d109SJon Medhurst
3796d55d109SJon Medhurst
3806d55d109SJon Medhurstdefine MAKE_S
3816d55d109SJon Medhurst
3826d55d109SJon Medhurst$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
3836d55d109SJon Medhurst$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ)))
3846d55d109SJon Medhurst
3856d55d109SJon Medhurst$(OBJ) : $(2)
3866d55d109SJon Medhurst	@echo "  AS      $$<"
38727905d0aSSoby Mathew	$$(Q)$$(AS) $$(ASFLAGS) -DIMAGE_BL$(3) -c $$< -o $$@
3886d55d109SJon Medhurst
3896d55d109SJon Medhurst$(PREREQUISITES) : $(2)
3906d55d109SJon Medhurst	@echo "  DEPS    $$@"
3916d55d109SJon Medhurst	@mkdir -p $(1)
3926d55d109SJon Medhurst	$$(Q)$$(AS) $$(ASFLAGS) -M -MT $(OBJ) -MF $$@ $$<
3936d55d109SJon Medhurst
3948d2296f3SSandrine Bailleuxifdef IS_ANYTHING_TO_BUILD
3956d55d109SJon Medhurst-include $(PREREQUISITES)
3966d55d109SJon Medhurstendif
3976d55d109SJon Medhurst
3986d55d109SJon Medhurstendef
3996d55d109SJon Medhurst
4006d55d109SJon Medhurst
4016d55d109SJon Medhurstdefine MAKE_LD
4026d55d109SJon Medhurst
4036d55d109SJon Medhurst$(eval PREREQUISITES := $(1).d)
4046d55d109SJon Medhurst
4056d55d109SJon Medhurst$(1) : $(2)
4066d55d109SJon Medhurst	@echo "  PP      $$<"
407513dd3a0SJuan Castillo	$$(Q)$$(AS) $$(ASFLAGS) -P -E -D__LINKER__ -o $$@ $$<
4086d55d109SJon Medhurst
4096d55d109SJon Medhurst$(PREREQUISITES) : $(2)
4106d55d109SJon Medhurst	@echo "  DEPS    $$@"
4116d55d109SJon Medhurst	@mkdir -p $$(dir $$@)
4126d55d109SJon Medhurst	$$(Q)$$(AS) $$(ASFLAGS) -M -MT $(1) -MF $$@ $$<
4136d55d109SJon Medhurst
4148d2296f3SSandrine Bailleuxifdef IS_ANYTHING_TO_BUILD
4156d55d109SJon Medhurst-include $(PREREQUISITES)
4166d55d109SJon Medhurstendif
4176d55d109SJon Medhurst
4186d55d109SJon Medhurstendef
4196d55d109SJon Medhurst
4206d55d109SJon Medhurst
4216d55d109SJon Medhurstdefine MAKE_OBJS
4226d55d109SJon Medhurst	$(eval C_OBJS := $(filter %.c,$(2)))
4236d55d109SJon Medhurst	$(eval REMAIN := $(filter-out %.c,$(2)))
42427905d0aSSoby Mathew	$(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
4256d55d109SJon Medhurst
4266d55d109SJon Medhurst	$(eval S_OBJS := $(filter %.S,$(REMAIN)))
4276d55d109SJon Medhurst	$(eval REMAIN := $(filter-out %.S,$(REMAIN)))
42827905d0aSSoby Mathew	$(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
4296d55d109SJon Medhurst
4306d55d109SJon Medhurst	$(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
4316d55d109SJon Medhurstendef
4326d55d109SJon Medhurst
4336d55d109SJon Medhurst
4346d55d109SJon Medhurst# NOTE: The line continuation '\' is required in the next define otherwise we
4356d55d109SJon Medhurst# end up with a line-feed characer at the end of the last c filename.
4366d55d109SJon Medhurst# Also bare this issue in mind if extending the list of supported filetypes.
4376d55d109SJon Medhurstdefine SOURCES_TO_OBJS
4386d55d109SJon Medhurst	$(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
4396d55d109SJon Medhurst	$(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
4406d55d109SJon Medhurstendef
4416d55d109SJon Medhurst
4426f971622SJuan Castillo
4436f971622SJuan Castillo# MAKE_TOOL_ARGS macro defines the command line arguments for the FIP and CRT
4446f971622SJuan Castillo# tools at each BL stage. Arguments:
4456f971622SJuan Castillo#   $(1) = BL stage (2, 30, 31, 32, 33)
4466f971622SJuan Castillo#   $(2) = Binary file
4476f971622SJuan Castillo#   $(3) = In FIP (false if empty)
4486f971622SJuan Castillo#   $(4) = Create certificates (false if empty)
4496f971622SJuan Castillo#   $(5) = Create key certificate (false if empty)
4506f971622SJuan Castillo#   $(6) = Private key (optional)
4516f971622SJuan Castillodefine MAKE_TOOL_ARGS
4526f971622SJuan Castillo
4536f971622SJuan Castillo$(eval FIP_DEPS += $(if $3,$(2),))
4546f971622SJuan Castillo$(eval FIP_ARGS += $(if $3,--bl$(1) $(2),))
455*b7124ea7SJuan Castillo$(eval FIP_ARGS += $(if $4,--bl$(1)-cert $(BUILD_PLAT)/bl$(1).crt))
456*b7124ea7SJuan Castillo$(eval FIP_ARGS += $(if $4,$(if $5,--bl$(1)-key-cert $(BUILD_PLAT)/bl$(1)_key.crt)))
4576f971622SJuan Castillo
4586f971622SJuan Castillo$(eval CRT_DEPS += $(if $4,$(2),))
4596f971622SJuan Castillo$(eval CRT_DEPS += $(if $4,$(if $6,$(6),)))
4606f971622SJuan Castillo$(eval CRT_ARGS += $(if $4,--bl$(1) $(2)))
4616f971622SJuan Castillo$(eval CRT_ARGS += $(if $4,$(if $6,--bl$(1)-key $(6))))
4626f971622SJuan Castillo$(eval CRT_ARGS += $(if $4,--bl$(1)-cert $(BUILD_PLAT)/bl$(1).crt))
4636f971622SJuan Castillo$(eval CRT_ARGS += $(if $4,$(if $5,--bl$(1)-key-cert $(BUILD_PLAT)/bl$(1)_key.crt)))
4646f971622SJuan Castillo
4656f971622SJuan Castilloendef
4666f971622SJuan Castillo
4676f971622SJuan Castillo
4686f971622SJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image.
4696f971622SJuan Castillo# Arguments:
4706f971622SJuan Castillo#   $(1) = BL stage (2, 30, 31, 32, 33)
4716f971622SJuan Castillo#   $(2) = In FIP (false if empty)
4726f971622SJuan Castillo#   $(3) = Create certificates (false if empty)
4736f971622SJuan Castillo#   $(4) = Create key certificate (false if empty)
4746f971622SJuan Castillo#   $(5) = Private key (optional)
4756d55d109SJon Medhurstdefine MAKE_BL
4766d55d109SJon Medhurst	$(eval BUILD_DIR  := ${BUILD_PLAT}/bl$(1))
4776d55d109SJon Medhurst	$(eval SOURCES    := $(BL$(1)_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
4786d55d109SJon Medhurst	$(eval OBJS       := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
4796d55d109SJon Medhurst	$(eval LINKERFILE := $(BUILD_DIR)/bl$(1).ld)
4806d55d109SJon Medhurst	$(eval MAPFILE    := $(BUILD_DIR)/bl$(1).map)
4816d55d109SJon Medhurst	$(eval ELF        := $(BUILD_DIR)/bl$(1).elf)
4826d55d109SJon Medhurst	$(eval DUMP       := $(BUILD_DIR)/bl$(1).dump)
4836d55d109SJon Medhurst	$(eval BIN        := $(BUILD_PLAT)/bl$(1).bin)
4846d55d109SJon Medhurst
48527905d0aSSoby Mathew	$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
4866d55d109SJon Medhurst	$(eval $(call MAKE_LD,$(LINKERFILE),$(BL$(1)_LINKERFILE)))
4876d55d109SJon Medhurst
4886d55d109SJon Medhurst$(BUILD_DIR) :
4896d55d109SJon Medhurst	$$(Q)mkdir -p "$$@"
4906d55d109SJon Medhurst
4916d55d109SJon Medhurst$(ELF) : $(OBJS) $(LINKERFILE)
4926d55d109SJon Medhurst	@echo "  LD      $$@"
493aaa3e722SJuan Castillo	@echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
494aaa3e722SJuan Castillo	       const char version_string[] = "${VERSION_STRING}";' | \
495fb052462SJon Medhurst		$$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o
4966d55d109SJon Medhurst	$$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \
4979f98aa1aSJeenu Viswambharan					$(BUILD_DIR)/build_message.o $(OBJS)
4986d55d109SJon Medhurst
4996d55d109SJon Medhurst$(DUMP) : $(ELF)
5006d55d109SJon Medhurst	@echo "  OD      $$@"
5016d55d109SJon Medhurst	$${Q}$${OD} -dx $$< > $$@
5026d55d109SJon Medhurst
5036d55d109SJon Medhurst$(BIN) : $(ELF)
5046d55d109SJon Medhurst	@echo "  BIN     $$@"
5056d55d109SJon Medhurst	$$(Q)$$(OC) -O binary $$< $$@
506eaaeece2SJames Morrissey	@echo
5076d55d109SJon Medhurst	@echo "Built $$@ successfully"
5084f6ad66aSAchin Gupta	@echo
5094f6ad66aSAchin Gupta
5106d55d109SJon Medhurst.PHONY : bl$(1)
5116d55d109SJon Medhurstbl$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
5124f6ad66aSAchin Gupta
5136d55d109SJon Medhurstall : bl$(1)
5146d55d109SJon Medhurst
5156f971622SJuan Castillo$(eval $(call MAKE_TOOL_ARGS,$(1),$(BIN),$(2),$(3),$(4),$(5)))
5166d55d109SJon Medhurst
5176d55d109SJon Medhurstendef
5186d55d109SJon Medhurst
5196d55d109SJon Medhurst
5204bfc2d21SJon Medhurstifeq (${NEED_BL1},yes)
5216d55d109SJon Medhurst$(eval $(call MAKE_BL,1))
5224bfc2d21SJon Medhurstendif
5236d55d109SJon Medhurst
5244bfc2d21SJon Medhurstifeq (${NEED_BL2},yes)
5256f971622SJuan Castillo$(if ${BL2}, $(eval $(call MAKE_TOOL_ARGS,2,${BL2},in_fip,${CERTS})),\
5266f971622SJuan Castillo	$(eval $(call MAKE_BL,2,in_fip,${CERTS})))
5274bfc2d21SJon Medhurstendif
5286d55d109SJon Medhurst
5294bfc2d21SJon Medhurstifeq (${NEED_BL31},yes)
5306d55d109SJon MedhurstBL31_SOURCES += ${SPD_SOURCES}
5316f971622SJuan Castillo$(if ${BL31}, $(eval $(call MAKE_TOOL_ARGS,31,${BL31},in_fip,${CERTS},${CERTS},${BL31_KEY})),\
5326f971622SJuan Castillo	$(eval $(call MAKE_BL,31,in_fip,${CERTS},${CERTS},${BL31_KEY})))
5334bfc2d21SJon Medhurstendif
5346d55d109SJon Medhurst
5356d55d109SJon Medhurstifeq (${NEED_BL32},yes)
5366f971622SJuan Castillo$(if ${BL32}, $(eval $(call MAKE_TOOL_ARGS,32,${BL32},in_fip,${CERTS},${CERTS},${BL32_KEY})),\
5376f971622SJuan Castillo	$(eval $(call MAKE_BL,32,in_fip,${CERTS},${CERTS},${BL32_KEY})))
5386d55d109SJon Medhurstendif
53972ee3314SRyan Harkin
54093d81d64SSandrine Bailleuxifeq (${NEED_BL30},yes)
5416f971622SJuan Castillo$(if ${BL30}, $(eval $(call MAKE_TOOL_ARGS,30,${BL30},in_fip,${CERTS},${CERTS},${BL30_KEY})))
54293d81d64SSandrine Bailleux
54393d81d64SSandrine Bailleux# If BL3-0 is needed by the platform then 'BL30' variable must be defined.
54493d81d64SSandrine Bailleuxcheck_bl30:
54593d81d64SSandrine Bailleux	$(if ${BL30},,$(error "To build a FIP for platform ${PLAT}, please set BL30 to point to the SCP firmware"))
54693d81d64SSandrine Bailleuxelse
54727713fb4SSoby Mathew
54893d81d64SSandrine Bailleux# If BL3-0 is not needed by the platform but the user still specified the path
54993d81d64SSandrine Bailleux# to a BL3-0 image then warn him that it will be ignored.
55093d81d64SSandrine Bailleuxcheck_bl30:
55193d81d64SSandrine Bailleux	$(if ${BL30},$(warning "BL3-0 is not supported on platform ${PLAT}, it will just be ignored"),)
55293d81d64SSandrine Bailleuxendif
55393d81d64SSandrine Bailleux
55427713fb4SSoby Mathewifeq (${NEED_BL33},yes)
5556f971622SJuan Castillo$(if ${BL33}, $(eval $(call MAKE_TOOL_ARGS,33,${BL33},in_fip,${CERTS},${CERTS},${BL33_KEY})))
55627713fb4SSoby Mathew
55727713fb4SSoby Mathew# If BL3-3 is needed by the platform then 'BL33' variable must be defined.
55827713fb4SSoby Mathewcheck_bl33:
5594bfc2d21SJon Medhurst	$(if ${BL33},,$(error "To build a FIP, please set BL33 to point to the Normal World binary, eg: BL33=../uefi/FVP_AARCH64_EFI.fd"))
56027713fb4SSoby Mathewelse
56127713fb4SSoby Mathew
56227713fb4SSoby Mathew# If BL3-3 is not needed by the platform but the user still specified the path
56327713fb4SSoby Mathew# to a BL3-3 image then warn him that it will be ignored.
56427713fb4SSoby Mathewcheck_bl33:
56527713fb4SSoby Mathew	$(if ${BL33},$(warning "BL3-3 is not supported on platform ${PLAT}, it will just be ignored"),)
56627713fb4SSoby Mathewendif
56727713fb4SSoby Mathew
5686f971622SJuan Castillo# Add the dependency on the certificates
5696f971622SJuan Castilloifneq (${GENERATE_COT},0)
5706f971622SJuan Castillo    all: certificates
5716f971622SJuan Castilloendif
5726f971622SJuan Castillo
5736f971622SJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL} check_bl30 check_bl33
5746f971622SJuan Castillo			${Q}${CRTTOOL} ${CRT_ARGS}
5756f971622SJuan Castillo			@echo
5766f971622SJuan Castillo			@echo "Built $@ successfully"
5776f971622SJuan Castillo			@echo "Certificates can be found in ${BUILD_PLAT}"
5786f971622SJuan Castillo			@echo
57927713fb4SSoby Mathew
5807f48fab9SJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} check_bl30 check_bl33
581f58ad36fSHarry Liebel			${Q}${FIPTOOL} --dump \
582375f538aSAchin Gupta				${FIP_ARGS} \
583f58ad36fSHarry Liebel				$@
584f58ad36fSHarry Liebel			@echo
5852f2cef46SJeenu Viswambharan			@echo "Built $@ successfully"
5862f2cef46SJeenu Viswambharan			@echo
587f58ad36fSHarry Liebel
588f58ad36fSHarry Liebel
58935fab8c9SJoakim Bechcscope:
59035fab8c9SJoakim Bech	@echo "  CSCOPE"
59135fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
59235fab8c9SJoakim Bech	${Q}cscope -b -q -k
59335fab8c9SJoakim Bech
59472ee3314SRyan Harkinhelp:
59508c7ed0fSSandrine Bailleux	@echo "usage: ${MAKE} PLAT=<${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch>"
59672ee3314SRyan Harkin	@echo ""
59772ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
59808c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
59972ee3314SRyan Harkin	@echo ""
60072ee3314SRyan Harkin	@echo "Supported Targets:"
6018aa559c0SJeenu Viswambharan	@echo "  all            Build the BL1, BL2 and BL31 binaries"
60236eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
6038aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
60436eaaf37SIan Spray	@echo "  bl31           Build the BL31 binary"
60536eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
60636eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
60736eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
60872ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
60935fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
61072ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
6116f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
612f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package(FIP) creation tool"
61372ee3314SRyan Harkin	@echo ""
61472ee3314SRyan Harkin	@echo "note: most build targets require PLAT to be set to a specific platform."
61572ee3314SRyan Harkin	@echo ""
61672ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
61772ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
618