Skip to content

Commit df3245c

Browse files
committed
M2351: Support non-PSA secure/non-secure combined build
Support secure/non-secure combined build for non-PSA target: 1. In secure post-build, deliver built secure image to TARGET_NU_PREBUILD_SECURE directory which is to combine later. 2. In non-secure post-build, merge non-secure image with secure image saved in TARGET_NU_PREBUILD_SECURE directory. 3. In non-secure post-build, user can also drop pre-built secure image saved in TARGET_NU_PREBUILD_SECURE directory and provide its own by adding the line below in mbed_app.json: "target.extra_labels_remove": ["NU_PREBUILD_SECURE"]
1 parent cf95343 commit df3245c

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

targets/targets.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8403,14 +8403,17 @@
84038403
"core": "Cortex-M23-NS",
84048404
"trustzone": true,
84058405
"extra_labels_add": [
8406-
"M23_NS"
8406+
"M23_NS",
8407+
"NU_PREBUILD_SECURE"
84078408
],
84088409
"device_has_remove": [],
84098410
"macros_add": [
84108411
"MBED_TZ_DEFAULT_ACCESS=1"
84118412
],
84128413
"components_add": ["FLASHIAP"],
84138414
"components_remove": [],
8415+
"post_binary_hook": {"function": "M2351Code.merge_secure"},
8416+
"secure_image_filename": "NuMaker-mbed-TZ-secure-example.hex",
84148417
"mbed_rom_start" : "0x10040000",
84158418
"mbed_rom_size" : "0x40000",
84168419
"mbed_ram_start" : "0x30008000",
@@ -8426,6 +8429,8 @@
84268429
"device_has_remove": ["TRNG", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES"],
84278430
"components_add": ["FLASHIAP"],
84288431
"components_remove": [],
8432+
"deliver_to_target": "NUMAKER_PFM_M2351_NOPSA_NS",
8433+
"delivery_dir": "TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NUMAKER_PFM_M2351_NOPSA_NS/TARGET_NU_PREBUILD_SECURE",
84298434
"mbed_rom_start" : "0x0",
84308435
"mbed_rom_size" : "0x40000",
84318436
"mbed_ram_start" : "0x20000000",

tools/targets/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,46 @@ def binary_hook(t_self, resources, elf, binf):
707707
)
708708
lpc55s69_complete(t_self, binf, secure_bin)
709709

710+
class M2351Code:
711+
"""M2351 Hooks"""
712+
@staticmethod
713+
def merge_secure(t_self, resources, ns_elf, ns_hex):
714+
t_self.notify.info("Merging non-secure image with secure image")
715+
configured_secure_image_filename = t_self.target.secure_image_filename
716+
t_self.notify.info("Non-secure elf image %s" % ns_elf)
717+
t_self.notify.info("Non-secure hex image %s" % ns_hex)
718+
t_self.notify.info("Finding secure image %s" % configured_secure_image_filename)
719+
s_hex = find_secure_image(
720+
t_self.notify,
721+
resources,
722+
ns_hex,
723+
configured_secure_image_filename,
724+
FileType.HEX
725+
)
726+
t_self.notify.info("Found secure image %s" % s_hex)
727+
728+
_, ext = os.path.splitext(s_hex)
729+
assert ext == ".hex", "Secure image %s must be in Intel HEX format" % s_hex
730+
assert os.path.isfile(s_hex), "Secure image %s must be regular file" % s_hex
731+
732+
_, ext = os.path.splitext(ns_hex)
733+
assert ext == ".hex", "Non-secure image %s must be in Intel HEX format" % s_hex
734+
assert os.path.isfile(ns_hex), "Non-secure image %s must be regular file" % s_hex
735+
736+
# Keep original non-secure before merge with secure
737+
ns_nosecure_hex = _ + "_no-secure-merge" + ext
738+
t_self.notify.info("Keep no-secure-merge image %s" % ns_nosecure_hex)
739+
shutil.copy2(ns_hex, ns_nosecure_hex)
740+
741+
# Merge secure and non-secure and save to non-secure (override it)
742+
from intelhex import IntelHex
743+
s_ih = IntelHex()
744+
s_ih.loadhex(s_hex)
745+
ns_ih = IntelHex()
746+
ns_ih.loadhex(ns_hex)
747+
ns_ih.start_addr = None
748+
s_ih.merge(ns_ih)
749+
s_ih.tofile(ns_hex, 'hex')
710750

711751
# End Target specific section
712752
###############################################################################

0 commit comments

Comments
 (0)