blob: 01df0db83ef4f1d1105fed816b6333a7f27b4c14 [file] [log] [blame]
Boyan Karatotev3df79ae2025-04-09 14:26:17 +01001#
2# Copyright (c) 2025, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
8PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
9
10################################################################################
11# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
12################################################################################
13ifeq (${ARM_ARCH_MAJOR},7)
14 target32-directive = -target arm-none-eabi
15# Will set march-directive from platform configuration
16else
17 target32-directive = -target armv8a-none-eabi
18endif #(ARM_ARCH_MAJOR)
19
20ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
21 ifeq ($($(ARCH)-cc-id),arm-clang)
22 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi
23 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi
24 else
25 TF_CFLAGS_aarch32 = $(target32-directive)
26 TF_CFLAGS_aarch64 := -target aarch64-elf
27 endif
28endif #(clang)
29
30# Process Debug flag
31ifneq (${DEBUG}, 0)
32 TF_CFLAGS += -g -gdwarf-4
33 ASFLAGS += -g -Wa,-gdwarf-4
34endif #(Debug)
35
36ifeq (${AARCH32_INSTRUCTION_SET},A32)
37 TF_CFLAGS_aarch32 += -marm
38else ifeq (${AARCH32_INSTRUCTION_SET},T32)
39 TF_CFLAGS_aarch32 += -mthumb
40endif #(AARCH32_INSTRUCTION_SET)
41
42TF_CFLAGS_aarch32 += -mno-unaligned-access
43TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
44
45##############################################################################
46# WARNINGS Configuration
47###############################################################################
48# General warnings
49WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
50 -Wdisabled-optimization -Wvla -Wshadow \
51 -Wredundant-decls
52# stricter warnings
53WARNINGS += -Wextra -Wno-trigraphs
54# too verbose for generic build
55WARNINGS += -Wno-missing-field-initializers \
56 -Wno-type-limits -Wno-sign-compare \
57# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
58WARNINGS += -Wno-unused-parameter
59
60# Additional warnings
61# Level 1 - infrequent warnings we should have none of
62# full -Wextra
63WARNING1 += -Wsign-compare
64WARNING1 += -Wtype-limits
65WARNING1 += -Wmissing-field-initializers
66
67# Level 2 - problematic warnings that we want
68# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
69# TODO: disable just for them and move into default build
70WARNING2 += -Wold-style-definition
71WARNING2 += -Wmissing-prototypes
72WARNING2 += -Wmissing-format-attribute
73# TF-A aims to comply with this eventually. Effort too large at present
74WARNING2 += -Wundef
75# currently very involved and many platforms set this off
76WARNING2 += -Wunused-const-variable=2
77
78# Level 3 - very pedantic, frequently ignored
79WARNING3 := -Wbad-function-cast
80WARNING3 += -Waggregate-return
81WARNING3 += -Wnested-externs
82WARNING3 += -Wcast-align
83WARNING3 += -Wcast-qual
84WARNING3 += -Wconversion
85WARNING3 += -Wpacked
86WARNING3 += -Wpointer-arith
87WARNING3 += -Wswitch-default
88
89ifeq (${W},1)
90 WARNINGS += $(WARNING1)
91else ifeq (${W},2)
92 WARNINGS += $(WARNING1) $(WARNING2)
93else ifeq (${W},3)
94 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
95endif #(W)
96
97ifneq (${E},0)
98 ERRORS := -Werror
99endif #(E)
100
101# Compiler specific warnings
102ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
103# not using clang
104# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
105TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
106TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
107
108ifeq ($(HARDEN_SLS), 1)
109 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
110 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
111endif
112
113WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
114 -Wpacked-bitfield-compat -Wshift-overflow=2 \
115 -Wlogical-op
116
117else
118# using clang
119WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
120 -Wlogical-op-parentheses
121endif #(Clang Warning)
122
123CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
124 $(ERRORS) $(WARNINGS)
125
126
127TF_CFLAGS += -ffunction-sections -fdata-sections \
128 -ffreestanding -fno-common \
129 -Os -std=gnu99
130
131ifneq (${BP_OPTION},none)
132 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
133endif #(BP_OPTION)
134
135ifeq (${SANITIZE_UB},on)
136 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
137endif #(${SANITIZE_UB},on)
138
139ifeq (${SANITIZE_UB},trap)
140 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
141 -fsanitize-undefined-trap-on-error
142endif #(${SANITIZE_UB},trap)
143
144ifeq ($($(ARCH)-cc-id),gnu-gcc)
145 # Enable LTO only for aarch64
146 LTO_CFLAGS = $(if $(filter-out 0,$(ENABLE_LTO)),-flto)
147endif #(gnu-gcc)
148
149ifeq (${ERROR_DEPRECATED},0)
150# Check if deprecated declarations and cpp warnings should be treated as error or not.
151ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
152 CPPFLAGS += -Wno-error=deprecated-declarations
153else
154 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
155endif
156endif #(!ERROR_DEPRECATED)
157
158################################################################################
159# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
160# up with appropriate march values for compiler.
161################################################################################
162include ${MAKE_HELPERS_DIRECTORY}march.mk
163ifeq (${ARM_ARCH_MAJOR},7)
164include make_helpers/armv7-a-cpus.mk
165endif
166
167TF_CFLAGS += $(march-directive)
168ASFLAGS += $(march-directive)
169
170ifneq ($(PIE_FOUND),)
171 TF_CFLAGS += -fno-PIE
172endif
173
174TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH))
175ASFLAGS += $(CPPFLAGS) \
176 -ffreestanding -Wa,--fatal-warnings
177TF_LDFLAGS += -z noexecstack
178
179# LD = armlink
180ifeq ($($(ARCH)-ld-id),arm-link)
181 TF_LDFLAGS += --diag_error=warning --lto_level=O1
182 TF_LDFLAGS += --remove --info=unused,unusedsymbols
183 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
184
185# LD = gcc (used when GCC LTO is enabled)
186else ifeq ($($(ARCH)-ld-id),gnu-gcc)
187 # Pass ld options with Wl or Xlinker switches
188 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
189 TF_LDFLAGS += -Wl,--fatal-warnings -O1
190 TF_LDFLAGS += -Wl,--gc-sections
191
192 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
193 TF_LDFLAGS += -Wl,-z,max-page-size=4096
194 TF_LDFLAGS += -Wl,--build-id=none
195
196 ifeq ($(ENABLE_LTO),1)
197 TF_LDFLAGS += -flto -fuse-linker-plugin
198 TF_LDFLAGS += -flto-partition=one
199 endif #(ENABLE_LTO)
200
201# GCC automatically adds fix-cortex-a53-843419 flag when used to link
202# which breaks some builds, so disable if errata fix is not explicitly enabled
203 ifeq (${ARCH},aarch64)
204 ifneq (${ERRATA_A53_843419},1)
205 TF_LDFLAGS += -mno-fix-cortex-a53-843419
206 endif
207 endif
208 TF_LDFLAGS += -nostdlib
209 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
210
211# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
212else
213# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
214# are not loaded by a elf loader.
215 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
216 TF_LDFLAGS += -O1
217 TF_LDFLAGS += --gc-sections
218
219 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
220 TF_LDFLAGS += -z max-page-size=4096
221 TF_LDFLAGS += --build-id=none
222
223# ld.lld doesn't recognize the errata flags,
224# therefore don't add those in that case.
225# ld.lld reports section type mismatch warnings,
226# therefore don't add --fatal-warnings to it.
227 ifneq ($($(ARCH)-ld-id),llvm-lld)
228 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
229 endif
230
231endif #(LD = armlink)
232
233ifneq ($(PIE_FOUND),)
234ifeq ($($(ARCH)-ld-id),gnu-gcc)
235 TF_LDFLAGS += -no-pie
236endif
237endif #(PIE_FOUND)
238
239ifeq ($($(ARCH)-ld-id),gnu-gcc)
240 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
241else
242 PIE_LDFLAGS += -pie --no-dynamic-linker
243endif
244
245ifeq ($(ENABLE_PIE),1)
246 ifeq ($(RESET_TO_BL2),1)
247 ifneq ($(BL2_IN_XIP_MEM),1)
248 BL2_CPPFLAGS += -fpie
249 BL2_CFLAGS += -fpie
250 BL2_LDFLAGS += $(PIE_LDFLAGS)
251 endif #(BL2_IN_XIP_MEM)
252 endif #(RESET_TO_BL2)
253 BL31_CPPFLAGS += -fpie
254 BL31_CFLAGS += -fpie
255 BL31_LDFLAGS += $(PIE_LDFLAGS)
256
257 BL32_CPPFLAGS += -fpie
258 BL32_CFLAGS += -fpie
259 BL32_LDFLAGS += $(PIE_LDFLAGS)
260endif #(ENABLE_PIE)
261
262BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
263BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
264BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
265
266BL1_CPPFLAGS += -DIMAGE_AT_EL3
267ifeq ($(RESET_TO_BL2),1)
268 BL2_CPPFLAGS += -DIMAGE_AT_EL3
269else
270 BL2_CPPFLAGS += -DIMAGE_AT_EL1
271endif #(RESET_TO_BL2)
272
273ifeq (${ARCH},aarch64)
274 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
275 BL31_CPPFLAGS += -DIMAGE_AT_EL3
276 BL32_CPPFLAGS += -DIMAGE_AT_EL1
277else
278 BL32_CPPFLAGS += -DIMAGE_AT_EL3
279endif
280
281ifeq (${SPD},spmd)
282 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
283 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
284 endif
285
286 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
287 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
288 endif
289
290 ifeq ($(TS_SP_FW_CONFIG),1)
291 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
292 endif
293
294 ifneq ($(ARM_BL2_SP_LIST_DTS),)
295 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
296 endif
297endif
298
299
300DTC_FLAGS += -I dts -O dtb
Boyan Karatotev1e8b5352025-04-29 09:32:12 +0100301DTC_CPPFLAGS += -Ifdts -undef
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100302