Upstream fork of ATF with a couple of rk3399 patches to remove HDCP blob and increase BAUD_RATE.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1036 lines
34 KiB

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