Skip to content

Commit a48ee11

Browse files
committed
PSOC6: refactor M0 image merging, enable export to makefile
Rename the existing PSoC-specific m0_core_img key in targets.json as a more generic hex_filename key. Update makefile exporter to select the subset of resources.hex_files matching the hex_filename value. Without this fix, multiple prebuilt CM0+ hex files are found in the target resources and erroneously passed to the srec_cat tool. The fix is generic so other targets that need post-build hex merging can use this key to pass the correct image to srecord tool. The fix also removes sub_target key: instead, rely hex_filename json key to detect if the hex image merging needs to be done. The sub_target is not used in mbed-os codebase for anything else. It is possible to override the hex file name in mbed_app.json: { "target_overrides": { "*": { "target.hex_filename": "my_custom_m0_image.hex" } }
1 parent 5b0daad commit a48ee11

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

targets/targets.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7837,12 +7837,11 @@
78377837
},
78387838
"FUTURE_SEQUANA": {
78397839
"inherits": ["MCU_PSOC6_M4"],
7840-
"sub_target": "FUTURE_SEQUANA_M0",
78417840
"supported_form_factors": ["ARDUINO"],
78427841
"extra_labels_add": ["CY8C63XX", "CORDIO"],
78437842
"macros_add": ["CY8C6347BZI_BLD53"],
78447843
"detect_code": ["6000"],
7845-
"m0_core_img": "psoc63_m0_default_1.02.hex",
7844+
"hex_filename": "psoc63_m0_default_1.02.hex",
78467845
"post_binary_hook": {
78477846
"function": "PSOC6Code.complete"
78487847
},
@@ -7892,12 +7891,11 @@
78927891
},
78937892
"FUTURE_SEQUANA_PSA": {
78947893
"inherits": ["NSPE_Target", "FUTURE_SEQUANA"],
7895-
"sub_target": "FUTURE_SEQUANA_M0_PSA",
78967894
"extra_labels_add": ["PSA"],
78977895
"extra_labels_remove": ["CORDIO"],
78987896
"components_add": ["SPM_MAILBOX"],
78997897
"macros_add": ["PSOC6_DYNSRM_DISABLE=1", "MBEDTLS_PSA_CRYPTO_C"],
7900-
"m0_core_img": "psa_release_1.0.hex",
7898+
"hex_filename": "psa_release_1.0.hex",
79017899
"overrides": {
79027900
"secure-rom-start": "0x10000000",
79037901
"secure-rom-size": "0x80000",

tools/export/makefile/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class Makefile(Exporter):
5454
"MCU_NRF51Code.binary_hook",
5555
"TEENSY3_1Code.binary_hook",
5656
"LPCTargetCode.lpc_patch",
57-
"LPC4088Code.binary_hook"
57+
"LPC4088Code.binary_hook",
58+
"PSOC6Code.complete"
5859
])
5960

6061
@classmethod
@@ -83,6 +84,11 @@ def generate(self):
8384
sys_libs = [self.prepare_sys_lib(lib) for lib
8485
in self.toolchain.sys_libs]
8586

87+
hex_files = self.resources.hex_files
88+
if hasattr(self.toolchain.target, 'hex_filename'):
89+
hex_filename = self.toolchain.target.hex_filename
90+
hex_files = list(f for f in hex_files if basename(f) == hex_filename)
91+
8692
ctx = {
8793
'name': self.project_name,
8894
'to_be_compiled': to_be_compiled,
@@ -92,7 +98,7 @@ def generate(self):
9298
'linker_script': self.resources.linker_script,
9399
'libraries': libraries,
94100
'ld_sys_libs': sys_libs,
95-
'hex_files': self.resources.hex_files,
101+
'hex_files': hex_files,
96102
'vpath': (["../../.."]
97103
if (basename(dirname(dirname(self.export_dir)))
98104
== "projectfiles")

tools/targets/PSOC6.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright (c) 2017-2018 Future Electronics
3+
# Copyright (c) 2018-2019 Cypress Semiconductor Corporation
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -114,18 +115,18 @@ def complete_func(message_func, elf0, hexf0, hexf1=None, dest=None):
114115
ihex.write_hex_file(dest if dest else hexf0, write_start_addr=False, byte_count=64)
115116

116117
# Find Cortex M0 image.
117-
def find_cm0_image(toolchain, resources, elf, hexf):
118+
def find_cm0_image(toolchain, resources, elf, hexf, hex_filename):
118119
# Locate user-specified image
119120
from tools.resources import FileType
120121
hex_files = resources.get_file_paths(FileType.HEX)
121-
m0hexf = next((f for f in hex_files if os.path.basename(f) == toolchain.target.m0_core_img), None)
122+
m0hexf = next((f for f in hex_files if os.path.basename(f) == hex_filename), None)
122123
if toolchain.target.name.endswith('_PSA'):
123124
m0hexf = next((f for f in hex_files if os.path.basename(f) == os.path.basename(hexf)), m0hexf)
124125

125126
if m0hexf:
126127
toolchain.notify.debug("M0 core image file found: %s." % os.path.basename(m0hexf))
127128
else:
128-
toolchain.notify.debug("M0 core hex image file %s not found. Aborting." % toolchain.target.m0_core_img)
129+
toolchain.notify.debug("M0 core hex image file %s not found. Aborting." % hex_filename)
129130
raise ConfigException("Required M0 core hex image not found.")
130131

131132
return m0hexf

tools/targets/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,11 @@ class PSOC6Code:
583583
@staticmethod
584584
def complete(t_self, resources, elf, binf):
585585
from tools.targets.PSOC6 import complete as psoc6_complete
586-
if hasattr(t_self.target, "sub_target"):
586+
if hasattr(t_self.target, "hex_filename"):
587+
hex_filename = t_self.target.hex_filename
587588
# Completing main image involves merging M0 image.
588589
from tools.targets.PSOC6 import find_cm0_image
589-
m0hexf = find_cm0_image(t_self, resources, elf, binf)
590+
m0hexf = find_cm0_image(t_self, resources, elf, binf, hex_filename)
590591
psoc6_complete(t_self, elf, binf, m0hexf)
591592
else:
592593
psoc6_complete(t_self, elf, binf)

0 commit comments

Comments
 (0)