2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-04-02 09:15:44 +02:00
|
|
|
add_custom_target(runner_yml_props_target)
|
|
|
|
|
|
|
|
function(runner_yml_write content)
|
|
|
|
# Append ${content}\n to a target property which is later evaluated as a
|
|
|
|
# generator expression when writing the flash runner yaml file.
|
|
|
|
# We define this function here to have access to the `flash` target.
|
|
|
|
|
|
|
|
set_property(
|
|
|
|
TARGET runner_yml_props_target
|
|
|
|
APPEND_STRING
|
|
|
|
PROPERTY yaml_contents
|
|
|
|
"${content}\n"
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2020-02-10 18:54:11 +01:00
|
|
|
# Save runner state in a YAML file, and put that YAML file's location
|
|
|
|
# in the cache.
|
|
|
|
function(create_runners_yaml)
|
|
|
|
set(runners ${ARGV})
|
2018-03-26 21:28:30 +02:00
|
|
|
|
2020-02-10 18:54:11 +01:00
|
|
|
set(runners_yaml "${PROJECT_BINARY_DIR}/runners.yaml")
|
|
|
|
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write("# Available runners configured by board.cmake.\nrunners:")
|
2020-02-10 18:54:11 +01:00
|
|
|
foreach(runner ${runners})
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write("- ${runner}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endforeach()
|
2017-11-27 20:39:43 +01:00
|
|
|
|
2020-02-10 18:54:11 +01:00
|
|
|
if(DEFINED BOARD_FLASH_RUNNER)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write("\n# Default flash runner if --runner is not given.")
|
|
|
|
runner_yml_write("flash-runner: ${BOARD_FLASH_RUNNER}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endif()
|
|
|
|
if(DEFINED BOARD_DEBUG_RUNNER)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write("\n# Default debug runner if --runner is not given.")
|
|
|
|
runner_yml_write("debug-runner: ${BOARD_DEBUG_RUNNER}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endif()
|
|
|
|
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write("\n# Default command line arguments. The ones in \"common\" are always given.\n# The other sub-keys give runner-specific arguments.")
|
|
|
|
runner_yml_write("args:\n common:")
|
2020-02-10 18:54:11 +01:00
|
|
|
|
|
|
|
# Get default settings for common arguments.
|
|
|
|
#
|
|
|
|
# TODO: clean up the host tools arguments. These are really runner
|
|
|
|
# specific; they only continue to exist here out of inertia.
|
2020-04-02 09:15:44 +02:00
|
|
|
|
|
|
|
runner_yml_write("\
|
2020-02-10 18:54:11 +01:00
|
|
|
- --board-dir=${BOARD_DIR}
|
|
|
|
- --elf-file=${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}
|
|
|
|
- --hex-file=${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}
|
2020-04-02 09:15:44 +02:00
|
|
|
- --bin-file=${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}")
|
2020-02-10 18:54:11 +01:00
|
|
|
if (DEFINED CMAKE_GDB)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write(" - --gdb=${CMAKE_GDB}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endif()
|
|
|
|
if (DEFINED OPENOCD)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write(" - --openocd=${OPENOCD}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endif()
|
|
|
|
if(DEFINED OPENOCD_DEFAULT_PATH)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write(" - --openocd-search=${OPENOCD_DEFAULT_PATH}")
|
2020-02-10 18:54:11 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Get runner-specific arguments set in the board files.
|
|
|
|
foreach(runner ${runners})
|
|
|
|
string(MAKE_C_IDENTIFIER ${runner} runner_id)
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write(" ${runner}:")
|
2020-02-10 18:54:11 +01:00
|
|
|
get_property(args GLOBAL PROPERTY "BOARD_RUNNER_ARGS_${runner_id}")
|
2020-02-21 18:37:40 +01:00
|
|
|
if(args)
|
|
|
|
# Usually, the runner has arguments. Append them to runners.yaml,
|
|
|
|
# one per line.
|
|
|
|
foreach(arg ${args})
|
2020-04-02 09:15:44 +02:00
|
|
|
runner_yml_write(" - ${arg}")
|
2020-02-21 18:37:40 +01:00
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
# If the runner doesn't need any arguments, just use an empty list.
|
2020-04-09 08:30:25 +02:00
|
|
|
runner_yml_write(" []\n")
|
2020-02-21 18:37:40 +01:00
|
|
|
endif()
|
2020-02-10 18:54:11 +01:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Write the final contents and set its location in the cache.
|
2020-04-02 09:15:44 +02:00
|
|
|
file(GENERATE OUTPUT "${runners_yaml}" CONTENT
|
|
|
|
$<TARGET_PROPERTY:runner_yml_props_target,yaml_contents>)
|
2020-02-10 18:54:11 +01:00
|
|
|
set(ZEPHYR_RUNNERS_YAML "${runners_yaml}" CACHE INTERNAL
|
|
|
|
"a configuration file for the runners Python package")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
get_property(RUNNERS GLOBAL PROPERTY ZEPHYR_RUNNERS)
|
|
|
|
|
|
|
|
# Persist the runner-related state.
|
|
|
|
#
|
|
|
|
# Available runners and their arguments are configured in board.cmake
|
|
|
|
# files.
|
2018-03-26 21:28:30 +02:00
|
|
|
#
|
|
|
|
# Everything is marked with FORCE so that re-running CMake updates the
|
|
|
|
# configuration if the board files change.
|
2020-02-10 18:54:11 +01:00
|
|
|
#
|
|
|
|
# TODO: drop the hack in sign.py that uses cached_runner_config to
|
|
|
|
# guess the .bin and .hex files, then delete the cache variables.
|
2018-03-26 21:28:30 +02:00
|
|
|
if(RUNNERS)
|
2020-02-10 18:54:11 +01:00
|
|
|
create_runners_yaml(${RUNNERS})
|
|
|
|
|
2018-03-26 21:28:30 +02:00
|
|
|
set(ZEPHYR_RUNNERS ${RUNNERS} CACHE INTERNAL "Available runners")
|
2018-05-10 06:58:03 +02:00
|
|
|
|
|
|
|
# Runner configuration. This is provided to all runners, and is
|
|
|
|
# distinct from the free-form arguments provided by e.g.
|
|
|
|
# board_runner_args().
|
|
|
|
#
|
|
|
|
# Always applicable:
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_BOARD_DIR "${BOARD_DIR}"
|
|
|
|
CACHE STRING "Board definition directory" FORCE)
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_KERNEL_ELF "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}"
|
|
|
|
CACHE STRING "Path to kernel image in ELF format" FORCE)
|
2018-10-30 08:39:13 +01:00
|
|
|
get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE)
|
|
|
|
if(HEX_FILES_TO_MERGE)
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${MERGED_HEX_NAME}"
|
|
|
|
CACHE STRING "Path to merged image in Intel Hex format" FORCE)
|
|
|
|
else()
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}"
|
|
|
|
CACHE STRING "Path to kernel image in Intel Hex format" FORCE)
|
|
|
|
endif()
|
2018-05-10 06:58:03 +02:00
|
|
|
set(ZEPHYR_RUNNER_CONFIG_KERNEL_BIN "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}"
|
|
|
|
CACHE STRING "Path to kernel image as raw binary" FORCE)
|
|
|
|
# Not always applicable, but so often needed that they're provided
|
|
|
|
# by default: (TODO: clean this up)
|
|
|
|
if(DEFINED CMAKE_GDB)
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_GDB "${CMAKE_GDB}"
|
|
|
|
CACHE STRING "Path to GDB binary, if applicable" FORCE)
|
|
|
|
endif()
|
|
|
|
if(DEFINED OPENOCD)
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_OPENOCD "${OPENOCD}"
|
|
|
|
CACHE STRING "Path to openocd binary, if applicable" FORCE)
|
|
|
|
endif()
|
|
|
|
if(DEFINED OPENOCD_DEFAULT_PATH)
|
|
|
|
set(ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH "${OPENOCD_DEFAULT_PATH}"
|
|
|
|
CACHE STRING "Path to add to openocd search path, if applicable" FORCE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Runner-specific command line arguments obtained from the board's
|
|
|
|
# build scripts, the application's scripts, etc.
|
2018-03-26 21:28:30 +02:00
|
|
|
foreach(runner ${RUNNERS})
|
|
|
|
string(MAKE_C_IDENTIFIER ${runner} runner_id)
|
|
|
|
# E.g. args = BOARD_RUNNER_ARGS_openocd, BOARD_RUNNER_ARGS_dfu_util, etc.
|
|
|
|
get_property(runner_args GLOBAL PROPERTY "BOARD_RUNNER_ARGS_${runner_id}")
|
|
|
|
set(ZEPHYR_RUNNER_ARGS_${runner_id} ${runner_args} CACHE STRING
|
|
|
|
"Runner-specific arguments for ${runner}" FORCE)
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
if(BOARD_FLASH_RUNNER)
|
|
|
|
set(ZEPHYR_BOARD_FLASH_RUNNER ${BOARD_FLASH_RUNNER} CACHE STRING
|
|
|
|
"Default runner for flashing binaries" FORCE)
|
|
|
|
endif()
|
|
|
|
if(BOARD_DEBUG_RUNNER)
|
|
|
|
set(ZEPHYR_BOARD_DEBUG_RUNNER ${BOARD_DEBUG_RUNNER} CACHE STRING
|
|
|
|
"Default runner for debugging" FORCE)
|
|
|
|
endif()
|
scripts: runner: use arguments, not environment vars
The various runners (flash/debug scripts) use environment variables to
take arguments. This is legacy behavior which is not desirable.
Use command line arguments instead.
Note: this leaves more general environment variables with publicly
documented behavior in place for now, for compatibility, e.g.:
ZEPHYR_FLASH_OVER_DFU, OPENSDA_FW, ESP_IDF_PATH, PYOCD_DAPARG
For example, when using dfu-util to flash arduino_101, instead of
setting DFUUTIL_PID, DFUUTIL_ALT, and DFUUTIL_IMG environment
variables, have the script invocation look like this:
python3 .../zephyr_flash_debug.py dfu-util flash \
[common arguments omitted] \
--pid=8087:0aba --alt=x86_app \
--img=.../build/zephyr/zephyr.bin
Make similar changes for other runners (openocd, etc.) and
targets (debug, debugserver).
To implement this in the scripts:
- have the individual scripts/support/runner/some-runner.py files
register their own command line arguments
- teach them to construct instances from arguments, not the
environment
- have zephyr_flash_debug.py request runners to register command
line argument parsers, and handle arguments
In the build system:
- add a new board_runner_args() extension function that board.cmake
files can use to add to the zephyr_flash_debug.py command line
- adjust cmake/flash/CMakeLists.txt to invoke with arguments
- add new helper include files for each runner (like
boards/common/dfu-util.board.cmake, etc.), which add default
options as needed and then add on overrides from
board_runner_args() calls
- update board.cmake files to use the new includes and extension
This implied some tweaking when using openocd to make the CMake string
escaping and unescaping work properly.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-16 23:45:38 +01:00
|
|
|
|
2018-11-12 15:23:51 +01:00
|
|
|
if(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR)
|
|
|
|
set(WEST_DIR $ENV{WEST_DIR})
|
|
|
|
endif(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR)
|
|
|
|
|
|
|
|
if(WEST_DIR)
|
2020-02-12 15:42:09 +01:00
|
|
|
set(WEST "PYTHONPATH=${WEST_DIR}/src" "${PYTHON_EXECUTABLE};${WEST_DIR}/src/west/app/main.py;--zephyr-base=${ZEPHYR_BASE} ")
|
2018-11-12 15:23:51 +01:00
|
|
|
endif()
|
|
|
|
|
2018-08-13 15:43:29 +02:00
|
|
|
# Generate the flash, debug, debugserver, attach targets within the build
|
2018-03-26 21:28:30 +02:00
|
|
|
# system itself.
|
2018-08-13 15:43:29 +02:00
|
|
|
foreach(target flash debug debugserver attach)
|
2017-10-27 15:43:34 +02:00
|
|
|
if(target STREQUAL flash)
|
|
|
|
set(comment "Flashing ${BOARD}")
|
|
|
|
elseif(target STREQUAL debug)
|
|
|
|
set(comment "Debugging ${BOARD}")
|
|
|
|
elseif(target STREQUAL debugserver)
|
|
|
|
set(comment "Debugging ${BOARD}")
|
|
|
|
if(EMU_PLATFORM)
|
|
|
|
# cmake/qemu/CMakeLists.txt will add a debugserver target for
|
|
|
|
# emulation platforms, so we don't add one here
|
|
|
|
continue()
|
|
|
|
endif()
|
2018-08-13 15:43:29 +02:00
|
|
|
elseif(target STREQUAL attach)
|
|
|
|
set(comment "Debugging ${BOARD}")
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2020-06-30 09:55:54 +02:00
|
|
|
string(TOUPPER ${target} TARGET_UPPER)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-06-30 09:55:54 +02:00
|
|
|
list(APPEND RUNNERS_DEPS ${logical_target_for_zephyr_elf})
|
2018-12-05 10:15:40 +01:00
|
|
|
|
2020-02-10 18:54:11 +01:00
|
|
|
# Enable verbose output, if requested.
|
|
|
|
if(CMAKE_VERBOSE_MAKEFILE)
|
|
|
|
set(RUNNER_VERBOSE "--verbose")
|
|
|
|
else()
|
|
|
|
set(RUNNER_VERBOSE)
|
|
|
|
endif()
|
|
|
|
|
2018-05-10 03:10:55 +02:00
|
|
|
# We pass --skip-rebuild here because the DEPENDS value ensures the
|
|
|
|
# build is already up to date before west is run.
|
2019-10-23 15:26:50 +02:00
|
|
|
if(WEST)
|
2018-11-12 15:23:51 +01:00
|
|
|
set(cmd
|
|
|
|
${CMAKE_COMMAND} -E env
|
|
|
|
${WEST}
|
|
|
|
${RUNNER_VERBOSE}
|
|
|
|
${target}
|
|
|
|
--skip-rebuild
|
2020-06-30 09:55:54 +02:00
|
|
|
DEPENDS ${RUNNERS_DEPS}
|
|
|
|
$<TARGET_PROPERTY:zephyr_property_target,${TARGET_UPPER}_DEPENDENCIES>
|
2018-11-12 15:23:51 +01:00
|
|
|
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2018-11-12 15:23:51 +01:00
|
|
|
add_custom_target(${target}
|
|
|
|
COMMAND
|
|
|
|
${cmd}
|
|
|
|
COMMENT
|
|
|
|
${comment}
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
cmake: west: west flash dependencies in sync with CMake flash target
This commit creates a list of a phony targets for each runner, that is:
`west_flash_depends`, `west_debug_depends`, and so on.
Those targets has identical dependencies as CMake runner target.
flash, debug, debugserver, attach targets.
As example `ninja flash` correctly ensures dependencies are taken into
consideration before calling `west flash`.
Unfortunately, calling `west flash` directly would not re-run the flash
dependencies, cause `west flash` would only build the default CMake
target.
Now, `west flash` calls the phony `west_flash_depends` target, ensuring
all deps are up-to-date before flashing (unless --skip-rebuild is given)
The same is true for the other mentioned runners.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-06-29 16:12:34 +02:00
|
|
|
|
|
|
|
# This is an artificial target to allow west to ensure all dependencies of
|
|
|
|
# target is build before carrying out the actual command.
|
|
|
|
# This allows `west` to run just the dependencies before flashing.
|
|
|
|
add_custom_target(west_${target}_depends
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo ""
|
|
|
|
DEPENDS ${RUNNERS_DEPS}
|
|
|
|
$<TARGET_PROPERTY:zephyr_property_target,${TARGET_UPPER}_DEPENDENCIES>
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2018-11-12 15:23:51 +01:00
|
|
|
else()
|
|
|
|
add_custom_target(${target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo \"West was not found in path. To support
|
2020-02-10 20:22:22 +01:00
|
|
|
'${CMAKE_MAKE_PROGRAM} ${target}', please create a west workspace.\"
|
2018-11-12 15:23:51 +01:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2019-10-23 15:26:50 +02:00
|
|
|
endif(WEST)
|
2017-10-27 15:43:34 +02:00
|
|
|
endforeach()
|