blob: 1064c21b5a1d5df81dfce5571dc964a11c71aae4 [file] [log] [blame]
Bryan Brattlof6d138132022-12-19 14:29:50 -06001.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2.. sectionauthor:: Bryan Brattlof <bb@ti.com>
3
4K3 Generation
5=============
6
7Summary
8-------
9
10Texas Instrument's K3 family of SoCs utilize a heterogeneous multicore
11and highly integrated device architecture targeted to maximize
12performance and power efficiency for a wide range of industrial,
13automotive and other broad market segments.
14
15Typically the processing cores and the peripherals for these devices are
16partitioned into three functional domains to provide ultra-low power
17modes as well as accommodating application and industrial safety systems
18on the same SoC. These functional domains are typically called the:
19
20* Wakeup (WKUP) domain
21* Micro-controller (MCU) domain
22* Main domain
23
24For a more detailed view of what peripherals are attached to each
25domain, consult the device specific documentation.
26
27K3 Based SoCs
28-------------
29
30.. toctree::
31 :maxdepth: 1
32
Jai Luthrae526653e2023-11-13 08:51:49 -060033 am62ax_sk
Bryan Brattlof6d138132022-12-19 14:29:50 -060034 am62x_sk
Nishanth Menon1f2b6f92023-11-04 03:01:36 -050035 ../beagle/am62x_beagleplay
Marcel Ziswiler315deb32023-08-04 12:08:08 +020036 ../toradex/verdin-am62
Roger Quadroscd87b1e2023-08-05 11:14:39 +030037 am64x_evm
Neha Malcom Francis507be122023-07-22 00:14:43 +053038 am65x_evm
Nishanth Menone83fe672023-07-27 13:59:01 -050039 j7200_evm
Nishanth Menon756b8782023-11-04 03:11:03 -050040 ../beagle/j721e_beagleboneai64
Nishanth Menone83fe672023-07-27 13:59:01 -050041 j721e_evm
Manorit Chawdhry670a22b2023-10-06 10:16:00 +053042 j721s2_evm
Bryan Brattlof6d138132022-12-19 14:29:50 -060043
44Boot Flow Overview
45------------------
46
47For all K3 SoCs the first core started will be inside the Security
48Management Subsystem (SMS) which will secure the device and start a core
49in the wakeup domain to run the ROM code. ROM will then initialize the
50boot media needed to load the binaries packaged inside `tiboot3.bin`,
51including a 32bit U-Boot SPL, (called the wakup SPL) that ROM will jump
52to after it has finished loading everything into internal SRAM.
53
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050054.. image:: img/boot_flow_01.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050055 :alt: Boot flow up to wakeup domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060056
57The wakeup SPL, running on a wakeup domain core, will initialize DDR and
58any peripherals needed load the larger binaries inside the `tispl.bin`
59into DDR. Once loaded the wakeup SPL will start one of the 'big'
60application cores inside the main domain to initialize the main domain,
Neha Malcom Francis507be122023-07-22 00:14:43 +053061starting with Trusted Firmware-A (TF-A), before moving on to start
62OP-TEE and the main domain's U-Boot SPL.
Bryan Brattlof6d138132022-12-19 14:29:50 -060063
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050064.. image:: img/boot_flow_02.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050065 :alt: Boot flow up to main domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060066
67The main domain's SPL, running on a 64bit application core, has
68virtually unlimited space (billions of bytes now that DDR is working) to
69initialize even more peripherals needed to load in the `u-boot.img`
70which loads more firmware into the micro-controller & wakeup domains and
71finally prepare the main domain to run Linux.
72
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050073.. image:: img/boot_flow_03.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050074 :alt: Complete boot flow up to Linux
Bryan Brattlof6d138132022-12-19 14:29:50 -060075
76This is the typical boot flow for all K3 based SoCs, however this flow
77offers quite a lot in the terms of flexibility, especially on High
78Security (HS) SoCs.
79
80Boot Flow Variations
81^^^^^^^^^^^^^^^^^^^^
82
83All K3 SoCs will generally use the above boot flow with two main
84differences depending on the capabilities of the boot ROM and the number
85of cores inside the device. These differences split the bootflow into
86essentially 4 unique but very similar flows:
87
88* Split binary with a combined firmware: (eg: AM65)
89* Combined binary with a combined firmware: (eg: AM64)
90* Split binary with a split firmware: (eg: J721E)
91* Combined binary with a split firmware: (eg: AM62)
92
93For devices that utilize the split binary approach, ROM is not capable
94of loading the firmware into the SoC requiring the wakeup domain's
95U-Boot SPL to load the firmware.
96
97Devices with a split firmware will have two firmwares loaded into the
98device at different times during the bootup process. TI's Foundational
99Security (TIFS), needed to operate the Security Management Subsystem,
100will either be loaded by ROM or the WKUP U-Boot SPL, then once the
101wakeup U-Boot SPL has completed, the second Device Management (DM)
102firmware can be loaded on the now free core in the wakeup domain.
103
104For more information on the bootup process of your SoC, consult the
105device specific boot flow documentation.
106
107Software Sources
108----------------
109
110All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and
111`u-boot.img` for all K3 SoCs can be located at the following places
112online
113
Nishanth Menonee91e482023-07-27 13:58:44 -0500114.. k3_rst_include_start_boot_sources
115
Bryan Brattlof6d138132022-12-19 14:29:50 -0600116* **Das U-Boot**
117
118 | **source:** https://source.denx.de/u-boot/u-boot.git
119 | **branch:** master
120
Neha Malcom Francis507be122023-07-22 00:14:43 +0530121* **Trusted Firmware-A (TF-A)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600122
Neha Malcom Francis507be122023-07-22 00:14:43 +0530123 | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Bryan Brattlof6d138132022-12-19 14:29:50 -0600124 | **branch:** master
125
Neha Malcom Francis507be122023-07-22 00:14:43 +0530126* **Open Portable Trusted Execution Environment (OP-TEE)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600127
128 | **source:** https://github.com/OP-TEE/optee_os.git
129 | **branch:** master
130
Nishanth Menone2a47452023-08-22 11:41:07 -0500131* **TI Firmware (TIFS, DM, SYSFW)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600132
133 | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git
134 | **branch:** ti-linux-firmware
135
Nishanth Menone2a47452023-08-22 11:41:07 -0500136.. note::
137
138 The TI Firmware required for functionality of the system can be
139 one of the following combination (see platform specific boot diagram for
140 further information as to which component runs on which processor):
141
142 * **TIFS** - TI Foundational Security Firmware - Consists of purely firmware
143 meant to run on the security enclave.
144 * **DM** - Device Management firmware also called TI System Control Interface
145 server (TISCI Server) - This component purely plays the role of managing
146 device resources such as power, clock, interrupts, dma etc. This firmware
147 runs on a dedicated or multi-use microcontroller outside the security
148 enclave.
149
150 OR
151
152 * **SYSFW** - System firmware - consists of both TIFS and DM both running on
153 the security enclave.
154
Nishanth Menonee91e482023-07-27 13:58:44 -0500155.. k3_rst_include_end_boot_sources
156
Bryan Brattlof6d138132022-12-19 14:29:50 -0600157Build Procedure
158---------------
159
160Depending on the specifics of your device, you will need three or more
161binaries to boot your SoC.
162
163* `tiboot3.bin` (bootloader for the wakeup domain)
164* `tispl.bin` (bootloader for the main domain)
165* `u-boot.img`
166
167During the bootup process, both the 32bit wakeup domain and the 64bit
168main domains will be involved. This means everything inside the
169`tiboot3.bin` running in the wakeup domain will need to be compiled for
17032bit cores and most binaries in the `tispl.bin` will need to be
171compiled for 64bit main domain CPU cores.
172
173All of that to say you will need both a 32bit and 64bit cross compiler
174(assuming you're using an x86 desktop)
175
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500176.. k3_rst_include_start_common_env_vars_desc
177.. list-table:: Generic environment variables
178 :widths: 25 25 50
179 :header-rows: 1
180
181 * - S/w Component
182 - Env Variable
183 - Description
184 * - All Software
185 - CC32
186 - Cross compiler for ARMv7 (ARM 32bit), typically arm-linux-gnueabihf-
187 * - All Software
188 - CC64
189 - Cross compiler for ARMv8 (ARM 64bit), typically aarch64-linux-gnu-
190 * - All Software
191 - LNX_FW_PATH
192 - Path to TI Linux firmware repository
193 * - All Software
194 - TFA_PATH
195 - Path to source of Trusted Firmware-A
196 * - All Software
197 - OPTEE_PATH
198 - Path to source of OP-TEE
199.. k3_rst_include_end_common_env_vars_desc
200
201.. k3_rst_include_start_common_env_vars_defn
Nishanth Menon740c41c2023-11-02 23:40:25 -0500202.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600203
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500204 export CC32=arm-linux-gnueabihf-
205 export CC64=aarch64-linux-gnu-
206 export LNX_FW_PATH=path/to/ti-linux-firmware
207 export TFA_PATH=path/to/trusted-firmware-a
208 export OPTEE_PATH=path/to/optee_os
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500209.. k3_rst_include_end_common_env_vars_defn
210
211We will also need some common environment variables set up for the various
212other build sources. we shall use the following, in the build descriptions below:
213
214.. k3_rst_include_start_board_env_vars_desc
215.. list-table:: Board specific environment variables
216 :widths: 25 25 50
217 :header-rows: 1
218
219 * - S/w Component
220 - Env Variable
221 - Description
222 * - U-Boot
223 - UBOOT_CFG_CORTEXR
224 - Defconfig for Cortex-R (Boot processor).
225 * - U-Boot
226 - UBOOT_CFG_CORTEXA
227 - Defconfig for Cortex-A (MPU processor).
228 * - Trusted Firmware-A
229 - TFA_BOARD
230 - Platform name used for building TF-A for Cortex-A Processor.
231 * - Trusted Firmware-A
232 - TFA_EXTRA_ARGS
233 - Any extra arguments used for building TF-A.
234 * - OP-TEE
235 - OPTEE_PLATFORM
236 - Platform name used for building OP-TEE for Cortex-A Processor.
237 * - OP-TEE
238 - OPTEE_EXTRA_ARGS
239 - Any extra arguments used for building OP-TEE.
240.. k3_rst_include_end_board_env_vars_desc
Bryan Brattlof6d138132022-12-19 14:29:50 -0600241
242Building tiboot3.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200243^^^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600244
2451. To generate the U-Boot SPL for the wakeup domain, use the following
246 commands, substituting :code:`{SOC}` for the name of your device (eg:
Neha Malcom Francis507be122023-07-22 00:14:43 +0530247 am62x) to package the various firmware and the wakeup UBoot SPL into
248 the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device
249 uses the split binary flow)
Bryan Brattlof6d138132022-12-19 14:29:50 -0600250
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530251.. _k3_rst_include_start_build_steps_spl_r5:
252
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500253.. k3_rst_include_start_build_steps_spl_r5
Nishanth Menon740c41c2023-11-02 23:40:25 -0500254.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600255
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500256 # inside u-boot source
257 make $UBOOT_CFG_CORTEXR
258 make CROSS_COMPILE=$CC32 BINMAN_INDIRS=$LNX_FW_PATH
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500259.. k3_rst_include_end_build_steps_spl_r5
Bryan Brattlof6d138132022-12-19 14:29:50 -0600260
261At this point you should have all the needed binaries to boot the wakeup
262domain of your K3 SoC.
263
264**Combined Binary Boot Flow** (eg: am62x, am64x, ... )
265
Neha Malcom Francis507be122023-07-22 00:14:43 +0530266 `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600267
268**Split Binary Boot Flow** (eg: j721e, am65x)
269
Neha Malcom Francis507be122023-07-22 00:14:43 +0530270 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
271 | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600272
273.. note ::
274
275 It's important to rename the generated `tiboot3.bin` and `sysfw.itb`
276 to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup
277 UBoot SPL will only look for and load the files with these names.
278
279Building tispl.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200280^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600281
282The `tispl.bin` is a standard fitImage combining the firmware need for
283the main domain to function properly as well as Device Management (DM)
284firmware if your device using a split firmware.
285
Neha Malcom Francis507be122023-07-22 00:14:43 +05302862. We will first need TF-A, as it's the first thing to run on the 'big'
Bryan Brattlof6d138132022-12-19 14:29:50 -0600287 application cores on the main domain.
288
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500289.. k3_rst_include_start_build_steps_tfa
Nishanth Menon740c41c2023-11-02 23:40:25 -0500290.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600291
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500292 # inside trusted-firmware-a source
293 make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS \
294 TARGET_BOARD=$TFA_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500295.. k3_rst_include_end_build_steps_tfa
Bryan Brattlof6d138132022-12-19 14:29:50 -0600296
Neha Malcom Francis507be122023-07-22 00:14:43 +0530297Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500298=j784s4` (if it is a J784S4 device), while typical Sitara (`am6*`) devices
Neha Malcom Francis507be122023-07-22 00:14:43 +0530299use the `lite` option.
Bryan Brattlof6d138132022-12-19 14:29:50 -0600300
Neha Malcom Francis507be122023-07-22 00:14:43 +05303013. The Open Portable Trusted Execution Environment (OP-TEE) is designed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600302 to run as a companion to a non-secure Linux kernel for Cortex-A cores
303 using the TrustZone technology built into the core.
304
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500305.. k3_rst_include_start_build_steps_optee
Nishanth Menon740c41c2023-11-02 23:40:25 -0500306.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600307
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500308 # inside optee_os source
309 make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 CFG_ARM64_core=y $OPTEE_EXTRA_ARGS \
310 PLATFORM=$OPTEE_PLATFORM
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500311.. k3_rst_include_end_build_steps_optee
Bryan Brattlof6d138132022-12-19 14:29:50 -0600312
Neha Malcom Francis507be122023-07-22 00:14:43 +05303134. Finally, after TF-A has initialized the main domain and OP-TEE has
Bryan Brattlof6d138132022-12-19 14:29:50 -0600314 finished, we can jump back into U-Boot again, this time running on a
315 64bit core in the main domain.
316
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530317.. _k3_rst_include_start_build_steps_uboot:
318
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500319.. k3_rst_include_start_build_steps_uboot
Nishanth Menon740c41c2023-11-02 23:40:25 -0500320.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600321
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500322 # inside u-boot source
323 make $UBOOT_CFG_CORTEXA
324 make CROSS_COMPILE=$CC64 BINMAN_INDIRS=$LNX_FW_PATH \
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500325 BL31=$TFA_PATH/build/k3/$TFA_BOARD/release/bl31.bin \
326 TEE=$OPTEE_PATH/out/arm-plat-k3/core/tee-raw.bin
Neha Malcom Francis2b259f02023-12-05 15:12:20 +0530327
328.. note::
329 It is also possible to pick up a custom DM binary by adding TI_DM argument
330 pointing to the file. If not provided, it defaults to picking up the DM
331 binary from BINMAN_INDIRS. This is only applicable to devices that utilize
332 split firmware.
333
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500334.. k3_rst_include_end_build_steps_uboot
Bryan Brattlof6d138132022-12-19 14:29:50 -0600335
336At this point you should have every binary needed initialize both the
337wakeup and main domain and to boot to the U-Boot prompt
338
339**Main Domain Bootloader**
340
Neha Malcom Francis507be122023-07-22 00:14:43 +0530341 | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices
342 | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530343
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530344FIT signature signing
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530345---------------------
346
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530347K3 platforms have FIT signature signing enabled by default on their primary
348platforms. Here we'll take an example for creating FIT Image for J721E platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530349and the same can be extended to other platforms
350
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530351Pre-requisites:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530352
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530353* U-boot build (:ref:`U-boot build <k3_rst_include_start_build_steps_spl_r5>`)
354* Linux Image and Linux DTB prebuilt
355
356Describing FIT source
357^^^^^^^^^^^^^^^^^^^^^
358
359FIT Image is a packed structure containing binary blobs and configurations.
360The Kernel FIT Image that we have has Kernel Image, DTB and the DTBOs. It
361supports packing multiple images and configurations that allow you to
362choose any configuration at runtime to boot from.
363
364.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530365
366 /dts-v1/;
367
368 / {
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530369 description = "FIT Image description";
370 #address-cells = <1>;
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530371
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530372 images {
373 [image-1]
374 [image-2]
375 [fdt-1]
376 [fdt-2]
377 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530378
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530379 configurations {
380 default = <conf-1>
381 [conf-1: image-1,fdt-1]
382 [conf-2: image-2,fdt-1]
383 }
384 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530385
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530386* Sample Images
387
388.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530389
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530390 kernel-1 {
391 description = "Linux kernel";
392 data = /incbin/("linux.bin");
393 type = "kernel";
394 arch = "arm64";
395 os = "linux";
396 compression = "gzip";
397 load = <0x81000000>;
398 entry = <0x81000000>;
399 hash-1 {
400 algo = "sha512";
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530401 };
402 };
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530403 fdt-ti_k3-j721e-common-proc-board.dtb {
404 description = "Flattened Device Tree blob";
405 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dtb");
406 type = "flat_dt";
407 arch = "arm64";
408 compression = "none";
409 load = <0x83000000>;
410 hash-1 {
411 algo = "sha512";
412 };
413 };
414 # Optional images
415 fdt-ti_k3-j721e-evm-virt-mac-client.dtbo {
416 description = "Flattened Device Tree blob";
417 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-evm-virt-mac-client.dtbo");
418 type = "flat_dt";
419 arch = "arm64";
420 compression = "none";
421 load = <0x83080000>;
422 hash-1 {
423 algo = "sha512";
424 };
425 };
426
427.. note::
428
429 Change the path in data variables to point to the respective files in your
430 local machine. For e.g change "linux.bin" to "<path-to-kernel-image>".
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530431
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530432For enabling usage of FIT signature, add the signature node to the
433corresponding configuration node as follows.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530434
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530435* Sample Configurations
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530436
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530437.. code-block::
438
439 conf-ti_k3-j721e-common-proc-board.dtb {
440 description = "Linux kernel, FDT blob";
441 fdt = "fdt-ti_k3-j721e-common-proc-board.dtb";
442 kernel = "kernel-1";
443 signature-1 {
444 algo = "sha512,rsa4096";
445 key-name-hint = "custMpk";
446 sign-images = "kernel", "fdt";
447 };
448 };
449 # Optional configurations
450 conf-ti_k3-j721e-evm-virt-mac-client.dtbo {
451 description = "FDTO blob";
452 fdt = "fdt-ti_k3-j721e-evm-virt-mac-client.dtbo";
453
454 signature-1 {
455 algo = "sha512,rsa4096";
456 key-name-hint = "custMpk";
457 sign-images = "fdt";
458 };
459 };
460
461Specify all images you need the signature to authenticate as a part of
462sign-images. The key-name-hint needs to be changed if you are using some
463other key other than the TI dummy key that we are using for this example.
464It should be the name of the file containing the keys.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530465
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500466.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530467
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530468 Generating new set of keys:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530469
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530470 .. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530471
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530472 mkdir keys
473 openssl genpkey -algorithm RSA -out keys/dev.key \
474 -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:65537
475 openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530476
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530477Generating the fitImage
478^^^^^^^^^^^^^^^^^^^^^^^
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530479
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530480.. note::
481
482 For signing a secondary platform like SK boards, you'll require
483 additional steps
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530484
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530485 - Change the CONFIG_DEFAULT_DEVICE_TREE
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530486
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530487 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530488
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530489 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530490
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530491 diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig
492 index a5c1df7e0054..6d0126d955ef 100644
493 --- a/configs/j721e_evm_a72_defconfig
494 +++ b/configs/j721e_evm_a72_defconfig
495 @@ -13,7 +13,7 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80480000
496 CONFIG_ENV_SIZE=0x20000
497 CONFIG_DM_GPIO=y
498 CONFIG_SPL_DM_SPI=y
499 -CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
500 +CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-sk"
501 CONFIG_SPL_TEXT_BASE=0x80080000
502 CONFIG_DM_RESET=y
503 CONFIG_SPL_MMC=y
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530504
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530505 - Change the binman nodes to package u-boot.dtb for the correct set of platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530506
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530507 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530508
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530509 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530510
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530511 diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi
512 index 673be646b1e3..752fa805fe8d 100644
513 --- a/arch/arm/dts/k3-j721e-binman.dtsi
514 +++ b/arch/arm/dts/k3-j721e-binman.dtsi
515 @@ -299,8 +299,8 @@
516 #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530517
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530518 #define UBOOT_NODTB "u-boot-nodtb.bin"
519 -#define J721E_EVM_DTB "u-boot.dtb"
520 -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb"
521 +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb"
522 +#define J721E_SK_DTB "u-boot.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530523
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530524This step will embed the public key in the u-boot.dtb file that was already
525built during the initial u-boot build.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530526
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530527.. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530528
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530529 mkimage -r -f fitImage.its -k $UBOOT_PATH/board/ti/keys -K $UBOOT_PATH/build/$ARMV8/dts/dt.dtb fitImage
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530530
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530531.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530532
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530533 If you have another set of keys then change the -k argument to point to
534 the folder where your keys are present, the build requires the presence
535 of both .key and .crt file.
536
537Build u-boot again
538^^^^^^^^^^^^^^^^^^
539
540The updated u-boot.dtb needs to be packed in u-boot.img for authentication
541so rebuild U-boot ARMV8 without changing any parameters.
542Refer (:ref:`U-boot ARMV8 build <k3_rst_include_start_build_steps_uboot>`)
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530543
544.. note::
545
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530546 The devices now also have distroboot enabled so if the FIT image doesn't
547 work then the fallback to normal distroboot will be there on HS devices.
548 This will need to be explicitly disabled by changing the boot_targets to
549 disallow fallback during testing.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530550
551Saving environment
552------------------
553
554SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default
555way for saving the environments. This has been done as Uenv.txt is more granular
556then the saveenv command and can be used across various bootmodes too.
557
558**Writing to MMC/EMMC**
559
Nishanth Menon740c41c2023-11-02 23:40:25 -0500560.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530561
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500562 env export -t $loadaddr <list of variables>
563 fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize}
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530564
565**Reading from MMC/EMMC**
566
567By default run envboot will read it from the MMC/EMMC partition ( based on
568mmcdev) and set the environments.
569
570If manually needs to be done then the environment can be read from the
571filesystem and then imported
572
Nishanth Menon740c41c2023-11-02 23:40:25 -0500573.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530574
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500575 fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile}
576 env import -t ${loadaddr} ${filesize}
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500577
578.. _k3_rst_refer_openocd:
579
580Common Debugging environment - OpenOCD
581--------------------------------------
582
583This section will show you how to connect a board to `OpenOCD
584<https://openocd.org/>`_ and load the SPL symbols for debugging with
585a K3 generation device. To follow this guide, you must build custom
586u-boot binaries, start your board from a boot media such as an SD
587card, and use an OpenOCD environment. This section uses generic
588examples, though you can apply these instructions to any supported K3
589generation device.
590
591The overall structure of this setup is in the following figure.
592
593.. image:: img/openocd-overview.svg
Nishanth Menon5746e032023-08-22 11:40:56 -0500594 :alt: Overview of OpenOCD setup.
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500595
596.. note::
597
598 If you find these instructions useful, please consider `donating
599 <https://openocd.org/pages/donations.html>`_ to OpenOCD.
600
601Step 1: Download and install OpenOCD
602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
603
604To get started, it is more convenient if the distribution you
605use supports OpenOCD by default. Follow the instructions in the
606`getting OpenOCD <https://openocd.org/pages/getting-openocd.html>`_
607documentation to pick the installation steps appropriate to your
608environment. Some references to OpenOCD documentation:
609
610* `OpenOCD User Guide <https://openocd.org/doc/html/index.html>`_
611* `OpenOCD Developer's Guide <https://openocd.org/doc/doxygen/html/index.html>`_
612
613Refer to the release notes corresponding to the `OpenOCD version
614<https://github.com/openocd-org/openocd/releases>`_ to ensure
615
616* Processor support: In general, processor support shouldn't present
617 any difficulties since OpenOCD provides solid support for both ARMv8
618 and ARMv7.
619* SoC support: When working with System-on-a-Chip (SoC), the support
620 usually comes as a TCL config file. It is vital to ensure the correct
621 version of OpenOCD or to use the TCL files from the latest release or
622 the one mentioned.
623* Board or the JTAG adapter support: In most cases, board support is
624 a relatively easy problem if the board has a JTAG pin header. All
625 you need to do is ensure that the adapter you select is compatible
626 with OpenOCD. Some boards come with an onboard JTAG adapter that
627 requires a USB cable to be plugged into the board, in which case, it
628 is vital to ensure that the JTAG adapter is supported. Fortunately,
629 almost all TI K3 SK/EVMs come with TI's XDS110, which has out of the
630 box support by OpenOCD. The board-specific documentation will
631 cover the details and any adapter/dongle recommendations.
632
Nishanth Menon740c41c2023-11-02 23:40:25 -0500633.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500634
635 openocd -v
636
637.. note::
638
639 OpenOCD version 0.12.0 is usually required to connect to most K3
640 devices. If your device is only supported by a newer version than the
641 one provided by your distribution, you may need to build it from the source.
642
643Building OpenOCD from source
644""""""""""""""""""""""""""""
645
646The dependency package installation instructions below are for Debian
647systems, but equivalent instructions should exist for systems with
648other package managers. Please refer to the `OpenOCD Documentation
649<https://openocd.org/>`_ for more recent installation steps.
650
Nishanth Menon740c41c2023-11-02 23:40:25 -0500651.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500652
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500653 # Check the packages to be installed: needs deb-src in sources.list
654 sudo apt build-dep openocd
655 # The following list is NOT complete - please check the latest
656 sudo apt-get install libtool pkg-config texinfo libusb-dev \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500657 libusb-1.0.0-dev libftdi-dev libhidapi-dev autoconf automake
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500658 git clone https://github.com/openocd-org/openocd.git openocd
659 cd openocd
660 git submodule init
661 git submodule update
662 ./bootstrap
663 ./configure --prefix=/usr/local/
664 make -j`nproc`
665 sudo make install
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500666
667.. note::
668
669 The example above uses the GitHub mirror site. See
670 `git repo information <https://openocd.org/doc/html/Developers.html#OpenOCD-Git-Repository>`_
671 information to pick the official git repo.
672 If a specific version is desired, select the version using `git checkout tag`.
673
674Installing OpenOCD udev rules
675"""""""""""""""""""""""""""""
676
677The step is not necessary if the distribution supports the OpenOCD, but
678if building from a source, ensure that the udev rules are installed
679correctly to ensure a sane system.
680
Nishanth Menon740c41c2023-11-02 23:40:25 -0500681.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500682
683 # Go to the OpenOCD source directory
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500684 cd openocd
685 Copy the udev rules to the correct system location
686 sudo cp ./contrib/60-openocd.rules \
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500687 ./src/jtag/drivers/libjaylink/contrib/99-libjaylink.rules \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500688 /etc/udev/rules.d/
689 # Get Udev to load the new rules up
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500690 sudo udevadm control --reload-rules
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500691 # Use the new rules on existing connected devices
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500692 sudo udevadm trigger
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500693
694Step 2: Setup GDB
695^^^^^^^^^^^^^^^^^
696
697Most systems come with gdb-multiarch package.
698
Nishanth Menon740c41c2023-11-02 23:40:25 -0500699.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500700
701 # Install gdb-multiarch package
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500702 sudo apt-get install gdb-multiarch
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500703
704Though using GDB natively is normal, developers with interest in using IDE
705may find a few of these interesting:
706
707* `gdb-dashboard <https://github.com/cyrus-and/gdb-dashboard>`_
708* `gef <https://github.com/hugsy/gef>`_
709* `peda <https://github.com/longld/peda>`_
710* `pwndbg <https://github.com/pwndbg/pwndbg>`_
711* `voltron <https://github.com/snare/voltron>`_
712* `ddd <https://www.gnu.org/software/ddd/>`_
713* `vscode <https://www.justinmklam.com/posts/2017/10/vscode-debugger-setup/>`_
714* `vim conque-gdb <https://github.com/vim-scripts/Conque-GDB>`_
715* `emacs realgud <https://github.com/realgud/realgud/wiki/gdb-notes>`_
716* `Lauterbach IDE <https://www2.lauterbach.com/pdf/backend_gdb.pdf>`_
717
718.. warning::
719 LLDB support for OpenOCD is still a work in progress as of this writing.
720 Using GDB is probably the safest option at this point in time.
721
722Step 3: Connect board to PC
723^^^^^^^^^^^^^^^^^^^^^^^^^^^
724There are few patterns of boards in the ecosystem
725
726.. k3_rst_include_start_openocd_connect_XDS110
727
728**Integrated JTAG adapter/dongle**: The board has a micro-USB connector labelled
729XDS110 USB or JTAG. Connect a USB cable to the board to the mentioned port.
730
731.. note::
732
733 There are multiple USB ports on a typical board, So, ensure you have read
734 the user guide for the board and confirmed the silk screen label to ensure
735 connecting to the correct port.
736
737.. k3_rst_include_end_openocd_connect_XDS110
738
739.. k3_rst_include_start_openocd_connect_cti20
740
741**cTI20 connector**: The TI's `cTI20
742<https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_JTAG_connectors.html#cti-20-pin-header-information>`_ connector
743is probably the most prevelant on TI platforms. Though many
744TI boards have an onboard XDS110, cTI20 connector is usually
745provided as an alternate scheme to connect alternatives such
746as `Lauterbach <https://www.lauterbach.com/>`_ or `XDS560
747<https://www.ti.com/tool/TMDSEMU560V2STM-U>`_.
748
749To debug on these boards, the following combinations is suggested:
750
751* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
752 or `equivalent dongles supported by OpenOCD. <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_
753* Cable such as `Tag-connect ribbon cable <https://www.tag-connect.com/product/20-pin-cortex-ribbon-cable-4-length-with-50-mil-connectors>`_
754* Adapter to convert cTI20 to ARM20 such as those from
755 `Segger <https://www.segger.com/products/debug-probes/j-link/accessories/adapters/ti-cti-20-adapter/>`_
756 or `Lauterbach LA-3780 <https://www.lauterbach.com/ad3780.html>`_
757 Or optionally, if you have manufacturing capability then you could try
758 `BeagleBone JTAG Adapter <https://github.com/mmorawiec/BeagleBone-Black-JTAG-Adapters>`_
759
760.. warning::
761 XDS560 and Lauterbach are proprietary solutions and is not supported by
762 OpenOCD.
763 When purchasing an off the shelf adapter/dongle, you do want to be careful
764 about the signalling though. Please
765 `read for additional info <https://software-dl.ti.com/ccs/esd/xdsdebugprobes/emu_JTAG_connectors.html>`_.
766
767.. k3_rst_include_end_openocd_connect_cti20
768
769.. k3_rst_include_start_openocd_connect_tag_connect
770
771**Tag-Connect**: `Tag-Connect <https://www.tag-connect.com/>`_
772pads on the boards which require special cable. Please check the documentation
773to `identify <https://www.tag-connect.com/info/legs-or-no-legs>`_ if "legged"
774or "no-leg" version of the cable is appropriate for the board.
775
776To debug on these boards, you will need:
777
778* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
779 or `equivalent dongles supported by OpenOCD <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_.
780* Tag-Connect cable appropriate to the board such as
781 `TC2050-IDC-NL <https://www.tag-connect.com/product/TC2050-IDC-NL-10-pin-no-legs-cable-with-ribbon-connector>`_
782* In case of no-leg, version, a
783 `retaining clip <https://www.tag-connect.com/product/tc2050-clip-3pack-retaining-clip>`_
784* Tag-Connect to ARM20
785 `adapter <https://www.tag-connect.com/product/tc2050-arm2010-arm-20-pin-to-tc2050-adapter>`_
786
787.. note::
788 You can optionally use a 3d printed solution such as
789 `Protective cap <https://www.thingiverse.com/thing:3025584>`_ or
790 `clip <https://www.thingiverse.com/thing:3035278>`_ to replace
791 the retaining clip.
792
793.. warning::
794 With the Tag-Connect to ARM20 adapter, Please solder the "Trst" signal for
795 connection to work.
796
797.. k3_rst_include_end_openocd_connect_tag_connect
798
799Debugging with OpenOCD
800^^^^^^^^^^^^^^^^^^^^^^
801
802Debugging U-Boot is different from debugging regular user space
803applications. The bootloader initialization process involves many boot
804media and hardware configuration operations. For K3 devices, there
805are also interactions with security firmware. While reloading the
806"elf" file works through GDB, developers must be mindful of cascading
807initialization's potential consequences.
808
809Consider the following code change:
810
811.. code-block:: diff
812
813 --- a/file.c 2023-07-29 10:55:29.647928811 -0500
814 +++ b/file.c 2023-07-29 10:55:46.091856816 -0500
815 @@ -1,3 +1,3 @@
816 val = readl(reg);
817 -val |= 0x2;
818 +val |= 0x1;
819 writel(val, reg);
820
821Re-running the elf file with the above change will result in the
822register setting 0x3 instead of the intended 0x1. There are other
823hardware blocks which may not behave very well with a re-initialization
824without proper shutdown.
825
826To help narrow the debug down, it is usually simpler to use the
827standard boot media to get to the bootloader and debug only in the area
828of interest.
829
830In general, to debug u-boot spl/u-boot with OpenOCD there are three steps:
831
832* Modify the code adding a loop to allow the debugger to attach
833 near the point of interest. Boot up normally to stop at the loop.
834* Connect with OpenOCD and step out of the loop.
835* Step through the code to find the root of issue.
836
837Typical debugging involves a few iterations of the above sequence.
838Though most bootloader developers like to use printf to debug,
839debug with JTAG tends to be most efficient since it is possible to
840investigate the code flow and inspect hardware registers without
841repeated iterations.
842
843Code modification
844"""""""""""""""""
845
846* **start.S**: Adding an infinite while loop at the very entry of
847 U-Boot. For this, look for the corresponding start.S entry file.
848 This is usually only required when debugging some core SoC or
849 processor related function. For example: arch/arm/cpu/armv8/start.S or
850 arch/arm/cpu/armv7/start.S
851
852.. code-block:: diff
853
854 diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
855 index 69e281b086..744929e825 100644
856 --- a/arch/arm/cpu/armv7/start.S
857 +++ b/arch/arm/cpu/armv7/start.S
858 @@ -37,6 +37,8 @@
859 #endif
860
861 reset:
862 +dead_loop:
863 + b dead_loop
864 /* Allow the board to save important registers */
865 b save_boot_params
866 save_boot_params_ret:
867
868* **board_init_f**: Adding an infinite while loop at the board entry
869 function. In many cases, it is important to debug the boot process if
870 any changes are made for board-specific applications. Below is a step
871 by step process for debugging the boot SPL or Armv8 SPL:
872
873 To debug the boot process in either domain, we will first
874 add a modification to the code we would like to debug.
875 In this example, we will debug ``board_init_f`` inside
876 ``arch/arm/mach-k3/{soc}_init.c``. Since some sections of U-Boot
877 will be executed multiple times during the bootup process of K3
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500878 devices, we will need to include either ``CONFIG_ARM64`` or
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500879 ``CONFIG_CPU_V7R`` to catch the CPU at the desired place during the
880 bootup process (Main or Wakeup domains). For example, modify the
881 file as follows (depending on need):
882
883.. code-block:: c
884
885 void board_init_f(ulong dummy)
886 {
887 .
888 .
889 /* Code to run on the R5F (Wakeup/Boot Domain) */
890 if (IS_ENABLED(CONFIG_CPU_V7R)) {
891 volatile int x = 1;
892 while(x) {};
893 }
894 ...
895 /* Code to run on the ARMV8 (Main Domain) */
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500896 if (IS_ENABLED(CONFIG_ARM64)) {
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500897 volatile int x = 1;
898 while(x) {};
899 }
900 .
901 .
902 }
903
904Connecting with OpenOCD for a debug session
905"""""""""""""""""""""""""""""""""""""""""""
906
907Startup OpenOCD to debug the platform as follows:
908
909* **Integrated JTAG interface**: If the evm has a debugger such as
910 XDS110 inbuilt, there is typically an evm board support added and a
911 cfg file will be available.
912
913.. k3_rst_include_start_openocd_cfg_XDS110
914
Nishanth Menon740c41c2023-11-02 23:40:25 -0500915.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500916
917 openocd -f board/{board_of_choice}.cfg
918
919.. k3_rst_include_end_openocd_cfg_XDS110
920
921.. k3_rst_include_start_openocd_cfg_external_intro
922
923* **External JTAG adapter/interface**: In other cases, where an
924 adapter/dongle is used, a simple cfg file can be created to integrate the
925 SoC and adapter information. See `supported TI K3 SoCs
926 <https://github.com/openocd-org/openocd/blob/master/tcl/target/ti_k3.cfg#L59>`_
927 to decide if the SoC is supported or not.
928
Nishanth Menon740c41c2023-11-02 23:40:25 -0500929.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500930
931 openocd -f openocd_connect.cfg
932
933.. k3_rst_include_end_openocd_cfg_external_intro
934
935 For example, with BeaglePlay (AM62X platform), the openocd_connect.cfg:
936
937.. code-block:: tcl
938
939 # TUMPA example:
940 # http://www.tiaowiki.com/w/TIAO_USB_Multi_Protocol_Adapter_User's_Manual
941 source [find interface/ftdi/tumpa.cfg]
942
943 transport select jtag
944
945 # default JTAG configuration has only SRST and no TRST
946 reset_config srst_only srst_push_pull
947
948 # delay after SRST goes inactive
949 adapter srst delay 20
950
951 if { ![info exists SOC] } {
952 # Set the SoC of interest
953 set SOC am625
954 }
955
956 source [find target/ti_k3.cfg]
957
958 ftdi tdo_sample_edge falling
959
960 # Speeds for FT2232H are in multiples of 2, and 32MHz is tops
961 # max speed we seem to achieve is ~20MHz.. so we pick 16MHz
962 adapter speed 16000
963
964Below is an example of the output of this command:
965
966.. code-block:: console
967
968 Info : Listening on port 6666 for tcl connections
969 Info : Listening on port 4444 for telnet connections
970 Info : XDS110: connected
971 Info : XDS110: vid/pid = 0451/bef3
972 Info : XDS110: firmware version = 3.0.0.20
973 Info : XDS110: hardware version = 0x002f
974 Info : XDS110: connected to target via JTAG
975 Info : XDS110: TCK set to 2500 kHz
976 Info : clock speed 2500 kHz
977 Info : JTAG tap: am625.cpu tap/device found: 0x0bb7e02f (mfg: 0x017 (Texas Instruments), part: 0xbb7e, ver: 0x0)
978 Info : starting gdb server for am625.cpu.sysctrl on 3333
979 Info : Listening on port 3333 for gdb connections
980 Info : starting gdb server for am625.cpu.a53.0 on 3334
981 Info : Listening on port 3334 for gdb connections
982 Info : starting gdb server for am625.cpu.a53.1 on 3335
983 Info : Listening on port 3335 for gdb connections
984 Info : starting gdb server for am625.cpu.a53.2 on 3336
985 Info : Listening on port 3336 for gdb connections
986 Info : starting gdb server for am625.cpu.a53.3 on 3337
987 Info : Listening on port 3337 for gdb connections
988 Info : starting gdb server for am625.cpu.main0_r5.0 on 3338
989 Info : Listening on port 3338 for gdb connections
990 Info : starting gdb server for am625.cpu.gp_mcu on 3339
991 Info : Listening on port 3339 for gdb connections
992
993.. note::
994 Notice the default configuration is non-SMP configuration allowing
995 for each of the core to be attached and debugged simultaneously.
996 ARMv8 SPL/U-Boot starts up on cpu0 of a53/a72.
997
998.. k3_rst_include_start_openocd_cfg_external_gdb
999
1000To debug using this server, use GDB directly or your preferred
1001GDB-based IDE. To start up GDB in the terminal, run the following
1002command.
1003
Nishanth Menon740c41c2023-11-02 23:40:25 -05001004.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001005
1006 gdb-multiarch
1007
1008To connect to your desired core, run the following command within GDB:
1009
Nishanth Menon740c41c2023-11-02 23:40:25 -05001010.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001011
1012 target extended-remote localhost:{port for desired core}
1013
1014To load symbols:
1015
1016.. warning::
1017
1018 SPL and U-Boot does a re-location of address compared to where it
1019 is loaded originally. This step takes place after the DDR size is
1020 determined from dt parsing. So, debugging can be split into either
1021 "before re-location" or "after re-location". Please refer to the
1022 file ''doc/README.arm-relocation'' to see how to grab the relocation
1023 address.
1024
1025* Prior to relocation:
1026
Nishanth Menon740c41c2023-11-02 23:40:25 -05001027.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001028
1029 symbol-file {path to elf file}
1030
1031* After relocation:
1032
Nishanth Menon740c41c2023-11-02 23:40:25 -05001033.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001034
1035 # Drop old symbol file
1036 symbol-file
1037 # Pick up new relocaddr
1038 add-symbol-file {path to elf file} {relocaddr}
1039
1040.. k3_rst_include_end_openocd_cfg_external_gdb
1041
1042In the above example of AM625,
1043
Nishanth Menon740c41c2023-11-02 23:40:25 -05001044.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001045
1046 target extended-remote localhost:3338 <- R5F (Wakeup Domain)
1047 target extended-remote localhost:3334 <- A53 (Main Domain)
1048
1049The core can now be debugged directly within GDB using GDB commands or
1050if using IDE, as appropriate to the IDE.
1051
1052Stepping through the code
1053"""""""""""""""""""""""""
1054
1055`GDB TUI Commands
1056<https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html>`_ can
1057help set up the display more sensible for debug. Provide the name
1058of the layout that can be used to debug. For example, use the GDB
1059command ``layout src`` after loading the symbols to see the code and
1060breakpoints. To exit the debug loop added above, add any breakpoints
1061needed and run the following GDB commands to step out of the debug
1062loop set in the ``board_init_f`` function.
1063
Nishanth Menon740c41c2023-11-02 23:40:25 -05001064.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001065
1066 set x = 0
1067 continue
1068
1069The platform has now been successfully setup to debug with OpenOCD
1070using GDB commands or a GDB-based IDE. See `OpenOCD documentation for
1071GDB <https://openocd.org/doc/html/GDB-and-OpenOCD.html>`_ for further
1072information.
1073
1074.. warning::
1075
1076 On the K3 family of devices, a watchdog timer within the DMSC is
1077 enabled by default by the ROM bootcode with a timeout of 3 minutes.
1078 The watchdog timer is serviced by System Firmware (SYSFW) or TI
1079 Foundational Security (TIFS) during normal operation. If debugging
1080 the SPL before the SYSFW is loaded, the watchdog timer will not get
1081 serviced automatically and the debug session will reset after 3
1082 minutes. It is recommended to start debugging SPL code only after
1083 the startup of SYSFW to avoid running into the watchdog timer reset.
1084
1085Miscellaneous notes with OpenOCD
1086^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1087
1088Currently, OpenOCD does not support tracing for K3 platforms. Tracing
1089function could be beneficial if the bug in code occurs deep within
1090nested function and can optionally save developers major trouble of
1091stepping through a large quantity of code.