Skip to content

Commit 15ab0c3

Browse files
author
Jamie Smith
authored
Tweak upload method dependencies to be specified at a higher level, add LinkServer version check (#404)
1 parent 156cd15 commit 15ab0c3

11 files changed

+31
-19
lines changed

tools/cmake/UploadMethodManager.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,10 @@ function(mbed_generate_upload_target target)
146146
else()
147147
gen_upload_target(${target} ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${target}>.hex)
148148
endif()
149+
150+
# Make sure building the upload target causes the target to be built first
151+
if(TARGET flash-${target})
152+
add_dependencies(flash-${target} ${target})
153+
endif()
154+
149155
endfunction()

tools/cmake/upload_methods/FindLinkServer.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# This module defines:
88
# LinkServer - Whether the reqested tools were found.
99
# LinkServer_PATH - full path to the LinkServer command line tool.
10+
# LinkServer_VERSION - version number of LinkServer
1011

1112
# Check for LinkServer install folders on Windows
1213
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
@@ -26,6 +27,16 @@ find_program(LinkServer_PATH
2627
HINTS ${LINKSERVER_HINTS}
2728
)
2829

29-
find_package_handle_standard_args(LinkServer REQUIRED_VARS LinkServer_PATH)
30+
if(EXISTS "${LinkServer_PATH}")
31+
# Detect version
32+
execute_process(COMMAND ${LinkServer_PATH} --version
33+
OUTPUT_VARIABLE LinkServer_VERSION_OUTPUT)
34+
35+
# The output looks like "LinkServer v1.2.45 [Build 45] [2023-07-25 09:54:50]", so use a regex to grab the version
36+
string(REGEX REPLACE "LinkServer v([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" LinkServer_VERSION ${LinkServer_VERSION_OUTPUT})
37+
endif()
38+
39+
40+
find_package_handle_standard_args(LinkServer REQUIRED_VARS LinkServer_PATH VERSION_VAR LinkServer_VERSION)
3041

3142

tools/cmake/upload_methods/UploadMethodARDUINO_BOSSAC.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,4 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
2828
--write ${BINARY_FILE}
2929
--reset)
3030

31-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
32-
3331
endfunction(gen_upload_target)

tools/cmake/upload_methods/UploadMethodJLINK.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ exit
7171
-ExitOnError
7272
-CommandFile ${COMMAND_FILE_PATH})
7373

74-
75-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
76-
7774
endfunction(gen_upload_target)
7875

7976
### Commands to run the debug server.

tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ endif()
2323
find_package(LinkServer)
2424
set(UPLOAD_LINKSERVER_FOUND ${LinkServer_FOUND})
2525

26+
if(LinkServer_FOUND)
27+
if(${LinkServer_VERSION} VERSION_LESS 1.5.30 AND "${MBED_OUTPUT_EXT}" STREQUAL "hex")
28+
message(FATAL_ERROR "LinkServer <1.5.30 does not support flashing hex files! Please upgrade LinkServer and then clean and rebuild the project.")
29+
endif()
30+
endif()
31+
2632
### Function to generate upload target
2733

2834
function(gen_upload_target TARGET_NAME BINARY_FILE)
@@ -37,8 +43,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
3743
--addr ${MBED_UPLOAD_BASE_ADDR}
3844
${BINARY_FILE})
3945

40-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
41-
4246
endfunction(gen_upload_target)
4347

4448
### Commands to run the debug server.

tools/cmake/upload_methods/UploadMethodMBED.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
2525
${mbed-os_SOURCE_DIR}/tools/python
2626
VERBATIM)
2727

28-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
29-
3028
endfunction(gen_upload_target)

tools/cmake/upload_methods/UploadMethodOPENOCD.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ endif()
4141

4242
function(gen_upload_target TARGET_NAME BINARY_FILE)
4343

44-
# unlike other upload methods, OpenOCD uses the elf file
4544
add_custom_target(flash-${TARGET_NAME}
4645
COMMENT "Flashing ${TARGET_NAME} with OpenOCD..."
4746
COMMAND ${OpenOCD}
@@ -51,7 +50,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
5150
-c "program ${BINARY_FILE} ${MBED_UPLOAD_BASE_ADDR} reset exit"
5251
VERBATIM)
5352

54-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
5553
endfunction(gen_upload_target)
5654

5755
### Commands to run the debug server.

tools/cmake/upload_methods/UploadMethodPICOTOOL.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
2929
list(APPEND PICOTOOL_TARGET_ARGS --address ${PICOTOOL_TARGET_ADDRESS})
3030
endif()
3131

32+
if("${MBED_OUTPUT_EXT}" STREQUAL "hex")
33+
message(FATAL_ERROR "Bin file output must be enabled to use picotool. Set MBED_OUTPUT_EXT to empty string or to 'bin' in your top level CMakeLists.txt!")
34+
endif()
35+
3236
add_custom_target(flash-${TARGET_NAME}
3337
COMMAND ${Picotool}
3438
load
39+
--verify
3540
--execute
36-
$<TARGET_FILE:${TARGET_NAME}>)
37-
38-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
41+
--offset ${MBED_UPLOAD_BASE_ADDR}
42+
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${TARGET_NAME}>.bin)
3943

4044
endfunction(gen_upload_target)

tools/cmake/upload_methods/UploadMethodPYOCD.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
3434
--base-address ${MBED_UPLOAD_BASE_ADDR}
3535
${BINARY_FILE})
3636

37-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
3837
endfunction(gen_upload_target)
3938

4039
### Commands to run the debug server.

tools/cmake/upload_methods/UploadMethodSTLINK.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
3232
${STLINK_ARGS}
3333
write ${BINARY_FILE} ${MBED_UPLOAD_BASE_ADDR})
3434

35-
add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
3635
endfunction(gen_upload_target)
3736

3837
### Commands to run the debug server.

0 commit comments

Comments
 (0)