diff --git a/CMakeLists.txt b/CMakeLists.txt index fe0587aec2..ad61efd96b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,18 @@ function(mbed_generate_bin_hex target) ) if(TARGET mbed-post-build-bin-${MBED_TARGET}) + # Remove the .elf file to force regenerate the application binaries + # (including .bin and .hex). This ensures that the post-build script runs + # on a raw application instead of a previous build that already went + # through the post-build process once. + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${target}.elf) + + # Pass the application's name to the Mbed target's post build operation + set_target_properties(mbed-post-build-bin-${MBED_TARGET} + PROPERTIES + application ${target} + ) + # The artefacts must be created before they can be further manipulated add_dependencies(mbed-post-build-bin-${MBED_TARGET} ${target}) diff --git a/targets/TARGET_Cypress/scripts/PSOC6.py b/targets/TARGET_Cypress/scripts/PSOC6.py index e9b299daf5..ea0d91a43e 100644 --- a/targets/TARGET_Cypress/scripts/PSOC6.py +++ b/targets/TARGET_Cypress/scripts/PSOC6.py @@ -318,29 +318,13 @@ 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, elf_file, m4hex_file, args.m0hex + print, args.elf, args.m4hex, 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, @@ -350,8 +334,8 @@ def sign_action(args): args.boot_scheme, args.cm0_img_id, args.cm4_img_id, - elf_file, - m4hex_file, + args.elf, + args.m4hex, args.m0hex ) @@ -368,7 +352,10 @@ def parse_args(): "merge", help="Merge Cortex-M4 and Cortex-M0 HEX files." ) merge_subcommand.add_argument( - "--artefacts-location", required=True, help="the path to the application artefacts." + "--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." ) merge_subcommand.add_argument( "--m0hex", help="the path to the Cortex-M0 HEX to merge." @@ -400,7 +387,10 @@ def parse_args(): "--cm4-img-id", type=int, help="the Cortex-M4 image ID." ) sign_subcommand.add_argument( - "--artefacts-location", required=True, help="the path to the application artefacts." + "--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." ) 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 01e950699e..399900d5a4 100644 --- a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake +++ b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake @@ -22,14 +22,16 @@ 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 - --artefacts-location ${CMAKE_BINARY_DIR} + --elf ${CMAKE_BINARY_DIR}/$.elf + --m4hex ${CMAKE_BINARY_DIR}/$.hex --m0hex ${cortex_m0_hex} ) else() set(post_build_command COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py merge - --artefacts-location ${CMAKE_BINARY_DIR} + --elf ${CMAKE_BINARY_DIR}/$.elf + --m4hex ${CMAKE_BINARY_DIR}/$.hex ) endif() @@ -61,7 +63,8 @@ function(mbed_post_build_psoc6_sign_image --boot-scheme ${boot_scheme} --cm0-img-id ${cm0_img_id} --cm4-img-id ${cm4_img_id} - --artefacts-location ${CMAKE_BINARY_DIR} + --elf ${CMAKE_BINARY_DIR}/$.elf + --m4hex ${CMAKE_BINARY_DIR}/$.hex --m0hex ${cortex_m0_hex} ) diff --git a/targets/TARGET_NXP/scripts/LPC.py b/targets/TARGET_NXP/scripts/LPC.py index 095b35cf28..9ef8615061 100644 --- a/targets/TARGET_NXP/scripts/LPC.py +++ b/targets/TARGET_NXP/scripts/LPC.py @@ -24,7 +24,6 @@ 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 @@ -53,13 +52,10 @@ def is_patched(bin_path): if __name__ == "__main__": - artefacts_location = sys.argv[1] - - try: - binary = list(pathlib.Path(artefacts_location).glob("*.bin"))[0] - except IndexError: + binary = sys.argv[1] + if not os.path.isfile(binary): raise ArtefactsError( - f"Could not find binary file in {artefacts_location}" + f"Could not find binary file {binary}" ) print("LPC Patch: %s" % os.path.split(binary)[1]) 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 9a63433250..8e18e3956b 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} + ${CMAKE_BINARY_DIR}/$.bin ) mbed_set_post_build_operation()