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