blob: c3513f0aee20a2cc4275c7b146f22863f69f6a13 [file] [log] [blame]
Bryan Brattlof6d138132022-12-19 14:29:50 -06001.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2.. sectionauthor:: Bryan Brattlof <bb@ti.com>
3
4K3 Generation
5=============
6
7Summary
8-------
9
10Texas Instrument's K3 family of SoCs utilize a heterogeneous multicore
11and highly integrated device architecture targeted to maximize
12performance and power efficiency for a wide range of industrial,
13automotive and other broad market segments.
14
15Typically the processing cores and the peripherals for these devices are
16partitioned into three functional domains to provide ultra-low power
17modes as well as accommodating application and industrial safety systems
18on the same SoC. These functional domains are typically called the:
19
20* Wakeup (WKUP) domain
21* Micro-controller (MCU) domain
22* Main domain
23
24For a more detailed view of what peripherals are attached to each
25domain, consult the device specific documentation.
26
27K3 Based SoCs
28-------------
29
30.. toctree::
31 :maxdepth: 1
32
Jai Luthrae526653e2023-11-13 08:51:49 -060033 am62ax_sk
Bryan Brattlof6d138132022-12-19 14:29:50 -060034 am62x_sk
Nishanth Menon1f2b6f92023-11-04 03:01:36 -050035 ../beagle/am62x_beagleplay
Wadim Egorov12722a42023-12-20 10:18:11 +010036 ../phytec/phycore-am62x
Marcel Ziswiler315deb32023-08-04 12:08:08 +020037 ../toradex/verdin-am62
Bryan Brattlofcf2e2b12024-03-12 15:20:30 -050038 am62px_sk
Roger Quadroscd87b1e2023-08-05 11:14:39 +030039 am64x_evm
Neha Malcom Francis507be122023-07-22 00:14:43 +053040 am65x_evm
Nishanth Menone83fe672023-07-27 13:59:01 -050041 j7200_evm
Nishanth Menon756b8782023-11-04 03:11:03 -050042 ../beagle/j721e_beagleboneai64
Nishanth Menone83fe672023-07-27 13:59:01 -050043 j721e_evm
Manorit Chawdhry670a22b2023-10-06 10:16:00 +053044 j721s2_evm
Jayesh Choudhary5e547a72024-06-12 14:41:23 +053045 j722s_evm
Apurva Nandan2b1c9ff2024-02-24 01:51:53 +053046 j784s4_evm
Bryan Brattlof6d138132022-12-19 14:29:50 -060047
48Boot Flow Overview
49------------------
50
51For all K3 SoCs the first core started will be inside the Security
52Management Subsystem (SMS) which will secure the device and start a core
53in the wakeup domain to run the ROM code. ROM will then initialize the
54boot media needed to load the binaries packaged inside `tiboot3.bin`,
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050055including a 32bit U-Boot SPL, (called the wakeup SPL) that ROM will jump
Bryan Brattlof6d138132022-12-19 14:29:50 -060056to after it has finished loading everything into internal SRAM.
57
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050058.. image:: img/boot_flow_01.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050059 :alt: Boot flow up to wakeup domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060060
61The wakeup SPL, running on a wakeup domain core, will initialize DDR and
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050062any peripherals needed to load the larger binaries inside the `tispl.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -060063into DDR. Once loaded the wakeup SPL will start one of the 'big'
64application cores inside the main domain to initialize the main domain,
Neha Malcom Francis507be122023-07-22 00:14:43 +053065starting with Trusted Firmware-A (TF-A), before moving on to start
66OP-TEE and the main domain's U-Boot SPL.
Bryan Brattlof6d138132022-12-19 14:29:50 -060067
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050068.. image:: img/boot_flow_02.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050069 :alt: Boot flow up to main domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060070
71The main domain's SPL, running on a 64bit application core, has
72virtually unlimited space (billions of bytes now that DDR is working) to
73initialize even more peripherals needed to load in the `u-boot.img`
74which loads more firmware into the micro-controller & wakeup domains and
75finally prepare the main domain to run Linux.
76
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050077.. image:: img/boot_flow_03.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050078 :alt: Complete boot flow up to Linux
Bryan Brattlof6d138132022-12-19 14:29:50 -060079
80This is the typical boot flow for all K3 based SoCs, however this flow
81offers quite a lot in the terms of flexibility, especially on High
82Security (HS) SoCs.
83
84Boot Flow Variations
85^^^^^^^^^^^^^^^^^^^^
86
87All K3 SoCs will generally use the above boot flow with two main
88differences depending on the capabilities of the boot ROM and the number
89of cores inside the device. These differences split the bootflow into
90essentially 4 unique but very similar flows:
91
92* Split binary with a combined firmware: (eg: AM65)
93* Combined binary with a combined firmware: (eg: AM64)
94* Split binary with a split firmware: (eg: J721E)
95* Combined binary with a split firmware: (eg: AM62)
96
97For devices that utilize the split binary approach, ROM is not capable
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050098of loading the firmware into the SoC, requiring the wakeup domain's
Bryan Brattlof6d138132022-12-19 14:29:50 -060099U-Boot SPL to load the firmware.
100
101Devices with a split firmware will have two firmwares loaded into the
102device at different times during the bootup process. TI's Foundational
103Security (TIFS), needed to operate the Security Management Subsystem,
104will either be loaded by ROM or the WKUP U-Boot SPL, then once the
105wakeup U-Boot SPL has completed, the second Device Management (DM)
106firmware can be loaded on the now free core in the wakeup domain.
107
108For more information on the bootup process of your SoC, consult the
109device specific boot flow documentation.
110
Manorit Chawdhry98346472023-12-29 16:16:33 +0530111Secure Boot
112-----------
113
114K3 HS-SE (High Security - Security Enforced) devices enforce an
115authenticated boot flow for secure boot. HS-FS (High Security - Field
116Securable) is the state of a K3 device before it has been eFused with
117customer security keys. In the HS-FS state the authentication still can
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -0500118function as in HS-SE, but as there are no customer keys to verify the
119signatures against, the authentication will pass for certificates signed
Manorit Chawdhry98346472023-12-29 16:16:33 +0530120with any key.
121
122Chain of trust
123^^^^^^^^^^^^^^
124
1251) Public ROM loads the tiboot3.bin (R5 SPL, TIFS)
1262) R5 SPL loads tispl.bin (ATF, OP-TEE, DM, SPL)
1273) SPL loads u-boot.img (U-Boot)
1284) U-Boot loads fitImage (Linux and DTBs)
129
130Steps 1-3 are all authenticated by either the Secure ROM or TIFS as the
131authenticating entity and step 4 uses U-boot standard mechanism for
132authenticating.
133
134All the authentication that are done for ROM/TIFS are done through x509
135certificates that are signed.
136
137Firewalls
138^^^^^^^^^
139
1401) Secure ROM comes up and sets up firewalls that are needed by itself
1412) TIFS will setup it's own firewalls to protect core system resources
1423) R5 SPL will remove any firewalls that are leftover from the Secure ROM stage
143 that are no longer required.
1444) Each stage beyond this: such as tispl.bin containing TFA/OPTEE uses OIDs to
145 set up firewalls to protect themselves (enforced by TIFS)
1465) TFA/OP-TEE can configure other firewalls at runtime if required as they
147 are already authenticated and firewalled off from illegal access.
1486) All later stages can setup or remove firewalls that have not been already
149 configured by previous stages, such as those created by TIFS, TFA, and OP-TEE.
150
151Futhur, firewalls have a lockdown bit in hardware that enforces the setting
152(and cannot be over-ridden) until the full system is reset.
153
Bryan Brattlof6d138132022-12-19 14:29:50 -0600154Software Sources
155----------------
156
157All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and
158`u-boot.img` for all K3 SoCs can be located at the following places
159online
160
Nishanth Menonee91e482023-07-27 13:58:44 -0500161.. k3_rst_include_start_boot_sources
162
Bryan Brattlof6d138132022-12-19 14:29:50 -0600163* **Das U-Boot**
164
165 | **source:** https://source.denx.de/u-boot/u-boot.git
166 | **branch:** master
167
Neha Malcom Francis507be122023-07-22 00:14:43 +0530168* **Trusted Firmware-A (TF-A)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600169
Neha Malcom Francis507be122023-07-22 00:14:43 +0530170 | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Bryan Brattlof6d138132022-12-19 14:29:50 -0600171 | **branch:** master
172
Neha Malcom Francis507be122023-07-22 00:14:43 +0530173* **Open Portable Trusted Execution Environment (OP-TEE)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600174
175 | **source:** https://github.com/OP-TEE/optee_os.git
176 | **branch:** master
177
Nishanth Menone2a47452023-08-22 11:41:07 -0500178* **TI Firmware (TIFS, DM, SYSFW)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600179
180 | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git
181 | **branch:** ti-linux-firmware
182
Nishanth Menone2a47452023-08-22 11:41:07 -0500183.. note::
184
Dhruva Gole4a395e92024-08-05 19:59:32 +0530185 The TI Firmwares required for functionality of the system are (see
186 platform specific boot diagram for further information as to which
187 component runs on which processor):
Nishanth Menone2a47452023-08-22 11:41:07 -0500188
Dhruva Gole4a395e92024-08-05 19:59:32 +0530189.. k3_rst_include_end_boot_sources
Nishanth Menone2a47452023-08-22 11:41:07 -0500190
Dhruva Gole4a395e92024-08-05 19:59:32 +0530191.. k3_rst_include_start_boot_firmwares
Nishanth Menone2a47452023-08-22 11:41:07 -0500192
Dhruva Gole4a395e92024-08-05 19:59:32 +0530193* **TIFS** - TI Foundational Security Firmware - Consists of purely firmware
194 meant to run on the security enclave.
195* **DM** - Device Management firmware also called TI System Control Interface
196 server (TISCI Server) - This component purely plays the role of managing
197 device resources such as power, clock, interrupts, dma etc. This firmware
198 runs on a dedicated or multi-use microcontroller outside the security
199 enclave.
Nishanth Menone2a47452023-08-22 11:41:07 -0500200
Dhruva Gole4a395e92024-08-05 19:59:32 +0530201.. k3_rst_include_end_boot_firmwares
202.. k3_rst_include_start_tifsstub
203
204* **TIFS Stub** - The TIFS stub is a small piece of binary designed to help
205 restore the required security context and resume the TIFS firmware when
206 the system resumes from low-power modes such as suspend-to-RAM/Deep
207 Sleep. This stub uses the same encryption and customer key signing model
208 as TIFS and is loaded into the ATCM (Tightly Coupled Memory 'A' of the
209 DM R5) during DM startup. Due to the independent certificate signing
210 process, the stub is maintained separately from DM.
211
212.. k3_rst_include_end_tifsstub
213
214OR
215
216.. k3_rst_include_start_boot_firmwares_sysfw
217
218* **SYSFW** - System firmware - consists of both TIFS and DM both running on
219 the security enclave.
220
221.. k3_rst_include_end_boot_firmwares_sysfw
Nishanth Menonee91e482023-07-27 13:58:44 -0500222
Bryan Brattlof6d138132022-12-19 14:29:50 -0600223Build Procedure
224---------------
225
Jonathan Humphreys43d44fa2024-06-21 15:17:06 -0500226.. note ::
227
228 Make sure you have installed all necessary host package dependencies
229 before proceeding. See :ref:`build/gcc:Building with GCC`.
230
Bryan Brattlof6d138132022-12-19 14:29:50 -0600231Depending on the specifics of your device, you will need three or more
232binaries to boot your SoC.
233
234* `tiboot3.bin` (bootloader for the wakeup domain)
235* `tispl.bin` (bootloader for the main domain)
236* `u-boot.img`
237
238During the bootup process, both the 32bit wakeup domain and the 64bit
239main domains will be involved. This means everything inside the
240`tiboot3.bin` running in the wakeup domain will need to be compiled for
24132bit cores and most binaries in the `tispl.bin` will need to be
242compiled for 64bit main domain CPU cores.
243
244All of that to say you will need both a 32bit and 64bit cross compiler
245(assuming you're using an x86 desktop)
246
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500247.. k3_rst_include_start_common_env_vars_desc
248.. list-table:: Generic environment variables
249 :widths: 25 25 50
250 :header-rows: 1
251
252 * - S/w Component
253 - Env Variable
254 - Description
255 * - All Software
256 - CC32
257 - Cross compiler for ARMv7 (ARM 32bit), typically arm-linux-gnueabihf-
258 * - All Software
259 - CC64
260 - Cross compiler for ARMv8 (ARM 64bit), typically aarch64-linux-gnu-
261 * - All Software
262 - LNX_FW_PATH
263 - Path to TI Linux firmware repository
264 * - All Software
265 - TFA_PATH
266 - Path to source of Trusted Firmware-A
267 * - All Software
268 - OPTEE_PATH
269 - Path to source of OP-TEE
270.. k3_rst_include_end_common_env_vars_desc
271
272.. k3_rst_include_start_common_env_vars_defn
Nishanth Menon740c41c2023-11-02 23:40:25 -0500273.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600274
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500275 export CC32=arm-linux-gnueabihf-
276 export CC64=aarch64-linux-gnu-
277 export LNX_FW_PATH=path/to/ti-linux-firmware
278 export TFA_PATH=path/to/trusted-firmware-a
279 export OPTEE_PATH=path/to/optee_os
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500280.. k3_rst_include_end_common_env_vars_defn
281
282We will also need some common environment variables set up for the various
283other build sources. we shall use the following, in the build descriptions below:
284
285.. k3_rst_include_start_board_env_vars_desc
286.. list-table:: Board specific environment variables
287 :widths: 25 25 50
288 :header-rows: 1
289
290 * - S/w Component
291 - Env Variable
292 - Description
293 * - U-Boot
294 - UBOOT_CFG_CORTEXR
295 - Defconfig for Cortex-R (Boot processor).
296 * - U-Boot
297 - UBOOT_CFG_CORTEXA
298 - Defconfig for Cortex-A (MPU processor).
299 * - Trusted Firmware-A
300 - TFA_BOARD
301 - Platform name used for building TF-A for Cortex-A Processor.
302 * - Trusted Firmware-A
303 - TFA_EXTRA_ARGS
304 - Any extra arguments used for building TF-A.
305 * - OP-TEE
306 - OPTEE_PLATFORM
307 - Platform name used for building OP-TEE for Cortex-A Processor.
308 * - OP-TEE
309 - OPTEE_EXTRA_ARGS
310 - Any extra arguments used for building OP-TEE.
311.. k3_rst_include_end_board_env_vars_desc
Bryan Brattlof6d138132022-12-19 14:29:50 -0600312
313Building tiboot3.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200314^^^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600315
3161. To generate the U-Boot SPL for the wakeup domain, use the following
317 commands, substituting :code:`{SOC}` for the name of your device (eg:
Neha Malcom Francis507be122023-07-22 00:14:43 +0530318 am62x) to package the various firmware and the wakeup UBoot SPL into
319 the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device
320 uses the split binary flow)
Bryan Brattlof6d138132022-12-19 14:29:50 -0600321
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530322.. _k3_rst_include_start_build_steps_spl_r5:
323
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500324.. k3_rst_include_start_build_steps_spl_r5
Nishanth Menon740c41c2023-11-02 23:40:25 -0500325.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600326
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500327 # inside u-boot source
328 make $UBOOT_CFG_CORTEXR
329 make CROSS_COMPILE=$CC32 BINMAN_INDIRS=$LNX_FW_PATH
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500330.. k3_rst_include_end_build_steps_spl_r5
Bryan Brattlof6d138132022-12-19 14:29:50 -0600331
332At this point you should have all the needed binaries to boot the wakeup
333domain of your K3 SoC.
334
335**Combined Binary Boot Flow** (eg: am62x, am64x, ... )
336
Neha Malcom Francis507be122023-07-22 00:14:43 +0530337 `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600338
339**Split Binary Boot Flow** (eg: j721e, am65x)
340
Neha Malcom Francis507be122023-07-22 00:14:43 +0530341 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
342 | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600343
344.. note ::
345
346 It's important to rename the generated `tiboot3.bin` and `sysfw.itb`
347 to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup
348 UBoot SPL will only look for and load the files with these names.
349
350Building tispl.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200351^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600352
353The `tispl.bin` is a standard fitImage combining the firmware need for
354the main domain to function properly as well as Device Management (DM)
355firmware if your device using a split firmware.
356
Neha Malcom Francis507be122023-07-22 00:14:43 +05303572. We will first need TF-A, as it's the first thing to run on the 'big'
Bryan Brattlof6d138132022-12-19 14:29:50 -0600358 application cores on the main domain.
359
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500360.. k3_rst_include_start_build_steps_tfa
Nishanth Menon740c41c2023-11-02 23:40:25 -0500361.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600362
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500363 # inside trusted-firmware-a source
364 make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS \
365 TARGET_BOARD=$TFA_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500366.. k3_rst_include_end_build_steps_tfa
Bryan Brattlof6d138132022-12-19 14:29:50 -0600367
Neha Malcom Francis507be122023-07-22 00:14:43 +0530368Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500369=j784s4` (if it is a J784S4 device), while typical Sitara (`am6*`) devices
Neha Malcom Francis507be122023-07-22 00:14:43 +0530370use the `lite` option.
Bryan Brattlof6d138132022-12-19 14:29:50 -0600371
Neha Malcom Francis507be122023-07-22 00:14:43 +05303723. The Open Portable Trusted Execution Environment (OP-TEE) is designed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600373 to run as a companion to a non-secure Linux kernel for Cortex-A cores
374 using the TrustZone technology built into the core.
375
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500376.. k3_rst_include_start_build_steps_optee
Nishanth Menon740c41c2023-11-02 23:40:25 -0500377.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600378
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500379 # inside optee_os source
380 make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 CFG_ARM64_core=y $OPTEE_EXTRA_ARGS \
381 PLATFORM=$OPTEE_PLATFORM
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500382.. k3_rst_include_end_build_steps_optee
Bryan Brattlof6d138132022-12-19 14:29:50 -0600383
Neha Malcom Francis507be122023-07-22 00:14:43 +05303844. Finally, after TF-A has initialized the main domain and OP-TEE has
Bryan Brattlof6d138132022-12-19 14:29:50 -0600385 finished, we can jump back into U-Boot again, this time running on a
386 64bit core in the main domain.
387
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530388.. _k3_rst_include_start_build_steps_uboot:
389
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500390.. k3_rst_include_start_build_steps_uboot
Nishanth Menon740c41c2023-11-02 23:40:25 -0500391.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600392
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500393 # inside u-boot source
394 make $UBOOT_CFG_CORTEXA
395 make CROSS_COMPILE=$CC64 BINMAN_INDIRS=$LNX_FW_PATH \
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500396 BL31=$TFA_PATH/build/k3/$TFA_BOARD/release/bl31.bin \
397 TEE=$OPTEE_PATH/out/arm-plat-k3/core/tee-raw.bin
Neha Malcom Francis2b259f02023-12-05 15:12:20 +0530398
399.. note::
400 It is also possible to pick up a custom DM binary by adding TI_DM argument
401 pointing to the file. If not provided, it defaults to picking up the DM
402 binary from BINMAN_INDIRS. This is only applicable to devices that utilize
403 split firmware.
404
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500405.. k3_rst_include_end_build_steps_uboot
Bryan Brattlof6d138132022-12-19 14:29:50 -0600406
407At this point you should have every binary needed initialize both the
408wakeup and main domain and to boot to the U-Boot prompt
409
410**Main Domain Bootloader**
411
Neha Malcom Francis507be122023-07-22 00:14:43 +0530412 | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices
413 | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530414
Jonathan Humphreys43d44fa2024-06-21 15:17:06 -0500415Capsules
416--------
417
418Most K3 boards have support for UEFI capsule update via capsule-on-disk
419functionality. Check the ``CONFIG_EFI_CAPSULE_ON_DISK`` config option for
420the board under question to verify. If configured, capsules for each of the
421binaries above are automatically generated as part of the binary's build.
422They are named `<binary>-capsule.bin`. For example, the capsule for
423`u-boot.img` would be called `uboot-capsule.bin`.
424
425See :ref:`uefi_capsule_update_ref` for more information on U-Boot's support
426for capsule update and how they are applied.
427
428Each board defines the capsules generated, including where those capsules
429are applied. See the ``update_info`` definition for a board, typically
430found at `board/ti/<board>/evm.c`. For example, `board/ti/am62x/evm.c`.
431Usually, if the board has OSPI flash, the capsules will be applied there,
432else the boot partition of the eMMC device.
433
434Once applied, the board will have U-Boot binaries in on-board non-volatile
435storage. To start booting from that storage, set the bootmode pins
436accordingly. Future updates can be performed by using the capsules
437generated from the corresponding U-Boot builds.
438
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530439FIT signature signing
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530440---------------------
441
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530442K3 platforms have FIT signature signing enabled by default on their primary
443platforms. Here we'll take an example for creating FIT Image for J721E platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530444and the same can be extended to other platforms
445
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530446Pre-requisites:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530447
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530448* U-boot build (:ref:`U-boot build <k3_rst_include_start_build_steps_spl_r5>`)
449* Linux Image and Linux DTB prebuilt
450
451Describing FIT source
452^^^^^^^^^^^^^^^^^^^^^
453
454FIT Image is a packed structure containing binary blobs and configurations.
455The Kernel FIT Image that we have has Kernel Image, DTB and the DTBOs. It
456supports packing multiple images and configurations that allow you to
457choose any configuration at runtime to boot from.
458
459.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530460
461 /dts-v1/;
462
463 / {
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530464 description = "FIT Image description";
465 #address-cells = <1>;
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530466
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530467 images {
468 [image-1]
469 [image-2]
470 [fdt-1]
471 [fdt-2]
472 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530473
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530474 configurations {
475 default = <conf-1>
476 [conf-1: image-1,fdt-1]
477 [conf-2: image-2,fdt-1]
478 }
479 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530480
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530481* Sample Images
482
483.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530484
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530485 kernel-1 {
486 description = "Linux kernel";
487 data = /incbin/("linux.bin");
488 type = "kernel";
489 arch = "arm64";
490 os = "linux";
491 compression = "gzip";
492 load = <0x81000000>;
493 entry = <0x81000000>;
494 hash-1 {
495 algo = "sha512";
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530496 };
497 };
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530498 fdt-ti_k3-j721e-common-proc-board.dtb {
499 description = "Flattened Device Tree blob";
500 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dtb");
501 type = "flat_dt";
502 arch = "arm64";
503 compression = "none";
504 load = <0x83000000>;
505 hash-1 {
506 algo = "sha512";
507 };
508 };
509 # Optional images
510 fdt-ti_k3-j721e-evm-virt-mac-client.dtbo {
511 description = "Flattened Device Tree blob";
512 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-evm-virt-mac-client.dtbo");
513 type = "flat_dt";
514 arch = "arm64";
515 compression = "none";
516 load = <0x83080000>;
517 hash-1 {
518 algo = "sha512";
519 };
520 };
521
522.. note::
523
524 Change the path in data variables to point to the respective files in your
525 local machine. For e.g change "linux.bin" to "<path-to-kernel-image>".
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530526
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530527For enabling usage of FIT signature, add the signature node to the
528corresponding configuration node as follows.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530529
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530530* Sample Configurations
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530531
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530532.. code-block::
533
534 conf-ti_k3-j721e-common-proc-board.dtb {
535 description = "Linux kernel, FDT blob";
536 fdt = "fdt-ti_k3-j721e-common-proc-board.dtb";
537 kernel = "kernel-1";
538 signature-1 {
539 algo = "sha512,rsa4096";
540 key-name-hint = "custMpk";
541 sign-images = "kernel", "fdt";
542 };
543 };
544 # Optional configurations
545 conf-ti_k3-j721e-evm-virt-mac-client.dtbo {
546 description = "FDTO blob";
547 fdt = "fdt-ti_k3-j721e-evm-virt-mac-client.dtbo";
548
549 signature-1 {
550 algo = "sha512,rsa4096";
551 key-name-hint = "custMpk";
552 sign-images = "fdt";
553 };
554 };
555
556Specify all images you need the signature to authenticate as a part of
557sign-images. The key-name-hint needs to be changed if you are using some
558other key other than the TI dummy key that we are using for this example.
559It should be the name of the file containing the keys.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530560
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500561.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530562
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530563 Generating new set of keys:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530564
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530565 .. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530566
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530567 mkdir keys
568 openssl genpkey -algorithm RSA -out keys/dev.key \
569 -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:65537
570 openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530571
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530572Generating the fitImage
573^^^^^^^^^^^^^^^^^^^^^^^
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530574
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530575.. note::
576
577 For signing a secondary platform like SK boards, you'll require
578 additional steps
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530579
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530580 - Change the CONFIG_DEFAULT_DEVICE_TREE
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530581
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530582 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530583
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530584 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530585
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530586 diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig
587 index a5c1df7e0054..6d0126d955ef 100644
588 --- a/configs/j721e_evm_a72_defconfig
589 +++ b/configs/j721e_evm_a72_defconfig
590 @@ -13,7 +13,7 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80480000
591 CONFIG_ENV_SIZE=0x20000
592 CONFIG_DM_GPIO=y
593 CONFIG_SPL_DM_SPI=y
594 -CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
595 +CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-sk"
596 CONFIG_SPL_TEXT_BASE=0x80080000
597 CONFIG_DM_RESET=y
598 CONFIG_SPL_MMC=y
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530599
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530600 - Change the binman nodes to package u-boot.dtb for the correct set of platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530601
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530602 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530603
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530604 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530605
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530606 diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi
607 index 673be646b1e3..752fa805fe8d 100644
608 --- a/arch/arm/dts/k3-j721e-binman.dtsi
609 +++ b/arch/arm/dts/k3-j721e-binman.dtsi
610 @@ -299,8 +299,8 @@
611 #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530612
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530613 #define UBOOT_NODTB "u-boot-nodtb.bin"
614 -#define J721E_EVM_DTB "u-boot.dtb"
615 -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb"
616 +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb"
617 +#define J721E_SK_DTB "u-boot.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530618
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530619This step will embed the public key in the u-boot.dtb file that was already
620built during the initial u-boot build.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530621
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530622.. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530623
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530624 mkimage -r -f fitImage.its -k $UBOOT_PATH/board/ti/keys -K $UBOOT_PATH/build/$ARMV8/dts/dt.dtb fitImage
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530625
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530626.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530627
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530628 If you have another set of keys then change the -k argument to point to
629 the folder where your keys are present, the build requires the presence
630 of both .key and .crt file.
631
632Build u-boot again
633^^^^^^^^^^^^^^^^^^
634
635The updated u-boot.dtb needs to be packed in u-boot.img for authentication
636so rebuild U-boot ARMV8 without changing any parameters.
637Refer (:ref:`U-boot ARMV8 build <k3_rst_include_start_build_steps_uboot>`)
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530638
639.. note::
640
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530641 The devices now also have distroboot enabled so if the FIT image doesn't
642 work then the fallback to normal distroboot will be there on HS devices.
643 This will need to be explicitly disabled by changing the boot_targets to
644 disallow fallback during testing.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530645
646Saving environment
647------------------
648
649SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default
650way for saving the environments. This has been done as Uenv.txt is more granular
651then the saveenv command and can be used across various bootmodes too.
652
653**Writing to MMC/EMMC**
654
Nishanth Menon740c41c2023-11-02 23:40:25 -0500655.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530656
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500657 env export -t $loadaddr <list of variables>
658 fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize}
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530659
660**Reading from MMC/EMMC**
661
662By default run envboot will read it from the MMC/EMMC partition ( based on
663mmcdev) and set the environments.
664
665If manually needs to be done then the environment can be read from the
666filesystem and then imported
667
Nishanth Menon740c41c2023-11-02 23:40:25 -0500668.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530669
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500670 fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile}
671 env import -t ${loadaddr} ${filesize}
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500672
673.. _k3_rst_refer_openocd:
674
675Common Debugging environment - OpenOCD
676--------------------------------------
677
678This section will show you how to connect a board to `OpenOCD
679<https://openocd.org/>`_ and load the SPL symbols for debugging with
680a K3 generation device. To follow this guide, you must build custom
681u-boot binaries, start your board from a boot media such as an SD
682card, and use an OpenOCD environment. This section uses generic
683examples, though you can apply these instructions to any supported K3
684generation device.
685
686The overall structure of this setup is in the following figure.
687
688.. image:: img/openocd-overview.svg
Nishanth Menon5746e032023-08-22 11:40:56 -0500689 :alt: Overview of OpenOCD setup.
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500690
691.. note::
692
693 If you find these instructions useful, please consider `donating
694 <https://openocd.org/pages/donations.html>`_ to OpenOCD.
695
696Step 1: Download and install OpenOCD
697^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
698
699To get started, it is more convenient if the distribution you
700use supports OpenOCD by default. Follow the instructions in the
701`getting OpenOCD <https://openocd.org/pages/getting-openocd.html>`_
702documentation to pick the installation steps appropriate to your
703environment. Some references to OpenOCD documentation:
704
705* `OpenOCD User Guide <https://openocd.org/doc/html/index.html>`_
706* `OpenOCD Developer's Guide <https://openocd.org/doc/doxygen/html/index.html>`_
707
708Refer to the release notes corresponding to the `OpenOCD version
709<https://github.com/openocd-org/openocd/releases>`_ to ensure
710
711* Processor support: In general, processor support shouldn't present
712 any difficulties since OpenOCD provides solid support for both ARMv8
713 and ARMv7.
714* SoC support: When working with System-on-a-Chip (SoC), the support
715 usually comes as a TCL config file. It is vital to ensure the correct
716 version of OpenOCD or to use the TCL files from the latest release or
717 the one mentioned.
718* Board or the JTAG adapter support: In most cases, board support is
719 a relatively easy problem if the board has a JTAG pin header. All
720 you need to do is ensure that the adapter you select is compatible
721 with OpenOCD. Some boards come with an onboard JTAG adapter that
722 requires a USB cable to be plugged into the board, in which case, it
723 is vital to ensure that the JTAG adapter is supported. Fortunately,
724 almost all TI K3 SK/EVMs come with TI's XDS110, which has out of the
725 box support by OpenOCD. The board-specific documentation will
726 cover the details and any adapter/dongle recommendations.
727
Nishanth Menon740c41c2023-11-02 23:40:25 -0500728.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500729
730 openocd -v
731
732.. note::
733
734 OpenOCD version 0.12.0 is usually required to connect to most K3
735 devices. If your device is only supported by a newer version than the
736 one provided by your distribution, you may need to build it from the source.
737
738Building OpenOCD from source
739""""""""""""""""""""""""""""
740
741The dependency package installation instructions below are for Debian
742systems, but equivalent instructions should exist for systems with
743other package managers. Please refer to the `OpenOCD Documentation
744<https://openocd.org/>`_ for more recent installation steps.
745
Nishanth Menon740c41c2023-11-02 23:40:25 -0500746.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500747
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500748 # Check the packages to be installed: needs deb-src in sources.list
749 sudo apt build-dep openocd
750 # The following list is NOT complete - please check the latest
751 sudo apt-get install libtool pkg-config texinfo libusb-dev \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500752 libusb-1.0.0-dev libftdi-dev libhidapi-dev autoconf automake
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500753 git clone https://github.com/openocd-org/openocd.git openocd
754 cd openocd
755 git submodule init
756 git submodule update
757 ./bootstrap
758 ./configure --prefix=/usr/local/
759 make -j`nproc`
760 sudo make install
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500761
762.. note::
763
764 The example above uses the GitHub mirror site. See
765 `git repo information <https://openocd.org/doc/html/Developers.html#OpenOCD-Git-Repository>`_
766 information to pick the official git repo.
767 If a specific version is desired, select the version using `git checkout tag`.
768
769Installing OpenOCD udev rules
770"""""""""""""""""""""""""""""
771
772The step is not necessary if the distribution supports the OpenOCD, but
773if building from a source, ensure that the udev rules are installed
774correctly to ensure a sane system.
775
Nishanth Menon740c41c2023-11-02 23:40:25 -0500776.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500777
778 # Go to the OpenOCD source directory
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500779 cd openocd
780 Copy the udev rules to the correct system location
781 sudo cp ./contrib/60-openocd.rules \
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500782 ./src/jtag/drivers/libjaylink/contrib/99-libjaylink.rules \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500783 /etc/udev/rules.d/
784 # Get Udev to load the new rules up
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500785 sudo udevadm control --reload-rules
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500786 # Use the new rules on existing connected devices
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500787 sudo udevadm trigger
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500788
789Step 2: Setup GDB
790^^^^^^^^^^^^^^^^^
791
792Most systems come with gdb-multiarch package.
793
Nishanth Menon740c41c2023-11-02 23:40:25 -0500794.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500795
796 # Install gdb-multiarch package
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500797 sudo apt-get install gdb-multiarch
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500798
799Though using GDB natively is normal, developers with interest in using IDE
800may find a few of these interesting:
801
802* `gdb-dashboard <https://github.com/cyrus-and/gdb-dashboard>`_
803* `gef <https://github.com/hugsy/gef>`_
804* `peda <https://github.com/longld/peda>`_
805* `pwndbg <https://github.com/pwndbg/pwndbg>`_
806* `voltron <https://github.com/snare/voltron>`_
807* `ddd <https://www.gnu.org/software/ddd/>`_
808* `vscode <https://www.justinmklam.com/posts/2017/10/vscode-debugger-setup/>`_
809* `vim conque-gdb <https://github.com/vim-scripts/Conque-GDB>`_
810* `emacs realgud <https://github.com/realgud/realgud/wiki/gdb-notes>`_
811* `Lauterbach IDE <https://www2.lauterbach.com/pdf/backend_gdb.pdf>`_
812
813.. warning::
814 LLDB support for OpenOCD is still a work in progress as of this writing.
815 Using GDB is probably the safest option at this point in time.
816
817Step 3: Connect board to PC
818^^^^^^^^^^^^^^^^^^^^^^^^^^^
819There are few patterns of boards in the ecosystem
820
821.. k3_rst_include_start_openocd_connect_XDS110
822
823**Integrated JTAG adapter/dongle**: The board has a micro-USB connector labelled
824XDS110 USB or JTAG. Connect a USB cable to the board to the mentioned port.
825
826.. note::
827
828 There are multiple USB ports on a typical board, So, ensure you have read
829 the user guide for the board and confirmed the silk screen label to ensure
830 connecting to the correct port.
831
832.. k3_rst_include_end_openocd_connect_XDS110
833
834.. k3_rst_include_start_openocd_connect_cti20
835
836**cTI20 connector**: The TI's `cTI20
837<https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_JTAG_connectors.html#cti-20-pin-header-information>`_ connector
838is probably the most prevelant on TI platforms. Though many
839TI boards have an onboard XDS110, cTI20 connector is usually
840provided as an alternate scheme to connect alternatives such
841as `Lauterbach <https://www.lauterbach.com/>`_ or `XDS560
842<https://www.ti.com/tool/TMDSEMU560V2STM-U>`_.
843
844To debug on these boards, the following combinations is suggested:
845
846* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
847 or `equivalent dongles supported by OpenOCD. <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_
848* Cable such as `Tag-connect ribbon cable <https://www.tag-connect.com/product/20-pin-cortex-ribbon-cable-4-length-with-50-mil-connectors>`_
849* Adapter to convert cTI20 to ARM20 such as those from
850 `Segger <https://www.segger.com/products/debug-probes/j-link/accessories/adapters/ti-cti-20-adapter/>`_
851 or `Lauterbach LA-3780 <https://www.lauterbach.com/ad3780.html>`_
852 Or optionally, if you have manufacturing capability then you could try
853 `BeagleBone JTAG Adapter <https://github.com/mmorawiec/BeagleBone-Black-JTAG-Adapters>`_
854
855.. warning::
856 XDS560 and Lauterbach are proprietary solutions and is not supported by
857 OpenOCD.
858 When purchasing an off the shelf adapter/dongle, you do want to be careful
859 about the signalling though. Please
860 `read for additional info <https://software-dl.ti.com/ccs/esd/xdsdebugprobes/emu_JTAG_connectors.html>`_.
861
862.. k3_rst_include_end_openocd_connect_cti20
863
864.. k3_rst_include_start_openocd_connect_tag_connect
865
866**Tag-Connect**: `Tag-Connect <https://www.tag-connect.com/>`_
867pads on the boards which require special cable. Please check the documentation
868to `identify <https://www.tag-connect.com/info/legs-or-no-legs>`_ if "legged"
869or "no-leg" version of the cable is appropriate for the board.
870
871To debug on these boards, you will need:
872
873* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
874 or `equivalent dongles supported by OpenOCD <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_.
875* Tag-Connect cable appropriate to the board such as
876 `TC2050-IDC-NL <https://www.tag-connect.com/product/TC2050-IDC-NL-10-pin-no-legs-cable-with-ribbon-connector>`_
877* In case of no-leg, version, a
878 `retaining clip <https://www.tag-connect.com/product/tc2050-clip-3pack-retaining-clip>`_
879* Tag-Connect to ARM20
880 `adapter <https://www.tag-connect.com/product/tc2050-arm2010-arm-20-pin-to-tc2050-adapter>`_
881
882.. note::
883 You can optionally use a 3d printed solution such as
884 `Protective cap <https://www.thingiverse.com/thing:3025584>`_ or
885 `clip <https://www.thingiverse.com/thing:3035278>`_ to replace
886 the retaining clip.
887
888.. warning::
889 With the Tag-Connect to ARM20 adapter, Please solder the "Trst" signal for
890 connection to work.
891
892.. k3_rst_include_end_openocd_connect_tag_connect
893
894Debugging with OpenOCD
895^^^^^^^^^^^^^^^^^^^^^^
896
897Debugging U-Boot is different from debugging regular user space
898applications. The bootloader initialization process involves many boot
899media and hardware configuration operations. For K3 devices, there
900are also interactions with security firmware. While reloading the
901"elf" file works through GDB, developers must be mindful of cascading
902initialization's potential consequences.
903
904Consider the following code change:
905
906.. code-block:: diff
907
908 --- a/file.c 2023-07-29 10:55:29.647928811 -0500
909 +++ b/file.c 2023-07-29 10:55:46.091856816 -0500
910 @@ -1,3 +1,3 @@
911 val = readl(reg);
912 -val |= 0x2;
913 +val |= 0x1;
914 writel(val, reg);
915
916Re-running the elf file with the above change will result in the
917register setting 0x3 instead of the intended 0x1. There are other
918hardware blocks which may not behave very well with a re-initialization
919without proper shutdown.
920
921To help narrow the debug down, it is usually simpler to use the
922standard boot media to get to the bootloader and debug only in the area
923of interest.
924
925In general, to debug u-boot spl/u-boot with OpenOCD there are three steps:
926
927* Modify the code adding a loop to allow the debugger to attach
928 near the point of interest. Boot up normally to stop at the loop.
929* Connect with OpenOCD and step out of the loop.
930* Step through the code to find the root of issue.
931
932Typical debugging involves a few iterations of the above sequence.
933Though most bootloader developers like to use printf to debug,
934debug with JTAG tends to be most efficient since it is possible to
935investigate the code flow and inspect hardware registers without
936repeated iterations.
937
938Code modification
939"""""""""""""""""
940
941* **start.S**: Adding an infinite while loop at the very entry of
942 U-Boot. For this, look for the corresponding start.S entry file.
943 This is usually only required when debugging some core SoC or
944 processor related function. For example: arch/arm/cpu/armv8/start.S or
945 arch/arm/cpu/armv7/start.S
946
947.. code-block:: diff
948
949 diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
950 index 69e281b086..744929e825 100644
951 --- a/arch/arm/cpu/armv7/start.S
952 +++ b/arch/arm/cpu/armv7/start.S
953 @@ -37,6 +37,8 @@
954 #endif
955
956 reset:
957 +dead_loop:
958 + b dead_loop
959 /* Allow the board to save important registers */
960 b save_boot_params
961 save_boot_params_ret:
962
963* **board_init_f**: Adding an infinite while loop at the board entry
964 function. In many cases, it is important to debug the boot process if
965 any changes are made for board-specific applications. Below is a step
966 by step process for debugging the boot SPL or Armv8 SPL:
967
968 To debug the boot process in either domain, we will first
969 add a modification to the code we would like to debug.
970 In this example, we will debug ``board_init_f`` inside
971 ``arch/arm/mach-k3/{soc}_init.c``. Since some sections of U-Boot
972 will be executed multiple times during the bootup process of K3
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500973 devices, we will need to include either ``CONFIG_ARM64`` or
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500974 ``CONFIG_CPU_V7R`` to catch the CPU at the desired place during the
975 bootup process (Main or Wakeup domains). For example, modify the
976 file as follows (depending on need):
977
978.. code-block:: c
979
980 void board_init_f(ulong dummy)
981 {
982 .
983 .
984 /* Code to run on the R5F (Wakeup/Boot Domain) */
985 if (IS_ENABLED(CONFIG_CPU_V7R)) {
986 volatile int x = 1;
987 while(x) {};
988 }
989 ...
990 /* Code to run on the ARMV8 (Main Domain) */
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500991 if (IS_ENABLED(CONFIG_ARM64)) {
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500992 volatile int x = 1;
993 while(x) {};
994 }
995 .
996 .
997 }
998
999Connecting with OpenOCD for a debug session
1000"""""""""""""""""""""""""""""""""""""""""""
1001
1002Startup OpenOCD to debug the platform as follows:
1003
1004* **Integrated JTAG interface**: If the evm has a debugger such as
1005 XDS110 inbuilt, there is typically an evm board support added and a
1006 cfg file will be available.
1007
1008.. k3_rst_include_start_openocd_cfg_XDS110
1009
Nishanth Menon740c41c2023-11-02 23:40:25 -05001010.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001011
1012 openocd -f board/{board_of_choice}.cfg
1013
1014.. k3_rst_include_end_openocd_cfg_XDS110
1015
1016.. k3_rst_include_start_openocd_cfg_external_intro
1017
1018* **External JTAG adapter/interface**: In other cases, where an
1019 adapter/dongle is used, a simple cfg file can be created to integrate the
1020 SoC and adapter information. See `supported TI K3 SoCs
1021 <https://github.com/openocd-org/openocd/blob/master/tcl/target/ti_k3.cfg#L59>`_
1022 to decide if the SoC is supported or not.
1023
Nishanth Menon740c41c2023-11-02 23:40:25 -05001024.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001025
1026 openocd -f openocd_connect.cfg
1027
1028.. k3_rst_include_end_openocd_cfg_external_intro
1029
1030 For example, with BeaglePlay (AM62X platform), the openocd_connect.cfg:
1031
1032.. code-block:: tcl
1033
1034 # TUMPA example:
1035 # http://www.tiaowiki.com/w/TIAO_USB_Multi_Protocol_Adapter_User's_Manual
1036 source [find interface/ftdi/tumpa.cfg]
1037
1038 transport select jtag
1039
1040 # default JTAG configuration has only SRST and no TRST
1041 reset_config srst_only srst_push_pull
1042
1043 # delay after SRST goes inactive
1044 adapter srst delay 20
1045
1046 if { ![info exists SOC] } {
1047 # Set the SoC of interest
1048 set SOC am625
1049 }
1050
1051 source [find target/ti_k3.cfg]
1052
1053 ftdi tdo_sample_edge falling
1054
1055 # Speeds for FT2232H are in multiples of 2, and 32MHz is tops
1056 # max speed we seem to achieve is ~20MHz.. so we pick 16MHz
1057 adapter speed 16000
1058
1059Below is an example of the output of this command:
1060
1061.. code-block:: console
1062
1063 Info : Listening on port 6666 for tcl connections
1064 Info : Listening on port 4444 for telnet connections
1065 Info : XDS110: connected
1066 Info : XDS110: vid/pid = 0451/bef3
1067 Info : XDS110: firmware version = 3.0.0.20
1068 Info : XDS110: hardware version = 0x002f
1069 Info : XDS110: connected to target via JTAG
1070 Info : XDS110: TCK set to 2500 kHz
1071 Info : clock speed 2500 kHz
1072 Info : JTAG tap: am625.cpu tap/device found: 0x0bb7e02f (mfg: 0x017 (Texas Instruments), part: 0xbb7e, ver: 0x0)
1073 Info : starting gdb server for am625.cpu.sysctrl on 3333
1074 Info : Listening on port 3333 for gdb connections
1075 Info : starting gdb server for am625.cpu.a53.0 on 3334
1076 Info : Listening on port 3334 for gdb connections
1077 Info : starting gdb server for am625.cpu.a53.1 on 3335
1078 Info : Listening on port 3335 for gdb connections
1079 Info : starting gdb server for am625.cpu.a53.2 on 3336
1080 Info : Listening on port 3336 for gdb connections
1081 Info : starting gdb server for am625.cpu.a53.3 on 3337
1082 Info : Listening on port 3337 for gdb connections
1083 Info : starting gdb server for am625.cpu.main0_r5.0 on 3338
1084 Info : Listening on port 3338 for gdb connections
1085 Info : starting gdb server for am625.cpu.gp_mcu on 3339
1086 Info : Listening on port 3339 for gdb connections
1087
1088.. note::
1089 Notice the default configuration is non-SMP configuration allowing
1090 for each of the core to be attached and debugged simultaneously.
1091 ARMv8 SPL/U-Boot starts up on cpu0 of a53/a72.
1092
1093.. k3_rst_include_start_openocd_cfg_external_gdb
1094
1095To debug using this server, use GDB directly or your preferred
1096GDB-based IDE. To start up GDB in the terminal, run the following
1097command.
1098
Nishanth Menon740c41c2023-11-02 23:40:25 -05001099.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001100
1101 gdb-multiarch
1102
1103To connect to your desired core, run the following command within GDB:
1104
Nishanth Menon740c41c2023-11-02 23:40:25 -05001105.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001106
1107 target extended-remote localhost:{port for desired core}
1108
1109To load symbols:
1110
1111.. warning::
1112
1113 SPL and U-Boot does a re-location of address compared to where it
1114 is loaded originally. This step takes place after the DDR size is
1115 determined from dt parsing. So, debugging can be split into either
1116 "before re-location" or "after re-location". Please refer to the
1117 file ''doc/README.arm-relocation'' to see how to grab the relocation
1118 address.
1119
1120* Prior to relocation:
1121
Nishanth Menon740c41c2023-11-02 23:40:25 -05001122.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001123
1124 symbol-file {path to elf file}
1125
1126* After relocation:
1127
Nishanth Menon740c41c2023-11-02 23:40:25 -05001128.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001129
1130 # Drop old symbol file
1131 symbol-file
1132 # Pick up new relocaddr
1133 add-symbol-file {path to elf file} {relocaddr}
1134
1135.. k3_rst_include_end_openocd_cfg_external_gdb
1136
1137In the above example of AM625,
1138
Nishanth Menon740c41c2023-11-02 23:40:25 -05001139.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001140
1141 target extended-remote localhost:3338 <- R5F (Wakeup Domain)
1142 target extended-remote localhost:3334 <- A53 (Main Domain)
1143
1144The core can now be debugged directly within GDB using GDB commands or
1145if using IDE, as appropriate to the IDE.
1146
1147Stepping through the code
1148"""""""""""""""""""""""""
1149
1150`GDB TUI Commands
1151<https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html>`_ can
1152help set up the display more sensible for debug. Provide the name
1153of the layout that can be used to debug. For example, use the GDB
1154command ``layout src`` after loading the symbols to see the code and
1155breakpoints. To exit the debug loop added above, add any breakpoints
1156needed and run the following GDB commands to step out of the debug
1157loop set in the ``board_init_f`` function.
1158
Nishanth Menon740c41c2023-11-02 23:40:25 -05001159.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001160
1161 set x = 0
1162 continue
1163
1164The platform has now been successfully setup to debug with OpenOCD
1165using GDB commands or a GDB-based IDE. See `OpenOCD documentation for
1166GDB <https://openocd.org/doc/html/GDB-and-OpenOCD.html>`_ for further
1167information.
1168
1169.. warning::
1170
1171 On the K3 family of devices, a watchdog timer within the DMSC is
1172 enabled by default by the ROM bootcode with a timeout of 3 minutes.
1173 The watchdog timer is serviced by System Firmware (SYSFW) or TI
1174 Foundational Security (TIFS) during normal operation. If debugging
1175 the SPL before the SYSFW is loaded, the watchdog timer will not get
1176 serviced automatically and the debug session will reset after 3
1177 minutes. It is recommended to start debugging SPL code only after
1178 the startup of SYSFW to avoid running into the watchdog timer reset.
1179
1180Miscellaneous notes with OpenOCD
1181^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1182
1183Currently, OpenOCD does not support tracing for K3 platforms. Tracing
1184function could be beneficial if the bug in code occurs deep within
1185nested function and can optionally save developers major trouble of
1186stepping through a large quantity of code.