xref: /rk3399_ARM-atf/Makefile (revision 91b48c9f8f44db91ae73635cc543fb89d292a6f7)
1#
2# Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7#
8# Trusted Firmware Version
9#
10VERSION_MAJOR			:= 2
11VERSION_MINOR			:= 0
12
13# Default goal is build all images
14.DEFAULT_GOAL			:= all
15
16# Avoid any implicit propagation of command line variable definitions to
17# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
18# usage. Other command line options like "-s" are still propagated as usual.
19MAKEOVERRIDES =
20
21MAKE_HELPERS_DIRECTORY := make_helpers/
22include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
23include ${MAKE_HELPERS_DIRECTORY}build_env.mk
24
25################################################################################
26# Default values for build configurations, and their dependencies
27################################################################################
28
29ifdef ASM_ASSERTION
30        $(warning ASM_ASSERTION is removed, use ENABLE_ASSERTIONS instead.)
31endif
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34
35# Assertions enabled for DEBUG builds by default
36ENABLE_ASSERTIONS		:= ${DEBUG}
37ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
38PLAT				:= ${DEFAULT_PLAT}
39
40################################################################################
41# Checkpatch script options
42################################################################################
43
44CHECKCODE_ARGS		:=	--no-patch
45# Do not check the coding style on imported library files or documentation files
46INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
47					include/lib/libfdt		\
48					include/lib/libc,		\
49					$(wildcard include/lib/*)))
50INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
51					include/lib,			\
52					$(wildcard include/*)))
53LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
54					lib/compiler-rt			\
55					lib/libfdt%			\
56					lib/libc,			\
57					$(wildcard lib/*)))
58ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					lib				\
60					include				\
61					docs				\
62					%.md,				\
63					$(wildcard *)))
64CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
65				${INC_DIRS_TO_CHECK}			\
66				${INC_LIB_DIRS_TO_CHECK}		\
67				${LIB_DIRS_TO_CHECK}
68
69
70################################################################################
71# Process build options
72################################################################################
73
74# Verbose flag
75ifeq (${V},0)
76        Q:=@
77        ECHO:=@echo
78        CHECKCODE_ARGS	+=	--no-summary --terse
79else
80        Q:=
81        ECHO:=$(ECHO_QUIET)
82endif
83
84ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
85        Q:=@
86        ECHO:=$(ECHO_QUIET)
87endif
88
89export Q ECHO
90
91# Process Debug flag
92$(eval $(call add_define,DEBUG))
93ifneq (${DEBUG}, 0)
94        BUILD_TYPE	:=	debug
95        TF_CFLAGS	+= 	-g
96
97        ifneq ($(findstring clang,$(notdir $(CC))),)
98             ASFLAGS		+= 	-g
99        else
100             ASFLAGS		+= 	-g -Wa,--gdwarf-2
101        endif
102
103        # Use LOG_LEVEL_INFO by default for debug builds
104        LOG_LEVEL	:=	40
105else
106        BUILD_TYPE	:=	release
107        # Use LOG_LEVEL_NOTICE by default for release builds
108        LOG_LEVEL	:=	20
109endif
110
111# Default build string (git branch and commit)
112ifeq (${BUILD_STRING},)
113        BUILD_STRING	:=	$(shell git describe --always --dirty --tags 2> /dev/null)
114endif
115VERSION_STRING		:=	v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
116
117# The cert_create tool cannot generate certificates individually, so we use the
118# target 'certificates' to create them all
119ifneq (${GENERATE_COT},0)
120        FIP_DEPS += certificates
121        FWU_FIP_DEPS += fwu_certificates
122endif
123
124
125################################################################################
126# Toolchain
127################################################################################
128
129HOSTCC			:=	gcc
130export HOSTCC
131
132CC			:=	${CROSS_COMPILE}gcc
133CPP			:=	${CROSS_COMPILE}cpp
134AS			:=	${CROSS_COMPILE}gcc
135AR			:=	${CROSS_COMPILE}ar
136LINKER			:=	${CROSS_COMPILE}ld
137OC			:=	${CROSS_COMPILE}objcopy
138OD			:=	${CROSS_COMPILE}objdump
139NM			:=	${CROSS_COMPILE}nm
140PP			:=	${CROSS_COMPILE}gcc -E
141DTC			:=	dtc
142
143# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
144ifneq ($(strip $(wildcard ${LD}.bfd) \
145	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
146LINKER			:=	${LINKER}.bfd
147endif
148
149ifeq (${ARM_ARCH_MAJOR},7)
150target32-directive	= 	-target arm-none-eabi
151# Will set march32-directive from platform configuration
152else
153target32-directive	= 	-target armv8a-none-eabi
154march32-directive	= 	-march=armv8-a
155endif
156
157ifeq ($(notdir $(CC)),armclang)
158TF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
159TF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi -march=armv8-a
160LD			=	$(LINKER)
161AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
162CPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
163PP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
164else ifneq ($(findstring clang,$(notdir $(CC))),)
165TF_CFLAGS_aarch32	=	$(target32-directive)
166TF_CFLAGS_aarch64	=	-target aarch64-elf
167LD			=	$(LINKER)
168AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
169CPP			=	$(CC) -E
170PP			=	$(CC) -E
171else
172TF_CFLAGS_aarch32	=	$(march32-directive)
173TF_CFLAGS_aarch64	=	-march=armv8-a
174LD			=	$(LINKER)
175endif
176
177ifeq (${AARCH32_INSTRUCTION_SET},A32)
178TF_CFLAGS_aarch32	+=	-marm
179else ifeq (${AARCH32_INSTRUCTION_SET},T32)
180TF_CFLAGS_aarch32	+=	-mthumb
181else
182$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
183endif
184
185TF_CFLAGS_aarch32	+=	-mno-unaligned-access
186TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
187
188ASFLAGS_aarch32		=	$(march32-directive)
189ASFLAGS_aarch64		=	-march=armv8-a
190
191CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc		\
192				-Wmissing-include-dirs -Werror
193ASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
194				-D__ASSEMBLY__ -ffreestanding 			\
195				-Wa,--fatal-warnings
196TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
197				-ffreestanding -fno-builtin -Wall -std=gnu99	\
198				-Os -ffunction-sections -fdata-sections
199
200GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
201
202TF_LDFLAGS		+=	--fatal-warnings -O1
203TF_LDFLAGS		+=	--gc-sections
204TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
205
206DTC_FLAGS		+=	-I dts -O dtb
207
208################################################################################
209# Common sources and include directories
210################################################################################
211include lib/compiler-rt/compiler-rt.mk
212include lib/libc/libc.mk
213
214BL_COMMON_SOURCES	+=	common/bl_common.c			\
215				common/tf_log.c				\
216				common/${ARCH}/debug.S			\
217				drivers/console/multi_console.c		\
218				lib/${ARCH}/cache_helpers.S		\
219				lib/${ARCH}/misc_helpers.S		\
220				plat/common/plat_bl_common.c		\
221				plat/common/plat_log_common.c		\
222				plat/common/${ARCH}/plat_common.c	\
223				plat/common/${ARCH}/platform_helpers.S	\
224				${COMPILER_RT_SRCS}
225
226ifeq ($(notdir $(CC)),armclang)
227BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
228endif
229
230INCLUDES		+=	-Iinclude				\
231				-Iinclude/bl1				\
232				-Iinclude/bl2				\
233				-Iinclude/bl2u				\
234				-Iinclude/bl31				\
235				-Iinclude/common			\
236				-Iinclude/common/${ARCH}		\
237				-Iinclude/drivers			\
238				-Iinclude/drivers/arm			\
239				-Iinclude/drivers/auth			\
240				-Iinclude/drivers/io			\
241				-Iinclude/drivers/ti/uart		\
242				-Iinclude/lib				\
243				-Iinclude/lib/${ARCH}			\
244				-Iinclude/lib/cpus			\
245				-Iinclude/lib/cpus/${ARCH}		\
246				-Iinclude/lib/el3_runtime		\
247				-Iinclude/lib/el3_runtime/${ARCH}	\
248				-Iinclude/lib/extensions		\
249				-Iinclude/lib/pmf			\
250				-Iinclude/lib/psci			\
251				-Iinclude/lib/xlat_tables		\
252				-Iinclude/plat/common			\
253				-Iinclude/services			\
254				${PLAT_INCLUDES}			\
255				${SPD_INCLUDES}				\
256				-Iinclude/tools_share
257
258include common/backtrace/backtrace.mk
259
260################################################################################
261# Generic definitions
262################################################################################
263
264include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
265
266BUILD_BASE		:=	./build
267BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
268
269SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
270
271# Platforms providing their own TBB makefile may override this value
272INCLUDE_TBBR_MK		:=	1
273
274
275################################################################################
276# Include SPD Makefile if one has been specified
277################################################################################
278
279ifneq (${SPD},none)
280ifeq (${ARCH},aarch32)
281        $(error "Error: SPD is incompatible with AArch32.")
282endif
283ifdef EL3_PAYLOAD_BASE
284        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
285        $(warning "The SPD and its BL32 companion will be present but ignored.")
286endif
287        # We expect to locate an spd.mk under the specified SPD directory
288        SPD_MAKE	:=	$(wildcard services/spd/${SPD}/${SPD}.mk)
289
290        ifeq (${SPD_MAKE},)
291                $(error Error: No services/spd/${SPD}/${SPD}.mk located)
292        endif
293        $(info Including ${SPD_MAKE})
294        include ${SPD_MAKE}
295
296        # If there's BL32 companion for the chosen SPD, we expect that the SPD's
297        # Makefile would set NEED_BL32 to "yes". In this case, the build system
298        # supports two mutually exclusive options:
299        # * BL32 is built from source: then BL32_SOURCES must contain the list
300        #   of source files to build BL32
301        # * BL32 is a prebuilt binary: then BL32 must point to the image file
302        #   that will be included in the FIP
303        # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
304        # over the sources.
305endif
306
307################################################################################
308# Include the platform specific Makefile after the SPD Makefile (the platform
309# makefile may use all previous definitions in this file)
310################################################################################
311
312include ${PLAT_MAKEFILE_FULL}
313
314$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
315
316ifeq (${ARM_ARCH_MAJOR},7)
317include make_helpers/armv7-a-cpus.mk
318endif
319
320ifeq ($(ENABLE_PIE),1)
321    TF_CFLAGS		+=	-fpie
322    TF_LDFLAGS		+=	-pie
323else
324    PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
325    ifneq ($(PIE_FOUND),)
326        TF_CFLAGS		+=	-fno-PIE
327    endif
328endif
329
330# Include the CPU specific operations makefile, which provides default
331# values for all CPU errata workarounds and CPU specific optimisations.
332# This can be overridden by the platform.
333include lib/cpus/cpu-ops.mk
334
335ifeq (${ARCH},aarch32)
336NEED_BL32 := yes
337
338################################################################################
339# Build `AARCH32_SP` as BL32 image for AArch32
340################################################################################
341ifneq (${AARCH32_SP},none)
342# We expect to locate an sp.mk under the specified AARCH32_SP directory
343AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
344
345ifeq (${AARCH32_SP_MAKE},)
346  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
347endif
348
349$(info Including ${AARCH32_SP_MAKE})
350include ${AARCH32_SP_MAKE}
351endif
352
353endif
354
355################################################################################
356# Check incompatible options
357################################################################################
358
359ifdef EL3_PAYLOAD_BASE
360        ifdef PRELOADED_BL33_BASE
361                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
362                incompatible build options. EL3_PAYLOAD_BASE has priority.")
363        endif
364        ifneq (${GENERATE_COT},0)
365                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
366        endif
367        ifneq (${TRUSTED_BOARD_BOOT},0)
368                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
369        endif
370endif
371
372ifeq (${NEED_BL33},yes)
373        ifdef EL3_PAYLOAD_BASE
374                $(warning "BL33 image is not needed when option \
375                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
376        endif
377        ifdef PRELOADED_BL33_BASE
378                $(warning "BL33 image is not needed when option \
379                PRELOADED_BL33_BASE is used and won't be added to the FIP \
380                file.")
381        endif
382endif
383
384# When building for systems with hardware-assisted coherency, there's no need to
385# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
386ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
387$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
388endif
389
390#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
391ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
392$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
393endif
394
395# SMC Calling Convention checks
396ifneq (${SMCCC_MAJOR_VERSION},1)
397    ifneq (${SPD},none)
398        $(error "SMC Calling Convention 1.X must be used with SPDs")
399    endif
400    ifeq (${ARCH},aarch32)
401        $(error "Only SMCCC 1.X is supported in AArch32 mode.")
402    endif
403endif
404
405# For RAS_EXTENSION, require that EAs are handled in EL3 first
406ifeq ($(RAS_EXTENSION),1)
407    ifneq ($(HANDLE_EA_EL3_FIRST),1)
408        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
409    endif
410endif
411
412# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
413ifeq ($(FAULT_INJECTION_SUPPORT),1)
414    ifneq ($(RAS_EXTENSION),1)
415        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
416    endif
417endif
418
419# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
420ifeq ($(DYN_DISABLE_AUTH), 1)
421    ifeq (${TRUSTED_BOARD_BOOT}, 0)
422        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
423    endif
424endif
425
426################################################################################
427# Process platform overrideable behaviour
428################################################################################
429
430# Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
431# supplied for the FIP and Certificate generation tools. This flag can be
432# overridden by the platform.
433ifdef BL2_SOURCES
434        ifdef EL3_PAYLOAD_BASE
435                # If booting an EL3 payload there is no need for a BL33 image
436                # in the FIP file.
437                NEED_BL33		:=	no
438        else
439                ifdef PRELOADED_BL33_BASE
440                        # If booting a BL33 preloaded image there is no need of
441                        # another one in the FIP file.
442                        NEED_BL33		:=	no
443                else
444                        NEED_BL33		?=	yes
445                endif
446        endif
447endif
448
449# If SCP_BL2 is given, we always want FIP to include it.
450ifdef SCP_BL2
451        NEED_SCP_BL2		:=	yes
452endif
453
454# For AArch32, BL31 is not currently supported.
455ifneq (${ARCH},aarch32)
456    ifdef BL31_SOURCES
457        # When booting an EL3 payload, there is no need to compile the BL31 image nor
458        # put it in the FIP.
459        ifndef EL3_PAYLOAD_BASE
460            NEED_BL31 := yes
461        endif
462    endif
463endif
464
465# Process TBB related flags
466ifneq (${GENERATE_COT},0)
467        # Common cert_create options
468        ifneq (${CREATE_KEYS},0)
469                $(eval CRT_ARGS += -n)
470                $(eval FWU_CRT_ARGS += -n)
471                ifneq (${SAVE_KEYS},0)
472                        $(eval CRT_ARGS += -k)
473                        $(eval FWU_CRT_ARGS += -k)
474                endif
475        endif
476        # Include TBBR makefile (unless the platform indicates otherwise)
477        ifeq (${INCLUDE_TBBR_MK},1)
478                include make_helpers/tbbr/tbbr_tools.mk
479        endif
480endif
481
482ifneq (${FIP_ALIGN},0)
483FIP_ARGS += --align ${FIP_ALIGN}
484endif
485
486################################################################################
487# Include libraries' Makefile that are used in all BL
488################################################################################
489
490include lib/stack_protector/stack_protector.mk
491
492################################################################################
493# Auxiliary tools (fiptool, cert_create, etc)
494################################################################################
495
496# Variables for use with Certificate Generation Tool
497CRTTOOLPATH		?=	tools/cert_create
498CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
499
500# Variables for use with Firmware Image Package
501FIPTOOLPATH		?=	tools/fiptool
502FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
503
504# Variables for use with ROMLIB
505ROMLIBPATH		?=	lib/romlib
506
507################################################################################
508# Include BL specific makefiles
509################################################################################
510ifdef BL1_SOURCES
511NEED_BL1 := yes
512include bl1/bl1.mk
513endif
514
515ifdef BL2_SOURCES
516NEED_BL2 := yes
517include bl2/bl2.mk
518endif
519
520ifdef BL2U_SOURCES
521NEED_BL2U := yes
522include bl2u/bl2u.mk
523endif
524
525ifeq (${NEED_BL31},yes)
526ifdef BL31_SOURCES
527include bl31/bl31.mk
528endif
529endif
530
531ifdef FDT_SOURCES
532NEED_FDT := yes
533endif
534
535################################################################################
536# Build options checks
537################################################################################
538
539$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
540$(eval $(call assert_boolean,CREATE_KEYS))
541$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
542$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
543$(eval $(call assert_boolean,DEBUG))
544$(eval $(call assert_boolean,DISABLE_PEDANTIC))
545$(eval $(call assert_boolean,DYN_DISABLE_AUTH))
546$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING))
547$(eval $(call assert_boolean,ENABLE_AMU))
548$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
549$(eval $(call assert_boolean,ENABLE_MPAM_FOR_LOWER_ELS))
550$(eval $(call assert_boolean,ENABLE_PIE))
551$(eval $(call assert_boolean,ENABLE_PMF))
552$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
553$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
554$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
555$(eval $(call assert_boolean,ENABLE_SPM))
556$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
557$(eval $(call assert_boolean,ERROR_DEPRECATED))
558$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT))
559$(eval $(call assert_boolean,GENERATE_COT))
560$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
561$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST))
562$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
563$(eval $(call assert_boolean,MULTI_CONSOLE_API))
564$(eval $(call assert_boolean,NS_TIMER_SWITCH))
565$(eval $(call assert_boolean,PL011_GENERIC_UART))
566$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
567$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
568$(eval $(call assert_boolean,RAS_EXTENSION))
569$(eval $(call assert_boolean,RESET_TO_BL31))
570$(eval $(call assert_boolean,SAVE_KEYS))
571$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
572$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
573$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
574$(eval $(call assert_boolean,USE_COHERENT_MEM))
575$(eval $(call assert_boolean,USE_ROMLIB))
576$(eval $(call assert_boolean,USE_TBBR_DEFS))
577$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
578$(eval $(call assert_boolean,BL2_AT_EL3))
579$(eval $(call assert_boolean,BL2_IN_XIP_MEM))
580
581$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
582$(eval $(call assert_numeric,ARM_ARCH_MINOR))
583$(eval $(call assert_numeric,SMCCC_MAJOR_VERSION))
584
585################################################################################
586# Add definitions to the cpp preprocessor based on the current build options.
587# This is done after including the platform specific makefile to allow the
588# platform to overwrite the default options
589################################################################################
590
591$(eval $(call add_define,ARM_ARCH_MAJOR))
592$(eval $(call add_define,ARM_ARCH_MINOR))
593$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
594$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
595$(eval $(call add_define,CTX_INCLUDE_FPREGS))
596$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
597$(eval $(call add_define,ENABLE_AMU))
598$(eval $(call add_define,ENABLE_ASSERTIONS))
599$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS))
600$(eval $(call add_define,ENABLE_PIE))
601$(eval $(call add_define,ENABLE_PMF))
602$(eval $(call add_define,ENABLE_PSCI_STAT))
603$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
604$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
605$(eval $(call add_define,ENABLE_SPM))
606$(eval $(call add_define,ENABLE_SVE_FOR_NS))
607$(eval $(call add_define,ERROR_DEPRECATED))
608$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
609$(eval $(call add_define,GICV2_G0_FOR_EL3))
610$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
611$(eval $(call add_define,HW_ASSISTED_COHERENCY))
612$(eval $(call add_define,LOG_LEVEL))
613$(eval $(call add_define,MULTI_CONSOLE_API))
614$(eval $(call add_define,NS_TIMER_SWITCH))
615$(eval $(call add_define,PL011_GENERIC_UART))
616$(eval $(call add_define,PLAT_${PLAT}))
617$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
618$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
619$(eval $(call add_define,RAS_EXTENSION))
620$(eval $(call add_define,RESET_TO_BL31))
621$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
622$(eval $(call add_define,RECLAIM_INIT_CODE))
623$(eval $(call add_define,SMCCC_MAJOR_VERSION))
624$(eval $(call add_define,SPD_${SPD}))
625$(eval $(call add_define,SPIN_ON_BL1_EXIT))
626$(eval $(call add_define,TRUSTED_BOARD_BOOT))
627$(eval $(call add_define,USE_COHERENT_MEM))
628$(eval $(call add_define,USE_ROMLIB))
629$(eval $(call add_define,USE_TBBR_DEFS))
630$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
631$(eval $(call add_define,BL2_AT_EL3))
632$(eval $(call add_define,BL2_IN_XIP_MEM))
633
634# Define the EL3_PAYLOAD_BASE flag only if it is provided.
635ifdef EL3_PAYLOAD_BASE
636        $(eval $(call add_define,EL3_PAYLOAD_BASE))
637else
638        # Define the PRELOADED_BL33_BASE flag only if it is provided and
639        # EL3_PAYLOAD_BASE is not defined, as it has priority.
640        ifdef PRELOADED_BL33_BASE
641                $(eval $(call add_define,PRELOADED_BL33_BASE))
642        endif
643endif
644# Define the AARCH32/AARCH64 flag based on the ARCH flag
645ifeq (${ARCH},aarch32)
646        $(eval $(call add_define,AARCH32))
647else
648        $(eval $(call add_define,AARCH64))
649endif
650
651# Define the DYN_DISABLE_AUTH flag only if set.
652ifeq (${DYN_DISABLE_AUTH},1)
653$(eval $(call add_define,DYN_DISABLE_AUTH))
654endif
655
656################################################################################
657# Build targets
658################################################################################
659
660.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip fwu_fip certtool dtbs
661.SUFFIXES:
662
663all: msg_start
664
665msg_start:
666	@echo "Building ${PLAT}"
667
668# Check if deprecated declarations and cpp warnings should be treated as error or not.
669ifeq (${ERROR_DEPRECATED},0)
670    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
671endif
672
673$(eval $(call MAKE_LIB_DIRS))
674$(eval $(call MAKE_LIB,c))
675
676# Expand build macros for the different images
677ifeq (${NEED_BL1},yes)
678$(eval $(call MAKE_BL,1))
679endif
680
681ifeq (${NEED_BL2},yes)
682ifeq (${BL2_AT_EL3}, 0)
683FIP_BL2_ARGS := tb-fw
684endif
685
686$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
687	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
688endif
689
690ifeq (${NEED_SCP_BL2},yes)
691$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
692endif
693
694ifeq (${NEED_BL31},yes)
695BL31_SOURCES += ${SPD_SOURCES}
696$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
697	$(eval $(call MAKE_BL,31,soc-fw)))
698endif
699
700# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
701# build system will call TOOL_ADD_IMG to print a warning message and abort the
702# process. Note that the dependency on BL32 applies to the FIP only.
703ifeq (${NEED_BL32},yes)
704
705BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
706
707$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
708	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
709endif
710
711# Add the BL33 image if required by the platform
712ifeq (${NEED_BL33},yes)
713$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
714endif
715
716ifeq (${NEED_BL2U},yes)
717$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
718	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
719endif
720
721# Expand build macros for the different images
722ifeq (${NEED_FDT},yes)
723    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
724endif
725
726locate-checkpatch:
727ifndef CHECKPATCH
728	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
729else
730ifeq (,$(wildcard ${CHECKPATCH}))
731	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
732endif
733endif
734
735clean:
736	@echo "  CLEAN"
737	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
738	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
739	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
740	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
741
742realclean distclean:
743	@echo "  REALCLEAN"
744	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
745	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
746	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
747	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
748	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
749
750checkcodebase:		locate-checkpatch
751	@echo "  CHECKING STYLE"
752	@if test -d .git ; then						\
753		git ls-files | grep -E -v 'libfdt|libc|docs|\.md' |	\
754		while read GIT_FILE ;					\
755		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
756		done ;							\
757	else								\
758		 find . -type f -not -iwholename "*.git*"		\
759		 -not -iwholename "*build*"				\
760		 -not -iwholename "*libfdt*"				\
761		 -not -iwholename "*libc*"				\
762		 -not -iwholename "*docs*"				\
763		 -not -iwholename "*.md"				\
764		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
765	fi
766
767checkpatch:		locate-checkpatch
768	@echo "  CHECKING STYLE"
769	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
770	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
771		printf "\n[*] Checking style of '$$commit'\n\n";	\
772		git log --format=email "$$commit~..$$commit"		\
773			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
774		git diff --format=email "$$commit~..$$commit"		\
775			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
776	done
777
778certtool: ${CRTTOOL}
779
780.PHONY: ${CRTTOOL}
781${CRTTOOL}:
782	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH}
783	@${ECHO_BLANK_LINE}
784	@echo "Built $@ successfully"
785	@${ECHO_BLANK_LINE}
786
787ifneq (${GENERATE_COT},0)
788certificates: ${CRT_DEPS} ${CRTTOOL}
789	${Q}${CRTTOOL} ${CRT_ARGS}
790	@${ECHO_BLANK_LINE}
791	@echo "Built $@ successfully"
792	@echo "Certificates can be found in ${BUILD_PLAT}"
793	@${ECHO_BLANK_LINE}
794endif
795
796${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
797	${Q}${FIPTOOL} create ${FIP_ARGS} $@
798	${Q}${FIPTOOL} info $@
799	@${ECHO_BLANK_LINE}
800	@echo "Built $@ successfully"
801	@${ECHO_BLANK_LINE}
802
803ifneq (${GENERATE_COT},0)
804fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
805	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
806	@${ECHO_BLANK_LINE}
807	@echo "Built $@ successfully"
808	@echo "FWU certificates can be found in ${BUILD_PLAT}"
809	@${ECHO_BLANK_LINE}
810endif
811
812${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
813	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
814	${Q}${FIPTOOL} info $@
815	@${ECHO_BLANK_LINE}
816	@echo "Built $@ successfully"
817	@${ECHO_BLANK_LINE}
818
819fiptool: ${FIPTOOL}
820fip: ${BUILD_PLAT}/${FIP_NAME}
821fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
822
823.PHONY: ${FIPTOOL}
824${FIPTOOL}:
825	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
826
827.PHONY: libraries
828romlib.bin: libraries
829	${Q}${MAKE} BUILD_PLAT=${BUILD_PLAT} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
830
831cscope:
832	@echo "  CSCOPE"
833	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
834	${Q}cscope -b -q -k
835
836help:
837	@echo "usage: ${MAKE} PLAT=<${PLATFORM_LIST}> [OPTIONS] [TARGET]"
838	@echo ""
839	@echo "PLAT is used to specify which platform you wish to build."
840	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
841	@echo ""
842	@echo "Please refer to the User Guide for a list of all supported options."
843	@echo "Note that the build system doesn't track dependencies for build "
844	@echo "options. Therefore, if any of the build options are changed "
845	@echo "from a previous build, a clean build must be performed."
846	@echo ""
847	@echo "Supported Targets:"
848	@echo "  all            Build all individual bootloader binaries"
849	@echo "  bl1            Build the BL1 binary"
850	@echo "  bl2            Build the BL2 binary"
851	@echo "  bl2u           Build the BL2U binary"
852	@echo "  bl31           Build the BL31 binary"
853	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
854	@echo "                 this builds secure payload specified by AARCH32_SP"
855	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
856	@echo "  fip            Build the Firmware Image Package (FIP)"
857	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
858	@echo "  checkcodebase  Check the coding style of the entire source tree"
859	@echo "  checkpatch     Check the coding style on changes in the current"
860	@echo "                 branch against BASE_COMMIT (default origin/master)"
861	@echo "  clean          Clean the build for the selected platform"
862	@echo "  cscope         Generate cscope index"
863	@echo "  distclean      Remove all build artifacts for all platforms"
864	@echo "  certtool       Build the Certificate generation tool"
865	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
866	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
867	@echo ""
868	@echo "Note: most build targets require PLAT to be set to a specific platform."
869	@echo ""
870	@echo "example: build all targets for the FVP platform:"
871	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
872