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