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