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