Skip to content

Commit ae432b2

Browse files
authored
Merge pull request #14378 from LDong-Arm/post_build_rework
CMake: Pass application/test name to post build operation
2 parents 8a1ce92 + 8483411 commit ae432b2

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ function(mbed_generate_bin_hex target)
171171
)
172172

173173
if(TARGET mbed-post-build-bin-${MBED_TARGET})
174+
# Remove the .elf file to force regenerate the application binaries
175+
# (including .bin and .hex). This ensures that the post-build script runs
176+
# on a raw application instead of a previous build that already went
177+
# through the post-build process once.
178+
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${target}.elf)
179+
180+
# Pass the application's name to the Mbed target's post build operation
181+
set_target_properties(mbed-post-build-bin-${MBED_TARGET}
182+
PROPERTIES
183+
application ${target}
184+
)
185+
174186
# The artefacts must be created before they can be further manipulated
175187
add_dependencies(mbed-post-build-bin-${MBED_TARGET} ${target})
176188

targets/TARGET_Cypress/scripts/PSOC6.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -318,29 +318,13 @@ def complete(message_func, elf0, hexf0, hexf1=None):
318318

319319
def merge_action(args):
320320
"""Entry point for the "merge" CLI command."""
321-
try:
322-
elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0]
323-
m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0]
324-
except IndexError:
325-
raise ArtefactsError(
326-
f"Could not find elf and/or hex file in {args.artefacts_location}"
327-
)
328-
329321
complete_func(
330-
print, elf_file, m4hex_file, args.m0hex
322+
print, args.elf, args.m4hex, args.m0hex
331323
)
332324

333325

334326
def sign_action(args):
335327
"""Entry point for the "sign" CLI command."""
336-
try:
337-
elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0]
338-
m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0]
339-
except IndexError:
340-
raise ArtefactsError(
341-
f"Could not find elf and/or hex file in {args.artefacts_location}"
342-
)
343-
344328
sign_hex(
345329
args.build_dir,
346330
args.m0hex_filename,
@@ -350,8 +334,8 @@ def sign_action(args):
350334
args.boot_scheme,
351335
args.cm0_img_id,
352336
args.cm4_img_id,
353-
elf_file,
354-
m4hex_file,
337+
args.elf,
338+
args.m4hex,
355339
args.m0hex
356340
)
357341

@@ -368,7 +352,10 @@ def parse_args():
368352
"merge", help="Merge Cortex-M4 and Cortex-M0 HEX files."
369353
)
370354
merge_subcommand.add_argument(
371-
"--artefacts-location", required=True, help="the path to the application artefacts."
355+
"--elf", required=True, help="the application ELF file."
356+
)
357+
merge_subcommand.add_argument(
358+
"--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge."
372359
)
373360
merge_subcommand.add_argument(
374361
"--m0hex", help="the path to the Cortex-M0 HEX to merge."
@@ -400,7 +387,10 @@ def parse_args():
400387
"--cm4-img-id", type=int, help="the Cortex-M4 image ID."
401388
)
402389
sign_subcommand.add_argument(
403-
"--artefacts-location", required=True, help="the path to the application artefacts."
390+
"--elf", required=True, help="the application ELF file."
391+
)
392+
sign_subcommand.add_argument(
393+
"--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge."
404394
)
405395
sign_subcommand.add_argument(
406396
"--m0hex", help="the path to the Cortex-M0 HEX to merge."

targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ function(mbed_post_build_psoc6_merge_hex mbed_target_name)
2222
set(post_build_command
2323
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
2424
merge
25-
--artefacts-location ${CMAKE_BINARY_DIR}
25+
--elf ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
26+
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.hex
2627
--m0hex ${cortex_m0_hex}
2728
)
2829
else()
2930
set(post_build_command
3031
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
3132
merge
32-
--artefacts-location ${CMAKE_BINARY_DIR}
33+
--elf ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
34+
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.hex
3335
)
3436
endif()
3537

@@ -61,7 +63,8 @@ function(mbed_post_build_psoc6_sign_image
6163
--boot-scheme ${boot_scheme}
6264
--cm0-img-id ${cm0_img_id}
6365
--cm4-img-id ${cm4_img_id}
64-
--artefacts-location ${CMAKE_BINARY_DIR}
66+
--elf ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.elf
67+
--m4hex ${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.hex
6568
--m0hex ${cortex_m0_hex}
6669
)
6770

targets/TARGET_NXP/scripts/LPC.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is
2525
transferred to the user code.
2626
"""
27-
import pathlib
2827
import os
2928
import sys
3029
from struct import unpack, pack
@@ -53,13 +52,10 @@ def is_patched(bin_path):
5352

5453

5554
if __name__ == "__main__":
56-
artefacts_location = sys.argv[1]
57-
58-
try:
59-
binary = list(pathlib.Path(artefacts_location).glob("*.bin"))[0]
60-
except IndexError:
55+
binary = sys.argv[1]
56+
if not os.path.isfile(binary):
6157
raise ArtefactsError(
62-
f"Could not find binary file in {artefacts_location}"
58+
f"Could not find binary file {binary}"
6359
)
6460

6561
print("LPC Patch: %s" % os.path.split(binary)[1])

targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function(mbed_post_build_lpc_patch_vtable mbed_target_name)
1111

1212
set(post_build_command
1313
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_NXP/scripts/LPC.py
14-
${CMAKE_BINARY_DIR}
14+
${CMAKE_BINARY_DIR}/$<TARGET_PROPERTY:mbed-post-build-bin-${mbed_target_name},application>.bin
1515
)
1616

1717
mbed_set_post_build_operation()

0 commit comments

Comments
 (0)