Merge pull request #14378 from LDong-Arm/post_build_rework

CMake: Pass application/test name to post build operation
pull/14386/head
Martin Kojtal 2021-03-05 15:49:53 +00:00 committed by GitHub
commit ae432b24a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 32 deletions

View File

@ -171,6 +171,18 @@ function(mbed_generate_bin_hex target)
) )
if(TARGET mbed-post-build-bin-${MBED_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 # The artefacts must be created before they can be further manipulated
add_dependencies(mbed-post-build-bin-${MBED_TARGET} ${target}) add_dependencies(mbed-post-build-bin-${MBED_TARGET} ${target})

View File

@ -318,29 +318,13 @@ def complete(message_func, elf0, hexf0, hexf1=None):
def merge_action(args): def merge_action(args):
"""Entry point for the "merge" CLI command.""" """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( complete_func(
print, elf_file, m4hex_file, args.m0hex print, args.elf, args.m4hex, args.m0hex
) )
def sign_action(args): def sign_action(args):
"""Entry point for the "sign" CLI command.""" """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( sign_hex(
args.build_dir, args.build_dir,
args.m0hex_filename, args.m0hex_filename,
@ -350,8 +334,8 @@ def sign_action(args):
args.boot_scheme, args.boot_scheme,
args.cm0_img_id, args.cm0_img_id,
args.cm4_img_id, args.cm4_img_id,
elf_file, args.elf,
m4hex_file, args.m4hex,
args.m0hex args.m0hex
) )
@ -368,7 +352,10 @@ def parse_args():
"merge", help="Merge Cortex-M4 and Cortex-M0 HEX files." "merge", help="Merge Cortex-M4 and Cortex-M0 HEX files."
) )
merge_subcommand.add_argument( 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( merge_subcommand.add_argument(
"--m0hex", help="the path to the Cortex-M0 HEX to merge." "--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." "--cm4-img-id", type=int, help="the Cortex-M4 image ID."
) )
sign_subcommand.add_argument( 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( sign_subcommand.add_argument(
"--m0hex", help="the path to the Cortex-M0 HEX to merge." "--m0hex", help="the path to the Cortex-M0 HEX to merge."

View File

@ -22,14 +22,16 @@ function(mbed_post_build_psoc6_merge_hex mbed_target_name)
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
merge 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} --m0hex ${cortex_m0_hex}
) )
else() else()
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
merge 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() endif()
@ -61,7 +63,8 @@ function(mbed_post_build_psoc6_sign_image
--boot-scheme ${boot_scheme} --boot-scheme ${boot_scheme}
--cm0-img-id ${cm0_img_id} --cm0-img-id ${cm0_img_id}
--cm4-img-id ${cm4_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} --m0hex ${cortex_m0_hex}
) )

View File

@ -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 the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is
transferred to the user code. transferred to the user code.
""" """
import pathlib
import os import os
import sys import sys
from struct import unpack, pack from struct import unpack, pack
@ -53,13 +52,10 @@ def is_patched(bin_path):
if __name__ == "__main__": if __name__ == "__main__":
artefacts_location = sys.argv[1] binary = sys.argv[1]
if not os.path.isfile(binary):
try:
binary = list(pathlib.Path(artefacts_location).glob("*.bin"))[0]
except IndexError:
raise ArtefactsError( 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]) print("LPC Patch: %s" % os.path.split(binary)[1])

View File

@ -11,7 +11,7 @@ function(mbed_post_build_lpc_patch_vtable mbed_target_name)
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_NXP/scripts/LPC.py 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() mbed_set_post_build_operation()