zephyr/cmake/flash/CMakeLists.txt

204 lines
6.4 KiB
CMake
Raw Normal View History

# SPDX-License-Identifier: Apache-2.0
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
function(runners_yaml_append 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 runners_yaml_props_target
APPEND_STRING
PROPERTY yaml_contents
"${content}\n"
)
endfunction()
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
function(get_runners_prop prop out_var default_value)
# Get property 'prop' from runners_yaml_props_target, storing its
# value in 'out_var'. If the property is not found (value is
# ...-NOTFOUND), 'out_var' is set to 'default_value'.
get_target_property(out runners_yaml_props_target "${prop}")
if("${out}" STREQUAL "out-NOTFOUND")
set("${out_var}" "${default_value}" PARENT_SCOPE)
else()
set("${out_var}" "${out}" PARENT_SCOPE)
endif()
endfunction()
function(runners_yaml_append_config)
# Append the common configuration values to the relevant property target.
runners_yaml_append("\n# Common runner configuration values.")
runners_yaml_append("config:")
runners_yaml_append(" board_dir: ${BOARD_DIR}")
get_runners_prop(elf_file elf "${KERNEL_ELF_NAME}")
runners_yaml_append(" # Build outputs:")
runners_yaml_append(" elf_file: ${elf}")
if(CONFIG_BUILD_OUTPUT_EXE)
get_runners_prop(exe_file exe "${KERNEL_EXE_NAME}")
else()
get_runners_prop(exe_file exe "")
endif()
if(exe)
runners_yaml_append(" exe_file: ${exe}")
endif()
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
if(CONFIG_BUILD_OUTPUT_HEX)
get_runners_prop(hex_file hex "${KERNEL_HEX_NAME}")
else()
get_runners_prop(hex_file hex "")
endif()
if(hex)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" hex_file: ${hex}")
endif()
if(CONFIG_BUILD_OUTPUT_BIN)
get_runners_prop(bin_file bin "${KERNEL_BIN_NAME}")
runners_yaml_append(" bin_file: ${bin}")
endif()
if(CONFIG_BUILD_OUTPUT_UF2)
get_runners_prop(uf2_file uf2 "${KERNEL_UF2_NAME}")
runners_yaml_append(" uf2_file: ${uf2}")
endif()
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
if(CMAKE_GDB OR OPENOCD OR OPENOCD_DEFAULT_PATH)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" # Host tools:")
endif()
if(CMAKE_GDB)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" gdb: ${CMAKE_GDB}")
endif()
if(OPENOCD)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" openocd: ${OPENOCD}")
runners_yaml_append(" openocd_search:")
if(OPENOCD_DEFAULT_PATH)
runners_yaml_append(" - ${OPENOCD_DEFAULT_PATH}")
endif()
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
endif()
runners_yaml_append("")
endfunction()
# Save runner state in a YAML file, and put that YAML file's location
# in the cache.
function(create_runners_yaml)
set(runners ${ARGV})
set(runners_yaml "${PROJECT_BINARY_DIR}/runners.yaml")
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append("# Available runners configured by board.cmake.\nrunners:")
foreach(runner ${runners})
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append("- ${runner}")
endforeach()
if(DEFINED BOARD_FLASH_RUNNER)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append("\n# Default flash runner if --runner is not given.")
runners_yaml_append("flash-runner: ${BOARD_FLASH_RUNNER}")
endif()
if(DEFINED BOARD_DEBUG_RUNNER)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append("\n# Default debug runner if --runner is not given.")
runners_yaml_append("debug-runner: ${BOARD_DEBUG_RUNNER}")
endif()
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
# Sets up common runner configuration values.
runners_yaml_append_config()
# Get runner-specific arguments set in the board files.
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append("# Runner specific arguments")
runners_yaml_append("args:")
foreach(runner ${runners})
string(MAKE_C_IDENTIFIER ${runner} runner_id)
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" ${runner}:")
get_property(args GLOBAL PROPERTY "BOARD_RUNNER_ARGS_${runner_id}")
if(args)
# Usually, the runner has arguments. Append them to runners.yaml,
# one per line.
foreach(arg ${args})
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" - ${arg}")
endforeach()
else()
# If the runner doesn't need any arguments, just use an empty list.
cmake: flash/debug: refactor runner configuration This commit message is a bit of a novel mostly: - because the issues involved are longstanding - as evidence this is not a capricious refactoring The runners.core.RunnerConfig Python class holds common configuration values used by multiple runners, such as the location of the build outputs and board directory. The runners code, first written in 2017-ish, replaced various shell scripts that got this information from the environment. Avoiding environment variables was a requirement, however. It's ghastly to set environment variables for a single command invocation on Windows, and the whole thing was part of a larger push to make Zephyr development on Windows better. I had a hammer (the argparse module). Finding a replacement naturally looked like a nail, so the information that ends up in RunnerConfig got shunted from the build system to Python in the form of 'west flash' / 'west debug' command line options like '--board-dir', '--elf-file', etc. I initially stored the options and their values in the CMake cache. This was chosen in hopes the build system maintainer would like the strategy (which worked). I knew the command line arguments approach was a bit hacky (this wasn't a nail), but I also honestly didn't have a better idea at the time. It did indeed cause issues: - users don't know that just because they specify --bin-file on the command line doesn't mean that their runner respects the option, and have gotten confused trying to flash alternate files, usually for chain-loading by MCUboot (for example, see #15961) - common options weren't possible to pass via board.cmake files (#22563, fixed partly via introduction of runners.yaml and the west flash/debug commands no longer relying on the cache) - it is confusing that "west flash --help" prints information about openocd related options even when the user's board has no openocd support. The same could be said about gdb in potential future use cases where debugging occurs via some other tool. Over time, they've caused enough users enough problems that improvements are a priority. To work towards this, put these values into runners.yaml using a new 'config: ...' key/value instead of command line options. For example, instead of this in the generated runners.yaml file: args: common: - --hex-file=.../zephyr.hex we now have: config: hex_file: zephyr.hex and similarly for other values. In Python, we still support the command line options, but they are not generated by the build system for any in-tree boards. Further work is needed to deprecate the confusing ones (like --hex-file) and move the runner-specific host tool related options (like --openocd) to the runners that need them. Individual board.cmake files should now influence these values by overriding the relevant target properties of the runners_yaml_props_target. For example, instead of: board_runner_args(foo "--hex-file=bar.hex") Do this: set_target_properties(runners_yaml_props_target PROPERTIES hex_file bar.hex) This change additionally allows us to stitch cmake/mcuboot.cmake and the runners together easily by having mcuboot.cmake override the properties that set the hex or bin file to flash. (The command line arguments are still supported as-is.) Combined with 98e0c95d91ae16f14e4997fb64ccdf0956595712 ("build: auto-generate signed mcuboot binaries"), this will allow users to build and flash images to be chain loaded by mcuboot in a way that avoids calling 'west sign' and passing 'west flash' its output files entirely. While we are here, rename runner_yml_write to runners_yaml_append(). This function doesn't actually write anything, and we're here refactoring this file anyway, so we might as well improve the situation while we're at it. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-08-25 00:21:15 +02:00
runners_yaml_append(" []\n")
endif()
endforeach()
# Write the final contents and set its location in the cache.
file(GENERATE OUTPUT "${runners_yaml}" CONTENT
$<TARGET_PROPERTY:runners_yaml_props_target,yaml_contents>)
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.
#
# Everything is marked with FORCE so that re-running CMake updates the
# configuration if the board files change.
if(RUNNERS)
create_runners_yaml(${RUNNERS})
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
zephyr_get(WEST_DIR)
if(WEST_DIR)
set(WEST "PYTHONPATH=${WEST_DIR}/src" "${PYTHON_EXECUTABLE};${WEST_DIR}/src/west/app/main.py;--zephyr-base=${ZEPHYR_BASE} ")
endif()
# Generate the flash, debug, debugserver, attach targets within the build
# system itself.
foreach(target flash debug debugserver attach)
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(SUPPORTED_EMU_PLATFORMS)
# cmake/qemu/CMakeLists.txt will add a debugserver target for
# emulation platforms, so we don't add one here
continue()
endif()
elseif(target STREQUAL attach)
set(comment "Debugging ${BOARD}")
endif()
string(TOUPPER ${target} TARGET_UPPER)
list(APPEND RUNNERS_DEPS ${logical_target_for_zephyr_elf})
# Enable verbose output, if requested.
if(CMAKE_VERBOSE_MAKEFILE)
set(RUNNER_VERBOSE "--verbose")
else()
set(RUNNER_VERBOSE)
endif()
if(WEST)
add_custom_target(${target}
# This script will print an error message and fail if <target> has added
# dependencies. This is done using dedicated CMake script, as
# `cmake -E {true|false}` is not available until CMake 3.16.
COMMAND ${CMAKE_COMMAND}
-DTARGET=${target}
-DDEPENDENCIES="$<TARGET_PROPERTY:${target},MANUALLY_ADDED_DEPENDENCIES>"
-P ${CMAKE_CURRENT_LIST_DIR}/check_runner_dependencies.cmake
COMMAND
${CMAKE_COMMAND} -E env
${WEST}
${RUNNER_VERBOSE}
${target}
WORKING_DIRECTORY
${APPLICATION_BINARY_DIR}
COMMENT
${comment}
USES_TERMINAL
)
else()
add_custom_target(${target}
COMMAND ${CMAKE_COMMAND} -E echo \"West was not found in path. To support
'${CMAKE_MAKE_PROGRAM} ${target}', please create a west workspace.\"
USES_TERMINAL
)
endif(WEST)
endforeach()