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