From 5d819621e9df1478789cfc31967fbd8c878b8c5d Mon Sep 17 00:00:00 2001 From: Volodymyr Medvid Date: Tue, 22 Jan 2019 15:40:22 -0800 Subject: [PATCH] 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" } } --- targets/targets.json | 6 ++---- tools/export/makefile/__init__.py | 10 ++++++++-- tools/targets/PSOC6.py | 7 ++++--- tools/targets/__init__.py | 5 +++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/targets/targets.json b/targets/targets.json index edf5e32e49..f4ce81e17b 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -7838,12 +7838,11 @@ }, "FUTURE_SEQUANA": { "inherits": ["MCU_PSOC6_M4"], - "sub_target": "FUTURE_SEQUANA_M0", "supported_form_factors": ["ARDUINO"], "extra_labels_add": ["CY8C63XX", "CORDIO"], "macros_add": ["CY8C6347BZI_BLD53"], "detect_code": ["6000"], - "m0_core_img": "psoc63_m0_default_1.02.hex", + "hex_filename": "psoc63_m0_default_1.02.hex", "post_binary_hook": { "function": "PSOC6Code.complete" }, @@ -7893,12 +7892,11 @@ }, "FUTURE_SEQUANA_PSA": { "inherits": ["NSPE_Target", "FUTURE_SEQUANA"], - "sub_target": "FUTURE_SEQUANA_M0_PSA", "extra_labels_add": ["PSA"], "extra_labels_remove": ["CORDIO"], "components_add": ["SPM_MAILBOX"], "macros_add": ["PSOC6_DYNSRM_DISABLE=1", "MBEDTLS_PSA_CRYPTO_C"], - "m0_core_img": "psa_release_1.0.hex", + "hex_filename": "psa_release_1.0.hex", "overrides": { "secure-rom-start": "0x10000000", "secure-rom-size": "0x80000", diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 430435e3bc..0c1c07bbd3 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -54,7 +54,8 @@ class Makefile(Exporter): "MCU_NRF51Code.binary_hook", "TEENSY3_1Code.binary_hook", "LPCTargetCode.lpc_patch", - "LPC4088Code.binary_hook" + "LPC4088Code.binary_hook", + "PSOC6Code.complete" ]) @classmethod @@ -83,6 +84,11 @@ class Makefile(Exporter): sys_libs = [self.prepare_sys_lib(lib) for lib in self.toolchain.sys_libs] + hex_files = self.resources.hex_files + if hasattr(self.toolchain.target, 'hex_filename'): + hex_filename = self.toolchain.target.hex_filename + hex_files = list(f for f in hex_files if basename(f) == hex_filename) + ctx = { 'name': self.project_name, 'to_be_compiled': to_be_compiled, @@ -92,7 +98,7 @@ class Makefile(Exporter): 'linker_script': self.resources.linker_script, 'libraries': libraries, 'ld_sys_libs': sys_libs, - 'hex_files': self.resources.hex_files, + 'hex_files': hex_files, 'vpath': (["../../.."] if (basename(dirname(dirname(self.export_dir))) == "projectfiles") diff --git a/tools/targets/PSOC6.py b/tools/targets/PSOC6.py index acc45a01f6..d6a32c0d01 100644 --- a/tools/targets/PSOC6.py +++ b/tools/targets/PSOC6.py @@ -1,5 +1,6 @@ # # Copyright (c) 2017-2018 Future Electronics +# Copyright (c) 2018-2019 Cypress Semiconductor Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # 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): ihex.write_hex_file(dest if dest else hexf0, write_start_addr=False, byte_count=64) # Find Cortex M0 image. -def find_cm0_image(toolchain, resources, elf, hexf): +def find_cm0_image(toolchain, resources, elf, hexf, hex_filename): # Locate user-specified image from tools.resources import FileType hex_files = resources.get_file_paths(FileType.HEX) - m0hexf = next((f for f in hex_files if os.path.basename(f) == toolchain.target.m0_core_img), None) + m0hexf = next((f for f in hex_files if os.path.basename(f) == hex_filename), None) if toolchain.target.name.endswith('_PSA'): m0hexf = next((f for f in hex_files if os.path.basename(f) == os.path.basename(hexf)), m0hexf) if m0hexf: toolchain.notify.debug("M0 core image file found: %s." % os.path.basename(m0hexf)) else: - toolchain.notify.debug("M0 core hex image file %s not found. Aborting." % toolchain.target.m0_core_img) + toolchain.notify.debug("M0 core hex image file %s not found. Aborting." % hex_filename) raise ConfigException("Required M0 core hex image not found.") return m0hexf diff --git a/tools/targets/__init__.py b/tools/targets/__init__.py index 48a24e9eca..9ec4fca800 100644 --- a/tools/targets/__init__.py +++ b/tools/targets/__init__.py @@ -583,10 +583,11 @@ class PSOC6Code: @staticmethod def complete(t_self, resources, elf, binf): from tools.targets.PSOC6 import complete as psoc6_complete - if hasattr(t_self.target, "sub_target"): + if hasattr(t_self.target, "hex_filename"): + hex_filename = t_self.target.hex_filename # Completing main image involves merging M0 image. from tools.targets.PSOC6 import find_cm0_image - m0hexf = find_cm0_image(t_self, resources, elf, binf) + m0hexf = find_cm0_image(t_self, resources, elf, binf, hex_filename) psoc6_complete(t_self, elf, binf, m0hexf) else: psoc6_complete(t_self, elf, binf)