Skip to content

Commit

Permalink
Merge pull request #14378 from LDong-Arm/post_build_rework
Browse files Browse the repository at this point in the history
CMake: Pass application/test name to post build operation
  • Loading branch information
0xc0170 committed Mar 5, 2021
2 parents 8a1ce92 + 8483411 commit ae432b2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
32 changes: 11 additions & 21 deletions targets/TARGET_Cypress/scripts/PSOC6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)

Expand All @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.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}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.hex
)
endif()

Expand Down Expand Up @@ -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}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.hex
--m0hex ${cortex_m0_hex}
)

Expand Down
10 changes: 3 additions & 7 deletions targets/TARGET_NXP/scripts/LPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.bin
)

mbed_set_post_build_operation()
Expand Down

0 comments on commit ae432b2

Please sign in to comment.