cmake: add helpers for setting board runners

This helps by letting us add checks for when the runner has already
been set. There is documentation saying you can set
-DBOARD_DEBUG_RUNNER at the command line and have it take effect,
which turns out not to be true for a large number of boards.
A status message helps the user debug.

(We'll address the existing in-tree boards in the next patch.)

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Marti Bolivar 2019-05-31 17:51:31 -06:00 committed by Carles Cufí
parent 9f851cc2dc
commit 1717332c7a
41 changed files with 148 additions and 88 deletions

View file

@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
if(DEFINED ENV{ZEPHYR_FLASH_OVER_DFU})
set(BOARD_FLASH_RUNNER dfu-util)
board_set_flasher(dfu-util)
else()
set(BOARD_FLASH_RUNNER openocd)
board_set_flasher(openocd)
endif()
set(BOARD_DEBUG_RUNNER openocd)
board_set_debugger(openocd)
board_runner_args(dfu-util "--pid=8087:0aba" "--alt=sensor_core")
board_runner_args(openocd --cmd-pre-load "targets 1" "--gdb-port=3334")

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# TODO: can this board just use the usual openocd runner?
set(BOARD_FLASH_RUNNER em-starterkit)
set(BOARD_DEBUG_RUNNER em-starterkit)
board_set_flasher(em-starterkit)
board_set_debugger(em-starterkit)
board_finalize_runner_args(em-starterkit)

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# TODO: can this board just use the usual openocd runner?
set(BOARD_FLASH_RUNNER em-starterkit)
set(BOARD_DEBUG_RUNNER em-starterkit)
board_set_flasher(em-starterkit)
board_set_debugger(em-starterkit)
board_finalize_runner_args(em-starterkit)

View file

@ -2,8 +2,8 @@
set(EMU_PLATFORM nsim)
set(BOARD_FLASH_RUNNER arc-nsim)
set(BOARD_DEBUG_RUNNER arc-nsim)
board_set_flasher(arc-nsim)
board_set_debugger(arc-nsim)
if(${CONFIG_SOC_NSIM_EM})
board_runner_args(arc-nsim "--props=nsim_em.props")

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW daplink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(jlink "--device=MK64FN1M0xxx12")

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW daplink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(jlink "--device=MKL25Z128xxx4")

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW daplink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(jlink "--device=MKW41Z512xxx4")

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(pyocd "--target=k64f")

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(jlink "--device=MKW40Z160xxx4")

View file

@ -7,8 +7,8 @@
set_ifndef(LPCLINK_FW jlink)
if(LPCLINK_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
endif()
if(CONFIG_BOARD_LPCXPRESSO54114_M4)

View file

@ -11,8 +11,8 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
endif()
if(CONFIG_BOARD_LPCXPRESSO55S69_CPU0)

View file

@ -6,8 +6,8 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
endif()
board_runner_args(jlink "--device=MIMXRT1015")

View file

@ -7,11 +7,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(pyocd "--target=mimxrt1020")

View file

@ -7,11 +7,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(pyocd "--target=mimxrt1050_hyperflash")

View file

@ -7,11 +7,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(pyocd "--target=cortex_m")

View file

@ -7,11 +7,11 @@
set_ifndef(OPENSDA_FW jlink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(pyocd "--target=cortex_m")

View file

@ -10,4 +10,4 @@ set(QEMU_FLAGS_${ARCH}
-vga none
)
set(BOARD_DEBUG_RUNNER qemu)
board_set_debugger(qemu)

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
set(BOARD_FLASH_RUNNER pyocd.sh)
set(BOARD_DEBUG_RUNNER pyocd.sh)
board_set_flasher(pyocd.sh)
board_set_debugger(pyocd.sh)
set(PYOCD_TARGET nrf52)

View file

@ -10,4 +10,4 @@ set(QEMU_FLAGS_${ARCH}
-vga none
)
set(BOARD_DEBUG_RUNNER qemu)
board_set_debugger(qemu)

View file

@ -3,11 +3,11 @@
set_ifndef(OPENSDA_FW daplink)
if(OPENSDA_FW STREQUAL jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
set_ifndef(BOARD_FLASH_RUNNER jlink)
board_set_debugger_ifnset(jlink)
board_set_flasher_ifnset(jlink)
elseif(OPENSDA_FW STREQUAL daplink)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
set_ifndef(BOARD_FLASH_RUNNER pyocd)
board_set_debugger_ifnset(pyocd)
board_set_flasher_ifnset(pyocd)
endif()
board_runner_args(jlink "--device=MKE18F512xxx16")

View file

@ -1,3 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
set(BOARD_DEBUG_RUNNER openocd)
board_set_debugger(openocd)

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER blackmagicprobe)
set_ifndef(BOARD_DEBUG_RUNNER blackmagicprobe)
board_set_flasher_ifnset(blackmagicprobe)
board_set_debugger_ifnset(blackmagicprobe)
board_finalize_runner_args(blackmagicprobe) # No default arguments to provide

View file

@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER bossac)
board_set_flasher_ifnset(bossac)
board_finalize_runner_args(bossac "--bossac=${BOSSAC}")

View file

@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER dfu-util)
board_set_flasher_ifnset(dfu-util)
board_finalize_runner_args(dfu-util) # No default arguments to provide.

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
set(BOARD_FLASH_RUNNER esp32)
board_set_flasher(esp32)
if(NOT DEFINED ESP_IDF_PATH)
if(DEFINED ENV{ESP_IDF_PATH})

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER jlink)
set_ifndef(BOARD_DEBUG_RUNNER jlink)
board_set_flasher_ifnset(jlink)
board_set_debugger_ifnset(jlink)
board_finalize_runner_args(jlink "--dt-flash=y")

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER nios2)
set_ifndef(BOARD_DEBUG_RUNNER nios2)
board_set_flasher_ifnset(nios2)
board_set_debugger_ifnset(nios2)
board_finalize_runner_args(nios2
# TODO: merge this script into nios2.py

View file

@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER nrfjprog)
board_set_flasher_ifnset(nrfjprog)
board_finalize_runner_args(nrfjprog) # No default arguments to provide.

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER openocd)
set_ifndef(BOARD_DEBUG_RUNNER openocd)
board_set_flasher_ifnset(openocd)
board_set_debugger_ifnset(openocd)
# "load_image" or "flash write_image erase"?
if(CONFIG_X86 OR CONFIG_ARC)

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(BOARD_FLASH_RUNNER pyocd)
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
board_set_flasher_ifnset(pyocd)
board_set_debugger_ifnset(pyocd)
board_finalize_runner_args(pyocd "--dt-flash=y")

