Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
| 2 | .. sectionauthor:: Bryan Brattlof <bb@ti.com> |
| 3 | |
| 4 | K3 Generation |
| 5 | ============= |
| 6 | |
| 7 | Summary |
| 8 | ------- |
| 9 | |
| 10 | Texas Instrument's K3 family of SoCs utilize a heterogeneous multicore |
| 11 | and highly integrated device architecture targeted to maximize |
| 12 | performance and power efficiency for a wide range of industrial, |
| 13 | automotive and other broad market segments. |
| 14 | |
| 15 | Typically the processing cores and the peripherals for these devices are |
| 16 | partitioned into three functional domains to provide ultra-low power |
| 17 | modes as well as accommodating application and industrial safety systems |
| 18 | on the same SoC. These functional domains are typically called the: |
| 19 | |
| 20 | * Wakeup (WKUP) domain |
| 21 | * Micro-controller (MCU) domain |
| 22 | * Main domain |
| 23 | |
| 24 | For a more detailed view of what peripherals are attached to each |
| 25 | domain, consult the device specific documentation. |
| 26 | |
| 27 | K3 Based SoCs |
| 28 | ------------- |
| 29 | |
| 30 | .. toctree:: |
| 31 | :maxdepth: 1 |
| 32 | |
Jai Luthra | e526653e | 2023-11-13 08:51:49 -0600 | [diff] [blame] | 33 | am62ax_sk |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 34 | am62x_sk |
Nishanth Menon | 1f2b6f9 | 2023-11-04 03:01:36 -0500 | [diff] [blame] | 35 | ../beagle/am62x_beagleplay |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 36 | ../toradex/verdin-am62 |
Roger Quadros | cd87b1e | 2023-08-05 11:14:39 +0300 | [diff] [blame] | 37 | am64x_evm |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 38 | am65x_evm |
Nishanth Menon | e83fe67 | 2023-07-27 13:59:01 -0500 | [diff] [blame] | 39 | j7200_evm |
Nishanth Menon | 756b878 | 2023-11-04 03:11:03 -0500 | [diff] [blame] | 40 | ../beagle/j721e_beagleboneai64 |
Nishanth Menon | e83fe67 | 2023-07-27 13:59:01 -0500 | [diff] [blame] | 41 | j721e_evm |
Manorit Chawdhry | 670a22b | 2023-10-06 10:16:00 +0530 | [diff] [blame] | 42 | j721s2_evm |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 43 | |
| 44 | Boot Flow Overview |
| 45 | ------------------ |
| 46 | |
| 47 | For all K3 SoCs the first core started will be inside the Security |
| 48 | Management Subsystem (SMS) which will secure the device and start a core |
| 49 | in the wakeup domain to run the ROM code. ROM will then initialize the |
| 50 | boot media needed to load the binaries packaged inside `tiboot3.bin`, |
| 51 | including a 32bit U-Boot SPL, (called the wakup SPL) that ROM will jump |
| 52 | to after it has finished loading everything into internal SRAM. |
| 53 | |
Nishanth Menon | 7bdb2d5 | 2023-07-27 13:59:02 -0500 | [diff] [blame] | 54 | .. image:: img/boot_flow_01.svg |
Heinrich Schuchardt | d0894b2 | 2023-08-22 11:40:55 -0500 | [diff] [blame] | 55 | :alt: Boot flow up to wakeup domain SPL |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 56 | |
| 57 | The wakeup SPL, running on a wakeup domain core, will initialize DDR and |
| 58 | any peripherals needed load the larger binaries inside the `tispl.bin` |
| 59 | into DDR. Once loaded the wakeup SPL will start one of the 'big' |
| 60 | application cores inside the main domain to initialize the main domain, |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 61 | starting with Trusted Firmware-A (TF-A), before moving on to start |
| 62 | OP-TEE and the main domain's U-Boot SPL. |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 63 | |
Nishanth Menon | 7bdb2d5 | 2023-07-27 13:59:02 -0500 | [diff] [blame] | 64 | .. image:: img/boot_flow_02.svg |
Heinrich Schuchardt | d0894b2 | 2023-08-22 11:40:55 -0500 | [diff] [blame] | 65 | :alt: Boot flow up to main domain SPL |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 66 | |
| 67 | The main domain's SPL, running on a 64bit application core, has |
| 68 | virtually unlimited space (billions of bytes now that DDR is working) to |
| 69 | initialize even more peripherals needed to load in the `u-boot.img` |
| 70 | which loads more firmware into the micro-controller & wakeup domains and |
| 71 | finally prepare the main domain to run Linux. |
| 72 | |
Nishanth Menon | 7bdb2d5 | 2023-07-27 13:59:02 -0500 | [diff] [blame] | 73 | .. image:: img/boot_flow_03.svg |
Heinrich Schuchardt | d0894b2 | 2023-08-22 11:40:55 -0500 | [diff] [blame] | 74 | :alt: Complete boot flow up to Linux |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 75 | |
| 76 | This is the typical boot flow for all K3 based SoCs, however this flow |
| 77 | offers quite a lot in the terms of flexibility, especially on High |
| 78 | Security (HS) SoCs. |
| 79 | |
| 80 | Boot Flow Variations |
| 81 | ^^^^^^^^^^^^^^^^^^^^ |
| 82 | |
| 83 | All K3 SoCs will generally use the above boot flow with two main |
| 84 | differences depending on the capabilities of the boot ROM and the number |
| 85 | of cores inside the device. These differences split the bootflow into |
| 86 | essentially 4 unique but very similar flows: |
| 87 | |
| 88 | * Split binary with a combined firmware: (eg: AM65) |
| 89 | * Combined binary with a combined firmware: (eg: AM64) |
| 90 | * Split binary with a split firmware: (eg: J721E) |
| 91 | * Combined binary with a split firmware: (eg: AM62) |
| 92 | |
| 93 | For devices that utilize the split binary approach, ROM is not capable |
| 94 | of loading the firmware into the SoC requiring the wakeup domain's |
| 95 | U-Boot SPL to load the firmware. |
| 96 | |
| 97 | Devices with a split firmware will have two firmwares loaded into the |
| 98 | device at different times during the bootup process. TI's Foundational |
| 99 | Security (TIFS), needed to operate the Security Management Subsystem, |
| 100 | will either be loaded by ROM or the WKUP U-Boot SPL, then once the |
| 101 | wakeup U-Boot SPL has completed, the second Device Management (DM) |
| 102 | firmware can be loaded on the now free core in the wakeup domain. |
| 103 | |
| 104 | For more information on the bootup process of your SoC, consult the |
| 105 | device specific boot flow documentation. |
| 106 | |
Manorit Chawdhry | 9834647 | 2023-12-29 16:16:33 +0530 | [diff] [blame] | 107 | Secure Boot |
| 108 | ----------- |
| 109 | |
| 110 | K3 HS-SE (High Security - Security Enforced) devices enforce an |
| 111 | authenticated boot flow for secure boot. HS-FS (High Security - Field |
| 112 | Securable) is the state of a K3 device before it has been eFused with |
| 113 | customer security keys. In the HS-FS state the authentication still can |
| 114 | function as in HS-SE but as there are no customer keys to verify the |
| 115 | signatures against the authentication will pass for certificates signed |
| 116 | with any key. |
| 117 | |
| 118 | Chain of trust |
| 119 | ^^^^^^^^^^^^^^ |
| 120 | |
| 121 | 1) Public ROM loads the tiboot3.bin (R5 SPL, TIFS) |
| 122 | 2) R5 SPL loads tispl.bin (ATF, OP-TEE, DM, SPL) |
| 123 | 3) SPL loads u-boot.img (U-Boot) |
| 124 | 4) U-Boot loads fitImage (Linux and DTBs) |
| 125 | |
| 126 | Steps 1-3 are all authenticated by either the Secure ROM or TIFS as the |
| 127 | authenticating entity and step 4 uses U-boot standard mechanism for |
| 128 | authenticating. |
| 129 | |
| 130 | All the authentication that are done for ROM/TIFS are done through x509 |
| 131 | certificates that are signed. |
| 132 | |
| 133 | Firewalls |
| 134 | ^^^^^^^^^ |
| 135 | |
| 136 | 1) Secure ROM comes up and sets up firewalls that are needed by itself |
| 137 | 2) TIFS will setup it's own firewalls to protect core system resources |
| 138 | 3) R5 SPL will remove any firewalls that are leftover from the Secure ROM stage |
| 139 | that are no longer required. |
| 140 | 4) Each stage beyond this: such as tispl.bin containing TFA/OPTEE uses OIDs to |
| 141 | set up firewalls to protect themselves (enforced by TIFS) |
| 142 | 5) TFA/OP-TEE can configure other firewalls at runtime if required as they |
| 143 | are already authenticated and firewalled off from illegal access. |
| 144 | 6) All later stages can setup or remove firewalls that have not been already |
| 145 | configured by previous stages, such as those created by TIFS, TFA, and OP-TEE. |
| 146 | |
| 147 | Futhur, firewalls have a lockdown bit in hardware that enforces the setting |
| 148 | (and cannot be over-ridden) until the full system is reset. |
| 149 | |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 150 | Software Sources |
| 151 | ---------------- |
| 152 | |
| 153 | All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and |
| 154 | `u-boot.img` for all K3 SoCs can be located at the following places |
| 155 | online |
| 156 | |
Nishanth Menon | ee91e48 | 2023-07-27 13:58:44 -0500 | [diff] [blame] | 157 | .. k3_rst_include_start_boot_sources |
| 158 | |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 159 | * **Das U-Boot** |
| 160 | |
| 161 | | **source:** https://source.denx.de/u-boot/u-boot.git |
| 162 | | **branch:** master |
| 163 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 164 | * **Trusted Firmware-A (TF-A)** |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 165 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 166 | | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 167 | | **branch:** master |
| 168 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 169 | * **Open Portable Trusted Execution Environment (OP-TEE)** |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 170 | |
| 171 | | **source:** https://github.com/OP-TEE/optee_os.git |
| 172 | | **branch:** master |
| 173 | |
Nishanth Menon | e2a4745 | 2023-08-22 11:41:07 -0500 | [diff] [blame] | 174 | * **TI Firmware (TIFS, DM, SYSFW)** |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 175 | |
| 176 | | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git |
| 177 | | **branch:** ti-linux-firmware |
| 178 | |
Nishanth Menon | e2a4745 | 2023-08-22 11:41:07 -0500 | [diff] [blame] | 179 | .. note:: |
| 180 | |
| 181 | The TI Firmware required for functionality of the system can be |
| 182 | one of the following combination (see platform specific boot diagram for |
| 183 | further information as to which component runs on which processor): |
| 184 | |
| 185 | * **TIFS** - TI Foundational Security Firmware - Consists of purely firmware |
| 186 | meant to run on the security enclave. |
| 187 | * **DM** - Device Management firmware also called TI System Control Interface |
| 188 | server (TISCI Server) - This component purely plays the role of managing |
| 189 | device resources such as power, clock, interrupts, dma etc. This firmware |
| 190 | runs on a dedicated or multi-use microcontroller outside the security |
| 191 | enclave. |
| 192 | |
| 193 | OR |
| 194 | |
| 195 | * **SYSFW** - System firmware - consists of both TIFS and DM both running on |
| 196 | the security enclave. |
| 197 | |
Nishanth Menon | ee91e48 | 2023-07-27 13:58:44 -0500 | [diff] [blame] | 198 | .. k3_rst_include_end_boot_sources |
| 199 | |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 200 | Build Procedure |
| 201 | --------------- |
| 202 | |
| 203 | Depending on the specifics of your device, you will need three or more |
| 204 | binaries to boot your SoC. |
| 205 | |
| 206 | * `tiboot3.bin` (bootloader for the wakeup domain) |
| 207 | * `tispl.bin` (bootloader for the main domain) |
| 208 | * `u-boot.img` |
| 209 | |
| 210 | During the bootup process, both the 32bit wakeup domain and the 64bit |
| 211 | main domains will be involved. This means everything inside the |
| 212 | `tiboot3.bin` running in the wakeup domain will need to be compiled for |
| 213 | 32bit cores and most binaries in the `tispl.bin` will need to be |
| 214 | compiled for 64bit main domain CPU cores. |
| 215 | |
| 216 | All of that to say you will need both a 32bit and 64bit cross compiler |
| 217 | (assuming you're using an x86 desktop) |
| 218 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 219 | .. k3_rst_include_start_common_env_vars_desc |
| 220 | .. list-table:: Generic environment variables |
| 221 | :widths: 25 25 50 |
| 222 | :header-rows: 1 |
| 223 | |
| 224 | * - S/w Component |
| 225 | - Env Variable |
| 226 | - Description |
| 227 | * - All Software |
| 228 | - CC32 |
| 229 | - Cross compiler for ARMv7 (ARM 32bit), typically arm-linux-gnueabihf- |
| 230 | * - All Software |
| 231 | - CC64 |
| 232 | - Cross compiler for ARMv8 (ARM 64bit), typically aarch64-linux-gnu- |
| 233 | * - All Software |
| 234 | - LNX_FW_PATH |
| 235 | - Path to TI Linux firmware repository |
| 236 | * - All Software |
| 237 | - TFA_PATH |
| 238 | - Path to source of Trusted Firmware-A |
| 239 | * - All Software |
| 240 | - OPTEE_PATH |
| 241 | - Path to source of OP-TEE |
| 242 | .. k3_rst_include_end_common_env_vars_desc |
| 243 | |
| 244 | .. k3_rst_include_start_common_env_vars_defn |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 245 | .. prompt:: bash $ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 246 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 247 | export CC32=arm-linux-gnueabihf- |
| 248 | export CC64=aarch64-linux-gnu- |
| 249 | export LNX_FW_PATH=path/to/ti-linux-firmware |
| 250 | export TFA_PATH=path/to/trusted-firmware-a |
| 251 | export OPTEE_PATH=path/to/optee_os |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 252 | .. k3_rst_include_end_common_env_vars_defn |
| 253 | |
| 254 | We will also need some common environment variables set up for the various |
| 255 | other build sources. we shall use the following, in the build descriptions below: |
| 256 | |
| 257 | .. k3_rst_include_start_board_env_vars_desc |
| 258 | .. list-table:: Board specific environment variables |
| 259 | :widths: 25 25 50 |
| 260 | :header-rows: 1 |
| 261 | |
| 262 | * - S/w Component |
| 263 | - Env Variable |
| 264 | - Description |
| 265 | * - U-Boot |
| 266 | - UBOOT_CFG_CORTEXR |
| 267 | - Defconfig for Cortex-R (Boot processor). |
| 268 | * - U-Boot |
| 269 | - UBOOT_CFG_CORTEXA |
| 270 | - Defconfig for Cortex-A (MPU processor). |
| 271 | * - Trusted Firmware-A |
| 272 | - TFA_BOARD |
| 273 | - Platform name used for building TF-A for Cortex-A Processor. |
| 274 | * - Trusted Firmware-A |
| 275 | - TFA_EXTRA_ARGS |
| 276 | - Any extra arguments used for building TF-A. |
| 277 | * - OP-TEE |
| 278 | - OPTEE_PLATFORM |
| 279 | - Platform name used for building OP-TEE for Cortex-A Processor. |
| 280 | * - OP-TEE |
| 281 | - OPTEE_EXTRA_ARGS |
| 282 | - Any extra arguments used for building OP-TEE. |
| 283 | .. k3_rst_include_end_board_env_vars_desc |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 284 | |
| 285 | Building tiboot3.bin |
Heinrich Schuchardt | b72160b | 2023-10-28 11:59:32 +0200 | [diff] [blame] | 286 | ^^^^^^^^^^^^^^^^^^^^ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 287 | |
| 288 | 1. To generate the U-Boot SPL for the wakeup domain, use the following |
| 289 | commands, substituting :code:`{SOC}` for the name of your device (eg: |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 290 | am62x) to package the various firmware and the wakeup UBoot SPL into |
| 291 | the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device |
| 292 | uses the split binary flow) |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 293 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 294 | .. _k3_rst_include_start_build_steps_spl_r5: |
| 295 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 296 | .. k3_rst_include_start_build_steps_spl_r5 |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 297 | .. prompt:: bash $ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 298 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 299 | # inside u-boot source |
| 300 | make $UBOOT_CFG_CORTEXR |
| 301 | make CROSS_COMPILE=$CC32 BINMAN_INDIRS=$LNX_FW_PATH |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 302 | .. k3_rst_include_end_build_steps_spl_r5 |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 303 | |
| 304 | At this point you should have all the needed binaries to boot the wakeup |
| 305 | domain of your K3 SoC. |
| 306 | |
| 307 | **Combined Binary Boot Flow** (eg: am62x, am64x, ... ) |
| 308 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 309 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin` |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 310 | |
| 311 | **Split Binary Boot Flow** (eg: j721e, am65x) |
| 312 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 313 | | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin` |
| 314 | | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb` |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 315 | |
| 316 | .. note :: |
| 317 | |
| 318 | It's important to rename the generated `tiboot3.bin` and `sysfw.itb` |
| 319 | to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup |
| 320 | UBoot SPL will only look for and load the files with these names. |
| 321 | |
| 322 | Building tispl.bin |
Heinrich Schuchardt | b72160b | 2023-10-28 11:59:32 +0200 | [diff] [blame] | 323 | ^^^^^^^^^^^^^^^^^^ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 324 | |
| 325 | The `tispl.bin` is a standard fitImage combining the firmware need for |
| 326 | the main domain to function properly as well as Device Management (DM) |
| 327 | firmware if your device using a split firmware. |
| 328 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 329 | 2. We will first need TF-A, as it's the first thing to run on the 'big' |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 330 | application cores on the main domain. |
| 331 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 332 | .. k3_rst_include_start_build_steps_tfa |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 333 | .. prompt:: bash $ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 334 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 335 | # inside trusted-firmware-a source |
| 336 | make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS \ |
| 337 | TARGET_BOARD=$TFA_BOARD |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 338 | .. k3_rst_include_end_build_steps_tfa |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 339 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 340 | Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 341 | =j784s4` (if it is a J784S4 device), while typical Sitara (`am6*`) devices |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 342 | use the `lite` option. |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 343 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 344 | 3. The Open Portable Trusted Execution Environment (OP-TEE) is designed |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 345 | to run as a companion to a non-secure Linux kernel for Cortex-A cores |
| 346 | using the TrustZone technology built into the core. |
| 347 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 348 | .. k3_rst_include_start_build_steps_optee |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 349 | .. prompt:: bash $ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 350 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 351 | # inside optee_os source |
| 352 | make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 CFG_ARM64_core=y $OPTEE_EXTRA_ARGS \ |
| 353 | PLATFORM=$OPTEE_PLATFORM |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 354 | .. k3_rst_include_end_build_steps_optee |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 355 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 356 | 4. Finally, after TF-A has initialized the main domain and OP-TEE has |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 357 | finished, we can jump back into U-Boot again, this time running on a |
| 358 | 64bit core in the main domain. |
| 359 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 360 | .. _k3_rst_include_start_build_steps_uboot: |
| 361 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 362 | .. k3_rst_include_start_build_steps_uboot |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 363 | .. prompt:: bash $ |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 364 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 365 | # inside u-boot source |
| 366 | make $UBOOT_CFG_CORTEXA |
| 367 | make CROSS_COMPILE=$CC64 BINMAN_INDIRS=$LNX_FW_PATH \ |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 368 | BL31=$TFA_PATH/build/k3/$TFA_BOARD/release/bl31.bin \ |
| 369 | TEE=$OPTEE_PATH/out/arm-plat-k3/core/tee-raw.bin |
Neha Malcom Francis | 2b259f0 | 2023-12-05 15:12:20 +0530 | [diff] [blame] | 370 | |
| 371 | .. note:: |
| 372 | It is also possible to pick up a custom DM binary by adding TI_DM argument |
| 373 | pointing to the file. If not provided, it defaults to picking up the DM |
| 374 | binary from BINMAN_INDIRS. This is only applicable to devices that utilize |
| 375 | split firmware. |
| 376 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 377 | .. k3_rst_include_end_build_steps_uboot |
Bryan Brattlof | 6d13813 | 2022-12-19 14:29:50 -0600 | [diff] [blame] | 378 | |
| 379 | At this point you should have every binary needed initialize both the |
| 380 | wakeup and main domain and to boot to the U-Boot prompt |
| 381 | |
| 382 | **Main Domain Bootloader** |
| 383 | |
Neha Malcom Francis | 507be12 | 2023-07-22 00:14:43 +0530 | [diff] [blame] | 384 | | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices |
| 385 | | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 386 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 387 | FIT signature signing |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 388 | --------------------- |
| 389 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 390 | K3 platforms have FIT signature signing enabled by default on their primary |
| 391 | platforms. Here we'll take an example for creating FIT Image for J721E platform |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 392 | and the same can be extended to other platforms |
| 393 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 394 | Pre-requisites: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 395 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 396 | * U-boot build (:ref:`U-boot build <k3_rst_include_start_build_steps_spl_r5>`) |
| 397 | * Linux Image and Linux DTB prebuilt |
| 398 | |
| 399 | Describing FIT source |
| 400 | ^^^^^^^^^^^^^^^^^^^^^ |
| 401 | |
| 402 | FIT Image is a packed structure containing binary blobs and configurations. |
| 403 | The Kernel FIT Image that we have has Kernel Image, DTB and the DTBOs. It |
| 404 | supports packing multiple images and configurations that allow you to |
| 405 | choose any configuration at runtime to boot from. |
| 406 | |
| 407 | .. code-block:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 408 | |
| 409 | /dts-v1/; |
| 410 | |
| 411 | / { |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 412 | description = "FIT Image description"; |
| 413 | #address-cells = <1>; |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 414 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 415 | images { |
| 416 | [image-1] |
| 417 | [image-2] |
| 418 | [fdt-1] |
| 419 | [fdt-2] |
| 420 | } |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 421 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 422 | configurations { |
| 423 | default = <conf-1> |
| 424 | [conf-1: image-1,fdt-1] |
| 425 | [conf-2: image-2,fdt-1] |
| 426 | } |
| 427 | } |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 428 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 429 | * Sample Images |
| 430 | |
| 431 | .. code-block:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 432 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 433 | kernel-1 { |
| 434 | description = "Linux kernel"; |
| 435 | data = /incbin/("linux.bin"); |
| 436 | type = "kernel"; |
| 437 | arch = "arm64"; |
| 438 | os = "linux"; |
| 439 | compression = "gzip"; |
| 440 | load = <0x81000000>; |
| 441 | entry = <0x81000000>; |
| 442 | hash-1 { |
| 443 | algo = "sha512"; |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 444 | }; |
| 445 | }; |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 446 | fdt-ti_k3-j721e-common-proc-board.dtb { |
| 447 | description = "Flattened Device Tree blob"; |
| 448 | data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dtb"); |
| 449 | type = "flat_dt"; |
| 450 | arch = "arm64"; |
| 451 | compression = "none"; |
| 452 | load = <0x83000000>; |
| 453 | hash-1 { |
| 454 | algo = "sha512"; |
| 455 | }; |
| 456 | }; |
| 457 | # Optional images |
| 458 | fdt-ti_k3-j721e-evm-virt-mac-client.dtbo { |
| 459 | description = "Flattened Device Tree blob"; |
| 460 | data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-evm-virt-mac-client.dtbo"); |
| 461 | type = "flat_dt"; |
| 462 | arch = "arm64"; |
| 463 | compression = "none"; |
| 464 | load = <0x83080000>; |
| 465 | hash-1 { |
| 466 | algo = "sha512"; |
| 467 | }; |
| 468 | }; |
| 469 | |
| 470 | .. note:: |
| 471 | |
| 472 | Change the path in data variables to point to the respective files in your |
| 473 | local machine. For e.g change "linux.bin" to "<path-to-kernel-image>". |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 474 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 475 | For enabling usage of FIT signature, add the signature node to the |
| 476 | corresponding configuration node as follows. |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 477 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 478 | * Sample Configurations |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 479 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 480 | .. code-block:: |
| 481 | |
| 482 | conf-ti_k3-j721e-common-proc-board.dtb { |
| 483 | description = "Linux kernel, FDT blob"; |
| 484 | fdt = "fdt-ti_k3-j721e-common-proc-board.dtb"; |
| 485 | kernel = "kernel-1"; |
| 486 | signature-1 { |
| 487 | algo = "sha512,rsa4096"; |
| 488 | key-name-hint = "custMpk"; |
| 489 | sign-images = "kernel", "fdt"; |
| 490 | }; |
| 491 | }; |
| 492 | # Optional configurations |
| 493 | conf-ti_k3-j721e-evm-virt-mac-client.dtbo { |
| 494 | description = "FDTO blob"; |
| 495 | fdt = "fdt-ti_k3-j721e-evm-virt-mac-client.dtbo"; |
| 496 | |
| 497 | signature-1 { |
| 498 | algo = "sha512,rsa4096"; |
| 499 | key-name-hint = "custMpk"; |
| 500 | sign-images = "fdt"; |
| 501 | }; |
| 502 | }; |
| 503 | |
| 504 | Specify all images you need the signature to authenticate as a part of |
| 505 | sign-images. The key-name-hint needs to be changed if you are using some |
| 506 | other key other than the TI dummy key that we are using for this example. |
| 507 | It should be the name of the file containing the keys. |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 508 | |
Nishanth Menon | b7ee22f | 2023-07-27 13:58:48 -0500 | [diff] [blame] | 509 | .. note:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 510 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 511 | Generating new set of keys: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 512 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 513 | .. prompt:: bash $ |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 514 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 515 | mkdir keys |
| 516 | openssl genpkey -algorithm RSA -out keys/dev.key \ |
| 517 | -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:65537 |
| 518 | openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 519 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 520 | Generating the fitImage |
| 521 | ^^^^^^^^^^^^^^^^^^^^^^^ |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 522 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 523 | .. note:: |
| 524 | |
| 525 | For signing a secondary platform like SK boards, you'll require |
| 526 | additional steps |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 527 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 528 | - Change the CONFIG_DEFAULT_DEVICE_TREE |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 529 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 530 | For e.g |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 531 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 532 | .. code-block:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 533 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 534 | diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig |
| 535 | index a5c1df7e0054..6d0126d955ef 100644 |
| 536 | --- a/configs/j721e_evm_a72_defconfig |
| 537 | +++ b/configs/j721e_evm_a72_defconfig |
| 538 | @@ -13,7 +13,7 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80480000 |
| 539 | CONFIG_ENV_SIZE=0x20000 |
| 540 | CONFIG_DM_GPIO=y |
| 541 | CONFIG_SPL_DM_SPI=y |
| 542 | -CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board" |
| 543 | +CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-sk" |
| 544 | CONFIG_SPL_TEXT_BASE=0x80080000 |
| 545 | CONFIG_DM_RESET=y |
| 546 | CONFIG_SPL_MMC=y |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 547 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 548 | - Change the binman nodes to package u-boot.dtb for the correct set of platform |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 549 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 550 | For e.g |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 551 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 552 | .. code-block:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 553 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 554 | diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi |
| 555 | index 673be646b1e3..752fa805fe8d 100644 |
| 556 | --- a/arch/arm/dts/k3-j721e-binman.dtsi |
| 557 | +++ b/arch/arm/dts/k3-j721e-binman.dtsi |
| 558 | @@ -299,8 +299,8 @@ |
| 559 | #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb" |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 560 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 561 | #define UBOOT_NODTB "u-boot-nodtb.bin" |
| 562 | -#define J721E_EVM_DTB "u-boot.dtb" |
| 563 | -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb" |
| 564 | +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb" |
| 565 | +#define J721E_SK_DTB "u-boot.dtb" |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 566 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 567 | This step will embed the public key in the u-boot.dtb file that was already |
| 568 | built during the initial u-boot build. |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 569 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 570 | .. prompt:: bash $ |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 571 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 572 | mkimage -r -f fitImage.its -k $UBOOT_PATH/board/ti/keys -K $UBOOT_PATH/build/$ARMV8/dts/dt.dtb fitImage |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 573 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 574 | .. note:: |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 575 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 576 | If you have another set of keys then change the -k argument to point to |
| 577 | the folder where your keys are present, the build requires the presence |
| 578 | of both .key and .crt file. |
| 579 | |
| 580 | Build u-boot again |
| 581 | ^^^^^^^^^^^^^^^^^^ |
| 582 | |
| 583 | The updated u-boot.dtb needs to be packed in u-boot.img for authentication |
| 584 | so rebuild U-boot ARMV8 without changing any parameters. |
| 585 | Refer (:ref:`U-boot ARMV8 build <k3_rst_include_start_build_steps_uboot>`) |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 586 | |
| 587 | .. note:: |
| 588 | |
Manorit Chawdhry | f64b3bd | 2023-12-29 16:16:32 +0530 | [diff] [blame] | 589 | The devices now also have distroboot enabled so if the FIT image doesn't |
| 590 | work then the fallback to normal distroboot will be there on HS devices. |
| 591 | This will need to be explicitly disabled by changing the boot_targets to |
| 592 | disallow fallback during testing. |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 593 | |
| 594 | Saving environment |
| 595 | ------------------ |
| 596 | |
| 597 | SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default |
| 598 | way for saving the environments. This has been done as Uenv.txt is more granular |
| 599 | then the saveenv command and can be used across various bootmodes too. |
| 600 | |
| 601 | **Writing to MMC/EMMC** |
| 602 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 603 | .. prompt:: bash => |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 604 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 605 | env export -t $loadaddr <list of variables> |
| 606 | fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize} |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 607 | |
| 608 | **Reading from MMC/EMMC** |
| 609 | |
| 610 | By default run envboot will read it from the MMC/EMMC partition ( based on |
| 611 | mmcdev) and set the environments. |
| 612 | |
| 613 | If manually needs to be done then the environment can be read from the |
| 614 | filesystem and then imported |
| 615 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 616 | .. prompt:: bash => |
Manorit Chawdhry | ce7a62f | 2023-07-14 11:22:29 +0530 | [diff] [blame] | 617 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 618 | fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile} |
| 619 | env import -t ${loadaddr} ${filesize} |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 620 | |
| 621 | .. _k3_rst_refer_openocd: |
| 622 | |
| 623 | Common Debugging environment - OpenOCD |
| 624 | -------------------------------------- |
| 625 | |
| 626 | This section will show you how to connect a board to `OpenOCD |
| 627 | <https://openocd.org/>`_ and load the SPL symbols for debugging with |
| 628 | a K3 generation device. To follow this guide, you must build custom |
| 629 | u-boot binaries, start your board from a boot media such as an SD |
| 630 | card, and use an OpenOCD environment. This section uses generic |
| 631 | examples, though you can apply these instructions to any supported K3 |
| 632 | generation device. |
| 633 | |
| 634 | The overall structure of this setup is in the following figure. |
| 635 | |
| 636 | .. image:: img/openocd-overview.svg |
Nishanth Menon | 5746e03 | 2023-08-22 11:40:56 -0500 | [diff] [blame] | 637 | :alt: Overview of OpenOCD setup. |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 638 | |
| 639 | .. note:: |
| 640 | |
| 641 | If you find these instructions useful, please consider `donating |
| 642 | <https://openocd.org/pages/donations.html>`_ to OpenOCD. |
| 643 | |
| 644 | Step 1: Download and install OpenOCD |
| 645 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 646 | |
| 647 | To get started, it is more convenient if the distribution you |
| 648 | use supports OpenOCD by default. Follow the instructions in the |
| 649 | `getting OpenOCD <https://openocd.org/pages/getting-openocd.html>`_ |
| 650 | documentation to pick the installation steps appropriate to your |
| 651 | environment. Some references to OpenOCD documentation: |
| 652 | |
| 653 | * `OpenOCD User Guide <https://openocd.org/doc/html/index.html>`_ |
| 654 | * `OpenOCD Developer's Guide <https://openocd.org/doc/doxygen/html/index.html>`_ |
| 655 | |
| 656 | Refer to the release notes corresponding to the `OpenOCD version |
| 657 | <https://github.com/openocd-org/openocd/releases>`_ to ensure |
| 658 | |
| 659 | * Processor support: In general, processor support shouldn't present |
| 660 | any difficulties since OpenOCD provides solid support for both ARMv8 |
| 661 | and ARMv7. |
| 662 | * SoC support: When working with System-on-a-Chip (SoC), the support |
| 663 | usually comes as a TCL config file. It is vital to ensure the correct |
| 664 | version of OpenOCD or to use the TCL files from the latest release or |
| 665 | the one mentioned. |
| 666 | * Board or the JTAG adapter support: In most cases, board support is |
| 667 | a relatively easy problem if the board has a JTAG pin header. All |
| 668 | you need to do is ensure that the adapter you select is compatible |
| 669 | with OpenOCD. Some boards come with an onboard JTAG adapter that |
| 670 | requires a USB cable to be plugged into the board, in which case, it |
| 671 | is vital to ensure that the JTAG adapter is supported. Fortunately, |
| 672 | almost all TI K3 SK/EVMs come with TI's XDS110, which has out of the |
| 673 | box support by OpenOCD. The board-specific documentation will |
| 674 | cover the details and any adapter/dongle recommendations. |
| 675 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 676 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 677 | |
| 678 | openocd -v |
| 679 | |
| 680 | .. note:: |
| 681 | |
| 682 | OpenOCD version 0.12.0 is usually required to connect to most K3 |
| 683 | devices. If your device is only supported by a newer version than the |
| 684 | one provided by your distribution, you may need to build it from the source. |
| 685 | |
| 686 | Building OpenOCD from source |
| 687 | """""""""""""""""""""""""""" |
| 688 | |
| 689 | The dependency package installation instructions below are for Debian |
| 690 | systems, but equivalent instructions should exist for systems with |
| 691 | other package managers. Please refer to the `OpenOCD Documentation |
| 692 | <https://openocd.org/>`_ for more recent installation steps. |
| 693 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 694 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 695 | |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 696 | # Check the packages to be installed: needs deb-src in sources.list |
| 697 | sudo apt build-dep openocd |
| 698 | # The following list is NOT complete - please check the latest |
| 699 | sudo apt-get install libtool pkg-config texinfo libusb-dev \ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 700 | libusb-1.0.0-dev libftdi-dev libhidapi-dev autoconf automake |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 701 | git clone https://github.com/openocd-org/openocd.git openocd |
| 702 | cd openocd |
| 703 | git submodule init |
| 704 | git submodule update |
| 705 | ./bootstrap |
| 706 | ./configure --prefix=/usr/local/ |
| 707 | make -j`nproc` |
| 708 | sudo make install |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 709 | |
| 710 | .. note:: |
| 711 | |
| 712 | The example above uses the GitHub mirror site. See |
| 713 | `git repo information <https://openocd.org/doc/html/Developers.html#OpenOCD-Git-Repository>`_ |
| 714 | information to pick the official git repo. |
| 715 | If a specific version is desired, select the version using `git checkout tag`. |
| 716 | |
| 717 | Installing OpenOCD udev rules |
| 718 | """"""""""""""""""""""""""""" |
| 719 | |
| 720 | The step is not necessary if the distribution supports the OpenOCD, but |
| 721 | if building from a source, ensure that the udev rules are installed |
| 722 | correctly to ensure a sane system. |
| 723 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 724 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 725 | |
| 726 | # Go to the OpenOCD source directory |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 727 | cd openocd |
| 728 | Copy the udev rules to the correct system location |
| 729 | sudo cp ./contrib/60-openocd.rules \ |
Jonathan Humphreys | 27fd498 | 2023-08-22 13:49:03 -0500 | [diff] [blame] | 730 | ./src/jtag/drivers/libjaylink/contrib/99-libjaylink.rules \ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 731 | /etc/udev/rules.d/ |
| 732 | # Get Udev to load the new rules up |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 733 | sudo udevadm control --reload-rules |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 734 | # Use the new rules on existing connected devices |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 735 | sudo udevadm trigger |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 736 | |
| 737 | Step 2: Setup GDB |
| 738 | ^^^^^^^^^^^^^^^^^ |
| 739 | |
| 740 | Most systems come with gdb-multiarch package. |
| 741 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 742 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 743 | |
| 744 | # Install gdb-multiarch package |
Nishanth Menon | 55fbcae | 2023-08-24 10:40:36 -0500 | [diff] [blame] | 745 | sudo apt-get install gdb-multiarch |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 746 | |
| 747 | Though using GDB natively is normal, developers with interest in using IDE |
| 748 | may find a few of these interesting: |
| 749 | |
| 750 | * `gdb-dashboard <https://github.com/cyrus-and/gdb-dashboard>`_ |
| 751 | * `gef <https://github.com/hugsy/gef>`_ |
| 752 | * `peda <https://github.com/longld/peda>`_ |
| 753 | * `pwndbg <https://github.com/pwndbg/pwndbg>`_ |
| 754 | * `voltron <https://github.com/snare/voltron>`_ |
| 755 | * `ddd <https://www.gnu.org/software/ddd/>`_ |
| 756 | * `vscode <https://www.justinmklam.com/posts/2017/10/vscode-debugger-setup/>`_ |
| 757 | * `vim conque-gdb <https://github.com/vim-scripts/Conque-GDB>`_ |
| 758 | * `emacs realgud <https://github.com/realgud/realgud/wiki/gdb-notes>`_ |
| 759 | * `Lauterbach IDE <https://www2.lauterbach.com/pdf/backend_gdb.pdf>`_ |
| 760 | |
| 761 | .. warning:: |
| 762 | LLDB support for OpenOCD is still a work in progress as of this writing. |
| 763 | Using GDB is probably the safest option at this point in time. |
| 764 | |
| 765 | Step 3: Connect board to PC |
| 766 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 767 | There are few patterns of boards in the ecosystem |
| 768 | |
| 769 | .. k3_rst_include_start_openocd_connect_XDS110 |
| 770 | |
| 771 | **Integrated JTAG adapter/dongle**: The board has a micro-USB connector labelled |
| 772 | XDS110 USB or JTAG. Connect a USB cable to the board to the mentioned port. |
| 773 | |
| 774 | .. note:: |
| 775 | |
| 776 | There are multiple USB ports on a typical board, So, ensure you have read |
| 777 | the user guide for the board and confirmed the silk screen label to ensure |
| 778 | connecting to the correct port. |
| 779 | |
| 780 | .. k3_rst_include_end_openocd_connect_XDS110 |
| 781 | |
| 782 | .. k3_rst_include_start_openocd_connect_cti20 |
| 783 | |
| 784 | **cTI20 connector**: The TI's `cTI20 |
| 785 | <https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_JTAG_connectors.html#cti-20-pin-header-information>`_ connector |
| 786 | is probably the most prevelant on TI platforms. Though many |
| 787 | TI boards have an onboard XDS110, cTI20 connector is usually |
| 788 | provided as an alternate scheme to connect alternatives such |
| 789 | as `Lauterbach <https://www.lauterbach.com/>`_ or `XDS560 |
| 790 | <https://www.ti.com/tool/TMDSEMU560V2STM-U>`_. |
| 791 | |
| 792 | To debug on these boards, the following combinations is suggested: |
| 793 | |
| 794 | * `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_ |
| 795 | or `equivalent dongles supported by OpenOCD. <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_ |
| 796 | * Cable such as `Tag-connect ribbon cable <https://www.tag-connect.com/product/20-pin-cortex-ribbon-cable-4-length-with-50-mil-connectors>`_ |
| 797 | * Adapter to convert cTI20 to ARM20 such as those from |
| 798 | `Segger <https://www.segger.com/products/debug-probes/j-link/accessories/adapters/ti-cti-20-adapter/>`_ |
| 799 | or `Lauterbach LA-3780 <https://www.lauterbach.com/ad3780.html>`_ |
| 800 | Or optionally, if you have manufacturing capability then you could try |
| 801 | `BeagleBone JTAG Adapter <https://github.com/mmorawiec/BeagleBone-Black-JTAG-Adapters>`_ |
| 802 | |
| 803 | .. warning:: |
| 804 | XDS560 and Lauterbach are proprietary solutions and is not supported by |
| 805 | OpenOCD. |
| 806 | When purchasing an off the shelf adapter/dongle, you do want to be careful |
| 807 | about the signalling though. Please |
| 808 | `read for additional info <https://software-dl.ti.com/ccs/esd/xdsdebugprobes/emu_JTAG_connectors.html>`_. |
| 809 | |
| 810 | .. k3_rst_include_end_openocd_connect_cti20 |
| 811 | |
| 812 | .. k3_rst_include_start_openocd_connect_tag_connect |
| 813 | |
| 814 | **Tag-Connect**: `Tag-Connect <https://www.tag-connect.com/>`_ |
| 815 | pads on the boards which require special cable. Please check the documentation |
| 816 | to `identify <https://www.tag-connect.com/info/legs-or-no-legs>`_ if "legged" |
| 817 | or "no-leg" version of the cable is appropriate for the board. |
| 818 | |
| 819 | To debug on these boards, you will need: |
| 820 | |
| 821 | * `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_ |
| 822 | or `equivalent dongles supported by OpenOCD <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_. |
| 823 | * Tag-Connect cable appropriate to the board such as |
| 824 | `TC2050-IDC-NL <https://www.tag-connect.com/product/TC2050-IDC-NL-10-pin-no-legs-cable-with-ribbon-connector>`_ |
| 825 | * In case of no-leg, version, a |
| 826 | `retaining clip <https://www.tag-connect.com/product/tc2050-clip-3pack-retaining-clip>`_ |
| 827 | * Tag-Connect to ARM20 |
| 828 | `adapter <https://www.tag-connect.com/product/tc2050-arm2010-arm-20-pin-to-tc2050-adapter>`_ |
| 829 | |
| 830 | .. note:: |
| 831 | You can optionally use a 3d printed solution such as |
| 832 | `Protective cap <https://www.thingiverse.com/thing:3025584>`_ or |
| 833 | `clip <https://www.thingiverse.com/thing:3035278>`_ to replace |
| 834 | the retaining clip. |
| 835 | |
| 836 | .. warning:: |
| 837 | With the Tag-Connect to ARM20 adapter, Please solder the "Trst" signal for |
| 838 | connection to work. |
| 839 | |
| 840 | .. k3_rst_include_end_openocd_connect_tag_connect |
| 841 | |
| 842 | Debugging with OpenOCD |
| 843 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 844 | |
| 845 | Debugging U-Boot is different from debugging regular user space |
| 846 | applications. The bootloader initialization process involves many boot |
| 847 | media and hardware configuration operations. For K3 devices, there |
| 848 | are also interactions with security firmware. While reloading the |
| 849 | "elf" file works through GDB, developers must be mindful of cascading |
| 850 | initialization's potential consequences. |
| 851 | |
| 852 | Consider the following code change: |
| 853 | |
| 854 | .. code-block:: diff |
| 855 | |
| 856 | --- a/file.c 2023-07-29 10:55:29.647928811 -0500 |
| 857 | +++ b/file.c 2023-07-29 10:55:46.091856816 -0500 |
| 858 | @@ -1,3 +1,3 @@ |
| 859 | val = readl(reg); |
| 860 | -val |= 0x2; |
| 861 | +val |= 0x1; |
| 862 | writel(val, reg); |
| 863 | |
| 864 | Re-running the elf file with the above change will result in the |
| 865 | register setting 0x3 instead of the intended 0x1. There are other |
| 866 | hardware blocks which may not behave very well with a re-initialization |
| 867 | without proper shutdown. |
| 868 | |
| 869 | To help narrow the debug down, it is usually simpler to use the |
| 870 | standard boot media to get to the bootloader and debug only in the area |
| 871 | of interest. |
| 872 | |
| 873 | In general, to debug u-boot spl/u-boot with OpenOCD there are three steps: |
| 874 | |
| 875 | * Modify the code adding a loop to allow the debugger to attach |
| 876 | near the point of interest. Boot up normally to stop at the loop. |
| 877 | * Connect with OpenOCD and step out of the loop. |
| 878 | * Step through the code to find the root of issue. |
| 879 | |
| 880 | Typical debugging involves a few iterations of the above sequence. |
| 881 | Though most bootloader developers like to use printf to debug, |
| 882 | debug with JTAG tends to be most efficient since it is possible to |
| 883 | investigate the code flow and inspect hardware registers without |
| 884 | repeated iterations. |
| 885 | |
| 886 | Code modification |
| 887 | """"""""""""""""" |
| 888 | |
| 889 | * **start.S**: Adding an infinite while loop at the very entry of |
| 890 | U-Boot. For this, look for the corresponding start.S entry file. |
| 891 | This is usually only required when debugging some core SoC or |
| 892 | processor related function. For example: arch/arm/cpu/armv8/start.S or |
| 893 | arch/arm/cpu/armv7/start.S |
| 894 | |
| 895 | .. code-block:: diff |
| 896 | |
| 897 | diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S |
| 898 | index 69e281b086..744929e825 100644 |
| 899 | --- a/arch/arm/cpu/armv7/start.S |
| 900 | +++ b/arch/arm/cpu/armv7/start.S |
| 901 | @@ -37,6 +37,8 @@ |
| 902 | #endif |
| 903 | |
| 904 | reset: |
| 905 | +dead_loop: |
| 906 | + b dead_loop |
| 907 | /* Allow the board to save important registers */ |
| 908 | b save_boot_params |
| 909 | save_boot_params_ret: |
| 910 | |
| 911 | * **board_init_f**: Adding an infinite while loop at the board entry |
| 912 | function. In many cases, it is important to debug the boot process if |
| 913 | any changes are made for board-specific applications. Below is a step |
| 914 | by step process for debugging the boot SPL or Armv8 SPL: |
| 915 | |
| 916 | To debug the boot process in either domain, we will first |
| 917 | add a modification to the code we would like to debug. |
| 918 | In this example, we will debug ``board_init_f`` inside |
| 919 | ``arch/arm/mach-k3/{soc}_init.c``. Since some sections of U-Boot |
| 920 | will be executed multiple times during the bootup process of K3 |
Jonathan Humphreys | 27fd498 | 2023-08-22 13:49:03 -0500 | [diff] [blame] | 921 | devices, we will need to include either ``CONFIG_ARM64`` or |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 922 | ``CONFIG_CPU_V7R`` to catch the CPU at the desired place during the |
| 923 | bootup process (Main or Wakeup domains). For example, modify the |
| 924 | file as follows (depending on need): |
| 925 | |
| 926 | .. code-block:: c |
| 927 | |
| 928 | void board_init_f(ulong dummy) |
| 929 | { |
| 930 | . |
| 931 | . |
| 932 | /* Code to run on the R5F (Wakeup/Boot Domain) */ |
| 933 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 934 | volatile int x = 1; |
| 935 | while(x) {}; |
| 936 | } |
| 937 | ... |
| 938 | /* Code to run on the ARMV8 (Main Domain) */ |
Jonathan Humphreys | 27fd498 | 2023-08-22 13:49:03 -0500 | [diff] [blame] | 939 | if (IS_ENABLED(CONFIG_ARM64)) { |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 940 | volatile int x = 1; |
| 941 | while(x) {}; |
| 942 | } |
| 943 | . |
| 944 | . |
| 945 | } |
| 946 | |
| 947 | Connecting with OpenOCD for a debug session |
| 948 | """"""""""""""""""""""""""""""""""""""""""" |
| 949 | |
| 950 | Startup OpenOCD to debug the platform as follows: |
| 951 | |
| 952 | * **Integrated JTAG interface**: If the evm has a debugger such as |
| 953 | XDS110 inbuilt, there is typically an evm board support added and a |
| 954 | cfg file will be available. |
| 955 | |
| 956 | .. k3_rst_include_start_openocd_cfg_XDS110 |
| 957 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 958 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 959 | |
| 960 | openocd -f board/{board_of_choice}.cfg |
| 961 | |
| 962 | .. k3_rst_include_end_openocd_cfg_XDS110 |
| 963 | |
| 964 | .. k3_rst_include_start_openocd_cfg_external_intro |
| 965 | |
| 966 | * **External JTAG adapter/interface**: In other cases, where an |
| 967 | adapter/dongle is used, a simple cfg file can be created to integrate the |
| 968 | SoC and adapter information. See `supported TI K3 SoCs |
| 969 | <https://github.com/openocd-org/openocd/blob/master/tcl/target/ti_k3.cfg#L59>`_ |
| 970 | to decide if the SoC is supported or not. |
| 971 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 972 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 973 | |
| 974 | openocd -f openocd_connect.cfg |
| 975 | |
| 976 | .. k3_rst_include_end_openocd_cfg_external_intro |
| 977 | |
| 978 | For example, with BeaglePlay (AM62X platform), the openocd_connect.cfg: |
| 979 | |
| 980 | .. code-block:: tcl |
| 981 | |
| 982 | # TUMPA example: |
| 983 | # http://www.tiaowiki.com/w/TIAO_USB_Multi_Protocol_Adapter_User's_Manual |
| 984 | source [find interface/ftdi/tumpa.cfg] |
| 985 | |
| 986 | transport select jtag |
| 987 | |
| 988 | # default JTAG configuration has only SRST and no TRST |
| 989 | reset_config srst_only srst_push_pull |
| 990 | |
| 991 | # delay after SRST goes inactive |
| 992 | adapter srst delay 20 |
| 993 | |
| 994 | if { ![info exists SOC] } { |
| 995 | # Set the SoC of interest |
| 996 | set SOC am625 |
| 997 | } |
| 998 | |
| 999 | source [find target/ti_k3.cfg] |
| 1000 | |
| 1001 | ftdi tdo_sample_edge falling |
| 1002 | |
| 1003 | # Speeds for FT2232H are in multiples of 2, and 32MHz is tops |
| 1004 | # max speed we seem to achieve is ~20MHz.. so we pick 16MHz |
| 1005 | adapter speed 16000 |
| 1006 | |
| 1007 | Below is an example of the output of this command: |
| 1008 | |
| 1009 | .. code-block:: console |
| 1010 | |
| 1011 | Info : Listening on port 6666 for tcl connections |
| 1012 | Info : Listening on port 4444 for telnet connections |
| 1013 | Info : XDS110: connected |
| 1014 | Info : XDS110: vid/pid = 0451/bef3 |
| 1015 | Info : XDS110: firmware version = 3.0.0.20 |
| 1016 | Info : XDS110: hardware version = 0x002f |
| 1017 | Info : XDS110: connected to target via JTAG |
| 1018 | Info : XDS110: TCK set to 2500 kHz |
| 1019 | Info : clock speed 2500 kHz |
| 1020 | Info : JTAG tap: am625.cpu tap/device found: 0x0bb7e02f (mfg: 0x017 (Texas Instruments), part: 0xbb7e, ver: 0x0) |
| 1021 | Info : starting gdb server for am625.cpu.sysctrl on 3333 |
| 1022 | Info : Listening on port 3333 for gdb connections |
| 1023 | Info : starting gdb server for am625.cpu.a53.0 on 3334 |
| 1024 | Info : Listening on port 3334 for gdb connections |
| 1025 | Info : starting gdb server for am625.cpu.a53.1 on 3335 |
| 1026 | Info : Listening on port 3335 for gdb connections |
| 1027 | Info : starting gdb server for am625.cpu.a53.2 on 3336 |
| 1028 | Info : Listening on port 3336 for gdb connections |
| 1029 | Info : starting gdb server for am625.cpu.a53.3 on 3337 |
| 1030 | Info : Listening on port 3337 for gdb connections |
| 1031 | Info : starting gdb server for am625.cpu.main0_r5.0 on 3338 |
| 1032 | Info : Listening on port 3338 for gdb connections |
| 1033 | Info : starting gdb server for am625.cpu.gp_mcu on 3339 |
| 1034 | Info : Listening on port 3339 for gdb connections |
| 1035 | |
| 1036 | .. note:: |
| 1037 | Notice the default configuration is non-SMP configuration allowing |
| 1038 | for each of the core to be attached and debugged simultaneously. |
| 1039 | ARMv8 SPL/U-Boot starts up on cpu0 of a53/a72. |
| 1040 | |
| 1041 | .. k3_rst_include_start_openocd_cfg_external_gdb |
| 1042 | |
| 1043 | To debug using this server, use GDB directly or your preferred |
| 1044 | GDB-based IDE. To start up GDB in the terminal, run the following |
| 1045 | command. |
| 1046 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1047 | .. prompt:: bash $ |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1048 | |
| 1049 | gdb-multiarch |
| 1050 | |
| 1051 | To connect to your desired core, run the following command within GDB: |
| 1052 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1053 | .. prompt:: bash (gdb) |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1054 | |
| 1055 | target extended-remote localhost:{port for desired core} |
| 1056 | |
| 1057 | To load symbols: |
| 1058 | |
| 1059 | .. warning:: |
| 1060 | |
| 1061 | SPL and U-Boot does a re-location of address compared to where it |
| 1062 | is loaded originally. This step takes place after the DDR size is |
| 1063 | determined from dt parsing. So, debugging can be split into either |
| 1064 | "before re-location" or "after re-location". Please refer to the |
| 1065 | file ''doc/README.arm-relocation'' to see how to grab the relocation |
| 1066 | address. |
| 1067 | |
| 1068 | * Prior to relocation: |
| 1069 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1070 | .. prompt:: bash (gdb) |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1071 | |
| 1072 | symbol-file {path to elf file} |
| 1073 | |
| 1074 | * After relocation: |
| 1075 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1076 | .. prompt:: bash (gdb) |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1077 | |
| 1078 | # Drop old symbol file |
| 1079 | symbol-file |
| 1080 | # Pick up new relocaddr |
| 1081 | add-symbol-file {path to elf file} {relocaddr} |
| 1082 | |
| 1083 | .. k3_rst_include_end_openocd_cfg_external_gdb |
| 1084 | |
| 1085 | In the above example of AM625, |
| 1086 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1087 | .. prompt:: bash (gdb) |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1088 | |
| 1089 | target extended-remote localhost:3338 <- R5F (Wakeup Domain) |
| 1090 | target extended-remote localhost:3334 <- A53 (Main Domain) |
| 1091 | |
| 1092 | The core can now be debugged directly within GDB using GDB commands or |
| 1093 | if using IDE, as appropriate to the IDE. |
| 1094 | |
| 1095 | Stepping through the code |
| 1096 | """"""""""""""""""""""""" |
| 1097 | |
| 1098 | `GDB TUI Commands |
| 1099 | <https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html>`_ can |
| 1100 | help set up the display more sensible for debug. Provide the name |
| 1101 | of the layout that can be used to debug. For example, use the GDB |
| 1102 | command ``layout src`` after loading the symbols to see the code and |
| 1103 | breakpoints. To exit the debug loop added above, add any breakpoints |
| 1104 | needed and run the following GDB commands to step out of the debug |
| 1105 | loop set in the ``board_init_f`` function. |
| 1106 | |
Nishanth Menon | 740c41c | 2023-11-02 23:40:25 -0500 | [diff] [blame] | 1107 | .. prompt:: bash (gdb) |
Jason Kacines | b0fdee9 | 2023-08-03 01:29:22 -0500 | [diff] [blame] | 1108 | |
| 1109 | set x = 0 |
| 1110 | continue |
| 1111 | |
| 1112 | The platform has now been successfully setup to debug with OpenOCD |
| 1113 | using GDB commands or a GDB-based IDE. See `OpenOCD documentation for |
| 1114 | GDB <https://openocd.org/doc/html/GDB-and-OpenOCD.html>`_ for further |
| 1115 | information. |
| 1116 | |
| 1117 | .. warning:: |
| 1118 | |
| 1119 | On the K3 family of devices, a watchdog timer within the DMSC is |
| 1120 | enabled by default by the ROM bootcode with a timeout of 3 minutes. |
| 1121 | The watchdog timer is serviced by System Firmware (SYSFW) or TI |
| 1122 | Foundational Security (TIFS) during normal operation. If debugging |
| 1123 | the SPL before the SYSFW is loaded, the watchdog timer will not get |
| 1124 | serviced automatically and the debug session will reset after 3 |
| 1125 | minutes. It is recommended to start debugging SPL code only after |
| 1126 | the startup of SYSFW to avoid running into the watchdog timer reset. |
| 1127 | |
| 1128 | Miscellaneous notes with OpenOCD |
| 1129 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1130 | |
| 1131 | Currently, OpenOCD does not support tracing for K3 platforms. Tracing |
| 1132 | function could be beneficial if the bug in code occurs deep within |
| 1133 | nested function and can optionally save developers major trouble of |
| 1134 | stepping through a large quantity of code. |