Commit Graph

90 Commits

Author SHA1 Message Date
Carles Cufi fdd94d3bd8 scripts: debug: J-Link script tweaks
* Add the interface speed option
* Select USB connection explicitly
* Use "J-Link" consistently

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-12-19 16:57:36 -05:00
Sebastian Bøe 8b2213f670 nrfjprog_py: Use RuntimeError instead of Exception
Be more specific with the exception type.

https://github.com/zephyrproject-rtos/zephyr/pull/5432#issuecomment-352492089

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-19 12:45:34 -05:00
Sebastian Bøe 5056ab24fb runner: nrfjprog: Improve error messages
When a debugger is already connected to the JLink debug adapter
nrfjprog.py would incorrectly detect that the snr is '0' and try to
flash a device with that snr.

Also, when there were no boards connected, nrfjprog.py would
incorrectly state that there were multiple boards connected.

This patch improves the error feedback so that a user can more easily
debug why he can't flash his device.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-18 21:46:12 -05:00
Marti Bolivar 86e6e674a5 scripts: zephyr_flash_debug.py: swallow exceptions by default
For readability, swallow exceptions unless --verbose is given on the
command line. Add a printline to direct the user how to ensure that's
set in case more information out of the flash script is desired.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-18 21:45:48 -05:00
Marti Bolivar 209e2676b4 scripts: runner: add internal DEBUG to core
Add a debug-only global that prevents commands from running, and just
prints what would have been run.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar ec01e0f876 scripts: zephyr_flash_debug: add 'runners' command
This just prints the available runner classes.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 57d5717bc6 scripts: runner: let users copy/paste failed commands
Print a copy/pastable version of any command which fails, to help
debugging.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar ad8b006bf2 scripts: runner: pyocd: support pyocd-flashtool options
Allow the user to specify additional options for pyocd-flashtool. This
grants finer-grained control to individual applications, e.g. to
perform a chip erase instead of a sector erase when flashing.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar ccacaab49f scripts: runner: pyocd: support DT-based flashing
Enable DT support in the pyOCD flasher, and turn it on in the build
system.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 1645d372d2 scripts: runner: dfu-util: add --dfuse-modifiers option
This gives callers finer-grained control over the flash. For example,
giving --dfuse-modifiers=force:mass-erase allows a chip-erase rather
than just erasing the sectors which need to be overwritten with the image.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 3ebc2e46b2 scripts: runner: dfu-util: support DT-based flashing for DfuSe
Enable DT support in the dfu-util flasher when the target is a
DfuSe (DFU + ST extensions) device.

Untangling DfuSe-specific options (currently, the default is 'leave',
to immediately start running after the flashing is done) from the
actual address makes this cleaner, and sets up a subsequent patch to
let callers set DfuSe options.

It also lets us fix an unnecessary printline when flashing DfuSe
devices. There's no need to reset those, since the 'leave' modifier
starts execution immediately.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 3830bc51f2 scripts: runner: add infrastructure for DT-based flashing
Add the necessary infrastructure to the runner core to support
computing flash addresses based on the devicetree. Specifically, add:

- a new RunnerCaps capability, flash_addr, which lets runners declare
  when they support flashing to an arbitrary address

- a common --dt-flash option to all runner command line parsers which
  support this capability, which lets users request flash addresses to
  be computed from device tree

- a ZephyrBinaryRunner helper method, get_flash_address(), which is
  the common code needed to compute a flash address from device
  tree (or return a default value if non-DT based flashing is
  requested). This relies on the BuildConfiguration parser introduced
  in an earlier patch.

Subsequent patches will use this functionality in individual runners.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 7a3462de7a 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-12-15 09:57:30 -05:00
Marti Bolivar f4ace33daf scripts: runner: add build-time .conf parser
This parses generated_dts_board.conf and auto.conf, given a build
directory.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar cd8d43b1c9 scripts: runner: generalize commands to "capabilities"
Some configuration options or device tree nodes affect the way that
runners ought to behave, but there's no good way for them to report
whether they can handle them.