View file

@ -9,4 +9,4 @@ set(QEMU_FLAGS_${ARCH}
-nographic
)
set(BOARD_DEBUG_RUNNER qemu)
board_set_debugger(qemu)

View file

@ -9,6 +9,6 @@ set(QEMU_FLAGS_${ARCH}
-machine sifive_e
)
set(BOARD_DEBUG_RUNNER qemu)
set(BOARD_FLASH_RUNNER hifive1)
board_set_debugger(qemu)
board_set_flasher(hifive1)
board_finalize_runner_args(hifive1)

View file

@ -9,4 +9,4 @@ set(QEMU_FLAGS_${ARCH}
-machine sifive_e
)
set(BOARD_DEBUG_RUNNER qemu)
board_set_debugger(qemu)

View file

@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
if(DEFINED ENV{ZEPHYR_FLASH_OVER_DFU})
set(BOARD_FLASH_RUNNER dfu-util)
board_set_flasher(dfu-util)
endif()
set(BOARD_DEBUG_RUNNER openocd)
board_set_debugger(openocd)
board_runner_args(dfu-util "--pid=8087:0aba" "--alt=x86_app")
board_runner_args(openocd --cmd-pre-load "targets 1")

View file

@ -17,6 +17,6 @@ set(QEMU_FLAGS_${ARCH}
)
# TODO: Support debug
# set(BOARD_DEBUG_RUNNER qemu)
# board_set_debugger(qemu)
# debugserver: QEMU_EXTRA_FLAGS += -s -S
# debugserver: qemu

