Skip to content

Commit

Permalink
Generate/Link secure object file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deepikabhavnani committed Feb 8, 2018
1 parent 964e6e7 commit a358eee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def __init__(self, target, *args, **kwargs):
raise NotSupportedException(
"this compiler does not support the core %s" % target.core)

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

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

# Create Secure library
if target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
secure_file = join(build_dir, "cmse_lib.o")
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]

asm_cpu = {
"Cortex-M0+": "Cortex-M0",
"Cortex-M4F": "Cortex-M4.fp",
Expand Down
10 changes: 9 additions & 1 deletion tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
"""
import re
from os.path import join, basename, splitext, dirname, exists
from os.path import join, basename, splitext, dirname, exists, split
from distutils.spawn import find_executable

from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
Expand Down Expand Up @@ -219,6 +219,12 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
# Build linker command
map_file = splitext(output)[0] + ".map"
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
# Create Secure library
if self.target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
secure_file = join(dirname(output), "cmse_lib.o")
cmd.extend(["-Wl,--cmse-implib"])
cmd.extend(["-Wl,--out-implib=%s" % secure_file])

if mem_map:
cmd.extend(['-T', mem_map])

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

@hook_tool
def archive(self, objects, lib_path):
Expand Down
10 changes: 9 additions & 1 deletion tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
import re
from os import remove
from os.path import join, splitext, exists
from os.path import join, splitext, exists, dirname

from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
Expand Down Expand Up @@ -66,6 +66,7 @@ def __init__(self, target, notify=None, macros=None,
cxx_flags_cmd = [
"--c++", "--no_rtti", "--no_exceptions"
]

if target.core == "Cortex-M7FD":
asm_flags_cmd += ["--fpu", "VFPv5"]
c_flags_cmd.append("--fpu=VFPv5")
Expand All @@ -74,6 +75,12 @@ def __init__(self, target, notify=None, macros=None,
c_flags_cmd.append("--fpu=VFPv5_sp")
elif target.core == "Cortex-M23" or target.core == "Cortex-M33":
self.flags["asm"] += ["--cmse"]
self.flags["common"] += ["--cmse"]

# Create Secure library
if target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
secure_file = join(build_dir, "cmse_lib.o")
self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]

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


if mem_map:
cmd.extend(["--config", mem_map])

Expand Down

0 comments on commit a358eee

Please sign in to comment.