One motivating example is CONFIG_FLASH_LOAD_OFFSET, as influenced by
the zephyr,code-partition chosen node in the DT for architectures
where CONFIG_HAS_FLASH_LOAD_OFFSET=y.

If CONFIG_FLASH_LOAD_OFFSET is nonzero, the 'flash' command ought to
place the kernel at that address offset from the device flash's start
address. Runners don't support this right now, which should be
fixed. However, we don't want to mandate support for this feature,
since not all targets need it.

We need to let runners declare what their capabilities are. Make it so
by adding a RunnerCaps class to the runner core. This currently just
states which commands a runner can handle, but can be generalized to
implement the above use case.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar e33ec242fd scripts: refactor flash/debug scripts to remove "shell"
The Python-based runners have replaced the old shell scripts. Refactor
the build system accordingly:

- FLASH_SCRIPT is now BOARD_FLASH_RUNNER
- DEBUG_SCRIPT is now BOARD_DEBUG_RUNNER

The values, rather than being the names of files, are now the names of
runners in scripts/support/runner. They are still short, descriptive
names like "openocd", "jlink", "em-starterkit", etc.

Adjust the zephyr_flash_debug.py call and runner internals
accordingly. Have each runner class report a name and the commands it
can handle. This lets us move some boilerplate from each do_run()
method into the common run() routine, and enables further improvements
in future patches.

The handles_command() method is temporary, and will be replaced by a
more general mechanism for describing runner capabilities in a
subsequent patch. The initial use case for extending this is to add
device tree awareness to the runners.

To try to avoid user confusion, abort the configuration if an
xxx_SCRIPT is defined.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 0fba4bf20c scripts: runner: refactor run() implementation
Have the subclasses implement a do_run() method instead, which run()
delegates to. This will make it possible to handle common
functionality in the superclass before runner-specific methods are
called. It is a prerequisite for tasks like loading the build time
configuration to add device tree awareness.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 5b0167ae79 scripts: runner: pyocd: fix stale comment
This isn't just a flasher anymore.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 36aee10bef scripts: zephyr_flash_debug: simple improvements
Delete an unused import to make flake8 happy. Update the module
docstring.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 66d4d83db1 scripts: runner: nrfjprog: remove BOARD environment requirement
The BOARD variable has been removed from the environment provided to
runners. It's not being used to flash the board, so just remove the
check for it to avoid an exception at runtime.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-06 16:58:49 -06:00
Maureen Helm 2358df2647 scripts: jlink: Don't reset after load
The mimxrt1052 does not have any internal flash, therefore a reset after
load blows away the code when loaded into sram. Reverse the order of the
jlink commands such that the load follows the reset.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2017-11-15 09:09:58 -06:00
Kumar Gala 5fe74ca1ce scripts: zephyr_flash_debug: Cleanup the script argument usage
The script argument isn't really a path, so stop assuming that it is
one.  We still use the shell script name at this point, but there isn't
any actual shell script in the system.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-11-14 12:07:44 -06:00
Anas Nashif 539d2af654 flash: support flashing multiple configurations of a single board
Some boards define multiple configuration which all are maintained under
the same board directory. The flasher was looking for an openocd.cfg
based on the board name, which can't be found for such boards.

Use the variable BOARD_DIR provided by cmake instead of trying to
assemble the board directory location on our own.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-13 10:55:26 -05:00
Anas Nashif 934a8cb077 flasher: remove obsolete KBUILD_VERBOSE
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-13 10:55:26 -05:00
Anas Nashif 5eddb087f0 flash: fix arc flasher script
We do not need python defined, we are running in python already.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-13 10:55:26 -05:00
Marti Bolivar 682a207409 scripts: runner: core: fix stale comments
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-07 15:43:55 -05:00
Marti Bolivar 2d21300a50 scripts: runner: core: fix comment typo
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-07 15:43:55 -05:00
Marti Bolivar 208526d340 scripts: runner: use ss on linux, not netstat
Netstat is deprecated.

