@@ -11,7 +11,7 @@ import sys
11
11
import shutil
12
12
from collections import namedtuple
13
13
14
- ALL_COMPILERS = [ "gcc" , "clang" , "armclang" , "arm-none-eabi-gcc" ]
14
+ ALL_COMPILERS = [ "gcc" , "clang" , "armclang" , "arm-none-eabi-gcc" , "iar" ]
15
15
NATIVE_TARGET = None
16
16
17
17
ARCHS = [ "mips" , "mipsel" , "mips64" , "mips64el" , "powerpc64le" , "s390x" , "riscv64" , "x86_64" , "x86" ]
@@ -42,6 +42,7 @@ NON_NATIVE_SUPPORT = {
42
42
"armclang" : [ "armv6-thumb1" , "armv7-arm" , "armv8-thumb2" , "armv8-aarch64" ],
43
43
"gcc" : [ "armv5-thumb1" , "armv5-arm" , "armv6-thumb1" , "armv6-thumb2" , "armv6-arm" , "armv7-thumb2" , "armv7-arm" , "armv8-thumb2" , "armv8-arm" , "armv8-aarch64" ] + ARCHS ,
44
44
"clang" : [ "armv5-thumb1" , "armv5-arm" , "armv6-thumb1" , "armv6-thumb2" , "armv6-arm" , "armv7-thumb2" , "armv7-arm" , "armv8-thumb2" , "armv8-arm" , "armv8-aarch64" ] + ARCHS ,
45
+ "iar" : [ "armv5-thumb1" , "armv5-arm" , "armv6-thumb1" , "armv6-thumb2" , "armv6-arm" , "armv7-thumb2" , "armv7-arm" , "armv8-thumb2" , "armv8-arm" , "armv8-aarch64" ]
45
46
}
46
47
47
48
QEMU_NAME_MAP = {
@@ -53,20 +54,28 @@ MEMSAN_OPTIONS = [ "MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN", "-MBEDTLS_USE_PSA_CRYPTO
53
54
MEMSAN_CFLAGS = ['-fsanitize=memory' , '-O1' , '-g3' , '-fno-omit-frame-pointer' , '-fno-optimize-sibling-calls' , '-fsanitize-memory-track-origins=2' ]
54
55
MEMSAN_CC = "clang"
55
56
57
+ # TODO: can some of the IAR limitations be removed?
56
58
COMPILER_CONFIGS = {
57
59
# "armclang": [ "MBEDTLS_NO_UDBL_DIVISION" ]
60
+ "iar" : [ "MBEDTLS_NO_PLATFORM_ENTROPY" , "-MBEDTLS_HAVE_TIME_DATE" , "-MBEDTLS_HAVE_TIME" , "-MBEDTLS_TIMING_C" , "-MBEDTLS_FS_IO" , "-MBEDTLS_PSA_ITS_FILE_C" , "-MBEDTLS_PSA_CRYPTO_STORAGE_C" , "-MBEDTLS_NET_C" ]
58
61
}
59
62
60
63
ASAN_CFLAGS = ['-fsanitize=address' , '-fno-common' , '-fsanitize=undefined' , '-fno-sanitize-recover=all' , '-O1' , '-g3' , '-fno-omit-frame-pointer' , '-fno-optimize-sibling-calls' ]
61
64
ASAN_LDFLAGS = ASAN_CFLAGS
62
65
63
66
WARNING_FLAGS = {
67
+ "iar" : ['--warnings_are_errors' ], # cannot enable --strict because then IAR will not recognise #warning
64
68
"clang" : ['-Werror' , '-Wall' , '-Wextra' , '-Wwrite-strings' , '-Wpointer-arith' , '-Wimplicit-fallthrough' , '-Wshadow' , '-Wvla' , '-Wformat=2' , '-Wno-format-nonliteral' , '-Wshadow' , '-Wasm-operand-widths' , '-Wunreachable-code' ],
65
69
"gcc" : ['-Werror' , '-Wall' , '-Wextra' , '-Wwrite-strings' , '-Wpointer-arith' , '-Wimplicit-fallthrough' , '-Wshadow' , '-Wvla' , '-Wformat=2' , '-Wno-format-nonliteral' , '-Wshadow' , '-Wformat-signedness' , '-Wformat-overflow=2' , '-Wformat-truncation' , '-Wlogical-op' ]
66
70
}
67
71
WARNING_FLAGS ["arm-none-eabi-gcc" ] = WARNING_FLAGS ["gcc" ]
68
72
WARNING_FLAGS ["armclang" ] = WARNING_FLAGS ["clang" ]
69
73
74
+ # Use full system libraries for IAR
75
+ COMPILER_FLAGS = {
76
+ "iar" : ["--dlib_config=full" ]
77
+ }
78
+
70
79
TFM_ARMCLANG_TARGET_FLAGS = ["--target=arm-arm-none-eabi" , "-mcpu=cortex-m33+nodsp+nofp" , "-mthumb" ]
71
80
TFM_CONFIG_FILES = [("config-tfm.h" , None ), ("tfm_mbedcrypto_config_profile_medium.h" , "crypto_config_profile_medium.h" )]
72
81
COPY_TFM_CONFIG = "//TFM-CONFIG//"
@@ -136,6 +145,7 @@ def clean():
136
145
137
146
def toolchain_exes (target ):
138
147
compiler_exe = target .compiler
148
+ archiver_exe = None
139
149
140
150
# construct triple needed in gcc and objdump executable name
141
151
triple_abi = "gnu"
@@ -180,6 +190,10 @@ def toolchain_exes(target):
180
190
compiler_exe = c
181
191
break
182
192
193
+ elif target .compiler_family == "iar" :
194
+ compiler_exe = "iccarm"
195
+ archiver_exe = "iarchive"
196
+
183
197
if target .compiler == "gcc" :
184
198
compiler_error = f"could not locate gcc executable { compiler_exe } or { compiler_exe } -<majorversion>"
185
199
elif target .compiler_family == "gcc" :
@@ -226,6 +240,7 @@ def toolchain_exes(target):
226
240
227
241
return {
228
242
"compiler" : compiler_exe ,
243
+ "archiver" : archiver_exe ,
229
244
"objdump" : objdump_exe ,
230
245
"size" : size_exe ,
231
246
"triple" : triple ,
@@ -239,19 +254,28 @@ def toolchain_exes(target):
239
254
240
255
def toolchain (target , exit_on_failure = True ):
241
256
# basic CFLAGS setup
242
- # target_c_flags may get overridden by the user (and dropped from the resulting set of flags);
243
- # c_flags is always applied
257
+ # target_c_flags are options generated by mtest, which may get overridden by the user (and dropped from the resulting set of flags)
244
258
245
- target_c_flags = ["-std=c99" , f"-I{ ROOT } /include" ]
259
+ target_c_flags = [f"-I{ ROOT } /include" ] + COMPILER_FLAGS .get (target .compiler_family , [])
260
+
261
+ if target .compiler_family != "iar" :
262
+ # IAR defaults to C99 and doesn't have an option for it to be explicitly specified
263
+ target_c_flags += ["-std=c99" ]
246
264
247
265
if args .size_tfm and "clang" in target .compiler :
248
266
target_c_flags += ["-Oz" ]
267
+ elif target .compiler_family == "iar" :
268
+ # -Ohz = high optimization, favouring size
269
+ # -Ol = fastest compile time (about 3x better than Ohz)
270
+ target_c_flags += ["-Ol" ]
249
271
else :
250
272
target_c_flags += ["-Os" ]
251
273
252
274
if args .no_warnings :
253
275
if target .compiler_family == "clang" :
254
276
target_c_flags += ["-Wno-everything" ]
277
+ elif target .compiler_family == "iar" :
278
+ target_c_flags += ["--no_warnings" ]
255
279
else :
256
280
target_c_flags += ["-Wno-all" , "-Wno-extra" ]
257
281
else :
@@ -344,6 +368,28 @@ def toolchain(target, exit_on_failure=True):
344
368
else :
345
369
error (f"unsupported target { target .arch } { target .isa } for clang" )
346
370
371
+ elif target .compiler_family == "iar" :
372
+ if target .arch == "armv5" and target .isa == "thumb1" :
373
+ target_c_flags += ["--cpu=ARM926EJ-S" , "--thumb" ]
374
+ elif target .arch == "armv5" and target .isa == "arm" :
375
+ target_c_flags += ["--cpu=ARM968E-S" , "--arm" ]
376
+ elif target .arch == "armv6" and target .isa == "thumb1" :
377
+ target_c_flags += ["--cpu=ARM1136J-S" , "--thumb" ]
378
+ elif target .arch == "armv6" and target .isa == "thumb2" :
379
+ target_c_flags += ["--cpu=ARM1156T2-S" , "--thumb" ]
380
+ elif target .arch == "armv6" and target .isa == "arm" :
381
+ target_c_flags += ["--cpu=ARM1156T2-S" , "--arm" ]
382
+ elif target .arch == "armv7" and target .isa == "thumb2" :
383
+ target_c_flags += ["--cpu=Cortex-A17" , "--thumb" ]
384
+ elif target .arch == "armv7" and target .isa == "arm" :
385
+ target_c_flags += ["--cpu=Cortex-A17" , "--arm" ]
386
+ elif target .arch == "armv8" and target .isa == "thumb2" :
387
+ target_c_flags += ["--cpu=Cortex-A32" , "--thumb" ]
388
+ elif target .arch == "armv8" and target .isa == "arm" :
389
+ target_c_flags += ["--cpu=Cortex-A32" , "--arm" ]
390
+ elif target .arch == "armv8" and target .isa == "aarch64" :
391
+ target_c_flags += ["--cpu=Cortex-A72" , "--aarch64" ]
392
+
347
393
# unconditionally add user-specified flags
348
394
c_flags = target .cflags .split (" " )
349
395
@@ -379,11 +425,20 @@ def toolchain(target, exit_on_failure=True):
379
425
if not target .is_native :
380
426
ld_flags += " --static"
381
427
428
+ if target .compiler_family == "iar" :
429
+ # Specify AR_FLAGS for IAR
430
+ ar_flags = "--create"
431
+ else :
432
+ # Do not specify AR_FLAGS - the Makefile will generate some IAR-incompatible flags
433
+ ar_flags = None
434
+
382
435
exes = toolchain_exes (target )
383
436
return {
384
437
"CFLAGS" : " " .join (x for x in c_flags if x != "" ).strip (),
385
438
"LDFLAGS" : ld_flags .strip (),
439
+ "ARFLAGS" : ar_flags ,
386
440
"CC" : exes ["compiler" ],
441
+ "AR" : exes ["archiver" ],
387
442
"OBJDUMP" : exes ["objdump" ],
388
443
"SIZE" : exes ["size" ]
389
444
}
@@ -425,7 +480,7 @@ def configure_options(target):
425
480
# target-specific options
426
481
options = target .config
427
482
# compiler-specific options
428
- options += COMPILER_CONFIGS .get (target .compiler , [])
483
+ options += COMPILER_CONFIGS .get (target .compiler_family , [])
429
484
# memsan options
430
485
if args .memsan :
431
486
options += MEMSAN_OPTIONS
@@ -553,7 +608,21 @@ def build(target, tests):
553
608
if not args .no_clean :
554
609
clean ()
555
610
t = toolchain (target )
556
- flags = ["CFLAGS=" + t ['CFLAGS' ], "LDFLAGS=" + t ['LDFLAGS' ], "CC=" + t ['CC' ]]
611
+
612
+ flags = ["CFLAGS=" + t ['CFLAGS' ], "CC=" + t ['CC' ]]
613
+
614
+ if target .compiler_family == "iar" :
615
+ # Clear WARNING_CFLAGS so that the Makefile doesn't automatically add -Wall etc, which IAR doesn't understand
616
+ flags += ["WARNING_CFLAGS=" ]
617
+
618
+ if t ['LDFLAGS' ] != "" :
619
+ flags += ["LDFLAGS=" + t ['LDFLAGS' ]]
620
+
621
+ if t ['AR' ] is not None :
622
+ flags += ['AR=' + t ['AR' ]]
623
+
624
+ if t ['ARFLAGS' ] is not None :
625
+ flags += ['ARFLAGS=' + t ['ARFLAGS' ]]
557
626
558
627
configure_options (target )
559
628
0 commit comments