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