From 03914d1875997a8090e15b0d2274f8c884a9663d Mon Sep 17 00:00:00 2001 From: Hugues Kamba Date: Tue, 23 Feb 2021 17:24:31 +0000 Subject: [PATCH] CMake: Remove references of APP_TARGET This needs to be removed as there should not be a name requirement for application CMake variable name. Furthermore, in certain uses cases it prevents successful builds for some Mbed targets. For instance when building Greentea test applications for Mbed targets that require post build operations as they do not define APP_TARGET. --- targets/TARGET_Cypress/scripts/PSOC6.py | 39 +++++++++++++------ .../scripts/mbed_set_post_build_cypress.cmake | 9 ++--- targets/TARGET_NXP/scripts/LPC.py | 16 +++++++- .../scripts/mbed_set_post_build_nxp.cmake | 2 +- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/targets/TARGET_Cypress/scripts/PSOC6.py b/targets/TARGET_Cypress/scripts/PSOC6.py index 75cf003fd9..263cac85a9 100644 --- a/targets/TARGET_Cypress/scripts/PSOC6.py +++ b/targets/TARGET_Cypress/scripts/PSOC6.py @@ -17,6 +17,7 @@ # import argparse +import pathlib import logging import os import sys @@ -59,6 +60,12 @@ class AddSignatureError(Exception): adding signature to Secure Boot image """ + +class ArtefactsError(Exception): + """An exception to indicate that the artefact(s) needed for processing + ave not been found.""" + + # Base class for all configuration exceptions class ConfigException(Exception): """Config system only exception. Makes it easier to distinguish config @@ -306,13 +313,29 @@ def complete(message_func, elf0, hexf0, hexf1=None): def merge_action(args): """Entry point for the "merge" CLI command.""" + try: + elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0] + m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0] + except IndexError: + raise ArtefactsError( + f"Could not find elf and/or hex file in {args.artefacts_location}" + ) + complete_func( - print, args.elf, args.m4hex, args.m0hex + print, elf_file, m4hex_file, args.m0hex ) def sign_action(args): """Entry point for the "sign" CLI command.""" + try: + elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0] + m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0] + except IndexError: + raise ArtefactsError( + f"Could not find elf and/or hex file in {args.artefacts_location}" + ) + sign_hex( args.build_dir, args.m0hex_filename, @@ -322,8 +345,8 @@ def sign_action(args): args.boot_scheme, args.cm0_img_id, args.cm4_img_id, - args.elf, - args.m4hex, + elf_file, + m4hex_file, args.m0hex ) @@ -340,10 +363,7 @@ def parse_args(): "merge", help="Merge Cortex-M4 and Cortex-M0 HEX files." ) merge_subcommand.add_argument( - "--elf", required=True, help="the application ELF file." - ) - merge_subcommand.add_argument( - "--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge." + "--artefacts-location", required=True, help="the path to the application artefacts." ) merge_subcommand.add_argument( "--m0hex", help="the path to the Cortex-M0 HEX to merge." @@ -375,10 +395,7 @@ def parse_args(): "--cm4-img-id", help="the Cortex-M4 image ID." ) sign_subcommand.add_argument( - "--elf", required=True, help="the application ELF file." - ) - sign_subcommand.add_argument( - "--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge." + "--artefacts-location", required=True, help="the path to the application artefacts." ) sign_subcommand.add_argument( "--m0hex", help="the path to the Cortex-M0 HEX to merge." diff --git a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake index 759edc774f..01e950699e 100644 --- a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake +++ b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake @@ -22,16 +22,14 @@ function(mbed_post_build_psoc6_merge_hex mbed_target_name) set(post_build_command COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py merge - --elf $ - --m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex + --artefacts-location ${CMAKE_BINARY_DIR} --m0hex ${cortex_m0_hex} ) else() set(post_build_command COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py merge - --elf $ - --m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex + --artefacts-location ${CMAKE_BINARY_DIR} ) endif() @@ -63,8 +61,7 @@ function(mbed_post_build_psoc6_sign_image --boot-scheme ${boot_scheme} --cm0-img-id ${cm0_img_id} --cm4-img-id ${cm4_img_id} - --elf $ - --m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex + --artefacts-location ${CMAKE_BINARY_DIR} --m0hex ${cortex_m0_hex} ) diff --git a/targets/TARGET_NXP/scripts/LPC.py b/targets/TARGET_NXP/scripts/LPC.py index bfccbfb756..095b35cf28 100644 --- a/targets/TARGET_NXP/scripts/LPC.py +++ b/targets/TARGET_NXP/scripts/LPC.py @@ -24,11 +24,17 @@ causes the checksum of the first 8 table entries to be 0. The boot loader code c the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is transferred to the user code. """ +import pathlib import os import sys from struct import unpack, pack +class ArtefactsError(Exception): + """An exception to indicate that the artefact(s) needed for processing + ave not been found.""" + + def patch(bin_path): with open(bin_path, 'r+b') as bin: # Read entries 0 through 6 (Little Endian 32bits words) @@ -47,6 +53,14 @@ def is_patched(bin_path): if __name__ == "__main__": - binary = sys.argv[1] + artefacts_location = sys.argv[1] + + try: + binary = list(pathlib.Path(artefacts_location).glob("*.bin"))[0] + except IndexError: + raise ArtefactsError( + f"Could not find binary file in {artefacts_location}" + ) + print("LPC Patch: %s" % os.path.split(binary)[1]) patch(binary) diff --git a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake index bfdc791e74..9a63433250 100644 --- a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake +++ b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake @@ -11,7 +11,7 @@ function(mbed_post_build_lpc_patch_vtable mbed_target_name) set(post_build_command COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_NXP/scripts/LPC.py - ${CMAKE_BINARY_DIR}/${APP_TARGET}.bin + ${CMAKE_BINARY_DIR} ) mbed_set_post_build_operation()