From 64badd97cd683ddfb7d72d3abdf89a979e91912a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 26 Mar 2018 15:28:30 -0400 Subject: [PATCH] cmake: flash: save runner configuration to CMake cache Persist all the important information needed by the runner package to the CMake cache. This serves as a parseable record for various tools which need to understand how to run the binary. In particular, it will be used by the west tool, which will be introduced in subsequent patches. Signed-off-by: Marti Bolivar --- cmake/extensions.cmake | 6 +++++- cmake/flash/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index d498360192d..f6e5a41b029 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -570,7 +570,8 @@ endfunction() # board_finalize_runner_args(runner) # # This ensures the build system captures all arguments added in any -# board_runner_args() calls. +# board_runner_args() calls, and otherwise finishes registering a +# runner for use. # # Extended usage: # board_runner_args(runner "--some-arg=default-value") @@ -598,6 +599,9 @@ function(board_finalize_runner_args runner) # last, so they take precedence. ${explicit} ) + + # Add the finalized runner to the global property list. + set_property(GLOBAL APPEND PROPERTY ZEPHYR_RUNNERS ${runner}) endfunction() # 1.5. Misc. diff --git a/cmake/flash/CMakeLists.txt b/cmake/flash/CMakeLists.txt index 7ebbba8e473..82b492f1864 100644 --- a/cmake/flash/CMakeLists.txt +++ b/cmake/flash/CMakeLists.txt @@ -1,6 +1,9 @@ assert_not(FLASH_SCRIPT "FLASH_SCRIPT has been removed; use BOARD_FLASH_RUNNER") assert_not(DEBUG_SCRIPT "DEBUG_SCRIPT has been removed; use BOARD_DEBUG_RUNNER") +get_property(RUNNERS GLOBAL PROPERTY ZEPHYR_RUNNERS) + +# These arguments are common to all runners. set(RUNNER_ARGS_COMMON # Required: "--board-dir=${BOARD_DIR}" @@ -21,9 +24,37 @@ else() set(RUNNER_VERBOSE) endif() -foreach(target flash debug debugserver) - string(TOUPPER "${target}" target_upper) +# Persist the runner-related state in the cache. Everything except +# the list of available runners is configurable, but the set of +# pre-configured runners is internal, since they must be configured through +# the board files. +# +# Everything is marked with FORCE so that re-running CMake updates the +# configuration if the board files change. +if(RUNNERS) + set(ZEPHYR_RUNNERS ${RUNNERS} CACHE INTERNAL "Available runners") + set(ZEPHYR_RUNNER_ARGS_COMMON ${RUNNER_ARGS_COMMON} CACHE STRING + "Common arguments to all runners" FORCE) + 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() +# Generate the flash, debug, debugserver targets within the build +# system itself. +foreach(target flash debug debugserver) if(target STREQUAL flash) set(comment "Flashing ${BOARD}") set(runner "${BOARD_FLASH_RUNNER}")