zephyr/scripts
Martí Bolívar 3124c02987 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-09-03 16:49:09 -05:00
..
checkpatch
ci ci: run module tests only on major changes 2020-09-03 18:11:19 +02:00
coccinelle scripts: coccinelle: Scripts for finding wrong device instance usage 2020-09-02 13:48:13 +02:00
coredump coredump: add support for ARM Cortex-M 2020-08-24 20:28:24 -04:00
dts devicetree: use edt.pickle more 2020-07-23 09:19:45 -05:00
footprint scripts: size_report: Fix colorized output 2020-09-03 09:54:21 -04:00
gitlint
kconfig hardening: remove the empty line before EOF 2020-08-21 15:09:07 -04:00
net scripts: net: Fix incorrect error messages 2020-05-21 14:45:07 +02:00
release
sanity_chk sanitycheck: do not report parent test 2020-09-01 15:02:22 -04:00
support
tests sanitycheck: inclusive language 2020-08-27 07:04:07 -04:00
tracing tracing: scripts: add scripts for parsing ctf data 2020-08-24 13:21:12 +02:00
west_commands cmake: flash/debug: refactor runner configuration 2020-09-03 16:49:09 -05:00
.gitignore scripts: tests: sanitycheck: Add basic foundation for sanitycheck testsuite 2020-03-24 22:32:26 -04:00
checkpatch.pl scripts: update checkpatch based on current linux kernel version 2020-08-21 13:57:02 -04:00
checkstack.pl
coccicheck scripts: Fix documunt referenc for coccicheck 2020-05-08 17:44:44 +02:00
dir_is_writeable.py global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
file2hex.py scripts: file2hex.py: PEP 8 style fix 2020-06-12 11:09:58 +02:00
filter-known-issues.py
gen_app_partitions.py
gen_cfb_font_header.py zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
gen_gcov_files.py scripts: gen_gcov_files.py: add argument help text 2020-06-13 16:33:22 -04:00
gen_kobject_list.py userspace: update k_object API to support immutable objects 2020-09-02 13:48:13 +02:00
gen_offset_header.py scripts: gen_offset_header: add argument help text 2020-05-21 14:45:24 +02:00
gen_relocate_app.py zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
gen_syscalls.py scripts: gen_syscalls: typo fix 2020-06-09 10:39:49 +02:00
get_maintainer.py scripts: add maintainer script 2020-07-24 17:07:48 +02:00
mergehex.py scripts: cmake: move print from python to cmake 2020-01-03 08:20:08 -05:00
parse_syscalls.py userspace: net sockets are kernel objects 2020-06-03 22:33:32 +02:00
process_gperf.py scripts: process_gperf: typo fix 2020-06-09 10:40:58 +02:00
requirements-base.txt requirements: add anytree 2020-08-14 18:49:26 -04:00
requirements-build-test.txt scripts: runners: add type checking for west_commands 2020-09-03 16:49:09 -05:00
requirements-compliance.txt python3: add check_compliance package requirements 2020-08-11 14:49:48 -04:00
requirements-doc.txt doc: update versions of build tools 2020-08-31 09:57:33 -04:00
requirements-extras.txt scripts/requirements: add lpc_checksum script 2020-07-29 20:12:24 +02:00
requirements-run-test.txt requirements: add psutil, needed by sanitycheck 2020-05-06 11:07:22 -05:00
requirements.txt python3: add check_compliance package requirements 2020-08-11 14:49:48 -04:00
sanitycheck sanitycheck: add argument --pre-script 2020-08-31 15:54:32 +02:00
series-push-hook.sh
spelling.txt
subfolder_list.py scripts: subfolder_list.py: refactor the code 2020-07-20 17:31:53 -04:00
tags.sh
user_wordsize.py posix arch: build on aarch64 / allow host-specific cmake includes 2020-05-09 12:17:24 +02:00
valgrind.supp
west-commands.yml cmake: West extension command for Zephyr config package registration 2020-03-27 16:23:46 +01:00
zephyr_module.py cmake: zephyr module processing improvements. 2020-08-31 12:15:02 +02:00