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