Reported-by: Leandro Pereira <leandro.pereira@intel.com>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-11-07 15:43:55 -05:00
Marti Bolivar 81f2d21fac build: remove flash/debug shell scripts
The functionality of the shell scripts for flashing and debugging has
now been replaced by zephyr_flash_debug.py. Remove the legacy scripts
as part of transitioning all of this to Python.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar a9aec55588 scripts: runner: add qemu.py, a stand-in for QEMU
This, like the shell script, is just a placeholder.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar d4d7cc72ee scripts: runner: add xtensa.py, with debug support
This is debug only, not debugserver.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar f13390e22b scripts: runner: add jlink.py, with debug and debugserver support
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 4732b96ae8 scripts: runner: add debug support to nios.py
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 10409099f9 scripts: runner: add network port helper class
Some of the flashing scripts try to be clever about picking unused
ports. That's convenient for the user, so add a helper class to
runner.core to accomplish similar ends portably.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 32b475ebb9 scripts: zephyr_flash_debug: refactor into new "runner" package
Factor the classes which do the work into a new "runner" package. This
package has a core module where ZephyrBinaryRunner and common helpers
will live, and one file per subclass / runner front-end.

The top-level script, zephyr_flash_debug.py, still exists, but just
delegates its work to the core.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 12802cf36e scripts: zephyr_flash_debug: improve debug logging
Ensure that the printed commands can be copy/pasted into a shell with
the same semantics.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar ade65bd055 scripts: zephyr_flash_debug: get bossac port from environment
Allow the environment variable BOSSAC_PORT to specify the device's
serial port, if present.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar f6c42cd7bc scripts: zephyr_flash_debug: fix Nios II comment
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar b5a78f1161 scripts: zephyr_flash_debug: refactor Nios II runner
Prep work for adding debug and debugserver support. No significant
functional differences.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 90c0cfdc81 scripts: zephyr_flash_debug: add debug support to pyocd
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 9cf7d106f1 scripts: zephyr_flash_debug: refactor pyocd runner
Prep work for adding debug and debugserver support. No significant
functional differences.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 77c2ef54f5 scripts: zephyr_flash_debug: add debug support to openocd
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 4a665366d9 scripts: zephyr_flash_debug: refactor openocd runner
Preparatory work for supporting debugging and flashing. No significant
behavioral changes.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 9224b54105 scripts: zephyr_flash_debug: fix ARC OPENOCD_EXTRA_INIT
Though it isn't used by any in-tree Makefile.boards, looking at the
RIOT OS build system, this is meant to be split along lexical
boundaries defined by the shell, not just whitespace.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 9e619b0d26 scripts: zephyr_flash_debug: make ARC runner portable
Use run_client_and_server() to work across supported platforms.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 3e01cef06f scripts: zephyr_flash_debug: teach runners a client/server abstraction
Several debugging scripts run setsid before executing a server
process, then run GDB with SIGINT ignored.

Relying on setsid is not portable. Add a popen_ignore_int() helper
that provides a portable alternative, and provide a generic
run_server_and_client() in ZephyrBinaryRunner which uses it to
abstract the pattern.

Subsequent patches will use this to implement the 'debug' command.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 45440be89e scripts: zephyr_flash_debug: debug like arc_debugger.sh
Add debug and debugserver support.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar 8ceb7ca385 scripts: zephyr_flash_debug: add missing nrfjprog line
The --pinreset line from the shell script is missing.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Marti Bolivar fbe2fcda88 scripts: zephyr_flash_debug: generalize to support debugging
Replace the 'flash' method with a 'run' method, which takes a command
to run (flash, debug, or debugserver).

Rename the classes involved appropriately, and generalize the factory
interfaces as needed.

Add documentation and theory of ops.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-28 13:31:22 -04:00
Kumar Gala 1f0c60cd4b bossa: add support for specifying the port
Now that we have a newer version of bossa in the SDK we can use a
version where there -p option works properly.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-10-25 03:55:15 +02:00