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