1# 2# Copyright (c) 2013-2023, 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 := 8 12VERSION := ${VERSION_MAJOR}.${VERSION_MINOR} 13 14# Default goal is build all images 15.DEFAULT_GOAL := all 16 17# Avoid any implicit propagation of command line variable definitions to 18# sub-Makefiles, like CFLAGS that we reserved for the firmware images' 19# usage. Other command line options like "-s" are still propagated as usual. 20MAKEOVERRIDES = 21 22MAKE_HELPERS_DIRECTORY := make_helpers/ 23include ${MAKE_HELPERS_DIRECTORY}build_macros.mk 24include ${MAKE_HELPERS_DIRECTORY}build_env.mk 25 26################################################################################ 27# Default values for build configurations, and their dependencies 28################################################################################ 29 30include ${MAKE_HELPERS_DIRECTORY}defaults.mk 31 32# Assertions enabled for DEBUG builds by default 33ENABLE_ASSERTIONS := ${DEBUG} 34ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION} 35PLAT := ${DEFAULT_PLAT} 36 37################################################################################ 38# Checkpatch script options 39################################################################################ 40 41CHECKCODE_ARGS := --no-patch 42# Do not check the coding style on imported library files or documentation files 43INC_ARM_DIRS_TO_CHECK := $(sort $(filter-out \ 44 include/drivers/arm/cryptocell, \ 45 $(wildcard include/drivers/arm/*))) 46INC_ARM_DIRS_TO_CHECK += include/drivers/arm/cryptocell/*.h 47INC_DRV_DIRS_TO_CHECK := $(sort $(filter-out \ 48 include/drivers/arm, \ 49 $(wildcard include/drivers/*))) 50INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 51 include/lib/libfdt \ 52 include/lib/libc, \ 53 $(wildcard include/lib/*))) 54INC_DIRS_TO_CHECK := $(sort $(filter-out \ 55 include/lib \ 56 include/drivers, \ 57 $(wildcard include/*))) 58LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 59 lib/compiler-rt \ 60 lib/libfdt% \ 61 lib/libc, \ 62 lib/zlib \ 63 $(wildcard lib/*))) 64ROOT_DIRS_TO_CHECK := $(sort $(filter-out \ 65 lib \ 66 include \ 67 docs \ 68 %.rst, \ 69 $(wildcard *))) 70CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \ 71 ${INC_DIRS_TO_CHECK} \ 72 ${INC_LIB_DIRS_TO_CHECK} \ 73 ${LIB_DIRS_TO_CHECK} \ 74 ${INC_DRV_DIRS_TO_CHECK} \ 75 ${INC_ARM_DIRS_TO_CHECK} 76 77 78################################################################################ 79# Process build options 80################################################################################ 81 82# Verbose flag 83ifeq (${V},0) 84 Q:=@ 85 ECHO:=@echo 86 CHECKCODE_ARGS += --no-summary --terse 87else 88 Q:= 89 ECHO:=$(ECHO_QUIET) 90endif 91 92ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) 93 Q:=@ 94 ECHO:=$(ECHO_QUIET) 95endif 96 97export Q ECHO 98 99# The cert_create tool cannot generate certificates individually, so we use the 100# target 'certificates' to create them all 101ifneq (${GENERATE_COT},0) 102 FIP_DEPS += certificates 103 FWU_FIP_DEPS += fwu_certificates 104endif 105 106# Process BRANCH_PROTECTION value and set 107# Pointer Authentication and Branch Target Identification flags 108ifeq (${BRANCH_PROTECTION},0) 109 # Default value turns off all types of branch protection 110 BP_OPTION := none 111else ifneq (${ARCH},aarch64) 112 $(error BRANCH_PROTECTION requires AArch64) 113else ifeq (${BRANCH_PROTECTION},1) 114 # Enables all types of branch protection features 115 BP_OPTION := standard 116 ENABLE_BTI := 1 117 ENABLE_PAUTH := 1 118else ifeq (${BRANCH_PROTECTION},2) 119 # Return address signing to its standard level 120 BP_OPTION := pac-ret 121 ENABLE_PAUTH := 1 122else ifeq (${BRANCH_PROTECTION},3) 123 # Extend the signing to include leaf functions 124 BP_OPTION := pac-ret+leaf 125 ENABLE_PAUTH := 1 126else ifeq (${BRANCH_PROTECTION},4) 127 # Turn on branch target identification mechanism 128 BP_OPTION := bti 129 ENABLE_BTI := 1 130else 131 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION}) 132endif 133 134# FEAT_RME 135ifeq (${ENABLE_RME},1) 136# RME doesn't support PIE 137ifneq (${ENABLE_PIE},0) 138 $(error ENABLE_RME does not support PIE) 139endif 140# RME doesn't support BRBE 141ifneq (${ENABLE_BRBE_FOR_NS},0) 142 $(error ENABLE_RME does not support BRBE.) 143endif 144# RME requires AARCH64 145ifneq (${ARCH},aarch64) 146 $(error ENABLE_RME requires AArch64) 147endif 148# RME requires el2 context to be saved for now. 149CTX_INCLUDE_EL2_REGS := 1 150CTX_INCLUDE_AARCH32_REGS := 0 151ARM_ARCH_MAJOR := 8 152ARM_ARCH_MINOR := 5 153ENABLE_FEAT_ECV = 1 154ENABLE_FEAT_FGT = 1 155 156# RME enables CSV2_2 extension by default. 157ENABLE_FEAT_CSV2_2 = 1 158 159endif 160 161# USE_SPINLOCK_CAS requires AArch64 build 162ifeq (${USE_SPINLOCK_CAS},1) 163ifneq (${ARCH},aarch64) 164 $(error USE_SPINLOCK_CAS requires AArch64) 165endif 166endif 167 168# USE_DEBUGFS experimental feature recommended only in debug builds 169ifeq (${USE_DEBUGFS},1) 170ifeq (${DEBUG},1) 171 $(warning DEBUGFS experimental feature is enabled.) 172else 173 $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY) 174endif 175endif 176 177ifneq (${DECRYPTION_SUPPORT},none) 178ENC_ARGS += -f ${FW_ENC_STATUS} 179ENC_ARGS += -k ${ENC_KEY} 180ENC_ARGS += -n ${ENC_NONCE} 181FIP_DEPS += enctool 182FWU_FIP_DEPS += enctool 183endif 184 185################################################################################ 186# Toolchain 187################################################################################ 188 189HOSTCC := gcc 190export HOSTCC 191 192CC := ${CROSS_COMPILE}gcc 193CPP := ${CROSS_COMPILE}cpp 194AS := ${CROSS_COMPILE}gcc 195AR := ${CROSS_COMPILE}ar 196LINKER := ${CROSS_COMPILE}ld 197OC := ${CROSS_COMPILE}objcopy 198OD := ${CROSS_COMPILE}objdump 199NM := ${CROSS_COMPILE}nm 200PP := ${CROSS_COMPILE}gcc -E 201DTC := dtc 202 203# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH). 204ifneq ($(strip $(wildcard ${LD}.bfd) \ 205 $(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),) 206LINKER := ${LINKER}.bfd 207endif 208 209ifeq (${ARM_ARCH_MAJOR},7) 210target32-directive = -target arm-none-eabi 211# Will set march32-directive from platform configuration 212else 213target32-directive = -target armv8a-none-eabi 214 215# Set the compiler's target architecture profile based on 216# ARM_ARCH_MAJOR ARM_ARCH_MINOR options 217ifeq (${ARM_ARCH_MINOR},0) 218march32-directive = -march=armv${ARM_ARCH_MAJOR}-a 219march64-directive = -march=armv${ARM_ARCH_MAJOR}-a 220else 221march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a 222march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a 223endif 224endif 225 226# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards 227ifeq ($(ARCH), aarch64) 228# Check if revision is greater than or equal to 8.5 229ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))" 230mem_tag_arch_support = yes 231endif 232endif 233 234# Get architecture feature modifiers 235arch-features = ${ARM_ARCH_FEATURE} 236 237# Enable required options for memory stack tagging. 238# Currently, these options are enabled only for clang and armclang compiler. 239ifeq (${SUPPORT_STACK_MEMTAG},yes) 240ifdef mem_tag_arch_support 241# Check for armclang and clang compilers 242ifneq ( ,$(filter $(notdir $(CC)),armclang clang)) 243# Add "memtag" architecture feature modifier if not specified 244ifeq ( ,$(findstring memtag,$(arch-features))) 245arch-features := $(arch-features)+memtag 246endif # memtag 247ifeq ($(notdir $(CC)),armclang) 248TF_CFLAGS += -mmemtag-stack 249else ifeq ($(notdir $(CC)),clang) 250TF_CFLAGS += -fsanitize=memtag 251endif # armclang 252endif # armclang clang 253else 254$(error "Error: stack memory tagging is not supported for architecture \ 255 ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a") 256endif # mem_tag_arch_support 257endif # SUPPORT_STACK_MEMTAG 258 259# Set the compiler's architecture feature modifiers 260ifneq ($(arch-features), none) 261# Strip "none+" from arch-features 262arch-features := $(subst none+,,$(arch-features)) 263ifeq ($(ARCH), aarch32) 264march32-directive := $(march32-directive)+$(arch-features) 265else 266march64-directive := $(march64-directive)+$(arch-features) 267endif 268# Print features 269$(info Arm Architecture Features specified: $(subst +, ,$(arch-features))) 270endif # arch-features 271 272# Determine if FEAT_RNG is supported 273ENABLE_FEAT_RNG = $(if $(findstring rng,${arch-features}),1,0) 274 275# Determine if FEAT_SB is supported 276ENABLE_FEAT_SB = $(if $(findstring sb,${arch-features}),1,0) 277 278ifneq ($(findstring clang,$(notdir $(CC))),) 279 ifneq ($(findstring armclang,$(notdir $(CC))),) 280 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi $(march32-directive) 281 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi $(march64-directive) 282 LD := $(LINKER) 283 else 284 TF_CFLAGS_aarch32 = $(target32-directive) $(march32-directive) 285 TF_CFLAGS_aarch64 := -target aarch64-elf $(march64-directive) 286 LD := $(shell $(CC) --print-prog-name ld.lld) 287 288 AR := $(shell $(CC) --print-prog-name llvm-ar) 289 OD := $(shell $(CC) --print-prog-name llvm-objdump) 290 OC := $(shell $(CC) --print-prog-name llvm-objcopy) 291 endif 292 293 CPP := $(CC) -E $(TF_CFLAGS_$(ARCH)) 294 PP := $(CC) -E $(TF_CFLAGS_$(ARCH)) 295 AS := $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) 296else ifneq ($(findstring gcc,$(notdir $(CC))),) 297TF_CFLAGS_aarch32 = $(march32-directive) 298TF_CFLAGS_aarch64 = $(march64-directive) 299ifeq ($(ENABLE_LTO),1) 300 # Enable LTO only for aarch64 301 ifeq (${ARCH},aarch64) 302 LTO_CFLAGS = -flto 303 # Use gcc as a wrapper for the ld, recommended for LTO 304 LINKER := ${CROSS_COMPILE}gcc 305 endif 306endif 307LD = $(LINKER) 308else 309TF_CFLAGS_aarch32 = $(march32-directive) 310TF_CFLAGS_aarch64 = $(march64-directive) 311LD = $(LINKER) 312endif 313 314# Process Debug flag 315$(eval $(call add_define,DEBUG)) 316ifneq (${DEBUG}, 0) 317 BUILD_TYPE := debug 318 TF_CFLAGS += -g -gdwarf-4 319 ASFLAGS += -g -Wa,-gdwarf-4 320 321 # Use LOG_LEVEL_INFO by default for debug builds 322 LOG_LEVEL := 40 323else 324 BUILD_TYPE := release 325 # Use LOG_LEVEL_NOTICE by default for release builds 326 LOG_LEVEL := 20 327endif 328 329# Default build string (git branch and commit) 330ifeq (${BUILD_STRING},) 331 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null) 332endif 333VERSION_STRING := v${VERSION}(${BUILD_TYPE}):${BUILD_STRING} 334 335ifeq (${AARCH32_INSTRUCTION_SET},A32) 336TF_CFLAGS_aarch32 += -marm 337else ifeq (${AARCH32_INSTRUCTION_SET},T32) 338TF_CFLAGS_aarch32 += -mthumb 339else 340$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET}) 341endif 342 343TF_CFLAGS_aarch32 += -mno-unaligned-access 344TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align 345 346ifneq (${BP_OPTION},none) 347TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION} 348endif 349 350ASFLAGS_aarch32 = $(march32-directive) 351ASFLAGS_aarch64 = $(march64-directive) 352 353# General warnings 354WARNINGS := -Wall -Wmissing-include-dirs -Wunused \ 355 -Wdisabled-optimization -Wvla -Wshadow \ 356 -Wredundant-decls 357# stricter warnings 358WARNINGS += -Wextra -Wno-trigraphs 359# too verbose for generic build 360WARNINGS += -Wno-missing-field-initializers \ 361 -Wno-type-limits -Wno-sign-compare \ 362# on clang this flag gets reset if -Wextra is set after it. No difference on gcc 363WARNINGS += -Wno-unused-parameter 364 365# Additional warnings 366# Level 1 - infrequent warnings we should have none of 367# full -Wextra 368WARNING1 += -Wsign-compare 369WARNING1 += -Wtype-limits 370WARNING1 += -Wmissing-field-initializers 371 372# Level 2 - problematic warnings that we want 373# zlib, compiler-rt, coreboot, and mbdedtls blow up with these 374# TODO: disable just for them and move into default build 375WARNING2 += -Wold-style-definition 376WARNING2 += -Wmissing-prototypes 377WARNING2 += -Wmissing-format-attribute 378# TF-A aims to comply with this eventually. Effort too large at present 379WARNING2 += -Wundef 380# currently very involved and many platforms set this off 381WARNING2 += -Wunused-const-variable=2 382 383# Level 3 - very pedantic, frequently ignored 384WARNING3 := -Wbad-function-cast 385WARNING3 += -Waggregate-return 386WARNING3 += -Wnested-externs 387WARNING3 += -Wcast-align 388WARNING3 += -Wcast-qual 389WARNING3 += -Wconversion 390WARNING3 += -Wpacked 391WARNING3 += -Wpointer-arith 392WARNING3 += -Wswitch-default 393 394# Setting W is quite verbose and most warnings will be pre-existing issues 395# outside of the contributor's control. Don't fail the build on them so warnings 396# can be seen and hopefully addressed 397ifdef W 398ifneq (${W},0) 399E ?= 0 400endif 401endif 402 403ifeq (${W},1) 404WARNINGS += $(WARNING1) 405else ifeq (${W},2) 406WARNINGS += $(WARNING1) $(WARNING2) 407else ifeq (${W},3) 408WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3) 409endif 410 411# Compiler specific warnings 412ifeq ($(findstring clang,$(notdir $(CC))),) 413# not using clang 414WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \ 415 -Wpacked-bitfield-compat -Wshift-overflow=2 \ 416 -Wlogical-op 417else 418# using clang 419WARNINGS += -Wshift-overflow -Wshift-sign-overflow \ 420 -Wlogical-op-parentheses 421endif 422 423ifneq (${E},0) 424ERRORS := -Werror 425endif 426 427CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \ 428 $(ERRORS) $(WARNINGS) 429ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ 430 -ffreestanding -Wa,--fatal-warnings 431TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \ 432 -ffunction-sections -fdata-sections \ 433 -ffreestanding -fno-builtin -fno-common \ 434 -Os -std=gnu99 435 436$(eval $(call add_define,SVE_VECTOR_LEN)) 437 438ifeq (${SANITIZE_UB},on) 439TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover 440endif 441ifeq (${SANITIZE_UB},trap) 442TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \ 443 -fsanitize-undefined-trap-on-error 444endif 445 446GCC_V_OUTPUT := $(shell $(CC) -v 2>&1) 447 448# LD = armlink 449ifneq ($(findstring armlink,$(notdir $(LD))),) 450TF_LDFLAGS += --diag_error=warning --lto_level=O1 451TF_LDFLAGS += --remove --info=unused,unusedsymbols 452TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) 453 454# LD = gcc (used when GCC LTO is enabled) 455else ifneq ($(findstring gcc,$(notdir $(LD))),) 456# Pass ld options with Wl or Xlinker switches 457TF_LDFLAGS += -Wl,--fatal-warnings -O1 458TF_LDFLAGS += -Wl,--gc-sections 459 460TF_LDFLAGS += -Wl,-z,common-page-size=4096 # Configure page size constants 461TF_LDFLAGS += -Wl,-z,max-page-size=4096 462 463ifeq ($(ENABLE_LTO),1) 464 ifeq (${ARCH},aarch64) 465 TF_LDFLAGS += -flto -fuse-linker-plugin 466 endif 467endif 468# GCC automatically adds fix-cortex-a53-843419 flag when used to link 469# which breaks some builds, so disable if errata fix is not explicitly enabled 470ifneq (${ERRATA_A53_843419},1) 471 TF_LDFLAGS += -mno-fix-cortex-a53-843419 472endif 473TF_LDFLAGS += -nostdlib 474TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH))) 475 476# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other 477else 478TF_LDFLAGS += -O1 479TF_LDFLAGS += --gc-sections 480 481TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants 482TF_LDFLAGS += -z max-page-size=4096 483 484# ld.lld doesn't recognize the errata flags, 485# therefore don't add those in that case. 486# ld.lld reports section type mismatch warnings, 487# therefore don't add --fatal-warnings to it. 488ifeq ($(findstring ld.lld,$(notdir $(LD))),) 489TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings 490endif 491endif 492 493DTC_FLAGS += -I dts -O dtb 494DTC_CPPFLAGS += -P -nostdinc -Iinclude -Ifdts -undef \ 495 -x assembler-with-cpp $(DEFINES) 496 497################################################################################ 498# Common sources and include directories 499################################################################################ 500include ${MAKE_HELPERS_DIRECTORY}arch_features.mk 501include lib/compiler-rt/compiler-rt.mk 502 503BL_COMMON_SOURCES += common/bl_common.c \ 504 common/tf_log.c \ 505 common/${ARCH}/debug.S \ 506 drivers/console/multi_console.c \ 507 lib/${ARCH}/cache_helpers.S \ 508 lib/${ARCH}/misc_helpers.S \ 509 plat/common/plat_bl_common.c \ 510 plat/common/plat_log_common.c \ 511 plat/common/${ARCH}/plat_common.c \ 512 plat/common/${ARCH}/platform_helpers.S \ 513 ${COMPILER_RT_SRCS} 514 515ifeq ($(notdir $(CC)),armclang) 516BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S 517endif 518 519ifeq (${SANITIZE_UB},on) 520BL_COMMON_SOURCES += plat/common/ubsan.c 521endif 522 523INCLUDES += -Iinclude \ 524 -Iinclude/arch/${ARCH} \ 525 -Iinclude/lib/cpus/${ARCH} \ 526 -Iinclude/lib/el3_runtime/${ARCH} \ 527 ${PLAT_INCLUDES} \ 528 ${SPD_INCLUDES} 529 530include common/backtrace/backtrace.mk 531 532################################################################################ 533# Generic definitions 534################################################################################ 535 536include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk 537 538ifeq (${BUILD_BASE},) 539 BUILD_BASE := ./build 540endif 541BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE} 542 543SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*)))) 544 545# Platforms providing their own TBB makefile may override this value 546INCLUDE_TBBR_MK := 1 547 548 549################################################################################ 550# Include SPD Makefile if one has been specified 551################################################################################ 552 553ifneq (${SPD},none) 554 ifeq (${ARCH},aarch32) 555 $(error "Error: SPD is incompatible with AArch32.") 556 endif 557 558 ifdef EL3_PAYLOAD_BASE 559 $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.") 560 $(warning "The SPD and its BL32 companion will be present but ignored.") 561 endif 562 563 ifeq (${SPD},spmd) 564 # SPMD is located in std_svc directory 565 SPD_DIR := std_svc 566 567 ifeq ($(SPMD_SPM_AT_SEL2),1) 568 CTX_INCLUDE_EL2_REGS := 1 569 ifeq ($(SPMC_AT_EL3),1) 570 $(error SPM cannot be enabled in both S-EL2 and EL3.) 571 endif 572 endif 573 574 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp) 575 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG 576 endif 577 578 ifeq ($(TS_SP_FW_CONFIG),1) 579 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG 580 endif 581 582 ifneq ($(ARM_BL2_SP_LIST_DTS),) 583 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS) 584 endif 585 586 ifneq ($(SP_LAYOUT_FILE),) 587 BL2_ENABLE_SP_LOAD := 1 588 endif 589 else 590 # All other SPDs in spd directory 591 SPD_DIR := spd 592 endif 593 594 # We expect to locate an spd.mk under the specified SPD directory 595 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk) 596 597 ifeq (${SPD_MAKE},) 598 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located) 599 endif 600 $(info Including ${SPD_MAKE}) 601 include ${SPD_MAKE} 602 603 # If there's BL32 companion for the chosen SPD, we expect that the SPD's 604 # Makefile would set NEED_BL32 to "yes". In this case, the build system 605 # supports two mutually exclusive options: 606 # * BL32 is built from source: then BL32_SOURCES must contain the list 607 # of source files to build BL32 608 # * BL32 is a prebuilt binary: then BL32 must point to the image file 609 # that will be included in the FIP 610 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence 611 # over the sources. 612endif 613 614ifeq (${CTX_INCLUDE_EL2_REGS}, 1) 615ifeq (${SPD},none) 616ifeq (${ENABLE_RME},0) 617 $(error CTX_INCLUDE_EL2_REGS is available only when SPD or RME is enabled) 618endif 619endif 620endif 621 622################################################################################ 623# Include rmmd Makefile if RME is enabled 624################################################################################ 625 626ifneq (${ENABLE_RME},0) 627ifneq (${ARCH},aarch64) 628 $(error ENABLE_RME requires AArch64) 629endif 630ifeq ($(SPMC_AT_EL3),1) 631 $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.) 632endif 633include services/std_svc/rmmd/rmmd.mk 634$(warning "RME is an experimental feature") 635endif 636 637################################################################################ 638# Include the platform specific Makefile after the SPD Makefile (the platform 639# makefile may use all previous definitions in this file) 640################################################################################ 641 642include ${PLAT_MAKEFILE_FULL} 643 644$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT})) 645 646ifeq (${ARM_ARCH_MAJOR},7) 647include make_helpers/armv7-a-cpus.mk 648endif 649 650PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT}) 651ifneq ($(PIE_FOUND),) 652 TF_CFLAGS += -fno-PIE 653ifneq ($(findstring gcc,$(notdir $(LD))),) 654 TF_LDFLAGS += -no-pie 655endif 656endif 657 658ifneq ($(findstring gcc,$(notdir $(LD))),) 659 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker 660else 661 PIE_LDFLAGS += -pie --no-dynamic-linker 662endif 663 664ifeq ($(ENABLE_PIE),1) 665ifeq ($(BL2_AT_EL3),1) 666ifneq ($(BL2_IN_XIP_MEM),1) 667 BL2_CPPFLAGS += -fpie 668 BL2_CFLAGS += -fpie 669 BL2_LDFLAGS += $(PIE_LDFLAGS) 670endif 671endif 672 BL31_CPPFLAGS += -fpie 673 BL31_CFLAGS += -fpie 674 BL31_LDFLAGS += $(PIE_LDFLAGS) 675 676 BL32_CPPFLAGS += -fpie 677 BL32_CFLAGS += -fpie 678 BL32_LDFLAGS += $(PIE_LDFLAGS) 679endif 680 681ifeq (${ARCH},aarch64) 682BL1_CPPFLAGS += -DIMAGE_AT_EL3 683ifeq ($(BL2_AT_EL3),1) 684BL2_CPPFLAGS += -DIMAGE_AT_EL3 685else 686BL2_CPPFLAGS += -DIMAGE_AT_EL1 687endif 688BL2U_CPPFLAGS += -DIMAGE_AT_EL1 689BL31_CPPFLAGS += -DIMAGE_AT_EL3 690BL32_CPPFLAGS += -DIMAGE_AT_EL1 691endif 692 693# Include the CPU specific operations makefile, which provides default 694# values for all CPU errata workarounds and CPU specific optimisations. 695# This can be overridden by the platform. 696include lib/cpus/cpu-ops.mk 697 698ifeq (${ARCH},aarch32) 699NEED_BL32 := yes 700 701################################################################################ 702# Build `AARCH32_SP` as BL32 image for AArch32 703################################################################################ 704ifneq (${AARCH32_SP},none) 705# We expect to locate an sp.mk under the specified AARCH32_SP directory 706AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk) 707 708ifeq (${AARCH32_SP_MAKE},) 709 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located) 710endif 711 712$(info Including ${AARCH32_SP_MAKE}) 713include ${AARCH32_SP_MAKE} 714endif 715 716endif 717 718################################################################################ 719# Include libc if not overridden 720################################################################################ 721ifeq (${OVERRIDE_LIBC},0) 722include lib/libc/libc.mk 723endif 724 725################################################################################ 726# Check incompatible options 727################################################################################ 728 729ifdef EL3_PAYLOAD_BASE 730 ifdef PRELOADED_BL33_BASE 731 $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \ 732 incompatible build options. EL3_PAYLOAD_BASE has priority.") 733 endif 734 ifneq (${GENERATE_COT},0) 735 $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.") 736 endif 737 ifneq (${TRUSTED_BOARD_BOOT},0) 738 $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.") 739 endif 740endif 741 742ifeq (${NEED_BL33},yes) 743 ifdef EL3_PAYLOAD_BASE 744 $(warning "BL33 image is not needed when option \ 745 BL33_PAYLOAD_BASE is used and won't be added to the FIP file.") 746 endif 747 ifdef PRELOADED_BL33_BASE 748 $(warning "BL33 image is not needed when option \ 749 PRELOADED_BL33_BASE is used and won't be added to the FIP \ 750 file.") 751 endif 752endif 753 754# When building for systems with hardware-assisted coherency, there's no need to 755# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too. 756ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1) 757$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY) 758endif 759 760#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1. 761ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1) 762$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled") 763endif 764 765# For RAS_EXTENSION, require that EAs are handled in EL3 first 766ifeq ($(RAS_EXTENSION),1) 767 ifneq ($(HANDLE_EA_EL3_FIRST_NS),1) 768 $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST_NS must also be 1) 769 endif 770endif 771 772# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled 773ifeq ($(FAULT_INJECTION_SUPPORT),1) 774 ifneq ($(RAS_EXTENSION),1) 775 $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1) 776 endif 777endif 778 779# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1 780ifeq ($(DYN_DISABLE_AUTH), 1) 781 ifeq (${TRUSTED_BOARD_BOOT}, 0) 782 $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.") 783 endif 784endif 785 786ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1) 787# Support authentication verification and hash calculation 788 CRYPTO_SUPPORT := 3 789else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1) 790# Support authentication verification and hash calculation 791 CRYPTO_SUPPORT := 3 792else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),) 793# Support hash calculation only 794 CRYPTO_SUPPORT := 2 795else ifeq (${TRUSTED_BOARD_BOOT},1) 796# Support authentication verification only 797 CRYPTO_SUPPORT := 1 798else 799 CRYPTO_SUPPORT := 0 800endif 801 802# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled. 803ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1) 804$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled") 805endif 806 807# If pointer authentication is used in the firmware, make sure that all the 808# registers associated to it are also saved and restored. 809# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1. 810ifeq ($(ENABLE_PAUTH),1) 811 ifeq ($(CTX_INCLUDE_PAUTH_REGS),0) 812 $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1) 813 endif 814endif 815 816ifeq ($(CTX_INCLUDE_PAUTH_REGS),1) 817 ifneq (${ARCH},aarch64) 818 $(error CTX_INCLUDE_PAUTH_REGS requires AArch64) 819 endif 820endif 821 822ifeq ($(CTX_INCLUDE_MTE_REGS),1) 823 ifneq (${ARCH},aarch64) 824 $(error CTX_INCLUDE_MTE_REGS requires AArch64) 825 endif 826endif 827 828ifeq ($(PSA_FWU_SUPPORT),1) 829 $(info PSA_FWU_SUPPORT is an experimental feature) 830endif 831 832ifeq ($(FEATURE_DETECTION),1) 833 $(info FEATURE_DETECTION is an experimental feature) 834endif 835 836ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1) 837 ifeq (${ALLOW_RO_XLAT_TABLES}, 1) 838 $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2") 839 endif 840endif 841 842ifneq (${DECRYPTION_SUPPORT},none) 843 ifeq (${TRUSTED_BOARD_BOOT}, 0) 844 $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set) 845 endif 846endif 847 848# Ensure that no Aarch64-only features are enabled in Aarch32 build 849ifeq (${ARCH},aarch32) 850 851 # SME/SVE only supported on AArch64 852 ifeq (${ENABLE_SME_FOR_NS},1) 853 $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32") 854 endif 855 ifeq (${ENABLE_SVE_FOR_NS},1) 856 # Warning instead of error due to CI dependency on this 857 $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32") 858 endif 859 860 # BRBE is not supported in AArch32 861 ifeq (${ENABLE_BRBE_FOR_NS},1) 862 $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32") 863 endif 864 865 # FEAT_RNG_TRAP is not supported in AArch32 866 ifeq (${ENABLE_FEAT_RNG_TRAP},1) 867 $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32") 868 endif 869endif 870 871# Ensure ENABLE_RME is not used with SME 872ifeq (${ENABLE_RME},1) 873 ifeq (${ENABLE_SME_FOR_NS},1) 874 $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME") 875 endif 876endif 877 878# Secure SME/SVE requires the non-secure component as well 879ifeq (${ENABLE_SME_FOR_SWD},1) 880 ifeq (${ENABLE_SME_FOR_NS},0) 881 $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS") 882 endif 883endif 884ifeq (${ENABLE_SVE_FOR_SWD},1) 885 ifeq (${ENABLE_SVE_FOR_NS},0) 886 $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS") 887 endif 888endif 889 890# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does 891# its own context management including FPU registers. 892ifeq (${CTX_INCLUDE_FPREGS},1) 893 ifeq (${ENABLE_SME_FOR_NS},1) 894 $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS") 895 endif 896 ifeq (${ENABLE_SVE_FOR_NS},1) 897 # Warning instead of error due to CI dependency on this 898 $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS") 899 $(warning "Forced ENABLE_SVE_FOR_NS=0") 900 override ENABLE_SVE_FOR_NS := 0 901 endif 902endif 903 904ifeq ($(DRTM_SUPPORT),1) 905 $(info DRTM_SUPPORT is an experimental feature) 906endif 907 908ifeq (${ENABLE_RME},1) 909 ifneq (${SEPARATE_CODE_AND_RODATA},1) 910 $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`) 911 endif 912endif 913 914################################################################################ 915# Process platform overrideable behaviour 916################################################################################ 917 918ifdef BL1_SOURCES 919NEED_BL1 := yes 920endif 921 922ifdef BL2_SOURCES 923 NEED_BL2 := yes 924 925 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and 926 # Certificate generation tools. This flag can be overridden by the platform. 927 ifdef EL3_PAYLOAD_BASE 928 # If booting an EL3 payload there is no need for a BL33 image 929 # in the FIP file. 930 NEED_BL33 := no 931 else 932 ifdef PRELOADED_BL33_BASE 933 # If booting a BL33 preloaded image there is no need of 934 # another one in the FIP file. 935 NEED_BL33 := no 936 else 937 NEED_BL33 ?= yes 938 endif 939 endif 940endif 941 942ifdef BL2U_SOURCES 943NEED_BL2U := yes 944endif 945 946# If SCP_BL2 is given, we always want FIP to include it. 947ifdef SCP_BL2 948 NEED_SCP_BL2 := yes 949endif 950 951# For AArch32, BL31 is not currently supported. 952ifneq (${ARCH},aarch32) 953 ifdef BL31_SOURCES 954 # When booting an EL3 payload, there is no need to compile the BL31 image nor 955 # put it in the FIP. 956 ifndef EL3_PAYLOAD_BASE 957 NEED_BL31 := yes 958 endif 959 endif 960endif 961 962# Process TBB related flags 963ifneq (${GENERATE_COT},0) 964 # Common cert_create options 965 ifneq (${CREATE_KEYS},0) 966 $(eval CRT_ARGS += -n) 967 $(eval FWU_CRT_ARGS += -n) 968 ifneq (${SAVE_KEYS},0) 969 $(eval CRT_ARGS += -k) 970 $(eval FWU_CRT_ARGS += -k) 971 endif 972 endif 973 # Include TBBR makefile (unless the platform indicates otherwise) 974 ifeq (${INCLUDE_TBBR_MK},1) 975 include make_helpers/tbbr/tbbr_tools.mk 976 endif 977endif 978 979ifneq (${FIP_ALIGN},0) 980FIP_ARGS += --align ${FIP_ALIGN} 981endif 982 983ifdef FDT_SOURCES 984NEED_FDT := yes 985endif 986 987################################################################################ 988# Include libraries' Makefile that are used in all BL 989################################################################################ 990 991include lib/stack_protector/stack_protector.mk 992 993################################################################################ 994# Auxiliary tools (fiptool, cert_create, etc) 995################################################################################ 996 997# Variables for use with Certificate Generation Tool 998CRTTOOLPATH ?= tools/cert_create 999CRTTOOL ?= ${CRTTOOLPATH}/cert_create${BIN_EXT} 1000 1001# Variables for use with Firmware Encryption Tool 1002ENCTOOLPATH ?= tools/encrypt_fw 1003ENCTOOL ?= ${ENCTOOLPATH}/encrypt_fw${BIN_EXT} 1004 1005# Variables for use with Firmware Image Package 1006FIPTOOLPATH ?= tools/fiptool 1007FIPTOOL ?= ${FIPTOOLPATH}/fiptool${BIN_EXT} 1008 1009# Variables for use with sptool 1010SPTOOLPATH ?= tools/sptool 1011SPTOOL ?= ${SPTOOLPATH}/sptool.py 1012SP_MK_GEN ?= ${SPTOOLPATH}/sp_mk_generator.py 1013 1014# Variables for use with ROMLIB 1015ROMLIBPATH ?= lib/romlib 1016 1017# Variable for use with Python 1018PYTHON ?= python3 1019 1020# Variables for use with PRINT_MEMORY_MAP 1021PRINT_MEMORY_MAP_PATH ?= tools/memory 1022PRINT_MEMORY_MAP ?= ${PRINT_MEMORY_MAP_PATH}/print_memory_map.py 1023 1024# Variables for use with documentation build using Sphinx tool 1025DOCS_PATH ?= docs 1026 1027# Defination of SIMICS flag 1028SIMICS_BUILD ?= 0 1029 1030################################################################################ 1031# Include BL specific makefiles 1032################################################################################ 1033 1034ifeq (${NEED_BL1},yes) 1035include bl1/bl1.mk 1036endif 1037 1038ifeq (${NEED_BL2},yes) 1039include bl2/bl2.mk 1040endif 1041 1042ifeq (${NEED_BL2U},yes) 1043include bl2u/bl2u.mk 1044endif 1045 1046ifeq (${NEED_BL31},yes) 1047include bl31/bl31.mk 1048endif 1049 1050################################################################################ 1051# Build options checks 1052################################################################################ 1053 1054$(eval $(call assert_booleans,\ 1055 $(sort \ 1056 ALLOW_RO_XLAT_TABLES \ 1057 BL2_ENABLE_SP_LOAD \ 1058 COLD_BOOT_SINGLE_CPU \ 1059 CREATE_KEYS \ 1060 CTX_INCLUDE_AARCH32_REGS \ 1061 CTX_INCLUDE_FPREGS \ 1062 CTX_INCLUDE_EL2_REGS \ 1063 DEBUG \ 1064 DISABLE_MTPMU \ 1065 DYN_DISABLE_AUTH \ 1066 EL3_EXCEPTION_HANDLING \ 1067 ENABLE_AMU \ 1068 ENABLE_AMU_AUXILIARY_COUNTERS \ 1069 ENABLE_AMU_FCONF \ 1070 AMU_RESTRICT_COUNTERS \ 1071 ENABLE_ASSERTIONS \ 1072 ENABLE_PIE \ 1073 ENABLE_PMF \ 1074 ENABLE_PSCI_STAT \ 1075 ENABLE_RUNTIME_INSTRUMENTATION \ 1076 ENABLE_SME_FOR_NS \ 1077 ENABLE_SME_FOR_SWD \ 1078 ENABLE_SPE_FOR_LOWER_ELS \ 1079 ENABLE_SVE_FOR_NS \ 1080 ENABLE_SVE_FOR_SWD \ 1081 ERROR_DEPRECATED \ 1082 FAULT_INJECTION_SUPPORT \ 1083 GENERATE_COT \ 1084 GICV2_G0_FOR_EL3 \ 1085 HANDLE_EA_EL3_FIRST_NS \ 1086 HW_ASSISTED_COHERENCY \ 1087 INVERTED_MEMMAP \ 1088 MEASURED_BOOT \ 1089 DRTM_SUPPORT \ 1090 NS_TIMER_SWITCH \ 1091 OVERRIDE_LIBC \ 1092 PL011_GENERIC_UART \ 1093 PLAT_RSS_NOT_SUPPORTED \ 1094 PROGRAMMABLE_RESET_ADDRESS \ 1095 PSCI_EXTENDED_STATE_ID \ 1096 RESET_TO_BL31 \ 1097 RESET_TO_BL31_WITH_PARAMS \ 1098 SAVE_KEYS \ 1099 SEPARATE_CODE_AND_RODATA \ 1100 SEPARATE_BL2_NOLOAD_REGION \ 1101 SEPARATE_NOBITS_REGION \ 1102 SPIN_ON_BL1_EXIT \ 1103 SPM_MM \ 1104 SPMC_AT_EL3 \ 1105 SPMD_SPM_AT_SEL2 \ 1106 TRUSTED_BOARD_BOOT \ 1107 USE_COHERENT_MEM \ 1108 USE_DEBUGFS \ 1109 ARM_IO_IN_DTB \ 1110 SDEI_IN_FCONF \ 1111 SEC_INT_DESC_IN_FCONF \ 1112 USE_ROMLIB \ 1113 USE_TBBR_DEFS \ 1114 WARMBOOT_ENABLE_DCACHE_EARLY \ 1115 BL2_AT_EL3 \ 1116 BL2_IN_XIP_MEM \ 1117 BL2_INV_DCACHE \ 1118 USE_SPINLOCK_CAS \ 1119 ENCRYPT_BL31 \ 1120 ENCRYPT_BL32 \ 1121 ERRATA_SPECULATIVE_AT \ 1122 RAS_TRAP_NS_ERR_REC_ACCESS \ 1123 COT_DESC_IN_DTB \ 1124 USE_SP804_TIMER \ 1125 PSA_FWU_SUPPORT \ 1126 ENABLE_SYS_REG_TRACE_FOR_NS \ 1127 ENABLE_MPMM \ 1128 ENABLE_MPMM_FCONF \ 1129 SIMICS_BUILD \ 1130 FEATURE_DETECTION \ 1131 TRNG_SUPPORT \ 1132 CONDITIONAL_CMO \ 1133))) 1134 1135$(eval $(call assert_numerics,\ 1136 $(sort \ 1137 ARM_ARCH_MAJOR \ 1138 ARM_ARCH_MINOR \ 1139 BRANCH_PROTECTION \ 1140 CTX_INCLUDE_PAUTH_REGS \ 1141 CTX_INCLUDE_MTE_REGS \ 1142 CTX_INCLUDE_NEVE_REGS \ 1143 CRYPTO_SUPPORT \ 1144 ENABLE_BRBE_FOR_NS \ 1145 ENABLE_TRBE_FOR_NS \ 1146 ENABLE_BTI \ 1147 ENABLE_PAUTH \ 1148 ENABLE_FEAT_AMUv1 \ 1149 ENABLE_FEAT_AMUv1p1 \ 1150 ENABLE_FEAT_CSV2_2 \ 1151 ENABLE_FEAT_DIT \ 1152 ENABLE_FEAT_ECV \ 1153 ENABLE_FEAT_FGT \ 1154 ENABLE_FEAT_HCX \ 1155 ENABLE_FEAT_PAN \ 1156 ENABLE_FEAT_RNG \ 1157 ENABLE_FEAT_RNG_TRAP \ 1158 ENABLE_FEAT_SB \ 1159 ENABLE_FEAT_SEL2 \ 1160 ENABLE_FEAT_VHE \ 1161 ENABLE_MPAM_FOR_LOWER_ELS \ 1162 ENABLE_RME \ 1163 ENABLE_TRF_FOR_NS \ 1164 FW_ENC_STATUS \ 1165 NR_OF_FW_BANKS \ 1166 NR_OF_IMAGES_IN_FW_BANK \ 1167 RAS_EXTENSION \ 1168 TWED_DELAY \ 1169 ENABLE_FEAT_TWED \ 1170 SVE_VECTOR_LEN \ 1171))) 1172 1173ifdef KEY_SIZE 1174 $(eval $(call assert_numeric,KEY_SIZE)) 1175endif 1176 1177ifeq ($(filter $(SANITIZE_UB), on off trap),) 1178 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap") 1179endif 1180 1181################################################################################ 1182# Add definitions to the cpp preprocessor based on the current build options. 1183# This is done after including the platform specific makefile to allow the 1184# platform to overwrite the default options 1185################################################################################ 1186 1187$(eval $(call add_defines,\ 1188 $(sort \ 1189 ALLOW_RO_XLAT_TABLES \ 1190 ARM_ARCH_MAJOR \ 1191 ARM_ARCH_MINOR \ 1192 BL2_ENABLE_SP_LOAD \ 1193 COLD_BOOT_SINGLE_CPU \ 1194 CTX_INCLUDE_AARCH32_REGS \ 1195 CTX_INCLUDE_FPREGS \ 1196 CTX_INCLUDE_PAUTH_REGS \ 1197 EL3_EXCEPTION_HANDLING \ 1198 CTX_INCLUDE_MTE_REGS \ 1199 CTX_INCLUDE_EL2_REGS \ 1200 CTX_INCLUDE_NEVE_REGS \ 1201 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \ 1202 DISABLE_MTPMU \ 1203 ENABLE_AMU \ 1204 ENABLE_AMU_AUXILIARY_COUNTERS \ 1205 ENABLE_AMU_FCONF \ 1206 AMU_RESTRICT_COUNTERS \ 1207 ENABLE_ASSERTIONS \ 1208 ENABLE_BTI \ 1209 ENABLE_MPAM_FOR_LOWER_ELS \ 1210 ENABLE_PAUTH \ 1211 ENABLE_PIE \ 1212 ENABLE_PMF \ 1213 ENABLE_PSCI_STAT \ 1214 ENABLE_RME \ 1215 ENABLE_RUNTIME_INSTRUMENTATION \ 1216 ENABLE_SME_FOR_NS \ 1217 ENABLE_SME_FOR_SWD \ 1218 ENABLE_SPE_FOR_LOWER_ELS \ 1219 ENABLE_SVE_FOR_NS \ 1220 ENABLE_SVE_FOR_SWD \ 1221 ENCRYPT_BL31 \ 1222 ENCRYPT_BL32 \ 1223 ERROR_DEPRECATED \ 1224 FAULT_INJECTION_SUPPORT \ 1225 GICV2_G0_FOR_EL3 \ 1226 HANDLE_EA_EL3_FIRST_NS \ 1227 HW_ASSISTED_COHERENCY \ 1228 LOG_LEVEL \ 1229 MEASURED_BOOT \ 1230 DRTM_SUPPORT \ 1231 NS_TIMER_SWITCH \ 1232 PL011_GENERIC_UART \ 1233 PLAT_${PLAT} \ 1234 PLAT_RSS_NOT_SUPPORTED \ 1235 PROGRAMMABLE_RESET_ADDRESS \ 1236 PSCI_EXTENDED_STATE_ID \ 1237 RAS_EXTENSION \ 1238 RESET_TO_BL31 \ 1239 RESET_TO_BL31_WITH_PARAMS \ 1240 SEPARATE_CODE_AND_RODATA \ 1241 SEPARATE_BL2_NOLOAD_REGION \ 1242 SEPARATE_NOBITS_REGION \ 1243 RECLAIM_INIT_CODE \ 1244 SPD_${SPD} \ 1245 SPIN_ON_BL1_EXIT \ 1246 SPM_MM \ 1247 SPMC_AT_EL3 \ 1248 SPMD_SPM_AT_SEL2 \ 1249 TRUSTED_BOARD_BOOT \ 1250 CRYPTO_SUPPORT \ 1251 TRNG_SUPPORT \ 1252 USE_COHERENT_MEM \ 1253 USE_DEBUGFS \ 1254 ARM_IO_IN_DTB \ 1255 SDEI_IN_FCONF \ 1256 SEC_INT_DESC_IN_FCONF \ 1257 USE_ROMLIB \ 1258 USE_TBBR_DEFS \ 1259 WARMBOOT_ENABLE_DCACHE_EARLY \ 1260 BL2_AT_EL3 \ 1261 BL2_IN_XIP_MEM \ 1262 BL2_INV_DCACHE \ 1263 USE_SPINLOCK_CAS \ 1264 ERRATA_SPECULATIVE_AT \ 1265 RAS_TRAP_NS_ERR_REC_ACCESS \ 1266 COT_DESC_IN_DTB \ 1267 USE_SP804_TIMER \ 1268 ENABLE_FEAT_RNG \ 1269 ENABLE_FEAT_RNG_TRAP \ 1270 ENABLE_FEAT_SB \ 1271 ENABLE_FEAT_DIT \ 1272 NR_OF_FW_BANKS \ 1273 NR_OF_IMAGES_IN_FW_BANK \ 1274 PSA_FWU_SUPPORT \ 1275 ENABLE_BRBE_FOR_NS \ 1276 ENABLE_TRBE_FOR_NS \ 1277 ENABLE_SYS_REG_TRACE_FOR_NS \ 1278 ENABLE_TRF_FOR_NS \ 1279 ENABLE_FEAT_HCX \ 1280 ENABLE_MPMM \ 1281 ENABLE_MPMM_FCONF \ 1282 ENABLE_FEAT_FGT \ 1283 ENABLE_FEAT_AMUv1 \ 1284 ENABLE_FEAT_ECV \ 1285 SIMICS_BUILD \ 1286 ENABLE_FEAT_AMUv1p1 \ 1287 ENABLE_FEAT_SEL2 \ 1288 ENABLE_FEAT_VHE \ 1289 ENABLE_FEAT_CSV2_2 \ 1290 ENABLE_FEAT_PAN \ 1291 FEATURE_DETECTION \ 1292 TWED_DELAY \ 1293 ENABLE_FEAT_TWED \ 1294 CONDITIONAL_CMO \ 1295))) 1296 1297ifeq (${SANITIZE_UB},trap) 1298 $(eval $(call add_define,MONITOR_TRAPS)) 1299endif 1300 1301# Define the EL3_PAYLOAD_BASE flag only if it is provided. 1302ifdef EL3_PAYLOAD_BASE 1303 $(eval $(call add_define,EL3_PAYLOAD_BASE)) 1304else 1305 # Define the PRELOADED_BL33_BASE flag only if it is provided and 1306 # EL3_PAYLOAD_BASE is not defined, as it has priority. 1307 ifdef PRELOADED_BL33_BASE 1308 $(eval $(call add_define,PRELOADED_BL33_BASE)) 1309 endif 1310endif 1311 1312# Define the DYN_DISABLE_AUTH flag only if set. 1313ifeq (${DYN_DISABLE_AUTH},1) 1314$(eval $(call add_define,DYN_DISABLE_AUTH)) 1315endif 1316 1317ifneq ($(findstring armlink,$(notdir $(LD))),) 1318$(eval $(call add_define,USE_ARM_LINK)) 1319endif 1320 1321# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined 1322ifeq (${SPD},spmd) 1323ifdef SP_LAYOUT_FILE 1324 -include $(BUILD_PLAT)/sp_gen.mk 1325 FIP_DEPS += sp 1326 CRT_DEPS += sp 1327 NEED_SP_PKG := yes 1328else 1329 ifeq (${SPMD_SPM_AT_SEL2},1) 1330 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE") 1331 endif 1332endif 1333endif 1334 1335################################################################################ 1336# Build targets 1337################################################################################ 1338 1339.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool 1340.SUFFIXES: 1341 1342all: msg_start 1343 1344msg_start: 1345 @echo "Building ${PLAT}" 1346 1347ifeq (${ERROR_DEPRECATED},0) 1348# Check if deprecated declarations and cpp warnings should be treated as error or not. 1349ifneq ($(findstring clang,$(notdir $(CC))),) 1350 CPPFLAGS += -Wno-error=deprecated-declarations 1351else 1352 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp 1353endif 1354endif # !ERROR_DEPRECATED 1355 1356$(eval $(call MAKE_LIB_DIRS)) 1357$(eval $(call MAKE_LIB,c)) 1358 1359# Expand build macros for the different images 1360ifeq (${NEED_BL1},yes) 1361BL1_SOURCES := $(sort ${BL1_SOURCES}) 1362 1363$(eval $(call MAKE_BL,bl1)) 1364endif 1365 1366ifeq (${NEED_BL2},yes) 1367ifeq (${BL2_AT_EL3}, 0) 1368FIP_BL2_ARGS := tb-fw 1369endif 1370 1371BL2_SOURCES := $(sort ${BL2_SOURCES}) 1372 1373$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\ 1374 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS}))) 1375endif 1376 1377ifeq (${NEED_SCP_BL2},yes) 1378$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw)) 1379endif 1380 1381ifeq (${NEED_BL31},yes) 1382BL31_SOURCES += ${SPD_SOURCES} 1383# Sort BL31 source files to remove duplicates 1384BL31_SOURCES := $(sort ${BL31_SOURCES}) 1385ifneq (${DECRYPTION_SUPPORT},none) 1386$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\ 1387 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31)))) 1388else 1389$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\ 1390 $(eval $(call MAKE_BL,bl31,soc-fw))) 1391endif 1392endif 1393 1394# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the 1395# build system will call TOOL_ADD_IMG to print a warning message and abort the 1396# process. Note that the dependency on BL32 applies to the FIP only. 1397ifeq (${NEED_BL32},yes) 1398# Sort BL32 source files to remove duplicates 1399BL32_SOURCES := $(sort ${BL32_SOURCES}) 1400BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1)) 1401 1402ifneq (${DECRYPTION_SUPPORT},none) 1403$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\ 1404 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32)))) 1405else 1406$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\ 1407 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw))) 1408endif 1409endif 1410 1411# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP) 1412# needs to be built from RMM_SOURCES. 1413ifeq (${NEED_RMM},yes) 1414# Sort RMM source files to remove duplicates 1415RMM_SOURCES := $(sort ${RMM_SOURCES}) 1416BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1)) 1417 1418$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\ 1419 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw))) 1420endif 1421 1422# Add the BL33 image if required by the platform 1423ifeq (${NEED_BL33},yes) 1424$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 1425endif 1426 1427ifeq (${NEED_BL2U},yes) 1428$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\ 1429 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_))) 1430endif 1431 1432# Expand build macros for the different images 1433ifeq (${NEED_FDT},yes) 1434 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES))) 1435endif 1436 1437# Add Secure Partition packages 1438ifeq (${NEED_SP_PKG},yes) 1439$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT} 1440 ${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} 1441sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS) 1442 @${ECHO_BLANK_LINE} 1443 @echo "Built SP Images successfully" 1444 @${ECHO_BLANK_LINE} 1445endif 1446 1447locate-checkpatch: 1448ifndef CHECKPATCH 1449 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 1450else 1451ifeq (,$(wildcard ${CHECKPATCH})) 1452 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 1453endif 1454endif 1455 1456clean: 1457 @echo " CLEAN" 1458 $(call SHELL_REMOVE_DIR,${BUILD_PLAT}) 1459ifdef UNIX_MK 1460 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 1461else 1462# Clear the MAKEFLAGS as we do not want 1463# to pass the gnumake flags to nmake. 1464 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean 1465endif 1466 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean 1467 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean 1468 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 1469 1470realclean distclean: 1471 @echo " REALCLEAN" 1472 $(call SHELL_REMOVE_DIR,${BUILD_BASE}) 1473 $(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*) 1474ifdef UNIX_MK 1475 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 1476else 1477# Clear the MAKEFLAGS as we do not want 1478# to pass the gnumake flags to nmake. 1479 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean 1480endif 1481 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean 1482 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean 1483 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 1484 1485checkcodebase: locate-checkpatch 1486 @echo " CHECKING STYLE" 1487 @if test -d .git ; then \ 1488 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \ 1489 while read GIT_FILE ; \ 1490 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \ 1491 done ; \ 1492 else \ 1493 find . -type f -not -iwholename "*.git*" \ 1494 -not -iwholename "*build*" \ 1495 -not -iwholename "*libfdt*" \ 1496 -not -iwholename "*libc*" \ 1497 -not -iwholename "*docs*" \ 1498 -not -iwholename "*.rst" \ 1499 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ 1500 fi 1501 1502checkpatch: locate-checkpatch 1503 @echo " CHECKING STYLE" 1504 @if test -n "${CHECKPATCH_OPTS}"; then \ 1505 echo " with ${CHECKPATCH_OPTS} option(s)"; \ 1506 fi 1507 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \ 1508 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \ 1509 do \ 1510 printf "\n[*] Checking style of '$$commit'\n\n"; \ 1511 git log --format=email "$$commit~..$$commit" \ 1512 -- ${CHECK_PATHS} | \ 1513 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 1514 git diff --format=email "$$commit~..$$commit" \ 1515 -- ${CHECK_PATHS} | \ 1516 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 1517 done 1518 1519certtool: ${CRTTOOL} 1520 1521${CRTTOOL}: FORCE 1522 ${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${CRTTOOLPATH} all 1523 @${ECHO_BLANK_LINE} 1524 @echo "Built $@ successfully" 1525 @${ECHO_BLANK_LINE} 1526 1527ifneq (${GENERATE_COT},0) 1528certificates: ${CRT_DEPS} ${CRTTOOL} 1529 ${Q}${CRTTOOL} ${CRT_ARGS} 1530 @${ECHO_BLANK_LINE} 1531 @echo "Built $@ successfully" 1532 @echo "Certificates can be found in ${BUILD_PLAT}" 1533 @${ECHO_BLANK_LINE} 1534endif 1535 1536${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} 1537 $(eval ${CHECK_FIP_CMD}) 1538 ${Q}${FIPTOOL} create ${FIP_ARGS} $@ 1539 ${Q}${FIPTOOL} info $@ 1540 @${ECHO_BLANK_LINE} 1541 @echo "Built $@ successfully" 1542 @${ECHO_BLANK_LINE} 1543 1544ifneq (${GENERATE_COT},0) 1545fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL} 1546 ${Q}${CRTTOOL} ${FWU_CRT_ARGS} 1547 @${ECHO_BLANK_LINE} 1548 @echo "Built $@ successfully" 1549 @echo "FWU certificates can be found in ${BUILD_PLAT}" 1550 @${ECHO_BLANK_LINE} 1551endif 1552 1553${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} 1554 $(eval ${CHECK_FWU_FIP_CMD}) 1555 ${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@ 1556 ${Q}${FIPTOOL} info $@ 1557 @${ECHO_BLANK_LINE} 1558 @echo "Built $@ successfully" 1559 @${ECHO_BLANK_LINE} 1560 1561fiptool: ${FIPTOOL} 1562fip: ${BUILD_PLAT}/${FIP_NAME} 1563fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME} 1564 1565${FIPTOOL}: FORCE 1566ifdef UNIX_MK 1567 ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all 1568else 1569# Clear the MAKEFLAGS as we do not want 1570# to pass the gnumake flags to nmake. 1571 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) 1572endif 1573 1574romlib.bin: libraries FORCE 1575 ${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 1576 1577# Call print_memory_map tool 1578memmap: all 1579 ${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP} 1580 1581doc: 1582 @echo " BUILD DOCUMENTATION" 1583 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html 1584 1585enctool: ${ENCTOOL} 1586 1587${ENCTOOL}: FORCE 1588 ${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all 1589 @${ECHO_BLANK_LINE} 1590 @echo "Built $@ successfully" 1591 @${ECHO_BLANK_LINE} 1592 1593cscope: 1594 @echo " CSCOPE" 1595 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files 1596 ${Q}cscope -b -q -k 1597 1598help: 1599 @echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]" 1600 @echo "" 1601 @echo "PLAT is used to specify which platform you wish to build." 1602 @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}" 1603 @echo "" 1604 @echo "platform = ${PLATFORM_LIST}" 1605 @echo "" 1606 @echo "Please refer to the User Guide for a list of all supported options." 1607 @echo "Note that the build system doesn't track dependencies for build " 1608 @echo "options. Therefore, if any of the build options are changed " 1609 @echo "from a previous build, a clean build must be performed." 1610 @echo "" 1611 @echo "Supported Targets:" 1612 @echo " all Build all individual bootloader binaries" 1613 @echo " bl1 Build the BL1 binary" 1614 @echo " bl2 Build the BL2 binary" 1615 @echo " bl2u Build the BL2U binary" 1616 @echo " bl31 Build the BL31 binary" 1617 @echo " bl32 Build the BL32 binary. If ARCH=aarch32, then " 1618 @echo " this builds secure payload specified by AARCH32_SP" 1619 @echo " certificates Build the certificates (requires 'GENERATE_COT=1')" 1620 @echo " fip Build the Firmware Image Package (FIP)" 1621 @echo " fwu_fip Build the FWU Firmware Image Package (FIP)" 1622 @echo " checkcodebase Check the coding style of the entire source tree" 1623 @echo " checkpatch Check the coding style on changes in the current" 1624 @echo " branch against BASE_COMMIT (default origin/master)" 1625 @echo " clean Clean the build for the selected platform" 1626 @echo " cscope Generate cscope index" 1627 @echo " distclean Remove all build artifacts for all platforms" 1628 @echo " certtool Build the Certificate generation tool" 1629 @echo " enctool Build the Firmware encryption tool" 1630 @echo " fiptool Build the Firmware Image Package (FIP) creation tool" 1631 @echo " sp Build the Secure Partition Packages" 1632 @echo " sptool Build the Secure Partition Package creation tool" 1633 @echo " dtbs Build the Device Tree Blobs (if required for the platform)" 1634 @echo " memmap Print the memory map of the built binaries" 1635 @echo " doc Build html based documentation using Sphinx tool" 1636 @echo "" 1637 @echo "Note: most build targets require PLAT to be set to a specific platform." 1638 @echo "" 1639 @echo "example: build all targets for the FVP platform:" 1640 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all" 1641 1642.PHONY: FORCE 1643FORCE:; 1644