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