Skip to content

Commit 161376a

Browse files
committed
CMake: Add post build operation support
A CMake custom target, mbed-post-build, is added as a dependency of the application CMake target if a Mbed target adds a CMake custom target named mbed-post-build-bin. mbed-post-build-bin is added as a dependency of mbed-post-build. mbed-post-build-bin depends on the application binary. This is done so a CMake custom command that executes post-build can be added. The Python scripts that implement the operations have been modified to add CLI entry points so they can be called from CMake. Dependency on the old tool has been removed on those scripts by passing them exactly what they require instead of passing old tool Python objects. A consequence of that was to slightly amend how the old tool calls some of those Python modules. Support has only been added for Mbed targets that currently have a requirement for post build operations. This includes: LPC1114, LPC1768, ARCH_PRO, LPC54114, LPC546XX, FF_LPC546XX, ARM_MUSCA_B1, ARM_MUSCA_B1_NS, ARM_MUSCA_S1, ARM_MUSCA_S1_NS, CY8CKIT064B0S2_4343W, CYTFM_064B0S2_4343W, CYSBSYSKIT_01
1 parent 0c6753b commit 161376a

File tree

19 files changed

+482
-51
lines changed

19 files changed

+482
-51
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ function(mbed_generate_bin_hex target)
192192
"executable:"
193193
VERBATIM
194194
)
195+
196+
if(TARGET mbed-post-build-bin)
197+
add_custom_target(mbed-post-build
198+
ALL
199+
DEPENDS
200+
mbed-post-build-bin
201+
)
202+
endif()
195203
endfunction()
196204

197205
#

targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_ARM_SSG/scripts/mbed_set_post_build_arm_ssg.cmake)
5+
46
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
57
set(LINKER_FILE device/TOOLCHAIN_ARMC6/musca_ns.sct)
68
set(STARTUP_FILE device/TOOLCHAIN_ARMC6/startup_cmsdk_musca_ns.S)
@@ -52,3 +54,7 @@ target_link_libraries(mbed-core
5254
INTERFACE
5355
${CMAKE_CURRENT_SOURCE_DIR}/s_veneers.o
5456
)
57+
58+
mbed_post_build_musca_b1_merge_secure_bin(
59+
"${MBED_PATH}/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/tfm_s.bin"
60+
)

targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_ARM_SSG/scripts/mbed_set_post_build_arm_ssg.cmake)
5+
46
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
57
set(LINKER_FILE device/TOOLCHAIN_ARMC6/musca_ns.sct)
68
set(STARTUP_FILE device/TOOLCHAIN_ARMC6/startup_cmsdk_musca_ns.S)
@@ -58,3 +60,7 @@ target_link_libraries(mbed-core
5860
INTERFACE
5961
${CMAKE_CURRENT_SOURCE_DIR}/s_veneers.o
6062
)
63+
64+
mbed_post_build_musca_s1_merge_secure_bin(
65+
"${MBED_PATH}/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/tfm_s.bin"
66+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake)
5+
6+
#
7+
# Merge ARM MUSCA B1 secure and non-secure images.
8+
#
9+
function(mbed_post_build_musca_b1_merge_secure_bin secure_binary)
10+
find_package(Python3)
11+
12+
set(post_build_command
13+
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/targets/ARM_MUSCA_B1.py
14+
--non-secure-bin ${CMAKE_BINARY_DIR}/${APP_TARGET}.bin
15+
--secure-bin ${secure_binary}
16+
)
17+
18+
mbed_set_post_build_operation()
19+
endfunction()
20+
21+
#
22+
# Merge ARM MUSCA S1 secure and non-secure images.
23+
#
24+
function(mbed_post_build_musca_s1_merge_secure_bin secure_binary)
25+
find_package(Python3)
26+
27+
set(post_build_command
28+
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/targets/ARM_MUSCA_S1.py
29+
--non-secure-bin ${CMAKE_BINARY_DIR}/${APP_TARGET}.bin
30+
--secure-bin ${secure_binary}
31+
)
32+
33+
mbed_set_post_build_operation()
34+
endfunction()

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT064B0S2_4343W/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake)
5+
46
if("BSP_DESIGN_MODUS" IN_LIST MBED_TARGET_LABELS)
57
target_include_directories(mbed-core
68
INTERFACE
@@ -58,3 +60,13 @@ target_sources(mbed-core
5860
${SYSTEM_SOURCE}
5961
${STARTUP_FILE}
6062
)
63+
64+
mbed_post_build_psoc6_sign_image(
65+
"psoc6_02_cm0p_secure.hex"
66+
"CY8CKIT064B0S2_4343W"
67+
"policy_single_CM0_CM4.json"
68+
"single_image"
69+
"1"
70+
"16"
71+
"${MBED_PATH}/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT064B0S2_4343W/device/COMPONENT_CM4/hex/psoc6_02_cm0p_secure.hex"
72+
)

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake)
5+
46
if("BSP_DESIGN_MODUS" IN_LIST MBED_TARGET_LABELS)
57
target_include_directories(mbed-core
68
INTERFACE
@@ -47,3 +49,5 @@ target_sources(mbed-core
4749
${SYSTEM_SOURCE}
4850
${STARTUP_FILE}
4951
)
52+
53+
mbed_post_build_psoc6_merge_hex()

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYTFM_064B0S2_4343W/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake)
5+
46
if("BSP_DESIGN_MODUS" IN_LIST MBED_TARGET_LABELS)
57
target_include_directories(mbed-core
68
INTERFACE
@@ -62,3 +64,13 @@ target_sources(mbed-core
6264
${SYSTEM_SOURCE}
6365
${STARTUP_FILE}
6466
)
67+
68+
mbed_post_build_psoc6_sign_image(
69+
"tfm_s.hex"
70+
"CYTFM_064B0S2_4343W"
71+
"policy_multi_CM0_CM4_tfm.json"
72+
"multi_image"
73+
"1"
74+
"16"
75+
${MBED_PATH}/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYTFM_064B0S2_4343W/COMPONENT_TFM_S_FW/tfm_s.hex
76+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake)
5+
6+
#
7+
# Merge Cortex-M4 HEX and a Cortex-M0 HEX.
8+
#
9+
function(mbed_post_build_psoc6_merge_hex)
10+
find_package(Python3)
11+
12+
set (extra_macro_args ${ARGN})
13+
14+
list(LENGTH cortex_m0_hex num_extra_args)
15+
16+
if(${num_extra_args} GREATER 0)
17+
list(GET extra_macro_args 0 cortex_m0_hex)
18+
set(post_build_command
19+
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/targets/PSOC6.py
20+
merge
21+
--elf $<TARGET_FILE:${APP_TARGET}>
22+
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
23+
--m0hex ${cortex_m0_hex}
24+
)
25+
else()
26+
set(post_build_command
27+
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/targets/PSOC6.py
28+
merge
29+
--elf $<TARGET_FILE:${APP_TARGET}>
30+
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
31+
)
32+
endif()
33+
34+
mbed_set_post_build_operation()
35+
endfunction()
36+
37+
38+
#
39+
# Sign a Cortex-M4 HEX with Cortex-M0 HEX.
40+
#
41+
function(mbed_post_build_psoc6_sign_image
42+
m0hex_filename
43+
mbed_target_name
44+
policy_file_name
45+
boot_scheme
46+
cm0_img_id
47+
cm4_img_id
48+
cortex_m0_hex
49+
)
50+
find_package(Python3)
51+
52+
set(post_build_command
53+
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/targets/PSOC6.py
54+
sign
55+
--build-dir ${CMAKE_BINARY_DIR}
56+
--m0hex-filename ${m0hex_filename}
57+
--target-name ${mbed_target_name}
58+
--policy-file-name ${policy_file_name}
59+
--boot-scheme ${boot_scheme}
60+
--cm0-img-id ${cm0_img_id}
61+
--cm4-img-id ${cm4_img_id}
62+
--elf $<TARGET_FILE:${APP_TARGET}>
63+
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
64+
--m0hex ${cortex_m0_hex}
65+
)
66+
67+
mbed_set_post_build_operation()
68+
endfunction()

targets/TARGET_NXP/TARGET_LPC11XX_11CXX/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake)
5+
46
if("LPC11XX" IN_LIST MBED_TARGET_LABELS)
57
target_include_directories(mbed-core
68
INTERFACE
@@ -19,6 +21,8 @@ if("LPC11XX" IN_LIST MBED_TARGET_LABELS)
1921
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_LPC11xx.S)
2022
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/TARGET_LPC11XX/LPC1114.ld)
2123
endif()
24+
25+
mbed_post_build_lpc_patch_vtable()
2226
endif()
2327

2428
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

targets/TARGET_NXP/TARGET_LPC176X/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
include(${MBED_PATH}/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake)
5+
6+
47
if("ARCH_PRO" IN_LIST MBED_TARGET_LABELS)
58
target_include_directories(mbed-core
69
INTERFACE
710
TARGET_ARCH_PRO
811
)
12+
13+
mbed_post_build_lpc_patch_vtable()
914
elseif("MBED_LPC1768" IN_LIST MBED_TARGET_LABELS)
1015
target_include_directories(mbed-core
1116
INTERFACE
1217
TARGET_MBED_LPC1768
1318
)
19+
20+
mbed_post_build_lpc_patch_vtable()
1421
endif()
1522

1623
if(${MBED_TOOLCHAIN} STREQUAL "ARM")

0 commit comments

Comments
 (0)