Skip to content

Commit a358eee

Browse files
author
deepikabhavnani
committed
Generate/Link secure object file
Cortex v8 architecture based devices support secure/non-secure builds. Secure build should generate the object file/library from elf during link process which is used by non-secure binary during linking. --out-implib=file specifies output library in which symbols are exported --cmse-implib requests libraries mentioned above are secure gateway libraries Creation of secure library is done as part of linking process in GCC/ARMC6/IAR Non-Secure project should add this secure object file as part of the linking process. Secure library is named as cmse_lib.o.
1 parent 964e6e7 commit a358eee

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

tools/toolchains/arm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def __init__(self, target, *args, **kwargs):
304304
raise NotSupportedException(
305305
"this compiler does not support the core %s" % target.core)
306306

307+
build_dir = kwargs['build_dir']
307308
if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
308309
raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
309310

@@ -337,6 +338,11 @@ def __init__(self, target, *args, **kwargs):
337338
if target.core == "Cortex-M23" or target.core == "Cortex-M33":
338339
self.flags['common'].append("-mcmse")
339340

341+
# Create Secure library
342+
if target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
343+
secure_file = join(build_dir, "cmse_lib.o")
344+
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
345+
340346
asm_cpu = {
341347
"Cortex-M0+": "Cortex-M0",
342348
"Cortex-M4F": "Cortex-M4.fp",

tools/toolchains/gcc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, basename, splitext, dirname, exists
18+
from os.path import join, basename, splitext, dirname, exists, split
1919
from distutils.spawn import find_executable
2020

2121
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
@@ -219,6 +219,12 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
219219
# Build linker command
220220
map_file = splitext(output)[0] + ".map"
221221
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
222+
# Create Secure library
223+
if self.target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
224+
secure_file = join(dirname(output), "cmse_lib.o")
225+
cmd.extend(["-Wl,--cmse-implib"])
226+
cmd.extend(["-Wl,--out-implib=%s" % secure_file])
227+
222228
if mem_map:
223229
cmd.extend(['-T', mem_map])
224230

@@ -238,6 +244,8 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
238244
# Exec command
239245
self.cc_verbose("Link: %s" % ' '.join(cmd))
240246
self.default_cmd(cmd)
247+
if self.target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
248+
self.info("Secure Library Object %s" %secure_file)
241249

242250
@hook_tool
243251
def archive(self, objects, lib_path):

tools/toolchains/iar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
import re
1818
from os import remove
19-
from os.path import join, splitext, exists
19+
from os.path import join, splitext, exists, dirname
2020

2121
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2222
from tools.hooks import hook_tool
@@ -66,6 +66,7 @@ def __init__(self, target, notify=None, macros=None,
6666
cxx_flags_cmd = [
6767
"--c++", "--no_rtti", "--no_exceptions"
6868
]
69+
6970
if target.core == "Cortex-M7FD":
7071
asm_flags_cmd += ["--fpu", "VFPv5"]
7172
c_flags_cmd.append("--fpu=VFPv5")
@@ -74,6 +75,12 @@ def __init__(self, target, notify=None, macros=None,
7475
c_flags_cmd.append("--fpu=VFPv5_sp")
7576
elif target.core == "Cortex-M23" or target.core == "Cortex-M33":
7677
self.flags["asm"] += ["--cmse"]
78+
self.flags["common"] += ["--cmse"]
79+
80+
# Create Secure library
81+
if target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
82+
secure_file = join(build_dir, "cmse_lib.o")
83+
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
7784

7885
IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin")
7986
main_cc = join(IAR_BIN, "iccarm")
@@ -188,6 +195,7 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
188195
map_file = splitext(output)[0] + ".map"
189196
cmd = self.ld + [ "-o", output, "--map=%s" % map_file] + objects + libraries
190197

198+
191199
if mem_map:
192200
cmd.extend(["--config", mem_map])
193201

0 commit comments

Comments
 (0)