Skip to content

Commit

Permalink
Tweak upload method dependencies to be specified at a higher level, a…
Browse files Browse the repository at this point in the history
…dd LinkServer version check
  • Loading branch information
multiplemonomials committed Dec 14, 2024
1 parent 156cd15 commit b49e4f3
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 19 deletions.
6 changes: 6 additions & 0 deletions tools/cmake/UploadMethodManager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ function(mbed_generate_upload_target target)
else()
gen_upload_target(${target} ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${target}>.hex)
endif()

# Make sure building the upload target causes the target to be built first
if(TARGET flash-${target})
add_dependencies(flash-${target} ${target})
endif()

endfunction()
13 changes: 12 additions & 1 deletion tools/cmake/upload_methods/FindLinkServer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# This module defines:
# LinkServer - Whether the reqested tools were found.
# LinkServer_PATH - full path to the LinkServer command line tool.
# LinkServer_VERSION - version number of LinkServer

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

find_package_handle_standard_args(LinkServer REQUIRED_VARS LinkServer_PATH)
if(EXISTS "${LinkServer_PATH}")
# Detect version
execute_process(COMMAND ${LinkServer_PATH} --version
OUTPUT_VARIABLE LinkServer_VERSION_OUTPUT)

# The output looks like "LinkServer v1.2.45 [Build 45] [2023-07-25 09:54:50]", so use a regex to grab the version
string(REGEX REPLACE "LinkServer v([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" LinkServer_VERSION ${LinkServer_VERSION_OUTPUT})
endif()


find_package_handle_standard_args(LinkServer REQUIRED_VARS LinkServer_PATH VERSION_VAR LinkServer_VERSION)


2 changes: 0 additions & 2 deletions tools/cmake/upload_methods/UploadMethodARDUINO_BOSSAC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
--write ${BINARY_FILE}
--reset)

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})

endfunction(gen_upload_target)
3 changes: 0 additions & 3 deletions tools/cmake/upload_methods/UploadMethodJLINK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ exit
-ExitOnError
-CommandFile ${COMMAND_FILE_PATH})


add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})

endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down
8 changes: 6 additions & 2 deletions tools/cmake/upload_methods/UploadMethodLINKSERVER.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ endif()
find_package(LinkServer)
set(UPLOAD_LINKSERVER_FOUND ${LinkServer_FOUND})

if(LinkServer_FOUND)
if(${LinkServer_VERSION} VERSION_LESS 1.5.30 AND "${MBED_OUTPUT_EXT}" STREQUAL "hex")
message(FATAL_ERROR "LinkServer <1.5.30 does not support flashing hex files! Please upgrade LinkServer and then clean and rebuild the project.")
endif()
endif()

### Function to generate upload target

function(gen_upload_target TARGET_NAME BINARY_FILE)
Expand All @@ -37,8 +43,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
--addr ${MBED_UPLOAD_BASE_ADDR}
${BINARY_FILE})

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})

endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down
2 changes: 0 additions & 2 deletions tools/cmake/upload_methods/UploadMethodMBED.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
${mbed-os_SOURCE_DIR}/tools/python
VERBATIM)

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})

endfunction(gen_upload_target)
2 changes: 0 additions & 2 deletions tools/cmake/upload_methods/UploadMethodOPENOCD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ endif()

function(gen_upload_target TARGET_NAME BINARY_FILE)

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

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down
10 changes: 7 additions & 3 deletions tools/cmake/upload_methods/UploadMethodPICOTOOL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
list(APPEND PICOTOOL_TARGET_ARGS --address ${PICOTOOL_TARGET_ADDRESS})
endif()

if("${MBED_OUTPUT_EXT}" STREQUAL "hex")
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!")
endif()

add_custom_target(flash-${TARGET_NAME}
COMMAND ${Picotool}
load
--verify
--execute
$<TARGET_FILE:${TARGET_NAME}>)

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
--offset ${MBED_UPLOAD_BASE_ADDR}
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${TARGET_NAME}>.bin)

endfunction(gen_upload_target)
1 change: 0 additions & 1 deletion tools/cmake/upload_methods/UploadMethodPYOCD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
--base-address ${MBED_UPLOAD_BASE_ADDR}
${BINARY_FILE})

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down
1 change: 0 additions & 1 deletion tools/cmake/upload_methods/UploadMethodSTLINK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
${STLINK_ARGS}
write ${BINARY_FILE} ${MBED_UPLOAD_BASE_ADDR})

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down
2 changes: 0 additions & 2 deletions tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function(gen_upload_target TARGET_NAME BINARY_FILE)
-w ${BINARY_FILE} ${MBED_UPLOAD_BASE_ADDR}
-rst)

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})

endfunction(gen_upload_target)

### Commands to run the debug server.
Expand Down

0 comments on commit b49e4f3

Please sign in to comment.