Makefile 53 KB

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