Makefile 43 KB

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