1# 2# Copyright (c) 2013-2019, 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 := 2 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 29include ${MAKE_HELPERS_DIRECTORY}defaults.mk 30 31# Assertions enabled for DEBUG builds by default 32ENABLE_ASSERTIONS := ${DEBUG} 33ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION} 34PLAT := ${DEFAULT_PLAT} 35 36################################################################################ 37# Checkpatch script options 38################################################################################ 39 40CHECKCODE_ARGS := --no-patch 41# Do not check the coding style on imported library files or documentation files 42INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 43 include/lib/libfdt \ 44 include/lib/libc, \ 45 $(wildcard include/lib/*))) 46INC_DIRS_TO_CHECK := $(sort $(filter-out \ 47 include/lib, \ 48 $(wildcard include/*))) 49LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 50 lib/compiler-rt \ 51 lib/libfdt% \ 52 lib/libc, \ 53 $(wildcard lib/*))) 54ROOT_DIRS_TO_CHECK := $(sort $(filter-out \ 55 lib \ 56 include \ 57 docs \ 58 %.rst, \ 59 $(wildcard *))) 60CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \ 61 ${INC_DIRS_TO_CHECK} \ 62 ${INC_LIB_DIRS_TO_CHECK} \ 63 ${LIB_DIRS_TO_CHECK} 64 65 66################################################################################ 67# Process build options 68################################################################################ 69 70# Verbose flag 71ifeq (${V},0) 72 Q:=@ 73 ECHO:=@echo 74 CHECKCODE_ARGS += --no-summary --terse 75else 76 Q:= 77 ECHO:=$(ECHO_QUIET) 78endif 79 80ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) 81 Q:=@ 82 ECHO:=$(ECHO_QUIET) 83endif 84 85export Q ECHO 86 87# Process Debug flag 88$(eval $(call add_define,DEBUG)) 89ifneq (${DEBUG}, 0) 90 BUILD_TYPE := debug 91 TF_CFLAGS += -g 92 93 ifneq ($(findstring clang,$(notdir $(CC))),) 94 ASFLAGS += -g 95 else 96 ASFLAGS += -g -Wa,--gdwarf-2 97 endif 98 99 # Use LOG_LEVEL_INFO by default for debug builds 100 LOG_LEVEL := 40 101else 102 BUILD_TYPE := release 103 # Use LOG_LEVEL_NOTICE by default for release builds 104 LOG_LEVEL := 20 105endif 106 107# Default build string (git branch and commit) 108ifeq (${BUILD_STRING},) 109 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null) 110endif 111VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING} 112 113# The cert_create tool cannot generate certificates individually, so we use the 114# target 'certificates' to create them all 115ifneq (${GENERATE_COT},0) 116 FIP_DEPS += certificates 117 FWU_FIP_DEPS += fwu_certificates 118endif 119 120# Process BRANCH_PROTECTION value and set 121# Pointer Authentication and Branch Target Identification flags 122ifeq (${BRANCH_PROTECTION},0) 123 # Default value turns off all types of branch protection 124 BP_OPTION := none 125else ifneq (${ARCH},aarch64) 126 $(error BRANCH_PROTECTION requires AArch64) 127else ifeq (${BRANCH_PROTECTION},1) 128 # Enables all types of branch protection features 129 BP_OPTION := standard 130 ENABLE_BTI := 1 131 ENABLE_PAUTH := 1 132else ifeq (${BRANCH_PROTECTION},2) 133 # Return address signing to its standard level 134 BP_OPTION := pac-ret 135 ENABLE_PAUTH := 1 136else ifeq (${BRANCH_PROTECTION},3) 137 # Extend the signing to include leaf functions 138 BP_OPTION := pac-ret+leaf 139 ENABLE_PAUTH := 1 140else 141 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION}) 142endif 143 144# USE_SPINLOCK_CAS requires AArch64 build 145ifeq (${USE_SPINLOCK_CAS},1) 146ifneq (${ARCH},aarch64) 147 $(error USE_SPINLOCK_CAS requires AArch64) 148else 149 $(info USE_SPINLOCK_CAS is an experimental feature) 150endif 151endif 152 153################################################################################ 154# Toolchain 155################################################################################ 156 157HOSTCC := gcc 158export HOSTCC 159 160CC := ${CROSS_COMPILE}gcc 161CPP := ${CROSS_COMPILE}cpp 162AS := ${CROSS_COMPILE}gcc 163AR := ${CROSS_COMPILE}ar 164LINKER := ${CROSS_COMPILE}ld 165OC := ${CROSS_COMPILE}objcopy 166OD := ${CROSS_COMPILE}objdump 167NM := ${CROSS_COMPILE}nm 168PP := ${CROSS_COMPILE}gcc -E 169DTC := dtc 170 171# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH). 172ifneq ($(strip $(wildcard ${LD}.bfd) \ 173 $(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),) 174LINKER := ${LINKER}.bfd 175endif 176 177ifeq (${ARM_ARCH_MAJOR},7) 178target32-directive = -target arm-none-eabi 179# Will set march32-directive from platform configuration 180else 181target32-directive = -target armv8a-none-eabi 182 183# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option 184ifeq (${ARM_ARCH_MINOR},0) 185march32-directive = -march=armv8-a 186march64-directive = -march=armv8-a 187else 188march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a 189march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a 190endif 191endif 192 193ifneq ($(findstring armclang,$(notdir $(CC))),) 194TF_CFLAGS_aarch32 = -target arm-arm-none-eabi $(march32-directive) 195TF_CFLAGS_aarch64 = -target aarch64-arm-none-eabi $(march64-directive) 196LD = $(LINKER) 197AS = $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) 198CPP = $(CC) -E $(TF_CFLAGS_$(ARCH)) 199PP = $(CC) -E $(TF_CFLAGS_$(ARCH)) 200else ifneq ($(findstring clang,$(notdir $(CC))),) 201TF_CFLAGS_aarch32 = $(target32-directive) $(march32-directive) 202TF_CFLAGS_aarch64 = -target aarch64-elf $(march64-directive) 203LD = $(LINKER) 204AS = $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) 205CPP = $(CC) -E 206PP = $(CC) -E 207else 208TF_CFLAGS_aarch32 = $(march32-directive) 209TF_CFLAGS_aarch64 = $(march64-directive) 210LD = $(LINKER) 211endif 212 213ifeq (${AARCH32_INSTRUCTION_SET},A32) 214TF_CFLAGS_aarch32 += -marm 215else ifeq (${AARCH32_INSTRUCTION_SET},T32) 216TF_CFLAGS_aarch32 += -mthumb 217else 218$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET}) 219endif 220 221TF_CFLAGS_aarch32 += -mno-unaligned-access 222TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align 223 224ifneq (${BP_OPTION},none) 225TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION} 226endif 227 228ASFLAGS_aarch32 = $(march32-directive) 229ASFLAGS_aarch64 = $(march64-directive) 230 231# General warnings 232WARNINGS := -Wall -Wmissing-include-dirs -Wunused \ 233 -Wdisabled-optimization -Wvla \ 234 -Wno-unused-parameter 235 236# Additional warnings 237# Level 1 238WARNING1 := -Wextra 239WARNING1 += -Wmissing-declarations 240WARNING1 += -Wmissing-format-attribute 241WARNING1 += -Wmissing-prototypes 242WARNING1 += -Wold-style-definition 243WARNING1 += -Wunused-const-variable 244 245WARNING2 := -Waggregate-return 246WARNING2 += -Wcast-align 247WARNING2 += -Wnested-externs 248WARNING2 += -Wshadow 249WARNING2 += -Wlogical-op 250WARNING2 += -Wmissing-field-initializers 251WARNING2 += -Wsign-compare 252 253WARNING3 := -Wbad-function-cast 254WARNING3 += -Wcast-qual 255WARNING3 += -Wconversion 256WARNING3 += -Wpacked 257WARNING3 += -Wpadded 258WARNING3 += -Wpointer-arith 259WARNING3 += -Wredundant-decls 260WARNING3 += -Wswitch-default 261 262ifeq (${W},1) 263WARNINGS += $(WARNING1) 264else ifeq (${W},2) 265WARNINGS += $(WARNING1) $(WARNING2) 266else ifeq (${W},3) 267WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3) 268endif 269 270# Compiler specific warnings 271ifeq ($(findstring clang,$(notdir $(CC))),) 272# not using clang 273WARNINGS += -Wunused-but-set-variable \ 274 -Wmaybe-uninitialized \ 275 -Wpacked-bitfield-compat \ 276 -Wshift-overflow=2 277else 278# using clang 279WARNINGS += -Wshift-overflow -Wshift-sign-overflow 280endif 281 282ifneq (${E},0) 283ERRORS := -Werror 284endif 285 286CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \ 287 $(ERRORS) $(WARNINGS) 288ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ 289 -ffreestanding -Wa,--fatal-warnings 290TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \ 291 -ffreestanding -fno-builtin -std=gnu99 \ 292 -Os -ffunction-sections -fdata-sections 293 294ifeq (${SANITIZE_UB},on) 295TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover 296endif 297ifeq (${SANITIZE_UB},trap) 298TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \ 299 -fsanitize-undefined-trap-on-error 300endif 301 302GCC_V_OUTPUT := $(shell $(CC) -v 2>&1) 303 304ifneq ($(findstring armlink,$(notdir $(LD))),) 305TF_LDFLAGS += --diag_error=warning --lto_level=O1 306TF_LDFLAGS += --remove --info=unused,unusedsymbols 307else 308TF_LDFLAGS += --fatal-warnings -O1 309TF_LDFLAGS += --gc-sections 310endif 311TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) 312 313DTC_FLAGS += -I dts -O dtb 314DTC_CPPFLAGS += -nostdinc -Iinclude -undef -x assembler-with-cpp 315 316################################################################################ 317# Common sources and include directories 318################################################################################ 319include lib/compiler-rt/compiler-rt.mk 320 321BL_COMMON_SOURCES += common/bl_common.c \ 322 common/tf_log.c \ 323 common/${ARCH}/debug.S \ 324 drivers/console/multi_console.c \ 325 lib/${ARCH}/cache_helpers.S \ 326 lib/${ARCH}/misc_helpers.S \ 327 plat/common/plat_bl_common.c \ 328 plat/common/plat_log_common.c \ 329 plat/common/${ARCH}/plat_common.c \ 330 plat/common/${ARCH}/platform_helpers.S \ 331 ${COMPILER_RT_SRCS} 332 333ifeq ($(notdir $(CC)),armclang) 334BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S 335endif 336 337ifeq (${SANITIZE_UB},on) 338BL_COMMON_SOURCES += plat/common/ubsan.c 339endif 340 341INCLUDES += -Iinclude \ 342 -Iinclude/arch/${ARCH} \ 343 -Iinclude/lib/cpus/${ARCH} \ 344 -Iinclude/lib/el3_runtime/${ARCH} \ 345 ${PLAT_INCLUDES} \ 346 ${SPD_INCLUDES} 347 348include common/backtrace/backtrace.mk 349 350################################################################################ 351# Generic definitions 352################################################################################ 353 354include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk 355 356BUILD_BASE := ./build 357BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE} 358 359SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*)))) 360 361# Platforms providing their own TBB makefile may override this value 362INCLUDE_TBBR_MK := 1 363 364 365################################################################################ 366# Include SPD Makefile if one has been specified 367################################################################################ 368 369ifneq (${SPD},none) 370ifeq (${ARCH},aarch32) 371 $(error "Error: SPD is incompatible with AArch32.") 372endif 373ifdef EL3_PAYLOAD_BASE 374 $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.") 375 $(warning "The SPD and its BL32 companion will be present but ignored.") 376endif 377 # We expect to locate an spd.mk under the specified SPD directory 378 SPD_MAKE := $(wildcard services/spd/${SPD}/${SPD}.mk) 379 380 ifeq (${SPD_MAKE},) 381 $(error Error: No services/spd/${SPD}/${SPD}.mk located) 382 endif 383 $(info Including ${SPD_MAKE}) 384 include ${SPD_MAKE} 385 386 # If there's BL32 companion for the chosen SPD, we expect that the SPD's 387 # Makefile would set NEED_BL32 to "yes". In this case, the build system 388 # supports two mutually exclusive options: 389 # * BL32 is built from source: then BL32_SOURCES must contain the list 390 # of source files to build BL32 391 # * BL32 is a prebuilt binary: then BL32 must point to the image file 392 # that will be included in the FIP 393 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence 394 # over the sources. 395endif 396 397################################################################################ 398# Include the platform specific Makefile after the SPD Makefile (the platform 399# makefile may use all previous definitions in this file) 400################################################################################ 401 402include ${PLAT_MAKEFILE_FULL} 403 404$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT})) 405 406ifeq (${ARM_ARCH_MAJOR},7) 407include make_helpers/armv7-a-cpus.mk 408endif 409 410ifeq ($(ENABLE_PIE),1) 411 TF_CFLAGS += -fpie 412 TF_LDFLAGS += -pie --no-dynamic-linker 413else 414 PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT}) 415 ifneq ($(PIE_FOUND),) 416 TF_CFLAGS += -fno-PIE 417 endif 418endif 419 420# Include the CPU specific operations makefile, which provides default 421# values for all CPU errata workarounds and CPU specific optimisations. 422# This can be overridden by the platform. 423include lib/cpus/cpu-ops.mk 424 425ifeq (${ARCH},aarch32) 426NEED_BL32 := yes 427 428################################################################################ 429# Build `AARCH32_SP` as BL32 image for AArch32 430################################################################################ 431ifneq (${AARCH32_SP},none) 432# We expect to locate an sp.mk under the specified AARCH32_SP directory 433AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk) 434 435ifeq (${AARCH32_SP_MAKE},) 436 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located) 437endif 438 439$(info Including ${AARCH32_SP_MAKE}) 440include ${AARCH32_SP_MAKE} 441endif 442 443endif 444 445################################################################################ 446# Include libc if not overridden 447################################################################################ 448ifeq (${OVERRIDE_LIBC},0) 449include lib/libc/libc.mk 450endif 451 452################################################################################ 453# Check incompatible options 454################################################################################ 455 456ifdef EL3_PAYLOAD_BASE 457 ifdef PRELOADED_BL33_BASE 458 $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \ 459 incompatible build options. EL3_PAYLOAD_BASE has priority.") 460 endif 461 ifneq (${GENERATE_COT},0) 462 $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.") 463 endif 464 ifneq (${TRUSTED_BOARD_BOOT},0) 465 $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.") 466 endif 467endif 468 469ifeq (${NEED_BL33},yes) 470 ifdef EL3_PAYLOAD_BASE 471 $(warning "BL33 image is not needed when option \ 472 BL33_PAYLOAD_BASE is used and won't be added to the FIP file.") 473 endif 474 ifdef PRELOADED_BL33_BASE 475 $(warning "BL33 image is not needed when option \ 476 PRELOADED_BL33_BASE is used and won't be added to the FIP \ 477 file.") 478 endif 479endif 480 481# When building for systems with hardware-assisted coherency, there's no need to 482# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too. 483ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1) 484$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY) 485endif 486 487#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1. 488ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1) 489$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled") 490endif 491 492# For RAS_EXTENSION, require that EAs are handled in EL3 first 493ifeq ($(RAS_EXTENSION),1) 494 ifneq ($(HANDLE_EA_EL3_FIRST),1) 495 $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1) 496 endif 497endif 498 499# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled 500ifeq ($(FAULT_INJECTION_SUPPORT),1) 501 ifneq ($(RAS_EXTENSION),1) 502 $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1) 503 endif 504endif 505 506# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1 507ifeq ($(DYN_DISABLE_AUTH), 1) 508 ifeq (${TRUSTED_BOARD_BOOT}, 0) 509 $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.") 510 endif 511endif 512 513# If pointer authentication is used in the firmware, make sure that all the 514# registers associated to it are also saved and restored. 515# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1. 516ifeq ($(ENABLE_PAUTH),1) 517 ifeq ($(CTX_INCLUDE_PAUTH_REGS),0) 518 $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1) 519 endif 520endif 521 522ifeq ($(CTX_INCLUDE_PAUTH_REGS),1) 523 ifneq (${ARCH},aarch64) 524 $(error CTX_INCLUDE_PAUTH_REGS requires AArch64) 525 else 526 $(info CTX_INCLUDE_PAUTH_REGS is an experimental feature) 527 endif 528endif 529 530ifeq ($(ENABLE_PAUTH),1) 531 $(info Pointer Authentication is an experimental feature) 532endif 533 534ifeq ($(ENABLE_BTI),1) 535 $(info Branch Protection is an experimental feature) 536endif 537 538ifeq ($(CTX_INCLUDE_MTE_REGS),1) 539 ifneq (${ARCH},aarch64) 540 $(error CTX_INCLUDE_MTE_REGS requires AArch64) 541 else 542 $(info CTX_INCLUDE_MTE_REGS is an experimental feature) 543 endif 544endif 545 546################################################################################ 547# Process platform overrideable behaviour 548################################################################################ 549 550# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and 551# Certificate generation tools. This flag can be overridden by the platform. 552ifdef BL2_SOURCES 553 ifdef EL3_PAYLOAD_BASE 554 # If booting an EL3 payload there is no need for a BL33 image 555 # in the FIP file. 556 NEED_BL33 := no 557 else 558 ifdef PRELOADED_BL33_BASE 559 # If booting a BL33 preloaded image there is no need of 560 # another one in the FIP file. 561 NEED_BL33 := no 562 else 563 NEED_BL33 ?= yes 564 endif 565 endif 566endif 567 568# If SCP_BL2 is given, we always want FIP to include it. 569ifdef SCP_BL2 570 NEED_SCP_BL2 := yes 571endif 572 573# For AArch32, BL31 is not currently supported. 574ifneq (${ARCH},aarch32) 575 ifdef BL31_SOURCES 576 # When booting an EL3 payload, there is no need to compile the BL31 image nor 577 # put it in the FIP. 578 ifndef EL3_PAYLOAD_BASE 579 NEED_BL31 := yes 580 endif 581 endif 582endif 583 584# Process TBB related flags 585ifneq (${GENERATE_COT},0) 586 # Common cert_create options 587 ifneq (${CREATE_KEYS},0) 588 $(eval CRT_ARGS += -n) 589 $(eval FWU_CRT_ARGS += -n) 590 ifneq (${SAVE_KEYS},0) 591 $(eval CRT_ARGS += -k) 592 $(eval FWU_CRT_ARGS += -k) 593 endif 594 endif 595 # Include TBBR makefile (unless the platform indicates otherwise) 596 ifeq (${INCLUDE_TBBR_MK},1) 597 include make_helpers/tbbr/tbbr_tools.mk 598 endif 599endif 600 601ifneq (${FIP_ALIGN},0) 602FIP_ARGS += --align ${FIP_ALIGN} 603endif 604 605################################################################################ 606# Include libraries' Makefile that are used in all BL 607################################################################################ 608 609include lib/stack_protector/stack_protector.mk 610 611################################################################################ 612# Auxiliary tools (fiptool, cert_create, etc) 613################################################################################ 614 615# Variables for use with Certificate Generation Tool 616CRTTOOLPATH ?= tools/cert_create 617CRTTOOL ?= ${CRTTOOLPATH}/cert_create${BIN_EXT} 618 619# Variables for use with Firmware Image Package 620FIPTOOLPATH ?= tools/fiptool 621FIPTOOL ?= ${FIPTOOLPATH}/fiptool${BIN_EXT} 622 623# Variables for use with sptool 624SPTOOLPATH ?= tools/sptool 625SPTOOL ?= ${SPTOOLPATH}/sptool${BIN_EXT} 626 627# Variables for use with ROMLIB 628ROMLIBPATH ?= lib/romlib 629 630################################################################################ 631# Include BL specific makefiles 632################################################################################ 633ifdef BL1_SOURCES 634NEED_BL1 := yes 635include bl1/bl1.mk 636endif 637 638ifdef BL2_SOURCES 639NEED_BL2 := yes 640include bl2/bl2.mk 641endif 642 643ifdef BL2U_SOURCES 644NEED_BL2U := yes 645include bl2u/bl2u.mk 646endif 647 648ifeq (${NEED_BL31},yes) 649ifdef BL31_SOURCES 650include bl31/bl31.mk 651endif 652endif 653 654ifdef FDT_SOURCES 655NEED_FDT := yes 656endif 657 658################################################################################ 659# Build options checks 660################################################################################ 661 662$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU)) 663$(eval $(call assert_boolean,CREATE_KEYS)) 664$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS)) 665$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS)) 666$(eval $(call assert_boolean,CTX_INCLUDE_PAUTH_REGS)) 667$(eval $(call assert_boolean,CTX_INCLUDE_MTE_REGS)) 668$(eval $(call assert_boolean,DEBUG)) 669$(eval $(call assert_boolean,DYN_DISABLE_AUTH)) 670$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING)) 671$(eval $(call assert_boolean,ENABLE_AMU)) 672$(eval $(call assert_boolean,ENABLE_ASSERTIONS)) 673$(eval $(call assert_boolean,ENABLE_MPAM_FOR_LOWER_ELS)) 674$(eval $(call assert_boolean,ENABLE_PIE)) 675$(eval $(call assert_boolean,ENABLE_PMF)) 676$(eval $(call assert_boolean,ENABLE_PSCI_STAT)) 677$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION)) 678$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS)) 679$(eval $(call assert_boolean,ENABLE_SPM)) 680$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS)) 681$(eval $(call assert_boolean,ERROR_DEPRECATED)) 682$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT)) 683$(eval $(call assert_boolean,GENERATE_COT)) 684$(eval $(call assert_boolean,GICV2_G0_FOR_EL3)) 685$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST)) 686$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY)) 687$(eval $(call assert_boolean,NS_TIMER_SWITCH)) 688$(eval $(call assert_boolean,OVERRIDE_LIBC)) 689$(eval $(call assert_boolean,PL011_GENERIC_UART)) 690$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS)) 691$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID)) 692$(eval $(call assert_boolean,RAS_EXTENSION)) 693$(eval $(call assert_boolean,RESET_TO_BL31)) 694$(eval $(call assert_boolean,SAVE_KEYS)) 695$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA)) 696$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT)) 697$(eval $(call assert_boolean,SPM_MM)) 698$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT)) 699$(eval $(call assert_boolean,USE_COHERENT_MEM)) 700$(eval $(call assert_boolean,USE_ROMLIB)) 701$(eval $(call assert_boolean,USE_TBBR_DEFS)) 702$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY)) 703$(eval $(call assert_boolean,BL2_AT_EL3)) 704$(eval $(call assert_boolean,BL2_IN_XIP_MEM)) 705$(eval $(call assert_boolean,BL2_INV_DCACHE)) 706$(eval $(call assert_boolean,USE_SPINLOCK_CAS)) 707 708$(eval $(call assert_numeric,ARM_ARCH_MAJOR)) 709$(eval $(call assert_numeric,ARM_ARCH_MINOR)) 710$(eval $(call assert_numeric,BRANCH_PROTECTION)) 711 712ifdef KEY_SIZE 713 $(eval $(call assert_numeric,KEY_SIZE)) 714endif 715 716ifeq ($(filter $(SANITIZE_UB), on off trap),) 717 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap") 718endif 719 720################################################################################ 721# Add definitions to the cpp preprocessor based on the current build options. 722# This is done after including the platform specific makefile to allow the 723# platform to overwrite the default options 724################################################################################ 725 726$(eval $(call add_define,ARM_ARCH_MAJOR)) 727$(eval $(call add_define,ARM_ARCH_MINOR)) 728$(eval $(call add_define,COLD_BOOT_SINGLE_CPU)) 729$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS)) 730$(eval $(call add_define,CTX_INCLUDE_FPREGS)) 731$(eval $(call add_define,CTX_INCLUDE_PAUTH_REGS)) 732$(eval $(call add_define,EL3_EXCEPTION_HANDLING)) 733$(eval $(call add_define,CTX_INCLUDE_MTE_REGS)) 734$(eval $(call add_define,ENABLE_AMU)) 735$(eval $(call add_define,ENABLE_ASSERTIONS)) 736$(eval $(call add_define,ENABLE_BTI)) 737$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS)) 738$(eval $(call add_define,ENABLE_PAUTH)) 739$(eval $(call add_define,ENABLE_PIE)) 740$(eval $(call add_define,ENABLE_PMF)) 741$(eval $(call add_define,ENABLE_PSCI_STAT)) 742$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION)) 743$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS)) 744$(eval $(call add_define,ENABLE_SPM)) 745$(eval $(call add_define,ENABLE_SVE_FOR_NS)) 746$(eval $(call add_define,ERROR_DEPRECATED)) 747$(eval $(call add_define,FAULT_INJECTION_SUPPORT)) 748$(eval $(call add_define,GICV2_G0_FOR_EL3)) 749$(eval $(call add_define,HANDLE_EA_EL3_FIRST)) 750$(eval $(call add_define,HW_ASSISTED_COHERENCY)) 751$(eval $(call add_define,LOG_LEVEL)) 752$(eval $(call add_define,NS_TIMER_SWITCH)) 753$(eval $(call add_define,PL011_GENERIC_UART)) 754$(eval $(call add_define,PLAT_${PLAT})) 755$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS)) 756$(eval $(call add_define,PSCI_EXTENDED_STATE_ID)) 757$(eval $(call add_define,RAS_EXTENSION)) 758$(eval $(call add_define,RESET_TO_BL31)) 759$(eval $(call add_define,SEPARATE_CODE_AND_RODATA)) 760$(eval $(call add_define,RECLAIM_INIT_CODE)) 761$(eval $(call add_define,SPD_${SPD})) 762$(eval $(call add_define,SPIN_ON_BL1_EXIT)) 763$(eval $(call add_define,SPM_MM)) 764$(eval $(call add_define,TRUSTED_BOARD_BOOT)) 765$(eval $(call add_define,USE_COHERENT_MEM)) 766$(eval $(call add_define,USE_ROMLIB)) 767$(eval $(call add_define,USE_TBBR_DEFS)) 768$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY)) 769$(eval $(call add_define,BL2_AT_EL3)) 770$(eval $(call add_define,BL2_IN_XIP_MEM)) 771$(eval $(call add_define,BL2_INV_DCACHE)) 772$(eval $(call add_define,USE_SPINLOCK_CAS)) 773 774ifeq (${SANITIZE_UB},trap) 775 $(eval $(call add_define,MONITOR_TRAPS)) 776endif 777 778# Define the EL3_PAYLOAD_BASE flag only if it is provided. 779ifdef EL3_PAYLOAD_BASE 780 $(eval $(call add_define,EL3_PAYLOAD_BASE)) 781else 782 # Define the PRELOADED_BL33_BASE flag only if it is provided and 783 # EL3_PAYLOAD_BASE is not defined, as it has priority. 784 ifdef PRELOADED_BL33_BASE 785 $(eval $(call add_define,PRELOADED_BL33_BASE)) 786 endif 787endif 788 789# Define the DYN_DISABLE_AUTH flag only if set. 790ifeq (${DYN_DISABLE_AUTH},1) 791$(eval $(call add_define,DYN_DISABLE_AUTH)) 792endif 793 794ifneq ($(findstring armlink,$(notdir $(LD))),) 795$(eval $(call add_define,USE_ARM_LINK)) 796endif 797 798################################################################################ 799# Build targets 800################################################################################ 801 802.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip fwu_fip certtool dtbs 803.SUFFIXES: 804 805all: msg_start 806 807msg_start: 808 @echo "Building ${PLAT}" 809 810ifeq (${ERROR_DEPRECATED},0) 811# Check if deprecated declarations and cpp warnings should be treated as error or not. 812ifneq ($(findstring clang,$(notdir $(CC))),) 813 CPPFLAGS += -Wno-error=deprecated-declarations 814else 815 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp 816endif 817# __ASSEMBLY__ is deprecated in favor of the compiler-builtin __ASSEMBLER__. 818ASFLAGS += -D__ASSEMBLY__ 819# AARCH32/AARCH64 macros are deprecated in favor of the compiler-builtin __aarch64__. 820ifeq (${ARCH},aarch32) 821 $(eval $(call add_define,AARCH32)) 822else 823 $(eval $(call add_define,AARCH64)) 824endif 825endif # !ERROR_DEPRECATED 826 827$(eval $(call MAKE_LIB_DIRS)) 828$(eval $(call MAKE_LIB,c)) 829 830# Expand build macros for the different images 831ifeq (${NEED_BL1},yes) 832$(eval $(call MAKE_BL,1)) 833endif 834 835ifeq (${NEED_BL2},yes) 836ifeq (${BL2_AT_EL3}, 0) 837FIP_BL2_ARGS := tb-fw 838endif 839 840$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\ 841 $(eval $(call MAKE_BL,2,${FIP_BL2_ARGS}))) 842endif 843 844ifeq (${NEED_SCP_BL2},yes) 845$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw)) 846endif 847 848ifeq (${NEED_BL31},yes) 849BL31_SOURCES += ${SPD_SOURCES} 850$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\ 851 $(eval $(call MAKE_BL,31,soc-fw))) 852endif 853 854# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the 855# build system will call TOOL_ADD_IMG to print a warning message and abort the 856# process. Note that the dependency on BL32 applies to the FIP only. 857ifeq (${NEED_BL32},yes) 858 859BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1)) 860 861$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\ 862 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw))) 863endif 864 865# Add the BL33 image if required by the platform 866ifeq (${NEED_BL33},yes) 867$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 868endif 869 870ifeq (${NEED_BL2U},yes) 871$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\ 872 $(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_))) 873endif 874 875# Expand build macros for the different images 876ifeq (${NEED_FDT},yes) 877 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES))) 878endif 879 880locate-checkpatch: 881ifndef CHECKPATCH 882 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 883else 884ifeq (,$(wildcard ${CHECKPATCH})) 885 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 886endif 887endif 888 889clean: 890 @echo " CLEAN" 891 $(call SHELL_REMOVE_DIR,${BUILD_PLAT}) 892 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 893 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean 894 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 895 896realclean distclean: 897 @echo " REALCLEAN" 898 $(call SHELL_REMOVE_DIR,${BUILD_BASE}) 899 $(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*) 900 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 901 ${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean 902 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean 903 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 904 905checkcodebase: locate-checkpatch 906 @echo " CHECKING STYLE" 907 @if test -d .git ; then \ 908 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \ 909 while read GIT_FILE ; \ 910 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \ 911 done ; \ 912 else \ 913 find . -type f -not -iwholename "*.git*" \ 914 -not -iwholename "*build*" \ 915 -not -iwholename "*libfdt*" \ 916 -not -iwholename "*libc*" \ 917 -not -iwholename "*docs*" \ 918 -not -iwholename "*.rst" \ 919 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ 920 fi 921 922checkpatch: locate-checkpatch 923 @echo " CHECKING STYLE" 924 @if test -n "${CHECKPATCH_OPTS}"; then \ 925 echo " with ${CHECKPATCH_OPTS} option(s)"; \ 926 fi 927 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \ 928 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \ 929 printf "\n[*] Checking style of '$$commit'\n\n"; \ 930 git log --format=email "$$commit~..$$commit" \ 931 -- ${CHECK_PATHS} | \ 932 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 933 git diff --format=email "$$commit~..$$commit" \ 934 -- ${CHECK_PATHS} | \ 935 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 936 done 937 938certtool: ${CRTTOOL} 939 940.PHONY: ${CRTTOOL} 941${CRTTOOL}: 942 ${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH} 943 @${ECHO_BLANK_LINE} 944 @echo "Built $@ successfully" 945 @${ECHO_BLANK_LINE} 946 947ifneq (${GENERATE_COT},0) 948certificates: ${CRT_DEPS} ${CRTTOOL} 949 ${Q}${CRTTOOL} ${CRT_ARGS} 950 @${ECHO_BLANK_LINE} 951 @echo "Built $@ successfully" 952 @echo "Certificates can be found in ${BUILD_PLAT}" 953 @${ECHO_BLANK_LINE} 954endif 955 956${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} 957 ${Q}${FIPTOOL} create ${FIP_ARGS} $@ 958 ${Q}${FIPTOOL} info $@ 959 @${ECHO_BLANK_LINE} 960 @echo "Built $@ successfully" 961 @${ECHO_BLANK_LINE} 962 963ifneq (${GENERATE_COT},0) 964fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL} 965 ${Q}${CRTTOOL} ${FWU_CRT_ARGS} 966 @${ECHO_BLANK_LINE} 967 @echo "Built $@ successfully" 968 @echo "FWU certificates can be found in ${BUILD_PLAT}" 969 @${ECHO_BLANK_LINE} 970endif 971 972${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} 973 ${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@ 974 ${Q}${FIPTOOL} info $@ 975 @${ECHO_BLANK_LINE} 976 @echo "Built $@ successfully" 977 @${ECHO_BLANK_LINE} 978 979fiptool: ${FIPTOOL} 980fip: ${BUILD_PLAT}/${FIP_NAME} 981fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME} 982 983.PHONY: ${FIPTOOL} 984${FIPTOOL}: 985 ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH} 986 987sptool: ${SPTOOL} 988.PHONY: ${SPTOOL} 989${SPTOOL}: 990 ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${SPTOOLPATH} 991 992.PHONY: libraries 993romlib.bin: libraries 994 ${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all 995 996cscope: 997 @echo " CSCOPE" 998 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files 999 ${Q}cscope -b -q -k 1000 1001help: 1002 @echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]" 1003 @echo "" 1004 @echo "PLAT is used to specify which platform you wish to build." 1005 @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}" 1006 @echo "" 1007 @echo "platform = ${PLATFORM_LIST}" 1008 @echo "" 1009 @echo "Please refer to the User Guide for a list of all supported options." 1010 @echo "Note that the build system doesn't track dependencies for build " 1011 @echo "options. Therefore, if any of the build options are changed " 1012 @echo "from a previous build, a clean build must be performed." 1013 @echo "" 1014 @echo "Supported Targets:" 1015 @echo " all Build all individual bootloader binaries" 1016 @echo " bl1 Build the BL1 binary" 1017 @echo " bl2 Build the BL2 binary" 1018 @echo " bl2u Build the BL2U binary" 1019 @echo " bl31 Build the BL31 binary" 1020 @echo " bl32 Build the BL32 binary. If ARCH=aarch32, then " 1021 @echo " this builds secure payload specified by AARCH32_SP" 1022 @echo " certificates Build the certificates (requires 'GENERATE_COT=1')" 1023 @echo " fip Build the Firmware Image Package (FIP)" 1024 @echo " fwu_fip Build the FWU Firmware Image Package (FIP)" 1025 @echo " checkcodebase Check the coding style of the entire source tree" 1026 @echo " checkpatch Check the coding style on changes in the current" 1027 @echo " branch against BASE_COMMIT (default origin/master)" 1028 @echo " clean Clean the build for the selected platform" 1029 @echo " cscope Generate cscope index" 1030 @echo " distclean Remove all build artifacts for all platforms" 1031 @echo " certtool Build the Certificate generation tool" 1032 @echo " fiptool Build the Firmware Image Package (FIP) creation tool" 1033 @echo " sptool Build the Secure Partition Package creation tool" 1034 @echo " dtbs Build the Device Tree Blobs (if required for the platform)" 1035 @echo "" 1036 @echo "Note: most build targets require PLAT to be set to a specific platform." 1037 @echo "" 1038 @echo "example: build all targets for the FVP platform:" 1039 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all" 1040