Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload: NUVOTON: Change GDB load command to flash post-build processed image #341

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tools/cmake/UploadMethodManager.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Change GDB load command to flash post-build processed image in debug launch.
# With this adjustment, GDB load command changes to "load <app>.hex" from
# just "load":
# 1. "Load" will load <app>.elf and is inappropriate for targets like
# bootloader or TF-M enabled which need to post-build process images.
# 2. "load <app>.bin" is not considered because GDB load command
# doesn't support binary format.
#
# NOTE: Place at the very start so that it can override by the below loaded
# upload method if need be.
function(mbed_adjust_upload_debug_commands target)
# MBED_UPLOAD_LAUNCH_COMMANDS defined?
if(NOT DEFINED MBED_UPLOAD_LAUNCH_COMMANDS)
return()
endif()

# GDB load command in MBED_UPLOAD_LAUNCH_COMMANDS?
list(FIND MBED_UPLOAD_LAUNCH_COMMANDS "load" LOAD_INDEX)
if(${LOAD_INDEX} LESS "0")
return()
endif()

# <app>.hex for debug launch load
set(HEX_FILE ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${target}>.hex)

# "load" -> "load <app>.hex"
#
# GDB load command doesn't support binary format. Ignore OUTPUT_EXT
# and fix to Intel Hex format.
#
# NOTE: The <app>.hex file name needs to be quoted (\\\") to pass along
# to gdb correctly.
list(TRANSFORM MBED_UPLOAD_LAUNCH_COMMANDS APPEND " \\\"${HEX_FILE}\\\"" AT ${LOAD_INDEX})

# Update MBED_UPLOAD_LAUNCH_COMMANDS in cache
set(MBED_UPLOAD_LAUNCH_COMMANDS ${MBED_UPLOAD_LAUNCH_COMMANDS} CACHE INTERNAL "" FORCE)
endfunction()

# ----------------------------------------------
# Load the upload method that the user selects

Expand Down
30 changes: 15 additions & 15 deletions tools/cmake/mbed_ide_debug_cfg_generator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,6 @@ elseif(MBED_UPLOAD_SUPPORTS_DEBUG)

function(mbed_generate_ide_debug_configuration CMAKE_TARGET)

# add debug target
if(MBED_UPLOAD_SUPPORTS_DEBUG AND MBED_GDB_FOUND)
add_custom_target(debug-${target}
COMMENT "Starting GDB to debug ${target}..."
COMMAND ${MBED_GDB}
--command=${CMAKE_BINARY_DIR}/mbed-cmake.gdbinit
$<TARGET_FILE:${target}>
USES_TERMINAL)
endif()

endfunction(mbed_generate_ide_debug_configuration)

function(mbed_finalize_ide_debug_configurations)

# create init file for GDB client
if(MBED_UPLOAD_WANTS_EXTENDED_REMOTE)
set(UPLOAD_GDB_REMOTE_KEYWORD "extended-remote")
Expand All @@ -264,13 +250,27 @@ elseif(MBED_UPLOAD_SUPPORTS_DEBUG)

list(JOIN MBED_UPLOAD_LAUNCH_COMMANDS "\n" MBED_UPLOAD_LAUNCH_COMMANDS_FOR_GDBINIT)

file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/mbed-cmake.gdbinit CONTENT
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${CMAKE_TARGET}>.gdbinit CONTENT
"# connect to GDB server
target ${UPLOAD_GDB_REMOTE_KEYWORD} 127.0.0.1:${GDB_PORT}
${MBED_UPLOAD_LAUNCH_COMMANDS_FOR_GDBINIT}
c"
)

# add debug target
if(MBED_UPLOAD_SUPPORTS_DEBUG AND MBED_GDB_FOUND)
add_custom_target(debug-${target}
COMMENT "Starting GDB to debug ${target}..."
COMMAND ${MBED_GDB}
--command=${CMAKE_BINARY_DIR}/$<TARGET_FILE_BASE_NAME:${CMAKE_TARGET}>.gdbinit
$<TARGET_FILE:${target}>
USES_TERMINAL)
endif()

endfunction(mbed_generate_ide_debug_configuration)

function(mbed_finalize_ide_debug_configurations)

# Create target to start the GDB server
add_custom_target(gdbserver
COMMENT "Starting ${UPLOAD_METHOD} GDB server"
Expand Down
23 changes: 17 additions & 6 deletions tools/cmake/mbed_target_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ function(mbed_generate_bin_hex target)

set(artifact_name $<TARGET_FILE_BASE_NAME:${target}>)

# Convert to BIN format just on demand because the resultant output
# can have large holes in addresses which BIN format cannot handle and
# can generate very large file.
#
# The first condition is quoted in case MBED_OUTPUT_EXT is unset
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
)
endif()
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
)
endif()
# Convert to Intel HEX format unconditionally which most flash programming
# tools can support. For example, GDB load command supports Intel HEX format
# but no BIN format.
list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
)

add_custom_command(
TARGET
Expand Down Expand Up @@ -169,6 +174,12 @@ function(mbed_set_post_build target)
mbed_generate_map_file(${target})
endif()

# Give chance to adjust MBED_UPLOAD_LAUNCH_COMMANDS or MBED_UPLOAD_RESTART_COMMANDS
# for debug launch
if(COMMAND mbed_adjust_upload_debug_commands)
mbed_adjust_upload_debug_commands(${target})
endif()

mbed_generate_upload_target(${target})
mbed_generate_ide_debug_configuration(${target})
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
endfunction()
Expand Down
4 changes: 4 additions & 0 deletions tools/cmake/upload_methods/UploadMethodPYOCD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ set(UPLOAD_LAUNCH_COMMANDS
"monitor reset halt"
"load"
"tbreak main"

# It appears the device under debug must be halted after UPLOAD_LAUNCH_COMMANDS,
# or debugger will become abnormal.
"monitor reset halt"
)
set(UPLOAD_RESTART_COMMANDS
"monitor reset halt"
Expand Down
Loading