xref: /rk3399_ARM-atf/Makefile (revision a443fbd0d34b4c1fbc8c648e07a9e1fe3d22dab9)
1#
2# Copyright (c) 2013-2025, 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			:= 13
12# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH			:= 0
14VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15
16# Default goal is build all images
17.DEFAULT_GOAL			:= all
18
19# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
24MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
27include ${MAKE_HELPERS_DIRECTORY}common.mk
28
29################################################################################
30# Default values for build configurations, and their dependencies
31################################################################################
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34# Include the CPU specific operations makefile, which provides default
35# values for all CPU errata workarounds and CPU specific optimisations.
36# This can be overridden by the platform.
37include lib/cpus/cpu-ops.mk
38
39PLAT				:= ${DEFAULT_PLAT}
40include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
41
42# To be able to set platform specific defaults
43ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
44include ${PLAT_DEFAULTS_MAKEFILE_FULL}
45endif
46
47################################################################################
48# Configure the toolchains used to build TF-A and its tools
49################################################################################
50
51include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
52
53# Assertions enabled for DEBUG builds by default
54ENABLE_ASSERTIONS		:= ${DEBUG}
55ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
56
57################################################################################
58# Checkpatch script options
59################################################################################
60
61CHECKCODE_ARGS		:=	--no-patch
62# Do not check the coding style on imported library files or documentation files
63INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
64					include/drivers/arm,		\
65					$(wildcard include/drivers/*)))
66INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
67					lib/libfdt		\
68					include/lib/libc,		\
69					$(wildcard include/lib/*)))
70INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
71					include/lib			\
72					include/drivers,		\
73					$(wildcard include/*)))
74LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
75					lib/compiler-rt			\
76					lib/libfdt%			\
77					lib/libc,			\
78					lib/zlib			\
79					$(wildcard lib/*)))
80ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
81					lib				\
82					include				\
83					docs				\
84					%.rst,				\
85					$(wildcard *)))
86CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
87				${INC_DIRS_TO_CHECK}			\
88				${INC_LIB_DIRS_TO_CHECK}		\
89				${LIB_DIRS_TO_CHECK}			\
90				${INC_DRV_DIRS_TO_CHECK}		\
91				${INC_ARM_DIRS_TO_CHECK}
92
93################################################################################
94# Process build options
95################################################################################
96
97ifeq ($(verbose),)
98	CHECKCODE_ARGS	+=	--no-summary --terse
99endif
100
101################################################################################
102# Auxiliary tools (fiptool, cert_create, etc)
103################################################################################
104
105# Variables for use with Certificate Generation Tool
106CRTTOOLPATH		?=	tools/cert_create
107CRTTOOL			?=	${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
108
109# Variables for use with Firmware Encryption Tool
110ENCTOOLPATH		?=	tools/encrypt_fw
111ENCTOOL			?=	${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
112
113# Variables for use with Firmware Image Package
114FIPTOOLPATH		?=	tools/fiptool
115FIPTOOL			?=	${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
116
117# Variables for use with sptool
118SPTOOLPATH		?=	tools/sptool
119SPTOOL			?=	${SPTOOLPATH}/sptool.py
120SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
121SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
122
123# Variables for use with sptool
124TLCTOOL 		?=	poetry run tlc
125
126# Variables for use with ROMLIB
127ROMLIBPATH		?=	lib/romlib
128
129# Variable for use with Python
130PYTHON			?=	python3
131
132# Variables for use with documentation build using Sphinx tool
133DOCS_PATH		?=	docs
134
135# Process Debug flag
136ifneq (${DEBUG}, 0)
137	BUILD_TYPE	:=	debug
138	# Use LOG_LEVEL_INFO by default for debug builds
139	LOG_LEVEL	:=	40
140else
141	BUILD_TYPE	:=	release
142	# Use LOG_LEVEL_NOTICE by default for release builds
143	LOG_LEVEL	:=	20
144endif #(Debug)
145
146# Default build string (git branch and commit)
147ifeq (${BUILD_STRING},)
148	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
149endif
150VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
151
152# Setting W is quite verbose and most warnings will be pre-existing issues
153# outside of the contributor's control. Don't fail the build on them so warnings
154# can be seen and hopefully addressed
155ifdef W
156	ifneq (${W},0)
157		E	 ?= 0
158	endif
159endif
160
161################################################################################
162# Setup ARCH_MAJOR/MINOR before parsing arch_features.
163################################################################################
164ifeq (${ENABLE_RME},1)
165	ARM_ARCH_MAJOR := 9
166	ARM_ARCH_MINOR := 2
167endif
168
169################################################################################
170# Common sources and include directories
171################################################################################
172include lib/compiler-rt/compiler-rt.mk
173
174# Allow overriding the timestamp, for example for reproducible builds, or to
175# synchronize timestamps across multiple projects.
176# This must be set to a C string (including quotes where applicable).
177BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
178
179DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
180DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
181DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
182
183BL_COMMON_SOURCES	+=	common/bl_common.c			\
184				common/tf_log.c				\
185				common/${ARCH}/debug.S			\
186				drivers/console/multi_console.c		\
187				lib/${ARCH}/cache_helpers.S		\
188				lib/${ARCH}/misc_helpers.S		\
189				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
190				plat/common/plat_bl_common.c		\
191				plat/common/plat_log_common.c		\
192				plat/common/${ARCH}/plat_common.c	\
193				plat/common/${ARCH}/platform_helpers.S	\
194				${COMPILER_RT_SRCS}
195
196ifeq ($($(ARCH)-cc-id),arm-clang)
197	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
198endif
199
200ifeq (${SANITIZE_UB},on)
201	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
202endif
203
204INCLUDES		+=	-Iinclude				\
205				-Iinclude/arch/${ARCH}			\
206				-Iinclude/lib/cpus/${ARCH}		\
207				-Iinclude/lib/el3_runtime/${ARCH}	\
208				${PLAT_INCLUDES}			\
209				${SPD_INCLUDES}
210
211include common/backtrace/backtrace.mk
212
213################################################################################
214# Generic definitions
215################################################################################
216
217ifeq (${BUILD_BASE},)
218     BUILD_BASE		:=	./build
219endif
220BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
221
222SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
223
224# Platforms providing their own TBB makefile may override this value
225INCLUDE_TBBR_MK		:=	1
226
227################################################################################
228# Include SPD Makefile if one has been specified
229################################################################################
230
231ifneq (${SPD},none)
232	ifeq (${SPD},spmd)
233	# SPMD is located in std_svc directory
234		SPD_DIR := std_svc
235
236		ifeq ($(SPMD_SPM_AT_SEL2),1)
237			CTX_INCLUDE_EL2_REGS := 1
238		endif
239
240		ifneq ($(SP_LAYOUT_FILE),)
241		BL2_ENABLE_SP_LOAD := 1
242		endif
243	else
244		# All other SPDs in spd directory
245		SPD_DIR := spd
246	endif #(SPD)
247
248	# We expect to locate an spd.mk under the specified SPD directory
249	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
250
251	ifeq (${SPD_MAKE},)
252                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
253	endif
254        $(info Including ${SPD_MAKE})
255        include ${SPD_MAKE}
256
257	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
258	# Makefile would set NEED_BL32 to "yes". In this case, the build system
259	# supports two mutually exclusive options:
260	# * BL32 is built from source: then BL32_SOURCES must contain the list
261	#   of source files to build BL32
262	# * BL32 is a prebuilt binary: then BL32 must point to the image file
263	#   that will be included in the FIP
264	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
265	# over the sources.
266endif #(SPD=none)
267
268################################################################################
269# Include the platform specific Makefile after the SPD Makefile (the platform
270# makefile may use all previous definitions in this file)
271################################################################################
272include ${PLAT_MAKEFILE_FULL}
273
274################################################################################
275# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
276# platform.
277################################################################################
278
279include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
280################################################################################
281# Process BRANCH_PROTECTION value and set
282# Pointer Authentication and Branch Target Identification flags
283################################################################################
284ifeq (${BRANCH_PROTECTION},0)
285	# Default value turns off all types of branch protection
286	BP_OPTION := none
287else ifneq (${ARCH},aarch64)
288        $(error BRANCH_PROTECTION requires AArch64)
289else ifeq (${BRANCH_PROTECTION},1)
290	# Enables all types of branch protection features
291	BP_OPTION := standard
292	ENABLE_BTI := 1
293	ENABLE_PAUTH := 1
294else ifeq (${BRANCH_PROTECTION},2)
295	# Return address signing to its standard level
296	BP_OPTION := pac-ret
297	ENABLE_PAUTH := 1
298else ifeq (${BRANCH_PROTECTION},3)
299	# Extend the signing to include leaf functions
300	BP_OPTION := pac-ret+leaf
301	ENABLE_PAUTH := 1
302else ifeq (${BRANCH_PROTECTION},4)
303	# Turn on branch target identification mechanism
304	BP_OPTION := bti
305	ENABLE_BTI := 1
306else ifeq (${BRANCH_PROTECTION},5)
307	# Turn on branch target identification mechanism
308	BP_OPTION := standard
309	ENABLE_BTI := 2
310	ENABLE_PAUTH := 2
311else
312        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
313endif #(BRANCH_PROTECTION)
314
315ifneq ($(ENABLE_PAUTH),0)
316	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
317endif
318
319# Pointer Authentication sources
320ifneq (${ENABLE_PAUTH},0)
321# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
322# Pauth support. As it's not secure, it must be reimplemented for real platforms
323	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
324endif
325
326################################################################################
327# RME dependent flags configuration, Enable optional features for RME.
328################################################################################
329# FEAT_RME
330ifeq (${ENABLE_RME},1)
331	# RME requires el2 context to be saved for now.
332	CTX_INCLUDE_EL2_REGS := 1
333	CTX_INCLUDE_AARCH32_REGS := 0
334	CTX_INCLUDE_PAUTH_REGS := 1
335
336	ifneq ($(ENABLE_FEAT_MPAM), 0)
337		CTX_INCLUDE_MPAM_REGS := 1
338	endif
339
340	# RME enables CSV2_2 extension by default.
341	ENABLE_FEAT_CSV2_2 = 1
342endif #(FEAT_RME)
343
344################################################################################
345# Include rmmd Makefile if RME is enabled
346################################################################################
347ifneq (${ENABLE_RME},0)
348include services/std_svc/rmmd/rmmd.mk
349$(warning "RME is an experimental feature")
350endif
351
352################################################################################
353# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
354################################################################################
355ifneq (${ENABLE_FEAT_D128}, 0)
356        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
357endif
358
359# This internal flag is common option which is set to 1 for scenarios
360# when the BL2 is running in EL3 level. This occurs in two scenarios -
361# 4 world system running BL2 at EL3 and two world system without BL1 running
362# BL2 in EL3
363
364ifeq (${RESET_TO_BL2},1)
365	BL2_RUNS_AT_EL3	:=	1
366	ifeq (${ENABLE_RME},1)
367                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
368                supported at the moment.)
369	endif
370else ifeq (${ENABLE_RME},1)
371	BL2_RUNS_AT_EL3	:=	1
372else
373	BL2_RUNS_AT_EL3	:=	0
374endif
375
376# This internal flag is set to 1 when Firmware First handling of External aborts
377# is required by lowe ELs. Currently only NS requires this support.
378ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
379	FFH_SUPPORT := 1
380else
381	FFH_SUPPORT := 0
382endif
383
384ifneq ($(filter 1,${ERRATA_A53_1530924} ${ERRATA_A55_1530923}	\
385        ${ERRATA_A57_1319537} ${ERRATA_A72_1319367} ${ERRATA_A76_1165522}),)
386ERRATA_SPECULATIVE_AT	:= 1
387else
388ERRATA_SPECULATIVE_AT	:= 0
389endif
390
391################################################################################
392# Build `AARCH32_SP` as BL32 image for AArch32
393################################################################################
394ifeq (${ARCH},aarch32)
395        NEED_BL32 := yes
396
397        ifneq (${AARCH32_SP},none)
398        # We expect to locate an sp.mk under the specified AARCH32_SP directory
399		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
400
401                ifeq (${AARCH32_SP_MAKE},)
402                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
403                endif
404                $(info Including ${AARCH32_SP_MAKE})
405                include ${AARCH32_SP_MAKE}
406        endif
407endif #(ARCH=aarch32)
408
409################################################################################
410# Include libc if not overridden
411################################################################################
412ifeq (${OVERRIDE_LIBC},0)
413include lib/libc/libc.mk
414endif
415
416ifneq (${USE_GIC_DRIVER},0)
417include drivers/arm/gic/gic.mk
418endif
419
420################################################################################
421# Check incompatible options and dependencies
422################################################################################
423include ${MAKE_HELPERS_DIRECTORY}constraints.mk
424
425# The cert_create tool cannot generate certificates individually, so we use the
426# target 'certificates' to create them all
427ifneq (${GENERATE_COT},0)
428    FIP_DEPS += certificates
429    FWU_FIP_DEPS += fwu_certificates
430    BL2_FIP_DEPS += bl2_certificates
431endif
432
433ifneq (${DECRYPTION_SUPPORT},none)
434	ENC_ARGS += -f ${FW_ENC_STATUS}
435	ENC_ARGS += -k ${ENC_KEY}
436	ENC_ARGS += -n ${ENC_NONCE}
437	FIP_DEPS += enctool
438	FWU_FIP_DEPS += enctool
439	BL2_FIP_DEPS += enctool
440endif #(DECRYPTION_SUPPORT)
441
442################################################################################
443# Process platform overrideable behaviour
444################################################################################
445
446ifdef BL1_SOURCES
447	NEED_BL1 := yes
448endif #(BL1_SOURCES)
449
450ifdef BL2_SOURCES
451	NEED_BL2 := yes
452
453	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
454	# Certificate generation tools. This flag can be overridden by the platform.
455	ifdef EL3_PAYLOAD_BASE
456		# If booting an EL3 payload there is no need for a BL33 image
457		# in the FIP file.
458		NEED_BL33		:=	no
459	else
460		ifdef PRELOADED_BL33_BASE
461			# If booting a BL33 preloaded image there is no need of
462			# another one in the FIP file.
463			NEED_BL33		:=	no
464		else
465			NEED_BL33		?=	yes
466		endif
467	endif
468endif #(BL2_SOURCES)
469
470ifdef BL2U_SOURCES
471	NEED_BL2U := yes
472endif #(BL2U_SOURCES)
473
474# If SCP_BL2 is given, we always want FIP to include it.
475ifdef SCP_BL2
476	NEED_SCP_BL2		:=	yes
477endif #(SCP_BL2)
478
479# For AArch32, BL31 is not currently supported.
480ifneq (${ARCH},aarch32)
481	ifdef BL31_SOURCES
482	# When booting an EL3 payload, there is no need to compile the BL31
483	# image nor put it in the FIP.
484		ifndef EL3_PAYLOAD_BASE
485			NEED_BL31 := yes
486		endif
487	endif
488endif #(ARCH=aarch64)
489
490# Process TBB related flags
491ifneq (${GENERATE_COT},0)
492    # Common cert_create options
493    ifneq (${CREATE_KEYS},0)
494        $(eval CRT_ARGS += -n)
495        $(eval FWU_CRT_ARGS += -n)
496        $(eval BL2_CRT_ARGS += -n)
497        ifneq (${SAVE_KEYS},0)
498            $(eval CRT_ARGS += -k)
499            $(eval FWU_CRT_ARGS += -k)
500            $(eval BL2_CRT_ARGS += -k)
501        endif
502    endif
503    # Include TBBR makefile (unless the platform indicates otherwise)
504    ifeq (${INCLUDE_TBBR_MK},1)
505        include make_helpers/tbbr/tbbr_tools.mk
506    endif
507endif #(GENERATE_COT)
508
509ifneq (${FIP_ALIGN},0)
510	FIP_ARGS += --align ${FIP_ALIGN}
511endif #(FIP_ALIGN)
512
513ifdef FDT_SOURCES
514	NEED_FDT := yes
515endif #(FDT_SOURCES)
516
517################################################################################
518# Include libraries' Makefile that are used in all BL
519################################################################################
520
521include lib/stack_protector/stack_protector.mk
522
523################################################################################
524# Include BL specific makefiles
525################################################################################
526
527ifeq (${NEED_BL1},yes)
528include bl1/bl1.mk
529endif
530
531ifeq (${NEED_BL2},yes)
532include bl2/bl2.mk
533endif
534
535ifeq (${NEED_BL2U},yes)
536include bl2u/bl2u.mk
537endif
538
539ifeq (${NEED_BL31},yes)
540include bl31/bl31.mk
541endif
542
543################################################################################
544# Build options checks
545################################################################################
546
547# Boolean_Flags
548$(eval $(call assert_booleans,\
549    $(sort \
550	ALLOW_RO_XLAT_TABLES \
551	BL2_ENABLE_SP_LOAD \
552	COLD_BOOT_SINGLE_CPU \
553	$(CPU_FLAG_LIST) \
554	CREATE_KEYS \
555	CTX_INCLUDE_AARCH32_REGS \
556	CTX_INCLUDE_FPREGS \
557	CTX_INCLUDE_SVE_REGS \
558	CTX_INCLUDE_EL2_REGS \
559	CTX_INCLUDE_MPAM_REGS \
560	DEBUG \
561	DYN_DISABLE_AUTH \
562	EL3_EXCEPTION_HANDLING \
563	ENABLE_AMU_AUXILIARY_COUNTERS \
564	AMU_RESTRICT_COUNTERS \
565	ENABLE_ASSERTIONS \
566	ENABLE_PIE \
567	ENABLE_PMF \
568	ENABLE_PSCI_STAT \
569	ENABLE_RUNTIME_INSTRUMENTATION \
570	ENABLE_SME_FOR_SWD \
571	ENABLE_SVE_FOR_SWD \
572	ENABLE_FEAT_GCIE \
573	ENABLE_FEAT_RAS	\
574	FFH_SUPPORT	\
575	ERROR_DEPRECATED \
576	FAULT_INJECTION_SUPPORT \
577	GENERATE_COT \
578	GICV2_G0_FOR_EL3 \
579	HANDLE_EA_EL3_FIRST_NS \
580	HARDEN_SLS \
581	HW_ASSISTED_COHERENCY \
582	MEASURED_BOOT \
583	DISCRETE_TPM \
584	DICE_PROTECTION_ENVIRONMENT \
585	RMMD_ENABLE_EL3_TOKEN_SIGN \
586	RMMD_ENABLE_IDE_KEY_PROG \
587	DRTM_SUPPORT \
588	NS_TIMER_SWITCH \
589	OVERRIDE_LIBC \
590	PL011_GENERIC_UART \
591	PLAT_EXTRA_LD_SCRIPT \
592	PROGRAMMABLE_RESET_ADDRESS \
593	PSCI_EXTENDED_STATE_ID \
594	PSCI_OS_INIT_MODE \
595	ARCH_FEATURE_AVAILABILITY \
596	RESET_TO_BL31 \
597	SAVE_KEYS \
598	SEPARATE_CODE_AND_RODATA \
599	SEPARATE_BL2_NOLOAD_REGION \
600	SEPARATE_NOBITS_REGION \
601	SEPARATE_RWDATA_REGION \
602	SEPARATE_SIMD_SECTION \
603	SPIN_ON_BL1_EXIT \
604	SPM_MM \
605	SPMC_AT_EL3 \
606	SPMC_AT_EL3_SEL0_SP \
607	SPMD_SPM_AT_SEL2 \
608	ENABLE_SPMD_LP \
609	TRANSFER_LIST \
610	TRUSTED_BOARD_BOOT \
611	USE_COHERENT_MEM \
612	USE_DEBUGFS \
613	USE_KERNEL_DT_CONVENTION \
614	ARM_IO_IN_DTB \
615	SDEI_IN_FCONF \
616	SEC_INT_DESC_IN_FCONF \
617	USE_ROMLIB \
618	USE_TBBR_DEFS \
619	WARMBOOT_ENABLE_DCACHE_EARLY \
620	RESET_TO_BL2 \
621	BL2_IN_XIP_MEM \
622	BL2_INV_DCACHE \
623	USE_SPINLOCK_CAS \
624	ENCRYPT_BL31 \
625	ENCRYPT_BL32 \
626	ERRATA_SPECULATIVE_AT \
627	ERRATA_SME_POWER_DOWN \
628	RAS_TRAP_NS_ERR_REC_ACCESS \
629	COT_DESC_IN_DTB \
630	USE_SP804_TIMER \
631	PSA_FWU_SUPPORT \
632	PSA_FWU_METADATA_FW_STORE_DESC \
633	ENABLE_MPMM \
634	FEATURE_DETECTION \
635	TRNG_SUPPORT \
636	ENABLE_ERRATA_ALL \
637	ERRATA_ABI_SUPPORT \
638	ERRATA_NON_ARM_INTERCONNECT \
639	CONDITIONAL_CMO \
640	PSA_CRYPTO	\
641	ENABLE_CONSOLE_GETC \
642	INIT_UNUSED_NS_EL2	\
643	PLATFORM_REPORT_CTX_MEM_USE \
644	EARLY_CONSOLE \
645	PRESERVE_DSU_PMU_REGS \
646	HOB_LIST \
647	LFA_SUPPORT \
648)))
649
650# Numeric_Flags
651$(eval $(call assert_numerics,\
652    $(sort \
653	ARM_ARCH_MAJOR \
654	ARM_ARCH_MINOR \
655	BRANCH_PROTECTION \
656	CTX_INCLUDE_PAUTH_REGS \
657	CTX_INCLUDE_NEVE_REGS \
658	DISABLE_MTPMU \
659	ENABLE_BRBE_FOR_NS \
660	ENABLE_TRBE_FOR_NS \
661	ENABLE_BTI \
662	ENABLE_PAUTH \
663	ENABLE_FEAT_PAUTH_LR \
664	ENABLE_FEAT_AIE \
665	ENABLE_FEAT_AMU \
666	ENABLE_FEAT_AMUv1p1 \
667	ENABLE_FEAT_CLRBHB \
668	ENABLE_FEAT_CPA2 \
669	ENABLE_FEAT_CSV2_2 \
670	ENABLE_FEAT_CSV2_3 \
671	ENABLE_FEAT_DEBUGV8P9 \
672	ENABLE_FEAT_DIT \
673	ENABLE_FEAT_ECV \
674	ENABLE_FEAT_EBEP \
675	ENABLE_FEAT_FGT \
676	ENABLE_FEAT_FGT2 \
677	ENABLE_FEAT_FGWTE3 \
678	ENABLE_FEAT_FPMR \
679	ENABLE_FEAT_HCX \
680	ENABLE_FEAT_LS64_ACCDATA \
681	ENABLE_FEAT_MEC \
682	ENABLE_FEAT_MOPS \
683	ENABLE_FEAT_MTE2 \
684	ENABLE_FEAT_PAN \
685	ENABLE_FEAT_PFAR \
686	ENABLE_FEAT_RNG \
687	ENABLE_FEAT_RNG_TRAP \
688	ENABLE_FEAT_SEL2 \
689	ENABLE_FEAT_TCR2 \
690	ENABLE_FEAT_THE \
691	ENABLE_FEAT_SB \
692	ENABLE_FEAT_S2PIE \
693	ENABLE_FEAT_S1PIE \
694	ENABLE_FEAT_S2POE \
695	ENABLE_FEAT_S1POE \
696	ENABLE_FEAT_SCTLR2 \
697	ENABLE_FEAT_D128 \
698	ENABLE_FEAT_GCS \
699	ENABLE_FEAT_VHE \
700	ENABLE_FEAT_MPAM \
701	ENABLE_FEAT_MPAM_PE_BW_CTRL \
702	ENABLE_RME \
703	ENABLE_SPE_FOR_NS \
704	ENABLE_SYS_REG_TRACE_FOR_NS \
705	ENABLE_SME_FOR_NS \
706	ENABLE_SME2_FOR_NS \
707	ENABLE_SVE_FOR_NS \
708	ENABLE_TRF_FOR_NS \
709	FW_ENC_STATUS \
710	NR_OF_FW_BANKS \
711	NR_OF_IMAGES_IN_FW_BANK \
712	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
713	TWED_DELAY \
714	ENABLE_FEAT_TWED \
715	SVE_VECTOR_LEN \
716	IMPDEF_SYSREG_TRAP \
717	W \
718)))
719
720ifdef KEY_SIZE
721        $(eval $(call assert_numeric,KEY_SIZE))
722endif
723
724ifeq ($(filter $(SANITIZE_UB), on off trap),)
725        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
726endif
727
728################################################################################
729# Add definitions to the cpp preprocessor based on the current build options.
730# This is done after including the platform specific makefile to allow the
731# platform to overwrite the default options
732################################################################################
733
734$(eval $(call add_defines,\
735    $(sort \
736	ALLOW_RO_XLAT_TABLES \
737	ARM_ARCH_MAJOR \
738	ARM_ARCH_MINOR \
739	BL2_ENABLE_SP_LOAD \
740	COLD_BOOT_SINGLE_CPU \
741	$(CPU_FLAG_LIST) \
742	CTX_INCLUDE_AARCH32_REGS \
743	CTX_INCLUDE_FPREGS \
744	CTX_INCLUDE_SVE_REGS \
745	CTX_INCLUDE_PAUTH_REGS \
746	CTX_INCLUDE_MPAM_REGS \
747	EL3_EXCEPTION_HANDLING \
748	CTX_INCLUDE_EL2_REGS \
749	CTX_INCLUDE_NEVE_REGS \
750	DEBUG \
751	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
752	DISABLE_MTPMU \
753	ENABLE_FEAT_AMU \
754	ENABLE_AMU_AUXILIARY_COUNTERS \
755	AMU_RESTRICT_COUNTERS \
756	ENABLE_ASSERTIONS \
757	ENABLE_BTI \
758	ENABLE_FEAT_DEBUGV8P9 \
759	ENABLE_FEAT_MPAM \
760	ENABLE_FEAT_MPAM_PE_BW_CTRL \
761	ENABLE_PAUTH \
762	ENABLE_FEAT_PAUTH_LR \
763	ENABLE_PIE \
764	ENABLE_PMF \
765	ENABLE_PSCI_STAT \
766	ENABLE_RME \
767	RMMD_ENABLE_EL3_TOKEN_SIGN \
768	RMMD_ENABLE_IDE_KEY_PROG \
769	ENABLE_RUNTIME_INSTRUMENTATION \
770	ENABLE_SME_FOR_NS \
771	ENABLE_SME2_FOR_NS \
772	ENABLE_SME_FOR_SWD \
773	ENABLE_SPE_FOR_NS \
774	ENABLE_SVE_FOR_NS \
775	ENABLE_SVE_FOR_SWD \
776	ENABLE_FEAT_RAS \
777	FFH_SUPPORT \
778	ENCRYPT_BL31 \
779	ENCRYPT_BL32 \
780	ERROR_DEPRECATED \
781	FAULT_INJECTION_SUPPORT \
782	GICV2_G0_FOR_EL3 \
783	HANDLE_EA_EL3_FIRST_NS \
784	HW_ASSISTED_COHERENCY \
785	LOG_LEVEL \
786	MEASURED_BOOT \
787	DISCRETE_TPM \
788	DICE_PROTECTION_ENVIRONMENT \
789	DRTM_SUPPORT \
790	NS_TIMER_SWITCH \
791	PL011_GENERIC_UART \
792	PLAT_EXTRA_LD_SCRIPT \
793	PLAT_${PLAT} \
794	PROGRAMMABLE_RESET_ADDRESS \
795	PSCI_EXTENDED_STATE_ID \
796	PSCI_OS_INIT_MODE \
797	ARCH_FEATURE_AVAILABILITY \
798	RESET_TO_BL31 \
799	RME_GPT_BITLOCK_BLOCK \
800	RME_GPT_MAX_BLOCK \
801	SEPARATE_CODE_AND_RODATA \
802	SEPARATE_BL2_FIP \
803	SEPARATE_BL2_NOLOAD_REGION \
804	SEPARATE_NOBITS_REGION \
805	SEPARATE_RWDATA_REGION \
806	SEPARATE_SIMD_SECTION \
807	RECLAIM_INIT_CODE \
808	SPD_${SPD} \
809	SPIN_ON_BL1_EXIT \
810	SPM_MM \
811	SPMC_AT_EL3 \
812	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
813	SPMC_AT_EL3_SEL0_SP \
814	SPMD_SPM_AT_SEL2 \
815	TRANSFER_LIST \
816	TRUSTED_BOARD_BOOT \
817	TRNG_SUPPORT \
818	ERRATA_ABI_SUPPORT \
819	ERRATA_NON_ARM_INTERCONNECT \
820	USE_COHERENT_MEM \
821	USE_DEBUGFS \
822	ARM_IO_IN_DTB \
823	SDEI_IN_FCONF \
824	SEC_INT_DESC_IN_FCONF \
825	USE_ROMLIB \
826	USE_TBBR_DEFS \
827	USE_KERNEL_DT_CONVENTION \
828	WARMBOOT_ENABLE_DCACHE_EARLY \
829	RESET_TO_BL2 \
830	BL2_RUNS_AT_EL3	\
831	BL2_IN_XIP_MEM \
832	BL2_INV_DCACHE \
833	USE_SPINLOCK_CAS \
834	ERRATA_SPECULATIVE_AT \
835	ERRATA_SME_POWER_DOWN \
836	RAS_TRAP_NS_ERR_REC_ACCESS \
837	COT_DESC_IN_DTB \
838	USE_SP804_TIMER \
839	ENABLE_FEAT_RNG \
840	ENABLE_FEAT_RNG_TRAP \
841	ENABLE_FEAT_SB \
842	ENABLE_FEAT_DIT \
843	NR_OF_FW_BANKS \
844	NR_OF_IMAGES_IN_FW_BANK \
845	PSA_FWU_SUPPORT \
846	PSA_FWU_METADATA_FW_STORE_DESC \
847	ENABLE_BRBE_FOR_NS \
848	ENABLE_TRBE_FOR_NS \
849	ENABLE_SYS_REG_TRACE_FOR_NS \
850	ENABLE_TRF_FOR_NS \
851	ENABLE_FEAT_AIE \
852	ENABLE_FEAT_HCX \
853	ENABLE_MPMM \
854	ENABLE_FEAT_FGT \
855	ENABLE_FEAT_FGT2 \
856	ENABLE_FEAT_FGWTE3 \
857	ENABLE_FEAT_FPMR \
858	ENABLE_FEAT_ECV \
859	ENABLE_FEAT_EBEP \
860	ENABLE_FEAT_AMUv1p1 \
861	ENABLE_FEAT_SEL2 \
862	ENABLE_FEAT_VHE \
863	ENABLE_FEAT_CLRBHB \
864	ENABLE_FEAT_CPA2 \
865	ENABLE_FEAT_CSV2_2 \
866	ENABLE_FEAT_CSV2_3 \
867	ENABLE_FEAT_LS64_ACCDATA \
868	ENABLE_FEAT_MEC \
869	ENABLE_FEAT_PAN \
870	ENABLE_FEAT_TCR2 \
871	ENABLE_FEAT_THE \
872	ENABLE_FEAT_S2PIE \
873	ENABLE_FEAT_S1PIE \
874	ENABLE_FEAT_S2POE \
875	ENABLE_FEAT_S1POE \
876	ENABLE_FEAT_SCTLR2 \
877	ENABLE_FEAT_D128 \
878	ENABLE_FEAT_GCS \
879	ENABLE_FEAT_MOPS \
880	ENABLE_FEAT_GCIE \
881	ENABLE_FEAT_MTE2 \
882	ENABLE_FEAT_PFAR \
883	FEATURE_DETECTION \
884	TWED_DELAY \
885	ENABLE_FEAT_TWED \
886	CONDITIONAL_CMO \
887	IMPDEF_SYSREG_TRAP \
888	SVE_VECTOR_LEN \
889	ENABLE_SPMD_LP \
890	PSA_CRYPTO	\
891	ENABLE_CONSOLE_GETC \
892	INIT_UNUSED_NS_EL2	\
893	PLATFORM_REPORT_CTX_MEM_USE \
894	EARLY_CONSOLE \
895	PRESERVE_DSU_PMU_REGS \
896	HOB_LIST \
897	HW_CONFIG_BASE \
898	LFA_SUPPORT \
899)))
900
901ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
902ifeq (${DEBUG}, 0)
903        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
904        override PLATFORM_REPORT_CTX_MEM_USE := 0
905endif
906endif
907
908ifeq (${SANITIZE_UB},trap)
909        $(eval $(call add_define,MONITOR_TRAPS))
910endif #(SANITIZE_UB)
911
912# Define the EL3_PAYLOAD_BASE flag only if it is provided.
913ifdef EL3_PAYLOAD_BASE
914        $(eval $(call add_define,EL3_PAYLOAD_BASE))
915else
916# Define the PRELOADED_BL33_BASE flag only if it is provided and
917# EL3_PAYLOAD_BASE is not defined, as it has priority.
918	ifdef PRELOADED_BL33_BASE
919                $(eval $(call add_define,PRELOADED_BL33_BASE))
920	endif
921endif #(EL3_PAYLOAD_BASE)
922
923# Define the DYN_DISABLE_AUTH flag only if set.
924ifeq (${DYN_DISABLE_AUTH},1)
925        $(eval $(call add_define,DYN_DISABLE_AUTH))
926endif
927
928ifeq ($($(ARCH)-ld-id),arm-link)
929        $(eval $(call add_define,USE_ARM_LINK))
930endif
931
932# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
933ifeq (${SPD},spmd)
934ifdef SP_LAYOUT_FILE
935	-include $(BUILD_PLAT)/sp_gen.mk
936	FIP_DEPS += sp
937	CRT_DEPS += sp
938	NEED_SP_PKG := yes
939else
940	ifeq (${SPMD_SPM_AT_SEL2},1)
941                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
942	endif
943endif #(SP_LAYOUT_FILE)
944endif #(SPD)
945
946################################################################################
947# Configure the flags for the specified compiler and linker
948################################################################################
949include ${MAKE_HELPERS_DIRECTORY}cflags.mk
950
951################################################################################
952# Build targets
953################################################################################
954
955.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
956
957all: msg_start
958
959msg_start:
960	$(s)echo "Building ${PLAT}"
961
962$(eval $(call MAKE_LIB,c))
963
964# Expand build macros for the different images
965ifeq (${NEED_BL1},yes)
966BL1_SOURCES := $(sort ${BL1_SOURCES})
967$(eval $(call MAKE_BL,bl1))
968endif #(NEED_BL1)
969
970ifeq (${NEED_BL2},yes)
971
972ifeq (${RESET_TO_BL2}, 0)
973FIP_BL2_ARGS := tb-fw
974endif
975
976BL2_SOURCES := $(sort ${BL2_SOURCES})
977
978ifeq (${SEPARATE_BL2_FIP},1)
979$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS},BL2_)), \
980	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS},BL2_)))
981else
982$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})), \
983	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
984endif #(SEPARATE_BL2_FIP)
985
986endif #(NEED_BL2)
987
988ifeq (${NEED_SCP_BL2},yes)
989$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
990endif #(NEED_SCP_BL2)
991
992ifeq (${NEED_BL31},yes)
993BL31_SOURCES += ${SPD_SOURCES}
994# Sort BL31 source files to remove duplicates
995BL31_SOURCES := $(sort ${BL31_SOURCES})
996ifneq (${DECRYPTION_SUPPORT},none)
997$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
998	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
999else
1000$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1001	$(eval $(call MAKE_BL,bl31,soc-fw)))
1002endif #(DECRYPTION_SUPPORT)
1003endif #(NEED_BL31)
1004
1005# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1006# build system will call TOOL_ADD_IMG to print a warning message and abort the
1007# process. Note that the dependency on BL32 applies to the FIP only.
1008ifeq (${NEED_BL32},yes)
1009# Sort BL32 source files to remove duplicates
1010BL32_SOURCES := $(sort ${BL32_SOURCES})
1011BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1012
1013ifneq (${DECRYPTION_SUPPORT},none)
1014$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1015	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1016else
1017$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1018	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1019endif #(DECRYPTION_SUPPORT)
1020endif #(NEED_BL32)
1021
1022# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1023# needs to be built from RMM_SOURCES.
1024ifeq (${NEED_RMM},yes)
1025# Sort RMM source files to remove duplicates
1026RMM_SOURCES := $(sort ${RMM_SOURCES})
1027BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1028
1029$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1030	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1031endif #(NEED_RMM)
1032
1033# Add the BL33 image if required by the platform
1034ifeq (${NEED_BL33},yes)
1035$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1036endif #(NEED_BL33)
1037
1038ifeq (${NEED_BL2U},yes)
1039$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1040	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1041endif #(NEED_BL2U)
1042
1043# Expand build macros for the different images
1044ifeq (${NEED_FDT},yes)
1045    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1046
1047    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1048        ifndef INITRD_BASE
1049            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1050        endif
1051
1052        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1053        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1054
1055        define $(HW_CONFIG)-after +=
1056            $(s)echo "  INITRD  $(HW_CONFIG)"
1057            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1058            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1059        endef
1060    endif
1061endif #(NEED_FDT)
1062
1063# Add Secure Partition packages
1064ifeq (${NEED_SP_PKG},yes)
1065$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1066	$(if $(host-poetry),$(q)poetry -q install --no-root)
1067	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1068sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1069	$(s)echo
1070	$(s)echo "Built SP Images successfully"
1071	$(s)echo
1072endif #(NEED_SP_PKG)
1073
1074locate-checkpatch:
1075ifndef CHECKPATCH
1076	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1077else
1078ifeq (,$(wildcard ${CHECKPATCH}))
1079	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1080endif
1081endif #(CHECKPATCH)
1082
1083clean:
1084	$(s)echo "  CLEAN"
1085	$(q)rm -rf $(BUILD_PLAT)
1086	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1087	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1088	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1089	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1090	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1091	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1092
1093realclean distclean:
1094	$(s)echo "  REALCLEAN"
1095	$(q)rm -rf $(BUILD_BASE)
1096	$(q)rm -rf $(CURDIR)/cscope.*
1097	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1098	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1099	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1100	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1101	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1102	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1103
1104checkcodebase:		locate-checkpatch
1105	$(s)echo "  CHECKING STYLE"
1106	$(q)if test -d .git ; then						\
1107		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1108		while read GIT_FILE ;					\
1109		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1110		done ;							\
1111	else								\
1112		 find . -type f -not -iwholename "*.git*"		\
1113		 -not -iwholename "*build*"				\
1114		 -not -iwholename "*libfdt*"				\
1115		 -not -iwholename "*libc*"				\
1116		 -not -iwholename "*docs*"				\
1117		 -not -iwholename "*.rst"				\
1118		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1119	fi
1120
1121checkpatch:		locate-checkpatch
1122	$(s)echo "  CHECKING STYLE"
1123	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1124		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1125	fi
1126	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1127	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1128	do								\
1129		printf "\n[*] Checking style of '$$commit'\n\n";	\
1130		( git log --format=email "$$commit~..$$commit"		\
1131			-- ${CHECK_PATHS} ;				\
1132		  git diff --format=email "$$commit~..$$commit"		\
1133			-- ${CHECK_PATHS}; ) |				\
1134			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1135	done
1136
1137certtool: ${CRTTOOL}
1138
1139${CRTTOOL}: FORCE | $$(@D)/
1140	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1141	$(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
1142	$(s)echo
1143	$(s)echo "Built $@ successfully"
1144	$(s)echo
1145
1146ifneq (${GENERATE_COT},0)
1147certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1148	$(q)${CRTTOOL} ${CRT_ARGS}
1149	$(s)echo
1150	$(s)echo "Built $@ successfully"
1151	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1152	$(s)echo
1153endif #(GENERATE_COT)
1154
1155ifeq (${SEPARATE_BL2_FIP},1)
1156${BUILD_PLAT}/${BL2_FIP_NAME}: ${BL2_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1157	$(eval ${CHECK_BL2_FIP_CMD})
1158	$(q)${FIPTOOL} create ${BL2_FIP_ARGS} $@
1159	$(q)${FIPTOOL} info $@
1160	$(s)echo
1161	$(s)echo "Built $@ successfully"
1162	$(s)echo
1163endif #(SEPARATE_BL2_FIP)
1164
1165${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} | $$(@D)/
1166	$(eval ${CHECK_FIP_CMD})
1167	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1168	$(q)${FIPTOOL} info $@
1169	$(s)echo
1170	$(s)echo "Built $@ successfully"
1171	$(s)echo
1172
1173ifneq (${GENERATE_COT},0)
1174fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1175	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1176	$(s)echo
1177	$(s)echo "Built $@ successfully"
1178	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1179	$(s)echo
1180endif #(GENERATE_COT)
1181
1182ifneq (${GENERATE_COT},0)
1183bl2_certificates: ${BUILD_PLAT}/${FIP_NAME} ${BL2_CRT_DEPS} ${CRTTOOL} | ${BUILD_PLAT}/
1184	$(q)${CRTTOOL} ${BL2_CRT_ARGS}
1185	$(s)echo
1186	$(s)echo "Built $@ successfully"
1187	$(s)echo "BL2 certificates can be found in ${BUILD_PLAT}"
1188	$(s)echo
1189endif #(GENERATE_COT)
1190
1191${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1192	$(eval ${CHECK_FWU_FIP_CMD})
1193	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1194	$(q)${FIPTOOL} info $@
1195	$(s)echo
1196	$(s)echo "Built $@ successfully"
1197	$(s)echo
1198
1199fiptool: ${FIPTOOL}
1200ifeq (${SEPARATE_BL2_FIP},1)
1201bl2_fip: ${BUILD_PLAT}/${BL2_FIP_NAME}
1202fip: bl2_fip
1203else
1204fip: ${BUILD_PLAT}/${FIP_NAME}
1205endif #(SEPARATE_BL2_FIP)
1206fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1207
1208# symlink for compatibility before tools were in the build directory
1209${FIPTOOL}: FORCE | $$(@D)/
1210	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1211	$(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
1212
1213$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB) | $$(@D)/
1214	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_LIB=$(CRYPTO_LIB) ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1215
1216memmap: all
1217	$(if $(host-poetry),$(q)poetry -q install --no-root)
1218	$(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
1219
1220tl: ${BUILD_PLAT}/tl.bin
1221${BUILD_PLAT}/tl.bin: ${HW_CONFIG} | $$(@D)/
1222	$(if $(host-poetry),$(q)poetry -q install --no-root)
1223	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1224
1225doc:
1226	$(s)echo "  BUILD DOCUMENTATION"
1227	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1228	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} BUILDDIR=$(abspath ${BUILD_BASE}/docs) html
1229
1230enctool: ${ENCTOOL}
1231
1232${ENCTOOL}: FORCE | $$(@D)/
1233	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1234	$(s)echo
1235	$(s)echo "Built $@ successfully"
1236	$(s)echo
1237
1238cscope:
1239	$(s)echo "  CSCOPE"
1240	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1241	$(q)cscope -b -q -k
1242
1243help:
1244	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1245	$(s)echo ""
1246	$(s)echo "PLAT is used to specify which platform you wish to build."
1247	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1248	$(s)echo ""
1249	$(s)echo "platform = ${PLATFORM_LIST}"
1250	$(s)echo ""
1251	$(s)echo "Please refer to the User Guide for a list of all supported options."
1252	$(s)echo "Note that the build system doesn't track dependencies for build "
1253	$(s)echo "options. Therefore, if any of the build options are changed "
1254	$(s)echo "from a previous build, a clean build must be performed."
1255	$(s)echo ""
1256	$(s)echo "Supported Targets:"
1257	$(s)echo "  all            Build all individual bootloader binaries"
1258	$(s)echo "  bl1            Build the BL1 binary"
1259	$(s)echo "  bl2            Build the BL2 binary"
1260	$(s)echo "  bl2u           Build the BL2U binary"
1261	$(s)echo "  bl31           Build the BL31 binary"
1262	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1263	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1264	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1265	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1266	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1267	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1268	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1269	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1270	$(s)echo "  clean          Clean the build for the selected platform"
1271	$(s)echo "  cscope         Generate cscope index"
1272	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1273	$(s)echo "  certtool       Build the Certificate generation tool"
1274	$(s)echo "  enctool        Build the Firmware encryption tool"
1275	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1276	$(s)echo "  sp             Build the Secure Partition Packages"
1277	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1278	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1279	$(s)echo "  memmap         Print the memory map of the built binaries"
1280	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1281	$(s)echo ""
1282	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1283	$(s)echo ""
1284	$(s)echo "example: build all targets for the FVP platform:"
1285	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1286
1287.PHONY: FORCE
1288FORCE:;
1289