MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 1 | ############### |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 2 | LPCXpresso55S69 |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 3 | ############### |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 4 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 5 | **************** |
| 6 | 1. Building TF-M |
| 7 | **************** |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 8 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 9 | There are two options for the TF-M build - with or without secondary bootloader (BL2). |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 10 | |
| 11 | 1.1 Building TF-M demo without BL2 |
| 12 | ================================== |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 13 | To build S and NS application image for the LPCXpresso55S69, run the ``build_tfm_demo.py`` script in ``platform/ext/target/nxp/lpcxpresso55s69/scripts`` |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 14 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 15 | Or do it manually using the following commands: |
David Vincze | b56c5ad | 2020-10-08 15:50:46 +0200 | [diff] [blame] | 16 | |
| 17 | .. code:: bash |
| 18 | |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 19 | $ cmake -S . -B build -DTFM_PLATFORM=nxp/lpcxpresso55s69 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTFM_PROFILE=profile_medium -DBL2=OFF -G"Unix Makefiles" |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 20 | $ cd build && make install |
David Vincze | b56c5ad | 2020-10-08 15:50:46 +0200 | [diff] [blame] | 21 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 22 | 1.2 Building TF-M demo with BL2 |
| 23 | =============================== |
| 24 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 25 | To build S and NS application along with a BL2 (bootloader) image for the |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 26 | LPCXpresso55S69 run the ``build_tfm_demo_bl2.py`` script in ``platform/ext/target/nxp/lpcxpresso55s69/scripts`` |
| 27 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 28 | Or do it manually using the following commands: |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 29 | |
| 30 | .. code:: bash |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 31 | |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 32 | $ cmake -S . -B build -DTFM_PLATFORM=nxp/lpcxpresso55s69 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTFM_PROFILE=profile_medium -DBL2=ON -G"Unix Makefiles" |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 33 | $ cd build && make install |
| 34 | |
| 35 | 1.3 Building TF-M regression tests |
| 36 | ================================== |
| 37 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 38 | To run the S and NS regression tests (``TEST_S=ON`` and ``TEST_NS=ON``), the |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 39 | secondary image areas must be set to 0 (firmware updates are not possible). |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 40 | Use the ``build_tfm_regression.py`` script in ``platform/ext/target/nxp/lpcxpresso55s69/scripts`` |
| 41 | or do it manually using following commands: |
| 42 | |
| 43 | .. code:: bash |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 44 | |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 45 | $ cmake -S . -B build -DTFM_PLATFORM=nxp/lpcxpresso55s69 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTFM_PROFILE=profile_medium -DBL2=OFF -DTEST_S=ON -DTEST_NS=ON -G"Unix Makefiles" |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 46 | $ cd build && make install |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 47 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 48 | **************** |
| 49 | 2. Flashing TF-M |
| 50 | **************** |
David Vincze | b56c5ad | 2020-10-08 15:50:46 +0200 | [diff] [blame] | 51 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 52 | After generating the binaries, there are three options to flash them using: |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 53 | 1) **External Segger J-Link flasher** |
| 54 | 2) **On-board J-Link debugger** - with update of LPC-Link2 debugger to the Segger J-Link firmware |
| 55 | 3) **PyOCD** - supports both DAPLink and J-Link interfaces. The LPCXpresso55S69 boards, by default, use DAPLink firmware. |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 56 | |
| 57 | 2.1 Flashing with Segger J-Link |
| 58 | =============================== |
| 59 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 60 | For command line flashing it is recommended to use external Segger J-Link flasher or to |
| 61 | update the LPC-Link 2 debugger on the development board with the firmware provided by Segger, |
| 62 | which makes the device behave as if there is an on-board J-Link debugger. |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 63 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 64 | For onboard J-Link debugger option please follow this step: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 65 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 66 | 2.1.1 Update the LPC-Link 2 to Segger J-Link |
| 67 | -------------------------------------------- |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 68 | |
| 69 | - Install a recent version of the `J-Link Software and Documentation |
| 70 | Pack <https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack>`__. |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 71 | Version **6.98b** was used with this guide. |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 72 | |
| 73 | - Update the on-board LPC-Link 2 to use the latest J-Link firmware, |
| 74 | following the instructions from Segger: `Getting Started with |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 75 | LPC-Link2 <https://www.segger.com/products/debug-probes/j-link/models/other-j-links/lpc-link-2/>`__. |
| 76 | - Link the DFU jumper (J4) and make power cycle |
| 77 | - Flash the **NXP LPCXpresso On-Board** firmware image with ``lpcscrypt`` from the ``lpcscrypt_2.1.2_57/scripts`` folder as follows: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 78 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 79 | .. tabs:: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 80 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 81 | .. group-tab:: Linux |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 82 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 83 | .. code-block:: bash |
| 84 | |
| 85 | $ ./program_JLINK ../probe_firmware/LPCXpressoV2/Firmware_JLink_LPCXpressoV2_20190404.bin |
| 86 | |
| 87 | .. group-tab:: Windows |
| 88 | |
| 89 | .. code-block:: bash |
| 90 | |
| 91 | $ program_JLINK ../probe_firmware/LPCXpressoV2/Firmware_JLink_LPCXpressoV2_20190404.bin |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 92 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 93 | Then remove the link on the DFU jumper and power cycle. |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 94 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 95 | 2.1.2 Flash images with ``JLinkCommander`` |
| 96 | ------------------------------------------ |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 97 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 98 | To flash TF-M images use the flash scripts provided in ``platform/ext/target/nxp/lpcxpresso55s69/scripts`` folder: |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 99 | - ``flash_JLink.py`` - for uploading image without BL2 |
| 100 | - ``flash_bl2_JLink.py`` - for uploading image with BL2 |
| 101 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 102 | Or you can do it manually according to paragraph ``2.1.2.1``. |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 103 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 104 | 2.1.2.1 Connect to the board using ``JLinkCommander`` |
| 105 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 106 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 107 | .. tabs:: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 108 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 109 | .. group-tab:: Linux |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 110 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 111 | .. code-block:: bash |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 112 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 113 | $ JLinkExe -device lpc55s69 -if swd -speed 2000 -autoconnect 1 |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 114 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 115 | SEGGER J-Link Commander V6.98b (Compiled Mar 12 2021 15:03:29) |
| 116 | DLL version V6.98b, compiled Mar 12 2021 15:02:22 |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 117 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 118 | Connecting to J-Link via USB...O.K. |
| 119 | Firmware: J-Link LPCXpresso V2 compiled Apr 4 2019 16:54:03 |
| 120 | Hardware version: V1.00 |
| 121 | S/N: 729458359 |
| 122 | VTref=3.300V |
| 123 | Device "LPC55S69_M33_0" selected. |
| 124 | ... |
| 125 | Cortex-M33 identified. |
| 126 | |
| 127 | .. group-tab:: Windows |
| 128 | |
| 129 | .. code-block:: bash |
| 130 | |
| 131 | $ JLink -device lpc55s69 -if swd -speed 2000 -autoconnect 1 |
| 132 | |
| 133 | SEGGER J-Link Commander V6.98b (Compiled Mar 12 2021 15:03:29) |
| 134 | DLL version V6.98b, compiled Mar 12 2021 15:02:22 |
| 135 | |
| 136 | Connecting to J-Link via USB...O.K. |
| 137 | Firmware: J-Link LPCXpresso V2 compiled Apr 4 2019 16:54:03 |
| 138 | Hardware version: V1.00 |
| 139 | S/N: 729458359 |
| 140 | VTref=3.300V |
| 141 | Device "LPC55S69_M33_0" selected. |
| 142 | ... |
| 143 | Cortex-M33 identified. |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 144 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 145 | 2.1.2.2 Flash the built images |
| 146 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 147 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 148 | When BL2 is disabled, flash the generated hex secure and non-secure images: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 149 | :: |
| 150 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 151 | J-Link> loadfile ${BUILD_DIR}/bl2.hex |
| 152 | J-Link> loadfile ${BUILD_DIR}/tfm_s_signed.bin 0x00008000 |
| 153 | J-Link> loadfile ${BUILD_DIR}/tfm_ns_signed.bin 0x00030000 |
David Vincze | b56c5ad | 2020-10-08 15:50:46 +0200 | [diff] [blame] | 154 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 155 | If you built TF-M with the BL2 secondary bootloader, use following commands: |
David Vincze | b56c5ad | 2020-10-08 15:50:46 +0200 | [diff] [blame] | 156 | :: |
| 157 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 158 | J-Link> loadfile ${BUILD_DIR}/tfm_s.hex |
| 159 | J-Link> loadfile ${BUILD_DIR}/tfm_ns.hex |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 160 | |
| 161 | 2.2 Flashing with PyOCD |
| 162 | ======================= |
| 163 | PyOCD is an open source Python package for programming and debugging Arm Cortex-M microcontrollers using multiple supported types of USB debug probes. |
| 164 | See: `PyOCD <https://pypi.org/project/pyocd/>`__ |
| 165 | |
| 166 | To flash TF-M images with PyOCD you can use the flash scripts provided in ``platform/ext/target/nxp/lpcxpresso55s69/scripts`` folder: |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 167 | - ``flash_PyOCD.py`` - for uploading image without BL2 |
| 168 | - ``flash_bl2_PyOCD.py`` - for uploading image with BL2 |
| 169 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 170 | You should get the following output (flashing without BL2): |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 171 | :: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 172 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 173 | $ python flash_PyOCD.py |
| 174 | 0001749:INFO:eraser:Mass erasing device... |
| 175 | 0001749:INFO:eraser:Erasing chip... |
| 176 | 0001902:INFO:eraser:Done |
| 177 | 0001902:INFO:eraser:Successfully erased. |
| 178 | [====================] 100% |
| 179 | 0007694:INFO:loader:Erased 262144 bytes (8 sectors), programmed 203776 bytes (398 pages), skipped 0 bytes (0 pages) at 33.91 kB/s |
| 180 | [====================] 100% |
| 181 | 0005187:INFO:loader:Erased 131072 bytes (4 sectors), programmed 121856 bytes (238 pages), skipped 0 bytes (0 pages) at 34.13 kB/s |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 182 | |
| 183 | |
| 184 | Or do it manually according the following steps: |
| 185 | |
| 186 | If you built TF-M with the BL2 secondary bootloader, use the following commands: |
| 187 | :: |
| 188 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 189 | $ pyocd erase --mass -t LPC55S69 |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 190 | $ pyocd flash ${BUILD_DIR}/tfm_s.hex ${BUILD_DIR}/tfm_ns.hex -t LPC55S69 |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 191 | |
| 192 | When BL2 is disabled, flash the generated hex secure and non-secure images: |
| 193 | :: |
| 194 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 195 | $ pyocd erase --mass -t LPC55S69 |
| 196 | $ pyocd flash ${BUILD_DIR}/bl2.hex -t LPC55S69 |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 197 | $ pyocd flash ${BUILD_DIR}/tfm_s_ns_signed.bin --base-address 0x8000 -t LPC55S69 |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 198 | |
| 199 | .. Note:: |
| 200 | |
| 201 | At present, the reset target command does not seem to respond, so you can reset the device to start firmware execution via the physical RESET button (S4). There is sometimes also a stability issue with the flash erasing, so if the script freezes, it is needed to terminate the script, physically reset the target an rerun it again. |
| 202 | |
| 203 | .. Warning:: |
| 204 | |
| 205 | When using PyOCD on Windows, there might currently occur an issue with the ``libusb`` library. In that case, download the ``libusb`` library from `here <https://libusb.info/>`__ and copy .DLL file into the Python installation folder (next to python.exe) |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 206 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 207 | ************ |
| 208 | 3. Debugging |
| 209 | ************ |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 210 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 211 | 3.1 Debugging with Segger Ozone |
| 212 | =============================== |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 213 | |
| 214 | If you have a commercially licensed Segger J-Link, or if you meet the |
| 215 | license terms for it's use, `Segger's cross-platform Ozone |
| 216 | tool <https://www.segger.com/products/development-tools/ozone-j-link-debugger/>`__ |
| 217 | can be used to debug TF-M firmware images. |
| 218 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 219 | To debug, flash the BL2, S and NS firmware images using the ``flash.py`` |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 220 | script or command-line options described earlier in this guide, and |
| 221 | configure a new project on Ozone as follows: |
| 222 | |
| 223 | - Device: LPC55S69 |
| 224 | - Target Interface: SWD |
| 225 | - Target Interface Speed: 2 MHz |
| 226 | - Host Interface: USB |
| 227 | - Program File: build/secure\_fw/tfm\_s.axf (etc.) |
| 228 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 229 | Once the project has been set up, and the firmware has previously been |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 230 | flashed to the board, connect to the target via: |
| 231 | |
| 232 | - Debug > Start Debug Session > Attach to a Running Program |
| 233 | |
| 234 | At this point, you can set a breakpoint somewhere in the code, such as |
| 235 | in ``startup_LPC55S69_cm33_core0.s`` at the start of the |
| 236 | ``Reset_Handler``, or near a line like ``bl SystemInit``, or at |
| 237 | another appropriate location, and reset the device to debug. |
| 238 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 239 | 3.2 Debugging with GDB |
| 240 | ====================== |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 241 | |
| 242 | **NOTE**: If you are debugging, make sure to set the |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 243 | build type variable to ``-DCMAKE_BUILD_TYPE=Debug`` when |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 244 | building TF-M so that debug information is available to GDB. |
| 245 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 246 | **NOTE**: When debugging with the mbed-crypto library, it is needed to add an |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 247 | additional ``-DMBEDCRYPTO_BUILD_TYPE=DEBUG`` compile-time switch. |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 248 | |
| 249 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 250 | 3.2.1 Start the GDB server, pointing to the secure application image: |
| 251 | --------------------------------------------------------------------- |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 252 | You can use JLinkGDBServer or PyOCD server depending on the interface configured in the previous step. |
| 253 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 254 | .. tabs:: |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 255 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 256 | .. group-tab:: J-Link GDB server |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 257 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 258 | .. code-block:: bash |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 259 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 260 | $ JLinkGDBServer -device lpc55s69 -if swd -speed 2000 |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 261 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 262 | .. group-tab:: PyOCD GDB server |
| 263 | |
| 264 | .. code:: bash |
| 265 | |
| 266 | $ pyocd gdbserver -f 2000k -t LPC55S69 |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 267 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 268 | 3.2.2 Connecting to the GDB server |
| 269 | ---------------------------------- |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 270 | |
| 271 | In a separate terminal, start the GDB client in ``tui`` (text UI) mode: |
| 272 | |
| 273 | .. code:: bash |
| 274 | |
| 275 | $ arm-none-eabi-gdb --tui secure_fw/tfm_s.axf |
| 276 | |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 277 | Then from the client connect to the remote GDB server that was started |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 278 | earlier: |
| 279 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 280 | .. tabs:: |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 281 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 282 | .. group-tab:: J-Link GDB server |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 283 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 284 | With ``JLinkGDBServer`` (default port 2331): |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 285 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 286 | .. code:: bash |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 287 | |
MartinaHanusovaNXP | 535aefd | 2021-07-20 14:45:01 +0200 | [diff] [blame] | 288 | (gdb) target remote:2331 |
| 289 | Remote debugging using :2331 |
| 290 | |
| 291 | .. group-tab:: PyOCD GDB server |
| 292 | |
| 293 | With ``pyocd gdbserver`` (default port 3333): |
| 294 | |
| 295 | .. code:: bash |
| 296 | |
| 297 | (gdb) target remote:3333 |
| 298 | Remote debugging using :3333 |
MartinaHanusovaNXP | 8dfc288 | 2021-04-29 16:53:49 +0200 | [diff] [blame] | 299 | |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 300 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 301 | 3.2.3 Reset and stop at ``main`` |
| 302 | -------------------------------- |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 303 | |
| 304 | Set a breakpoint at ``main()`` (found in ``tfm_core.c``), reset the |
| 305 | device (``monitor reset``), and continue (``c``) execution. |
| 306 | |
| 307 | :: |
| 308 | |
| 309 | (gdb) break main |
| 310 | Breakpoint 1 at 0x10024220: file [path]/secure_fw/core/tfm_core.c, line 189. |
| 311 | (gdb) monitor reset |
| 312 | (gdb) c |
| 313 | Continuing. |
| 314 | Note: automatically using hardware breakpoints for read-only addresses. |
| 315 | |
| 316 | Breakpoint 1, main () |
| 317 | at [path]/secure_fw/core/tfm_core.c:189 |
Kevin Peng | 300c68d | 2021-08-12 17:40:17 +0800 | [diff] [blame] | 318 | 189 tfm_arch_init_secure_msp((uint32_t)®ION_NAME(Image$$, ARM_LIB_STACK, |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 319 | |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 320 | 3.2.4 Commonly used GDB commands |
| 321 | -------------------------------- |
Kevin Townsend | a26983f | 2020-04-06 13:26:21 +0200 | [diff] [blame] | 322 | |
| 323 | You can start, step through, and analyse the code using some of the |
| 324 | following GDB commands: |
| 325 | |
| 326 | +-------------------+---------------------------------------------------------+ |
| 327 | | GDB Command | Description | |
| 328 | +===================+=========================================================+ |
| 329 | | ``next`` | Execute the next statement in the program | |
| 330 | +-------------------+---------------------------------------------------------+ |
| 331 | | ``step`` | Step until new source line, entering called functions | |
| 332 | +-------------------+---------------------------------------------------------+ |
| 333 | | ``until <n>`` | Run until source line ``n`` in the current file | |
| 334 | +-------------------+---------------------------------------------------------+ |
| 335 | | ``info locals`` | Display the local variables and their current values | |
| 336 | +-------------------+---------------------------------------------------------+ |
| 337 | | ``bt`` | Display a stack backtrace up to the current function | |
| 338 | +-------------------+---------------------------------------------------------+ |
| 339 | | ``print <x>`` | Print the expression (ex. ``print my_var``) | |
| 340 | +-------------------+---------------------------------------------------------+ |
| 341 | | ``x`` | Examine memory (ex. ``x/s *my_string``) | |
| 342 | +-------------------+---------------------------------------------------------+ |
| 343 | |
| 344 | From here, you should consult a tutorial or book on GDB to know how to debug |
| 345 | common problems. |
| 346 | |
| 347 | -------------- |
| 348 | |
| 349 | *Copyright (c) 2020, Linaro. All rights reserved.* |
Kevin Peng | 300c68d | 2021-08-12 17:40:17 +0800 | [diff] [blame] | 350 | *Copyright (c) 2020-2021, Arm Limited. All rights reserved.* |
Andrej Butok | f424016 | 2023-05-30 14:56:31 +0200 | [diff] [blame] | 351 | *Copyright 2020-2023 NXP. All rights reserved. |
MartinaHanusovaNXP | 11644b6 | 2021-04-22 10:16:47 +0200 | [diff] [blame] | 352 | *SPDX-License-Identifier: BSD-3-Clause* |