Skip to content

Commit 2e2a340

Browse files
ccli8adbridge
authored andcommitted
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 f7c7c73 commit 2e2a340

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

targets/targets.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8694,12 +8694,15 @@
86948694
"core": "Cortex-M23-NS",
86958695
"trustzone": true,
86968696
"extra_labels_add": [
8697-
"M23_NS"
8697+
"M23_NS",
8698+
"NU_PREBUILD_SECURE"
86988699
],
86998700
"macros_add": [
87008701
"MBED_TZ_DEFAULT_ACCESS=1"
87018702
],
87028703
"components_add": ["FLASHIAP"],
8704+
"post_binary_hook": {"function": "M2351Code.merge_secure"},
8705+
"secure_image_filename": "NuMaker-mbed-TZ-secure-example.hex",
87038706
"mbed_rom_start" : "0x10040000",
87048707
"mbed_rom_size" : "0x40000",
87058708
"mbed_ram_start" : "0x30008000",
@@ -8714,6 +8717,8 @@
87148717
],
87158718
"device_has_remove": ["TRNG", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES"],
87168719
"components_add": ["FLASHIAP"],
8720+
"deliver_to_target": "NU_PFM_M2351_NPSA_NS",
8721+
"delivery_dir": "TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NPSA_NS/TARGET_NU_PREBUILD_SECURE",
87178722
"mbed_rom_start" : "0x0",
87188723
"mbed_rom_size" : "0x40000",
87198724
"mbed_ram_start" : "0x20000000",

tools/targets/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,54 @@ def binary_hook(t_self, resources, elf, binf):
725725
)
726726
lpc55s69_complete(t_self, binf, secure_bin)
727727

728+
class M2351Code:
729+
"""M2351 Hooks"""
730+
@staticmethod
731+
def merge_secure(t_self, resources, ns_elf, ns_hex):
732+
t_self.notify.info("Merging non-secure image with secure image")
733+
configured_secure_image_filename = t_self.target.secure_image_filename
734+
t_self.notify.info("Non-secure elf image %s" % ns_elf)
735+
t_self.notify.info("Non-secure hex image %s" % ns_hex)
736+
t_self.notify.info("Finding secure image %s" % configured_secure_image_filename)
737+
s_hex = find_secure_image(
738+
t_self.notify,
739+
resources,
740+
ns_hex,
741+
configured_secure_image_filename,
742+
FileType.HEX
743+
)
744+
t_self.notify.info("Found secure image %s" % s_hex)
745+
746+
_, ext = os.path.splitext(s_hex)
747+
if ext != ".hex":
748+
t_self.notify.debug("Secure image %s must be in Intel HEX format" % s_hex)
749+
return
750+
if not os.path.isfile(s_hex):
751+
t_self.notify.debug("Secure image %s must be regular file" % s_hex)
752+
return
753+
754+
ns_main, ext = os.path.splitext(ns_hex)
755+
if ext != ".hex":
756+
t_self.notify.debug("Non-secure image %s must be in Intel HEX format" % s_hex)
757+
return
758+
if not os.path.isfile(ns_hex):
759+
t_self.notify.debug("Non-secure image %s must be regular file" % s_hex)
760+
return
761+
762+
# Keep original non-secure before merge with secure
763+
ns_nosecure_hex = ns_main + "_no-secure-merge" + ext
764+
t_self.notify.info("Keep no-secure-merge image %s" % ns_nosecure_hex)
765+
shutil.copy2(ns_hex, ns_nosecure_hex)
766+
767+
# Merge secure and non-secure and save to non-secure (override it)
768+
from intelhex import IntelHex
769+
s_ih = IntelHex()
770+
s_ih.loadhex(s_hex)
771+
ns_ih = IntelHex()
772+
ns_ih.loadhex(ns_hex)
773+
ns_ih.start_addr = None
774+
s_ih.merge(ns_ih)
775+
s_ih.tofile(ns_hex, 'hex')
728776

729777
# End Target specific section
730778
###############################################################################

0 commit comments

Comments
 (0)