|
| 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 |
0 commit comments