Skip to content

Commit 869e9cc

Browse files
Marti BolivarMaureenHelm
authored andcommitted
doc: add initial west documentation
This covers its design and scope, and provides usage and some implementation documentation on the existing flashing and debugging commands. Signed-off-by: Marti Bolivar <[email protected]>
1 parent 3a766ae commit 869e9cc

File tree

3 files changed

+347
-0
lines changed

3 files changed

+347
-0
lines changed

doc/application/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Developer Guides
1212
../reference/kconfig/index.rst
1313
../api/api.rst
1414
../README.rst
15+
../west/index.rst

doc/west/flash-debug.rst

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
.. _west-flash-debug:
2+
3+
West: Flashing and Debugging
4+
############################
5+
6+
West provides three commands for running and interacting with Zephyr
7+
programs running on a board: ``flash``, ``debug``, and
8+
``debugserver``.
9+
10+
These use information stored in the CMake cache [#cmakecache]_ to
11+
flash or attach a debugger to a board supported by Zephyr. The CMake
12+
build system commands with the same names directly delegate to West.
13+
14+
.. _west-flashing:
15+
16+
Flashing: ``west flash``
17+
************************
18+
19+
.. tip:: Run ``west flash -h`` for additional help.
20+
21+
Basics
22+
======
23+
24+
From a Zephyr build directory, re-build the binary and flash it to
25+
your board::
26+
27+
west flash
28+
29+
Without options, the behavior is the same as ``ninja flash`` (or
30+
``make flash``, etc.).
31+
32+
To specify the build directory, use ``--build-dir`` (or ``-d``)::
33+
34+
west flash --build-dir path/to/build/directory
35+
36+
Choosing a Runner
37+
=================
38+
39+
If your board's Zephyr integration supports flashing with multiple
40+
programs, you can specify which one to use using the ``--runner`` (or
41+
``-r``) option. For example, if West flashes your board with
42+
``nrfjprog`` by default, but it also supports JLink, you can override
43+
the default with::
44+
45+
west flash --runner jlink
46+
47+
See :ref:`west-runner` below for more information on the ``runner``
48+
library used by West. The list of runners which support flashing can
49+
be obtained with ``west flash -H``; if run from a build directory or
50+
with ``--build-dir``, this will print additional information on
51+
available runners for your board.
52+
53+
Configuration Overrides
54+
=======================
55+
56+
The CMake cache contains default values West uses while flashing, such
57+
as where the board directory is on the file system, the path to the
58+
kernel binaries to flash in several formats, and more. You can
59+
override any of this configuration at runtime with additional options.
60+
61+
For example, to override the HEX file containing the Zephyr image to
62+
flash (assuming your runner expects a HEX file), but keep other
63+
flash configuration at default values::
64+
65+
west flash --kernel-hex path/to/some/other.hex
66+
67+
The ``west flash -h`` output includes a complete list of overrides
68+
supported by all runners.
69+
70+
Runner-Specific Overrides
71+
=========================
72+
73+
Each runner may support additional options related to flashing. For
74+
example, some runners support an ``--erase`` flag, which mass-erases
75+
the flash storage on your board before flashing the Zephyr image.
76+
77+
To view all of the available options for the runners your board
78+
supports, as well as their usage information, use ``--context`` (or
79+
``-H``)::
80+
81+
west flash --context
82+
83+
.. important::
84+
85+
Note the capital H in the short option name. This re-runs the build
86+
in order to ensure the information displayed is up to date!
87+
88+
When running West outside of a build directory, ``west flash -H`` just
89+
prints a list of runners. You can use ``west flash -H -r
90+
<runner-name>`` to print usage information for options supported by
91+
that runner.
92+
93+
For example, to print usage information about the ``jlink`` runner::
94+
95+
west flash -H -r jlink
96+
97+
.. _west-debugging:
98+
99+
Debugging: ``west debug``, ``west debugserver``
100+
***********************************************
101+
102+
.. tip::
103+
104+
Run ``west debug -h`` or ``west debugserver -h`` for additional help.
105+
106+
Basics
107+
======
108+
109+
From a Zephyr build directory, to attach a debugger to your board and
110+
open up a debug console (e.g. a GDB session)::
111+
112+
west debug
113+
114+
To attach a debugger to your board and open up a local network port
115+
you can connect a debugger to (e.g. an IDE debugger)::
116+
117+
west debugserver
118+
119+
Without options, the behavior is the same as ``ninja debug`` and
120+
``ninja debugserver`` (or ``make debug``, etc.).
121+
122+
To specify the build directory, use ``--build-dir`` (or ``-d``)::
123+
124+
west debug --build-dir path/to/build/directory
125+
west debugserver --build-dir path/to/build/directory
126+
127+
Choosing a Runner
128+
=================
129+
130+
If your board's Zephyr integration supports debugging with multiple
131+
programs, you can specify which one to use using the ``--runner`` (or
132+
``-r``) option. For example, if West debugs your board with
133+
``pyocd-gdbserver`` by default, but it also supports JLink, you can
134+
override the default with::
135+
136+
west debug --runner jlink
137+
west debugserver --runner jlink
138+
139+
See :ref:`west-runner` below for more information on the ``runner``
140+
library used by West. The list of runners which support debugging can
141+
be obtained with ``west debug -H``; if run from a build directory or
142+
with ``--build-dir``, this will print additional information on
143+
available runners for your board.
144+
145+
Configuration Overrides
146+
=======================
147+
148+
The CMake cache contains default values West uses for debugging, such
149+
as where the board directory is on the file system, the path to the
150+
kernel binaries containing symbol tables, and more. You can override
151+
any of this configuration at runtime with additional options.
152+
153+
For example, to override the ELF file containing the Zephyr binary and
154+
symbol tables (assuming your runner expects an ELF file), but keep
155+
other debug configuration at default values::
156+
157+
west debug --kernel-elf path/to/some/other.elf
158+
west debugserver --kernel-elf path/to/some/other.elf
159+
160+
The ``west debug -h`` output includes a complete list of overrides
161+
supported by all runners.
162+
163+
Runner-Specific Overrides
164+
=========================
165+
166+
Each runner may support additional options related to debugging. For
167+
example, some runners support flags which allow you to set the network
168+
ports used by debug servers.
169+
170+
To view all of the available options for the runners your board
171+
supports, as well as their usage information, use ``--context`` (or
172+
``-H``)::
173+
174+
west debug --context
175+
176+
(The command ``west debugserver --context`` will print the same output.)
177+
178+
.. important::
179+
180+
Note the capital H in the short option name. This re-runs the build
181+
in order to ensure the information displayed is up to date!
182+
183+
When running West outside of a build directory, ``west debug -H`` just
184+
prints a list of runners. You can use ``west debug -H -r
185+
<runner-name>`` to print usage information for options supported by
186+
that runner.
187+
188+
For example, to print usage information about the ``jlink`` runner::
189+
190+
west debug -H -r jlink
191+
192+
.. _west-runner:
193+
194+
Library Backend: ``west.runner``
195+
********************************
196+
197+
In keeping with West's :ref:`west-design-constraints`, the flash and
198+
debug commands are wrappers around a separate library that is part of
199+
West, and can be used by other code.
200+
201+
This library is the ``west.runner`` subpackage of West itself. The
202+
central abstraction within this library is ``ZephyrBinaryRunner``, an
203+
abstract class which represents *runner* objects, which can flash
204+
and/or debug Zephyr programs. The set of available runners is
205+
determined by the imported subclasses of ``ZephyrBinaryRunner``.
206+
``ZephyrBinaryRunner`` is available in the ``west.runner.core``
207+
module; individual runner implementations are in other submodules,
208+
such as ``west.runner.nrfjprog``, ``west.runner.openocd``, etc.
209+
210+
Developers can add support for new ways to flash and debug Zephyr
211+
programs by implementing additional runners. To get this support into
212+
upstream Zephyr, the runner should be added into a new or existing
213+
``west.runner`` module, and imported from
214+
:file:`west/runner/__init__.py`.
215+
216+
.. important::
217+
218+
Submit any changes to West to its own separate Git repository
219+
(https://github.com/zephyrproject-rtos/west), not to the copy of
220+
West currently present in the Zephyr tree. This copy is a temporary
221+
measure; when West learns how to manage multiple repositories, the
222+
copy will be removed.
223+
224+
API documentation for the core module follows.
225+
226+
.. automodule:: west.runner.core
227+
:members:
228+
229+
Doing it By Hand
230+
****************
231+
232+
If you prefer not to use West to flash or debug your board, simply
233+
inspect the build directory for the binaries output by the build
234+
system. These will be named something like ``zephyr/zephyr.elf``,
235+
``zephyr/zephyr.hex``, etc., depending on your board's build system
236+
integration. These binaries may be flashed to a board using
237+
alternative tools of your choice, or used for debugging as needed,
238+
e.g. as a source of symbol tables.
239+
240+
By default, these West commands rebuild binaries before flashing and
241+
debugging. This can of course also be accomplished using the usual
242+
targets provided by Zephyr's build system (in fact, that's how West
243+
does it).
244+
245+
.. rubric:: Footnotes
246+
247+
.. [#cmakecache]
248+
249+
The CMake cache is a file containing saved variables and values
250+
which is created by CMake when it is first run to generate a build
251+
system. See the `cmake(1)`_ manual for more details.
252+
253+
.. _cmake(1):
254+
https://cmake.org/cmake/help/latest/manual/cmake.1.html

doc/west/index.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.. _west:
2+
3+
West (Experimental)
4+
###################
5+
6+
The Zephyr project is developing a swiss-army knife command line tool
7+
named ``west``. (Zephyr is an English name for the Greek god of the
8+
west wind.)
9+
10+
West is developed in its own `repository on GitHub`_. A copy is
11+
currently maintained in Zephyr's :file:`scripts/meta/west` directory.
12+
13+
Usage
14+
*****
15+
16+
West's usage is similar to Git's: general options are followed by a
17+
command, which may also take options and arguments::
18+
19+
$ west [common-opts] <command-name> [command-opts] [<command-args>]
20+
21+
Usage guides for specific groups of subcommands are in the following
22+
pages.
23+
24+
.. toctree::
25+
26+
flash-debug.rst
27+
28+
(This list will expand as additional features are developed.)
29+
30+
Planned Features
31+
****************
32+
33+
Additional features are under development for future versions of
34+
Zephyr:
35+
36+
- Building Zephyr images.
37+
38+
- Running Zephyr in emulation.
39+
40+
- Bootloader integration: bootloader-aware image building, signing,
41+
and flashing, as well as building and flashing the bootloader itself.
42+
43+
- Multiple repository support: fetching and updating repositories that
44+
integrate with Zephyr, such as `MCUboot`_, `OpenThread`_ and others.
45+
46+
See `Zephyr issue #6205`_ for more details and discussion.
47+
48+
.. _west-design-constraints:
49+
50+
Design Constraints
51+
******************
52+
53+
West is:
54+
55+
- **Optional**: it is always *possible* to drop back to "raw"
56+
command-line tools, i.e. use Zephyr without using West. It may not
57+
always be *convenient* to do so, however. (If all of West's features
58+
were already conveniently available, there would be no reason to
59+
develop it.)
60+
61+
- **Compatible with CMake**: building, flashing and debugging, and
62+
emulator support will always remain compatible with direct use of
63+
CMake.
64+
65+
- **Cross-platform**: West is written in Python 3, and works on all
66+
platforms supported by Zephyr.
67+
68+
- **Usable as a Library**: whenever possible, West features are
69+
implemented as libraries that can be used standalone in other
70+
programs, along with separate command line interfaces that wrap
71+
them. West itself is a Python package named ``west``; its libraries
72+
are implemented as subpackages.
73+
74+
- **Conservative about features**: no features will be accepted without
75+
strong and compelling motivation.
76+
77+
- **Clearly specified**: West's behavior in cases where it wraps other
78+
commands is clearly specified and documented. This enables
79+
interoperability with third party tools, and means Zephyr developers
80+
can always find out what is happening "under the hood" when using West.
81+
82+
.. _repository on GitHub:
83+
https://github.com/zephyrproject-rtos/west
84+
85+
.. _MCUboot:
86+
https://mcuboot.com/
87+
88+
.. _OpenThread:
89+
https://openthread.io/
90+
91+
.. _Zephyr issue #6205:
92+
https://github.com/zephyrproject-rtos/zephyr/issues/6205

0 commit comments

Comments
 (0)