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