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