View file

@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
if(DEFINED ENV{ZEPHYR_FLASH_OVER_DFU})
set(BOARD_FLASH_RUNNER dfu-util)
board_set_flasher(dfu-util)
endif()
set(BOARD_DEBUG_RUNNER openocd)
board_set_debugger(openocd)
board_runner_args(dfu-util "--pid=8087:0aba" "--alt=x86_app")
board_runner_args(openocd --cmd-pre-load "targets 1")

View file

@ -37,6 +37,6 @@ set(QEMU_FLAGS_${ARCH}
)
# TODO: Support debug
# set(BOARD_DEBUG_RUNNER qemu)
# board_set_debugger(qemu)
# debugserver: QEMU_EXTRA_FLAGS += -s -S
# debugserver: qemu

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
set(BOARD_FLASH_RUNNER intel_s1000)
set(BOARD_DEBUG_RUNNER intel_s1000)
board_set_flasher(intel_s1000)
board_set_debugger(intel_s1000)
board_finalize_runner_args(intel_s1000
"--xt-ocd-dir=/opt/tensilica/xocd-12.0.4/xt-ocd"

View file

@ -9,6 +9,6 @@ set(QEMU_FLAGS_${ARCH}
)
# TODO: Support debug
# set(BOARD_DEBUG_RUNNER qemu)
# board_set_debugger(qemu)
# debugserver: QEMU_EXTRA_FLAGS += -s -S
# debugserver: qemu

View file

@ -1,3 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
set(BOARD_DEBUG_RUNNER xtensa)
board_set_debugger(xtensa)

View file

@ -559,6 +559,66 @@ endfunction()
# This section provides glue between CMake and the Python code that
# manages the runners.
function(_board_check_runner_type type) # private helper
if (NOT (("${type}" STREQUAL "FLASH") OR ("${type}" STREQUAL "DEBUG")))
message(FATAL_ERROR "invalid type ${type}; should be FLASH or DEBUG")
endif()
endfunction()
# This function sets the runner for the board unconditionally. It's
# meant to be used from application CMakeLists.txt files.
#
# NOTE: Usually board_set_xxx_ifnset() is best in board.cmake files.
# This lets the user set the runner at cmake time, or in their
# own application's CMakeLists.txt.
#
# Usage:
# board_set_runner(FLASH pyocd)
#
# This would set the board's flash runner to "pyocd".
#
# In general, "type" is FLASH or DEBUG, and "runner" is the name of a
# runner.
function(board_set_runner type runner)
_board_check_runner_type(${type})
if (DEFINED BOARD_${type}_RUNNER)
message(STATUS "overriding ${type} runner ${BOARD_${type}_RUNNER}; it's now ${runner}")
endif()
set(BOARD_${type}_RUNNER ${runner} PARENT_SCOPE)
endfunction()
# This macro is like board_set_runner(), but will only make a change
# if that runner is currently not set.
#
# See also board_set_flasher_ifnset() and board_set_debugger_ifnset().
macro(board_set_runner_ifnset type runner)
_board_check_runner_type(${type})
# This is a macro because set_ifndef() works at parent scope.
# If this were a function, that would be this function's scope,
# which wouldn't work.
set_ifndef(BOARD_${type}_RUNNER ${runner})
endmacro()
# A convenience macro for board_set_runner(FLASH ${runner}).
macro(board_set_flasher runner)
board_set_runner(FLASH ${runner})
endmacro()
# A convenience macro for board_set_runner(DEBUG ${runner}).
macro(board_set_debugger runner)
board_set_runner(DEBUG ${runner})
endmacro()
# A convenience macro for board_set_runner_ifnset(FLASH ${runner}).
macro(board_set_flasher_ifnset runner)
board_set_runner_ifnset(FLASH ${runner})
endmacro()
# A convenience macro for board_set_runner_ifnset(DEBUG ${runner}).
macro(board_set_debugger_ifnset runner)
board_set_runner_ifnset(DEBUG ${runner})
endmacro()
# This function is intended for board.cmake files and application
# CMakeLists.txt files.
#