Skip to content

Commit 4b856de

Browse files
committed
Permit non-TrustZone ARMv8 build
Change the heuristic for selection of CMSE in the tools python, so that a non-TrustZone ARMv8 build can happen. Ideally we would have more direct flagging in the targets, but this refines the heuristic so the necessary behaviour can be easily achieved. * DOMAIN_NS=1 is based purely on the `-NS` suffix on the core name. * Enabling CMSE in the compiler and outputting a secure import library is now enabled by the target label `TFM` being present when the core doesn't have an `-NS` suffix. (Rather than simply being ARMv8 without an `-NS` suffix).
1 parent ba429a8 commit 4b856de

File tree

5 files changed

+58
-40
lines changed

5 files changed

+58
-40
lines changed

tools/build_api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
600600
if into_dir:
601601
copy_when_different(res[0], into_dir)
602602
if not extra_artifacts:
603-
if (
604-
CORE_ARCH[toolchain.target.core] == 8 and
605-
not toolchain.target.core.endswith("NS")
606-
):
603+
if toolchain.target.is_TrustZone_secure_target:
607604
cmse_lib = join(dirname(res[0]), "cmse_lib.o")
608605
copy_when_different(cmse_lib, into_dir)
609606
else:

tools/targets/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ def labels(self):
379379
labels = (names + CORE_LABELS[self.core] + self.extra_labels)
380380
return labels
381381

382+
@property
383+
def core_without_NS(self):
384+
if self.core.endswith('-NS'):
385+
return self.core[:-3]
386+
else:
387+
return self.core
388+
389+
@property
390+
def is_TrustZone_secure_target(self):
391+
return 'TFM' in self.labels and not self.core.endswith('-NS')
392+
393+
@property
394+
def is_TrustZone_non_secure_target(self):
395+
return self.core.endswith('-NS')
396+
382397
@property
383398
def is_PSA_secure_target(self):
384399
return 'SPE_Target' in self.labels

tools/toolchains/arm.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,25 @@ def __init__(self, target, *args, **kwargs):
521521
if "--library_type=microlib" not in self.flags['asm']:
522522
self.flags['asm'].append("--library_type=microlib")
523523

524-
core = target.core
525-
if CORE_ARCH[target.core] == 8:
526-
if ((not target.core.endswith("-NS")) and
527-
kwargs.get('build_dir', False)):
528-
# Create Secure library
524+
if target.is_TrustZone_secure_target:
525+
if kwargs.get('build_dir', False):
526+
# Output secure import library
529527
build_dir = kwargs['build_dir']
530528
secure_file = join(build_dir, "cmse_lib.o")
531529
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
532530

531+
# Enable compiler security extensions
532+
self.flags['cxx'].append("-mcmse")
533+
self.flags['c'].append("-mcmse")
534+
535+
if target.is_TrustZone_non_secure_target:
533536
# Add linking time preprocessor macro DOMAIN_NS
534-
if target.core.endswith("-NS"):
535-
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
536-
self.flags["ld"].append(define_string)
537-
core = target.core[:-3]
538-
else:
539-
# Add secure build flag
540-
self.flags['cxx'].append("-mcmse")
541-
self.flags['c'].append("-mcmse")
537+
# (DOMAIN_NS is passed to compiler and assembler via CORTEX_SYMBOLS
538+
# in mbedToolchain.get_symbols)
539+
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
540+
self.flags["ld"].append(define_string)
542541

542+
core = target.core_without_NS
543543
cpu = {
544544
"Cortex-M0+": "cortex-m0plus",
545545
"Cortex-M4F": "cortex-m4",

tools/toolchains/gcc.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,23 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5959
self.flags["common"].append("-DMBED_RTOS_SINGLE_THREAD")
6060
self.flags["ld"].append("--specs=nano.specs")
6161

62-
core = target.core
6362
self.cpu = []
64-
if CORE_ARCH[target.core] == 8:
63+
if target.is_TrustZone_secure_target:
64+
# Enable compiler security extensions
65+
self.cpu.append("-mcmse")
66+
# Output secure import library
67+
self.flags["ld"].extend([
68+
"-Wl,--cmse-implib",
69+
"-Wl,--out-implib=%s" % join(build_dir, "cmse_lib.o")
70+
])
71+
72+
if target.is_TrustZone_non_secure_target:
6573
# Add linking time preprocessor macro DOMAIN_NS
66-
if target.core.endswith("-NS"):
67-
self.flags["ld"].append("-DDOMAIN_NS=1")
68-
core = target.core[:-3]
69-
else:
70-
self.cpu.append("-mcmse")
71-
self.flags["ld"].extend([
72-
"-Wl,--cmse-implib",
73-
"-Wl,--out-implib=%s" % join(build_dir, "cmse_lib.o")
74-
])
74+
# (DOMAIN_NS is passed to compiler and assembler via CORTEX_SYMBOLS
75+
# in mbedToolchain.get_symbols)
76+
self.flags["ld"].append("-DDOMAIN_NS=1")
7577

78+
core = target.core_without_NS
7679
cpu = {
7780
"Cortex-M0+": "cortex-m0plus",
7881
"Cortex-M4F": "cortex-m4",

tools/toolchains/iar.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5454
build_dir=build_dir,
5555
build_profile=build_profile
5656
)
57-
core = target.core
58-
if CORE_ARCH[target.core] == 8:
57+
58+
if target.is_TrustZone_secure_target:
59+
# Enable compiler security extensions
60+
self.flags["asm"] += ["--cmse"]
61+
self.flags["common"] += ["--cmse"]
62+
# Output secure import library
63+
secure_file = join(build_dir, "cmse_lib.o")
64+
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
65+
66+
if target.is_TrustZone_non_secure_target:
5967
# Add linking time preprocessor macro DOMAIN_NS
60-
if target.core.endswith("-NS"):
61-
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
62-
self.flags["ld"].append(define_string)
63-
core = target.core[:-3]
64-
else:
65-
# Create Secure library
66-
self.flags["asm"] += ["--cmse"]
67-
self.flags["common"] += ["--cmse"]
68-
secure_file = join(build_dir, "cmse_lib.o")
69-
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
68+
# (DOMAIN_NS is passed to compiler and assembler via CORTEX_SYMBOLS
69+
# in mbedToolchain.get_symbols)
70+
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
71+
self.flags["ld"].append(define_string)
7072

73+
core = target.core_without_NS
7174
cpu = {
7275
"Cortex-M7F": "Cortex-M7.fp.sp",
7376
"Cortex-M7FD": "Cortex-M7.fp.dp",

0 commit comments

Comments
 (0)