xref: /rk3399_ARM-atf/Makefile (revision 1d7bcaa636200cad91e6dcece4333533d697915d)
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				lib/${ARCH}/cache_helpers.S		\
218				lib/${ARCH}/misc_helpers.S		\
219				plat/common/plat_bl_common.c		\
220				plat/common/plat_log_common.c		\
221				plat/common/${ARCH}/plat_common.c	\
222				plat/common/${ARCH}/platform_helpers.S	\
223				${COMPILER_RT_SRCS}
224
225ifeq ($(notdir $(CC)),armclang)
226BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
227endif
228
229INCLUDES		+=	-Iinclude				\
230				-Iinclude/bl1				\
231				-Iinclude/bl2				\
232				-Iinclude/bl2u				\
233				-Iinclude/bl31				\
234				-Iinclude/common			\
235				-Iinclude/common/${ARCH}		\
236				-Iinclude/drivers			\
237				-Iinclude/drivers/arm			\
238				-Iinclude/drivers/auth			\
239				-Iinclude/drivers/io			\
240				-Iinclude/drivers/ti/uart		\
241				-Iinclude/lib				\
242				-Iinclude/lib/${ARCH}			\
243				-Iinclude/lib/cpus			\
244				-Iinclude/lib/cpus/${ARCH}		\
245				-Iinclude/lib/el3_runtime		\
246				-Iinclude/lib/el3_runtime/${ARCH}	\
247				-Iinclude/lib/extensions		\
248				-Iinclude/lib/pmf			\
249				-Iinclude/lib/psci			\
250				-Iinclude/lib/xlat_tables		\
251				-Iinclude/plat/common			\
252				-Iinclude/services			\
253				${PLAT_INCLUDES}			\
254				${SPD_INCLUDES}				\
255				-Iinclude/tools_share
256
257include common/backtrace/backtrace.mk
258
259################################################################################
260# Generic definitions
261################################################################################
262
263include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
264
265BUILD_BASE		:=	./build
266BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
267
268SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
269
270# Platforms providing their own TBB makefile may override this value
271INCLUDE_TBBR_MK		:=	1
272
273
274################################################################################
275# Include SPD Makefile if one has been specified
276################################################################################
277
278ifneq (${SPD},none)
279ifeq (${ARCH},aarch32)
280        $(error "Error: SPD is incompatible with AArch32.")
281endif
282ifdef EL3_PAYLOAD_BASE
283        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
284        $(warning "The SPD and its BL32 companion will be present but ignored.")
285endif
286        # We expect to locate an spd.mk under the specified SPD directory
287        SPD_MAKE	:=	$(wildcard services/spd/${SPD}/${SPD}.mk)
288
289        ifeq (${SPD_MAKE},)
290                $(error Error: No services/spd/${SPD}/${SPD}.mk located)
291        endif
292        $(info Including ${SPD_MAKE})
293        include ${SPD_MAKE}
294
295        # If there's BL32 companion for the chosen SPD, we expect that the SPD's
296        # Makefile would set NEED_BL32 to "yes". In this case, the build system
297        # supports two mutually exclusive options:
298        # * BL32 is built from source: then BL32_SOURCES must contain the list
299        #   of source files to build BL32
300        # * BL32 is a prebuilt binary: then BL32 must point to the image file
301        #   that will be included in the FIP
302        # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
303        # over the sources.
304endif
305
306################################################################################
307# Include the platform specific Makefile after the SPD Makefile (the platform
308# makefile may use all previous definitions in this file)
309################################################################################
310
311include ${PLAT_MAKEFILE_FULL}
312
313$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
314
315ifeq (${ARM_ARCH_MAJOR},7)
316include make_helpers/armv7-a-cpus.mk
317endif
318
319ifeq ($(ENABLE_PIE),1)
320    TF_CFLAGS		+=	-fpie
321    TF_LDFLAGS		+=	-pie
322else
323    PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
324    ifneq ($(PIE_FOUND),)
325        TF_CFLAGS		+=	-fno-PIE
326    endif
327endif
328
329# Include the CPU specific operations makefile, which provides default
330# values for all CPU errata workarounds and CPU specific optimisations.
331# This can be overridden by the platform.
332include lib/cpus/cpu-ops.mk
333
334ifeq (${ARCH},aarch32)
335NEED_BL32 := yes
336
337################################################################################
338# Build `AARCH32_SP` as BL32 image for AArch32
339################################################################################
340ifneq (${AARCH32_SP},none)
341# We expect to locate an sp.mk under the specified AARCH32_SP directory
342AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
343
344ifeq (${AARCH32_SP_MAKE},)
345  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
346endif
347
348$(info Including ${AARCH32_SP_MAKE})
349include ${AARCH32_SP_MAKE}
350endif
351
352endif
353
354################################################################################
355# Check incompatible options
356################################################################################
357
358ifdef EL3_PAYLOAD_BASE
359        ifdef PRELOADED_BL33_BASE
360                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
361                incompatible build options. EL3_PAYLOAD_BASE has priority.")
362        endif
363        ifneq (${GENERATE_COT},0)
364                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
365        endif
366        ifneq (${TRUSTED_BOARD_BOOT},0)
367                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
368        endif
369endif
370
371ifeq (${NEED_BL33},yes)
372        ifdef EL3_PAYLOAD_BASE
373                $(warning "BL33 image is not needed when option \
374                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
375        endif
376        ifdef PRELOADED_BL33_BASE
377                $(warning "BL33 image is not needed when option \
378                PRELOADED_BL33_BASE is used and won't be added to the FIP \
379                file.")
380        endif
381endif
382
383# When building for systems with hardware-assisted coherency, there's no need to
384# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
385ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
386$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
387endif
388
389#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
390ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
391$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
392endif
393
394# SMC Calling Convention checks
395ifneq (${SMCCC_MAJOR_VERSION},1)
396    ifneq (${SPD},none)
397        $(error "SMC Calling Convention 1.X must be used with SPDs")
398    endif
399    ifeq (${ARCH},aarch32)
400        $(error "Only SMCCC 1.X is supported in AArch32 mode.")
401    endif
402endif
403
404# For RAS_EXTENSION, require that EAs are handled in EL3 first
405ifeq ($(RAS_EXTENSION),1)
406    ifneq ($(HANDLE_EA_EL3_FIRST),1)
407        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
408    endif
409endif
410
411# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
412ifeq ($(FAULT_INJECTION_SUPPORT),1)
413    ifneq ($(RAS_EXTENSION),1)
414        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
415    endif
416endif
417
418# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
419ifeq ($(DYN_DISABLE_AUTH), 1)
420    ifeq (${TRUSTED_BOARD_BOOT}, 0)
421        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
422    endif
423endif
424
425################################################################################
426# Process platform overrideable behaviour
427################################################################################
428
429# Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
430# supplied for the FIP and Certificate generation tools. This flag can be
431# overridden by the platform.
432ifdef BL2_SOURCES
433        ifdef EL3_PAYLOAD_BASE
434                # If booting an EL3 payload there is no need for a BL33 image
435                # in the FIP file.
436                NEED_BL33		:=	no
437        else
438                ifdef PRELOADED_BL33_BASE
439                        # If booting a BL33 preloaded image there is no need of
440                        # another one in the FIP file.
441                        NEED_BL33		:=	no
442                else
443                        NEED_BL33		?=	yes
444                endif
445        endif
446endif
447
448# If SCP_BL2 is given, we always want FIP to include it.
449ifdef SCP_BL2
450        NEED_SCP_BL2		:=	yes
451endif
452
453# For AArch32, BL31 is not currently supported.
454ifneq (${ARCH},aarch32)
455    ifdef BL31_SOURCES
456        # When booting an EL3 payload, there is no need to compile the BL31 image nor
457        # put it in the FIP.
458        ifndef EL3_PAYLOAD_BASE
459            NEED_BL31 := yes
460        endif
461    endif
462endif
463
464# Process TBB related flags
465ifneq (${GENERATE_COT},0)
466        # Common cert_create options
467        ifneq (${CREATE_KEYS},0)
468                $(eval CRT_ARGS += -n)
469                $(eval FWU_CRT_ARGS += -n)
470                ifneq (${SAVE_KEYS},0)
471                        $(eval CRT_ARGS += -k)
472                        $(eval FWU_CRT_ARGS += -k)
473                endif
474        endif
475        # Include TBBR makefile (unless the platform indicates otherwise)
476        ifeq (${INCLUDE_TBBR_MK},1)
477                include make_helpers/tbbr/tbbr_tools.mk
478        endif
479endif
480
481ifneq (${FIP_ALIGN},0)
482FIP_ARGS += --align ${FIP_ALIGN}
483endif
484
485################################################################################
486# Include libraries' Makefile that are used in all BL
487################################################################################
488
489include lib/stack_protector/stack_protector.mk
490
491################################################################################
492# Auxiliary tools (fiptool, cert_create, etc)
493################################################################################
494
495# Variables for use with Certificate Generation Tool
496CRTTOOLPATH		?=	tools/cert_create
497CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
498
499# Variables for use with Firmware Image Package
500FIPTOOLPATH		?=	tools/fiptool
501FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
502
503# Variables for use with ROMLIB
504ROMLIBPATH		?=	lib/romlib
505
506################################################################################
507# Include BL specific makefiles
508################################################################################
509ifdef BL1_SOURCES
510NEED_BL1 := yes
511include bl1/bl1.mk
512endif
513
514ifdef BL2_SOURCES
515NEED_BL2 := yes
516include bl2/bl2.mk
517endif
518
519ifdef BL2U_SOURCES
520NEED_BL2U := yes
521include bl2u/bl2u.mk
522endif
523
524ifeq (${NEED_BL31},yes)
525ifdef BL31_SOURCES
526include bl31/bl31.mk
527endif
528endif
529
530ifdef FDT_SOURCES
531NEED_FDT := yes
532endif
533
534################################################################################
535# Build options checks
536################################################################################
537
538$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
539$(eval $(call assert_boolean,CREATE_KEYS))
540$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
541$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
542$(eval $(call assert_boolean,DEBUG))
543$(eval $(call assert_boolean,DISABLE_PEDANTIC))
544$(eval $(call assert_boolean,DYN_DISABLE_AUTH))
545$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING))
546$(eval $(call assert_boolean,ENABLE_AMU))
547$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
548$(eval $(call assert_boolean,ENABLE_MPAM_FOR_LOWER_ELS))
549$(eval $(call assert_boolean,ENABLE_PIE))
550$(eval $(call assert_boolean,ENABLE_PMF))
551$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
552$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
553$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
554$(eval $(call assert_boolean,ENABLE_SPM))
555$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
556$(eval $(call assert_boolean,ERROR_DEPRECATED))
557$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT))
558$(eval $(call assert_boolean,GENERATE_COT))
559$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
560$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST))
561$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
562$(eval $(call assert_boolean,MULTI_CONSOLE_API))
563$(eval $(call assert_boolean,NS_TIMER_SWITCH))
564$(eval $(call assert_boolean,PL011_GENERIC_UART))
565$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
566$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
567$(eval $(call assert_boolean,RAS_EXTENSION))
568$(eval $(call assert_boolean,RESET_TO_BL31))
569$(eval $(call assert_boolean,SAVE_KEYS))
570$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
571$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
572$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
573$(eval $(call assert_boolean,USE_COHERENT_MEM))
574$(eval $(call assert_boolean,USE_ROMLIB))
575$(eval $(call assert_boolean,USE_TBBR_DEFS))
576$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
577$(eval $(call assert_boolean,BL2_AT_EL3))
578$(eval $(call assert_boolean,BL2_IN_XIP_MEM))
579
580$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
581$(eval $(call assert_numeric,ARM_ARCH_MINOR))
582$(eval $(call assert_numeric,SMCCC_MAJOR_VERSION))
583
584################################################################################
585# Add definitions to the cpp preprocessor based on the current build options.
586# This is done after including the platform specific makefile to allow the
587# platform to overwrite the default options
588################################################################################
589
590$(eval $(call add_define,ARM_ARCH_MAJOR))
591$(eval $(call add_define,ARM_ARCH_MINOR))
592$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
593$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
594$(eval $(call add_define,CTX_INCLUDE_FPREGS))
595$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
596$(eval $(call add_define,ENABLE_AMU))
597$(eval $(call add_define,ENABLE_ASSERTIONS))
598$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS))
599$(eval $(call add_define,ENABLE_PIE))
600$(eval $(call add_define,ENABLE_PMF))
601$(eval $(call add_define,ENABLE_PSCI_STAT))
602$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
603$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
604$(eval $(call add_define,ENABLE_SPM))
605$(eval $(call add_define,ENABLE_SVE_FOR_NS))
606$(eval $(call add_define,ERROR_DEPRECATED))
607$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
608$(eval $(call add_define,GICV2_G0_FOR_EL3))
609$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
610$(eval $(call add_define,HW_ASSISTED_COHERENCY))
611$(eval $(call add_define,LOG_LEVEL))
612$(eval $(call add_define,MULTI_CONSOLE_API))
613$(eval $(call add_define,NS_TIMER_SWITCH))
614$(eval $(call add_define,PL011_GENERIC_UART))
615$(eval $(call add_define,PLAT_${PLAT}))
616$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
617$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
618$(eval $(call add_define,RAS_EXTENSION))
619$(eval $(call add_define,RESET_TO_BL31))
620$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
621$(eval $(call add_define,RECLAIM_INIT_CODE))
622$(eval $(call add_define,SMCCC_MAJOR_VERSION))
623$(eval $(call add_define,SPD_${SPD}))
624$(eval $(call add_define,SPIN_ON_BL1_EXIT))
625$(eval $(call add_define,TRUSTED_BOARD_BOOT))
626$(eval $(call add_define,USE_COHERENT_MEM))
627$(eval $(call add_define,USE_ROMLIB))
628$(eval $(call add_define,USE_TBBR_DEFS))
629$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
630$(eval $(call add_define,BL2_AT_EL3))
631$(eval $(call add_define,BL2_IN_XIP_MEM))
632
633# Define the EL3_PAYLOAD_BASE flag only if it is provided.
634ifdef EL3_PAYLOAD_BASE
635        $(eval $(call add_define,EL3_PAYLOAD_BASE))
636else
637        # Define the PRELOADED_BL33_BASE flag only if it is provided and
638        # EL3_PAYLOAD_BASE is not defined, as it has priority.
639        ifdef PRELOADED_BL33_BASE
640                $(eval $(call add_define,PRELOADED_BL33_BASE))
641        endif
642endif
643# Define the AARCH32/AARCH64 flag based on the ARCH flag
644ifeq (${ARCH},aarch32)
645        $(eval $(call add_define,AARCH32))
646else
647        $(eval $(call add_define,AARCH64))
648endif
649
650# Define the DYN_DISABLE_AUTH flag only if set.
651ifeq (${DYN_DISABLE_AUTH},1)
652$(eval $(call add_define,DYN_DISABLE_AUTH))
653endif
654
655################################################################################
656# Build targets
657################################################################################
658
659.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip fwu_fip certtool dtbs
660.SUFFIXES:
661
662all: msg_start
663
664msg_start:
665	@echo "Building ${PLAT}"
666
667# Check if deprecated declarations and cpp warnings should be treated as error or not.
668ifeq (${ERROR_DEPRECATED},0)
669    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
670endif
671
672$(eval $(call MAKE_LIB_DIRS))
673$(eval $(call MAKE_LIB,c))
674
675# Expand build macros for the different images
676ifeq (${NEED_BL1},yes)
677$(eval $(call MAKE_BL,1))
678endif
679
680ifeq (${NEED_BL2},yes)
681ifeq (${BL2_AT_EL3}, 0)
682FIP_BL2_ARGS := tb-fw
683endif
684
685$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
686	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
687endif
688
689ifeq (${NEED_SCP_BL2},yes)
690$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
691endif
692
693ifeq (${NEED_BL31},yes)
694BL31_SOURCES += ${SPD_SOURCES}
695$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
696	$(eval $(call MAKE_BL,31,soc-fw)))
697endif
698
699# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
700# build system will call TOOL_ADD_IMG to print a warning message and abort the
701# process. Note that the dependency on BL32 applies to the FIP only.
702ifeq (${NEED_BL32},yes)
703
704BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
705
706$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
707	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
708endif
709
710# Add the BL33 image if required by the platform
711ifeq (${NEED_BL33},yes)
712$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
713endif
714
715ifeq (${NEED_BL2U},yes)
716$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
717	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
718endif
719
720# Expand build macros for the different images
721ifeq (${NEED_FDT},yes)
722    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
723endif
724
725locate-checkpatch:
726ifndef CHECKPATCH
727	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
728else
729ifeq (,$(wildcard ${CHECKPATCH}))
730	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
731endif
732endif
733
734clean:
735	@echo "  CLEAN"
736	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
737	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
738	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
739	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
740
741realclean distclean:
742	@echo "  REALCLEAN"
743	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
744	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
745	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
746	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
747	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
748
749checkcodebase:		locate-checkpatch
750	@echo "  CHECKING STYLE"
751	@if test -d .git ; then						\
752		git ls-files | grep -E -v 'libfdt|libc|docs|\.md' |	\
753		while read GIT_FILE ;					\
754		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
755		done ;							\
756	else								\
757		 find . -type f -not -iwholename "*.git*"		\
758		 -not -iwholename "*build*"				\
759		 -not -iwholename "*libfdt*"				\
760		 -not -iwholename "*libc*"				\
761		 -not -iwholename "*docs*"				\
762		 -not -iwholename "*.md"				\
763		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
764	fi
765
766checkpatch:		locate-checkpatch
767	@echo "  CHECKING STYLE"
768	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
769	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
770		printf "\n[*] Checking style of '$$commit'\n\n";	\
771		git log --format=email "$$commit~..$$commit"		\
772			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
773		git diff --format=email "$$commit~..$$commit"		\
774			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
775	done
776
777certtool: ${CRTTOOL}
778
779.PHONY: ${CRTTOOL}
780${CRTTOOL}:
781	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH}
782	@${ECHO_BLANK_LINE}
783	@echo "Built $@ successfully"
784	@${ECHO_BLANK_LINE}
785
786ifneq (${GENERATE_COT},0)
787certificates: ${CRT_DEPS} ${CRTTOOL}
788	${Q}${CRTTOOL} ${CRT_ARGS}
789	@${ECHO_BLANK_LINE}
790	@echo "Built $@ successfully"
791	@echo "Certificates can be found in ${BUILD_PLAT}"
792	@${ECHO_BLANK_LINE}
793endif
794
795${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
796	${Q}${FIPTOOL} create ${FIP_ARGS} $@
797	${Q}${FIPTOOL} info $@
798	@${ECHO_BLANK_LINE}
799	@echo "Built $@ successfully"
800	@${ECHO_BLANK_LINE}
801
802ifneq (${GENERATE_COT},0)
803fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
804	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
805	@${ECHO_BLANK_LINE}
806	@echo "Built $@ successfully"
807	@echo "FWU certificates can be found in ${BUILD_PLAT}"
808	@${ECHO_BLANK_LINE}
809endif
810
811${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
812	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
813	${Q}${FIPTOOL} info $@
814	@${ECHO_BLANK_LINE}
815	@echo "Built $@ successfully"
816	@${ECHO_BLANK_LINE}
817
818fiptool: ${FIPTOOL}
819fip: ${BUILD_PLAT}/${FIP_NAME}
820fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
821
822.PHONY: ${FIPTOOL}
823${FIPTOOL}:
824	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
825
826.PHONY: libraries
827romlib.bin: libraries
828	${Q}${MAKE} BUILD_PLAT=${BUILD_PLAT} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
829
830cscope:
831	@echo "  CSCOPE"
832	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
833	${Q}cscope -b -q -k
834
835help:
836	@echo "usage: ${MAKE} PLAT=<${PLATFORM_LIST}> [OPTIONS] [TARGET]"
837	@echo ""
838	@echo "PLAT is used to specify which platform you wish to build."
839	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
840	@echo ""
841	@echo "Please refer to the User Guide for a list of all supported options."
842	@echo "Note that the build system doesn't track dependencies for build "
843	@echo "options. Therefore, if any of the build options are changed "
844	@echo "from a previous build, a clean build must be performed."
845	@echo ""
846	@echo "Supported Targets:"
847	@echo "  all            Build all individual bootloader binaries"
848	@echo "  bl1            Build the BL1 binary"
849	@echo "  bl2            Build the BL2 binary"
850	@echo "  bl2u           Build the BL2U binary"
851	@echo "  bl31           Build the BL31 binary"
852	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
853	@echo "                 this builds secure payload specified by AARCH32_SP"
854	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
855	@echo "  fip            Build the Firmware Image Package (FIP)"
856	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
857	@echo "  checkcodebase  Check the coding style of the entire source tree"
858	@echo "  checkpatch     Check the coding style on changes in the current"
859	@echo "                 branch against BASE_COMMIT (default origin/master)"
860	@echo "  clean          Clean the build for the selected platform"
861	@echo "  cscope         Generate cscope index"
862	@echo "  distclean      Remove all build artifacts for all platforms"
863	@echo "  certtool       Build the Certificate generation tool"
864	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
865	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
866	@echo ""
867	@echo "Note: most build targets require PLAT to be set to a specific platform."
868	@echo ""
869	@echo "example: build all targets for the FVP platform:"
870	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
871