blob: 7dfe39c5fa57d6c09658ac49085ec6b6a3177df6 [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
Manorit Chawdhry98346472023-12-29 16:16:33 +0530107Secure Boot
108-----------
109
110K3 HS-SE (High Security - Security Enforced) devices enforce an
111authenticated boot flow for secure boot. HS-FS (High Security - Field
112Securable) is the state of a K3 device before it has been eFused with
113customer security keys. In the HS-FS state the authentication still can
114function as in HS-SE but as there are no customer keys to verify the
115signatures against the authentication will pass for certificates signed
116with any key.
117
118Chain of trust
119^^^^^^^^^^^^^^
120
1211) Public ROM loads the tiboot3.bin (R5 SPL, TIFS)
1222) R5 SPL loads tispl.bin (ATF, OP-TEE, DM, SPL)
1233) SPL loads u-boot.img (U-Boot)
1244) U-Boot loads fitImage (Linux and DTBs)
125
126Steps 1-3 are all authenticated by either the Secure ROM or TIFS as the
127authenticating entity and step 4 uses U-boot standard mechanism for
128authenticating.
129
130All the authentication that are done for ROM/TIFS are done through x509
131certificates that are signed.
132
133Firewalls
134^^^^^^^^^
135
1361) Secure ROM comes up and sets up firewalls that are needed by itself
1372) TIFS will setup it's own firewalls to protect core system resources
1383) R5 SPL will remove any firewalls that are leftover from the Secure ROM stage
139 that are no longer required.
1404) Each stage beyond this: such as tispl.bin containing TFA/OPTEE uses OIDs to
141 set up firewalls to protect themselves (enforced by TIFS)
1425) TFA/OP-TEE can configure other firewalls at runtime if required as they
143 are already authenticated and firewalled off from illegal access.
1446) All later stages can setup or remove firewalls that have not been already
145 configured by previous stages, such as those created by TIFS, TFA, and OP-TEE.
146
147Futhur, firewalls have a lockdown bit in hardware that enforces the setting
148(and cannot be over-ridden) until the full system is reset.
149
Bryan Brattlof6d138132022-12-19 14:29:50 -0600150Software Sources
151----------------
152
153All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and
154`u-boot.img` for all K3 SoCs can be located at the following places
155online
156
Nishanth Menonee91e482023-07-27 13:58:44 -0500157.. k3_rst_include_start_boot_sources
158
Bryan Brattlof6d138132022-12-19 14:29:50 -0600159* **Das U-Boot**
160
161 | **source:** https://source.denx.de/u-boot/u-boot.git
162 | **branch:** master
163
Neha Malcom Francis507be122023-07-22 00:14:43 +0530164* **Trusted Firmware-A (TF-A)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600165
Neha Malcom Francis507be122023-07-22 00:14:43 +0530166 | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Bryan Brattlof6d138132022-12-19 14:29:50 -0600167 | **branch:** master
168
Neha Malcom Francis507be122023-07-22 00:14:43 +0530169* **Open Portable Trusted Execution Environment (OP-TEE)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600170
171 | **source:** https://github.com/OP-TEE/optee_os.git
172 | **branch:** master
173
Nishanth Menone2a47452023-08-22 11:41:07 -0500174* **TI Firmware (TIFS, DM, SYSFW)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600175
176 | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git
177 | **branch:** ti-linux-firmware
178
Nishanth Menone2a47452023-08-22 11:41:07 -0500179.. note::
180
181 The TI Firmware required for functionality of the system can be
182 one of the following combination (see platform specific boot diagram for
183 further information as to which component runs on which processor):
184
185 * **TIFS** - TI Foundational Security Firmware - Consists of purely firmware
186 meant to run on the security enclave.
187 * **DM** - Device Management firmware also called TI System Control Interface
188 server (TISCI Server) - This component purely plays the role of managing
189 device resources such as power, clock, interrupts, dma etc. This firmware
190 runs on a dedicated or multi-use microcontroller outside the security
191 enclave.
192
193 OR
194
195 * **SYSFW** - System firmware - consists of both TIFS and DM both running on
196 the security enclave.
197
Nishanth Menonee91e482023-07-27 13:58:44 -0500198.. k3_rst_include_end_boot_sources
199
Bryan Brattlof6d138132022-12-19 14:29:50 -0600200Build Procedure
201---------------
202
203Depending on the specifics of your device, you will need three or more
204binaries to boot your SoC.
205
206* `tiboot3.bin` (bootloader for the wakeup domain)
207* `tispl.bin` (bootloader for the main domain)
208* `u-boot.img`
209
210During the bootup process, both the 32bit wakeup domain and the 64bit
211main domains will be involved. This means everything inside the
212`tiboot3.bin` running in the wakeup domain will need to be compiled for
21332bit cores and most binaries in the `tispl.bin` will need to be
214compiled for 64bit main domain CPU cores.
215
216All of that to say you will need both a 32bit and 64bit cross compiler
217(assuming you're using an x86 desktop)
218
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500219.. k3_rst_include_start_common_env_vars_desc
220.. list-table:: Generic environment variables
221 :widths: 25 25 50
222 :header-rows: 1
223
224 * - S/w Component
225 - Env Variable
226 - Description
227 * - All Software
228 - CC32
229 - Cross compiler for ARMv7 (ARM 32bit), typically arm-linux-gnueabihf-
230 * - All Software
231 - CC64
232 - Cross compiler for ARMv8 (ARM 64bit), typically aarch64-linux-gnu-
233 * - All Software
234 - LNX_FW_PATH
235 - Path to TI Linux firmware repository
236 * - All Software
237 - TFA_PATH
238 - Path to source of Trusted Firmware-A
239 * - All Software
240 - OPTEE_PATH
241 - Path to source of OP-TEE
242.. k3_rst_include_end_common_env_vars_desc
243
244.. k3_rst_include_start_common_env_vars_defn
Nishanth Menon740c41c2023-11-02 23:40:25 -0500245.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600246
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500247 export CC32=arm-linux-gnueabihf-
248 export CC64=aarch64-linux-gnu-
249 export LNX_FW_PATH=path/to/ti-linux-firmware
250 export TFA_PATH=path/to/trusted-firmware-a
251 export OPTEE_PATH=path/to/optee_os
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500252.. k3_rst_include_end_common_env_vars_defn
253
254We will also need some common environment variables set up for the various
255other build sources. we shall use the following, in the build descriptions below:
256
257.. k3_rst_include_start_board_env_vars_desc
258.. list-table:: Board specific environment variables
259 :widths: 25 25 50
260 :header-rows: 1
261
262 * - S/w Component
263 - Env Variable
264 - Description
265 * - U-Boot
266 - UBOOT_CFG_CORTEXR
267 - Defconfig for Cortex-R (Boot processor).
268 * - U-Boot
269 - UBOOT_CFG_CORTEXA
270 - Defconfig for Cortex-A (MPU processor).
271 * - Trusted Firmware-A
272 - TFA_BOARD
273 - Platform name used for building TF-A for Cortex-A Processor.
274 * - Trusted Firmware-A
275 - TFA_EXTRA_ARGS
276 - Any extra arguments used for building TF-A.
277 * - OP-TEE
278 - OPTEE_PLATFORM
279 - Platform name used for building OP-TEE for Cortex-A Processor.
280 * - OP-TEE
281 - OPTEE_EXTRA_ARGS
282 - Any extra arguments used for building OP-TEE.
283.. k3_rst_include_end_board_env_vars_desc
Bryan Brattlof6d138132022-12-19 14:29:50 -0600284
285Building tiboot3.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200286^^^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600287
2881. To generate the U-Boot SPL for the wakeup domain, use the following
289 commands, substituting :code:`{SOC}` for the name of your device (eg:
Neha Malcom Francis507be122023-07-22 00:14:43 +0530290 am62x) to package the various firmware and the wakeup UBoot SPL into
291 the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device
292 uses the split binary flow)
Bryan Brattlof6d138132022-12-19 14:29:50 -0600293
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530294.. _k3_rst_include_start_build_steps_spl_r5:
295
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500296.. k3_rst_include_start_build_steps_spl_r5
Nishanth Menon740c41c2023-11-02 23:40:25 -0500297.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600298
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500299 # inside u-boot source
300 make $UBOOT_CFG_CORTEXR
301 make CROSS_COMPILE=$CC32 BINMAN_INDIRS=$LNX_FW_PATH
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500302.. k3_rst_include_end_build_steps_spl_r5
Bryan Brattlof6d138132022-12-19 14:29:50 -0600303
304At this point you should have all the needed binaries to boot the wakeup
305domain of your K3 SoC.
306
307**Combined Binary Boot Flow** (eg: am62x, am64x, ... )
308
Neha Malcom Francis507be122023-07-22 00:14:43 +0530309 `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600310
311**Split Binary Boot Flow** (eg: j721e, am65x)
312
Neha Malcom Francis507be122023-07-22 00:14:43 +0530313 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
314 | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600315
316.. note ::
317
318 It's important to rename the generated `tiboot3.bin` and `sysfw.itb`
319 to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup
320 UBoot SPL will only look for and load the files with these names.
321
322Building tispl.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200323^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600324
325The `tispl.bin` is a standard fitImage combining the firmware need for
326the main domain to function properly as well as Device Management (DM)
327firmware if your device using a split firmware.
328
Neha Malcom Francis507be122023-07-22 00:14:43 +05303292. We will first need TF-A, as it's the first thing to run on the 'big'
Bryan Brattlof6d138132022-12-19 14:29:50 -0600330 application cores on the main domain.
331
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500332.. k3_rst_include_start_build_steps_tfa
Nishanth Menon740c41c2023-11-02 23:40:25 -0500333.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600334
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500335 # inside trusted-firmware-a source
336 make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS \
337 TARGET_BOARD=$TFA_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500338.. k3_rst_include_end_build_steps_tfa
Bryan Brattlof6d138132022-12-19 14:29:50 -0600339
Neha Malcom Francis507be122023-07-22 00:14:43 +0530340Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500341=j784s4` (if it is a J784S4 device), while typical Sitara (`am6*`) devices
Neha Malcom Francis507be122023-07-22 00:14:43 +0530342use the `lite` option.
Bryan Brattlof6d138132022-12-19 14:29:50 -0600343
Neha Malcom Francis507be122023-07-22 00:14:43 +05303443. The Open Portable Trusted Execution Environment (OP-TEE) is designed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600345 to run as a companion to a non-secure Linux kernel for Cortex-A cores
346 using the TrustZone technology built into the core.
347
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500348.. k3_rst_include_start_build_steps_optee
Nishanth Menon740c41c2023-11-02 23:40:25 -0500349.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600350
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500351 # inside optee_os source
352 make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 CFG_ARM64_core=y $OPTEE_EXTRA_ARGS \
353 PLATFORM=$OPTEE_PLATFORM
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500354.. k3_rst_include_end_build_steps_optee
Bryan Brattlof6d138132022-12-19 14:29:50 -0600355
Neha Malcom Francis507be122023-07-22 00:14:43 +05303564. Finally, after TF-A has initialized the main domain and OP-TEE has
Bryan Brattlof6d138132022-12-19 14:29:50 -0600357 finished, we can jump back into U-Boot again, this time running on a
358 64bit core in the main domain.
359
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530360.. _k3_rst_include_start_build_steps_uboot:
361
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500362.. k3_rst_include_start_build_steps_uboot
Nishanth Menon740c41c2023-11-02 23:40:25 -0500363.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600364
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500365 # inside u-boot source
366 make $UBOOT_CFG_CORTEXA
367 make CROSS_COMPILE=$CC64 BINMAN_INDIRS=$LNX_FW_PATH \
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500368 BL31=$TFA_PATH/build/k3/$TFA_BOARD/release/bl31.bin \
369 TEE=$OPTEE_PATH/out/arm-plat-k3/core/tee-raw.bin
Neha Malcom Francis2b259f02023-12-05 15:12:20 +0530370
371.. note::
372 It is also possible to pick up a custom DM binary by adding TI_DM argument
373 pointing to the file. If not provided, it defaults to picking up the DM
374 binary from BINMAN_INDIRS. This is only applicable to devices that utilize
375 split firmware.
376
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500377.. k3_rst_include_end_build_steps_uboot
Bryan Brattlof6d138132022-12-19 14:29:50 -0600378
379At this point you should have every binary needed initialize both the
380wakeup and main domain and to boot to the U-Boot prompt
381
382**Main Domain Bootloader**
383
Neha Malcom Francis507be122023-07-22 00:14:43 +0530384 | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices
385 | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530386
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530387FIT signature signing
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530388---------------------
389
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530390K3 platforms have FIT signature signing enabled by default on their primary
391platforms. Here we'll take an example for creating FIT Image for J721E platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530392and the same can be extended to other platforms
393
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530394Pre-requisites:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530395
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530396* U-boot build (:ref:`U-boot build <k3_rst_include_start_build_steps_spl_r5>`)
397* Linux Image and Linux DTB prebuilt
398
399Describing FIT source
400^^^^^^^^^^^^^^^^^^^^^
401
402FIT Image is a packed structure containing binary blobs and configurations.
403The Kernel FIT Image that we have has Kernel Image, DTB and the DTBOs. It
404supports packing multiple images and configurations that allow you to
405choose any configuration at runtime to boot from.
406
407.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530408
409 /dts-v1/;
410
411 / {
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530412 description = "FIT Image description";
413 #address-cells = <1>;
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530414
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530415 images {
416 [image-1]
417 [image-2]
418 [fdt-1]
419 [fdt-2]
420 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530421
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530422 configurations {
423 default = <conf-1>
424 [conf-1: image-1,fdt-1]
425 [conf-2: image-2,fdt-1]
426 }
427 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530428
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530429* Sample Images
430
431.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530432
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530433 kernel-1 {
434 description = "Linux kernel";
435 data = /incbin/("linux.bin");
436 type = "kernel";
437 arch = "arm64";
438 os = "linux";
439 compression = "gzip";
440 load = <0x81000000>;
441 entry = <0x81000000>;
442 hash-1 {
443 algo = "sha512";
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530444 };
445 };
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530446 fdt-ti_k3-j721e-common-proc-board.dtb {
447 description = "Flattened Device Tree blob";
448 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dtb");
449 type = "flat_dt";
450 arch = "arm64";
451 compression = "none";
452 load = <0x83000000>;
453 hash-1 {
454 algo = "sha512";
455 };
456 };
457 # Optional images
458 fdt-ti_k3-j721e-evm-virt-mac-client.dtbo {
459 description = "Flattened Device Tree blob";
460 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-evm-virt-mac-client.dtbo");
461 type = "flat_dt";
462 arch = "arm64";
463 compression = "none";
464 load = <0x83080000>;
465 hash-1 {
466 algo = "sha512";
467 };
468 };
469
470.. note::
471
472 Change the path in data variables to point to the respective files in your
473 local machine. For e.g change "linux.bin" to "<path-to-kernel-image>".
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530474
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530475For enabling usage of FIT signature, add the signature node to the
476corresponding configuration node as follows.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530477
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530478* Sample Configurations
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530479
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530480.. code-block::
481
482 conf-ti_k3-j721e-common-proc-board.dtb {
483 description = "Linux kernel, FDT blob";
484 fdt = "fdt-ti_k3-j721e-common-proc-board.dtb";
485 kernel = "kernel-1";
486 signature-1 {
487 algo = "sha512,rsa4096";
488 key-name-hint = "custMpk";
489 sign-images = "kernel", "fdt";
490 };
491 };
492 # Optional configurations
493 conf-ti_k3-j721e-evm-virt-mac-client.dtbo {
494 description = "FDTO blob";
495 fdt = "fdt-ti_k3-j721e-evm-virt-mac-client.dtbo";
496
497 signature-1 {
498 algo = "sha512,rsa4096";
499 key-name-hint = "custMpk";
500 sign-images = "fdt";
501 };
502 };
503
504Specify all images you need the signature to authenticate as a part of
505sign-images. The key-name-hint needs to be changed if you are using some
506other key other than the TI dummy key that we are using for this example.
507It should be the name of the file containing the keys.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530508
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500509.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530510
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530511 Generating new set of keys:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530512
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530513 .. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530514
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530515 mkdir keys
516 openssl genpkey -algorithm RSA -out keys/dev.key \
517 -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:65537
518 openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530519
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530520Generating the fitImage
521^^^^^^^^^^^^^^^^^^^^^^^
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530522
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530523.. note::
524
525 For signing a secondary platform like SK boards, you'll require
526 additional steps
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530527
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530528 - Change the CONFIG_DEFAULT_DEVICE_TREE
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530529
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530530 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530531
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530532 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530533
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530534 diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig
535 index a5c1df7e0054..6d0126d955ef 100644
536 --- a/configs/j721e_evm_a72_defconfig
537 +++ b/configs/j721e_evm_a72_defconfig
538 @@ -13,7 +13,7 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80480000
539 CONFIG_ENV_SIZE=0x20000
540 CONFIG_DM_GPIO=y
541 CONFIG_SPL_DM_SPI=y
542 -CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
543 +CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-sk"
544 CONFIG_SPL_TEXT_BASE=0x80080000
545 CONFIG_DM_RESET=y
546 CONFIG_SPL_MMC=y
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530547
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530548 - Change the binman nodes to package u-boot.dtb for the correct set of platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530549
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530550 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530551
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530552 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530553
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530554 diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi
555 index 673be646b1e3..752fa805fe8d 100644
556 --- a/arch/arm/dts/k3-j721e-binman.dtsi
557 +++ b/arch/arm/dts/k3-j721e-binman.dtsi
558 @@ -299,8 +299,8 @@
559 #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530560
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530561 #define UBOOT_NODTB "u-boot-nodtb.bin"
562 -#define J721E_EVM_DTB "u-boot.dtb"
563 -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb"
564 +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb"
565 +#define J721E_SK_DTB "u-boot.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530566
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530567This step will embed the public key in the u-boot.dtb file that was already
568built during the initial u-boot build.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530569
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530570.. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530571
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530572 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 +0530573
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530574.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530575
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530576 If you have another set of keys then change the -k argument to point to
577 the folder where your keys are present, the build requires the presence
578 of both .key and .crt file.
579
580Build u-boot again
581^^^^^^^^^^^^^^^^^^
582
583The updated u-boot.dtb needs to be packed in u-boot.img for authentication
584so rebuild U-boot ARMV8 without changing any parameters.
585Refer (:ref:`U-boot ARMV8 build <k3_rst_include_start_build_steps_uboot>`)
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530586
587.. note::
588
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530589 The devices now also have distroboot enabled so if the FIT image doesn't
590 work then the fallback to normal distroboot will be there on HS devices.
591 This will need to be explicitly disabled by changing the boot_targets to
592 disallow fallback during testing.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530593
594Saving environment
595------------------
596
597SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default
598way for saving the environments. This has been done as Uenv.txt is more granular
599then the saveenv command and can be used across various bootmodes too.
600
601**Writing to MMC/EMMC**
602
Nishanth Menon740c41c2023-11-02 23:40:25 -0500603.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530604
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500605 env export -t $loadaddr <list of variables>
606 fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize}
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530607
608**Reading from MMC/EMMC**
609
610By default run envboot will read it from the MMC/EMMC partition ( based on
611mmcdev) and set the environments.
612
613If manually needs to be done then the environment can be read from the
614filesystem and then imported
615
Nishanth Menon740c41c2023-11-02 23:40:25 -0500616.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530617
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500618 fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile}
619 env import -t ${loadaddr} ${filesize}
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500620
621.. _k3_rst_refer_openocd:
622
623Common Debugging environment - OpenOCD
624--------------------------------------
625
626This section will show you how to connect a board to `OpenOCD
627<https://openocd.org/>`_ and load the SPL symbols for debugging with
628a K3 generation device. To follow this guide, you must build custom
629u-boot binaries, start your board from a boot media such as an SD
630card, and use an OpenOCD environment. This section uses generic
631examples, though you can apply these instructions to any supported K3
632generation device.
633
634The overall structure of this setup is in the following figure.
635
636.. image:: img/openocd-overview.svg
Nishanth Menon5746e032023-08-22 11:40:56 -0500637 :alt: Overview of OpenOCD setup.
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500638
639.. note::
640
641 If you find these instructions useful, please consider `donating
642 <https://openocd.org/pages/donations.html>`_ to OpenOCD.
643
644Step 1: Download and install OpenOCD
645^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
646
647To get started, it is more convenient if the distribution you
648use supports OpenOCD by default. Follow the instructions in the
649`getting OpenOCD <https://openocd.org/pages/getting-openocd.html>`_
650documentation to pick the installation steps appropriate to your
651environment. Some references to OpenOCD documentation:
652
653* `OpenOCD User Guide <https://openocd.org/doc/html/index.html>`_
654* `OpenOCD Developer's Guide <https://openocd.org/doc/doxygen/html/index.html>`_
655
656Refer to the release notes corresponding to the `OpenOCD version
657<https://github.com/openocd-org/openocd/releases>`_ to ensure
658
659* Processor support: In general, processor support shouldn't present
660 any difficulties since OpenOCD provides solid support for both ARMv8
661 and ARMv7.
662* SoC support: When working with System-on-a-Chip (SoC), the support
663 usually comes as a TCL config file. It is vital to ensure the correct
664 version of OpenOCD or to use the TCL files from the latest release or
665 the one mentioned.
666* Board or the JTAG adapter support: In most cases, board support is
667 a relatively easy problem if the board has a JTAG pin header. All
668 you need to do is ensure that the adapter you select is compatible
669 with OpenOCD. Some boards come with an onboard JTAG adapter that
670 requires a USB cable to be plugged into the board, in which case, it
671 is vital to ensure that the JTAG adapter is supported. Fortunately,
672 almost all TI K3 SK/EVMs come with TI's XDS110, which has out of the
673 box support by OpenOCD. The board-specific documentation will
674 cover the details and any adapter/dongle recommendations.
675
Nishanth Menon740c41c2023-11-02 23:40:25 -0500676.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500677
678 openocd -v
679
680.. note::
681
682 OpenOCD version 0.12.0 is usually required to connect to most K3
683 devices. If your device is only supported by a newer version than the
684 one provided by your distribution, you may need to build it from the source.
685
686Building OpenOCD from source
687""""""""""""""""""""""""""""
688
689The dependency package installation instructions below are for Debian
690systems, but equivalent instructions should exist for systems with
691other package managers. Please refer to the `OpenOCD Documentation
692<https://openocd.org/>`_ for more recent installation steps.
693
Nishanth Menon740c41c2023-11-02 23:40:25 -0500694.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500695
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500696 # Check the packages to be installed: needs deb-src in sources.list
697 sudo apt build-dep openocd
698 # The following list is NOT complete - please check the latest
699 sudo apt-get install libtool pkg-config texinfo libusb-dev \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500700 libusb-1.0.0-dev libftdi-dev libhidapi-dev autoconf automake
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500701 git clone https://github.com/openocd-org/openocd.git openocd
702 cd openocd
703 git submodule init
704 git submodule update
705 ./bootstrap
706 ./configure --prefix=/usr/local/
707 make -j`nproc`
708 sudo make install
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500709
710.. note::
711
712 The example above uses the GitHub mirror site. See
713 `git repo information <https://openocd.org/doc/html/Developers.html#OpenOCD-Git-Repository>`_
714 information to pick the official git repo.
715 If a specific version is desired, select the version using `git checkout tag`.
716
717Installing OpenOCD udev rules
718"""""""""""""""""""""""""""""
719
720The step is not necessary if the distribution supports the OpenOCD, but
721if building from a source, ensure that the udev rules are installed
722correctly to ensure a sane system.
723
Nishanth Menon740c41c2023-11-02 23:40:25 -0500724.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500725
726 # Go to the OpenOCD source directory
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500727 cd openocd
728 Copy the udev rules to the correct system location
729 sudo cp ./contrib/60-openocd.rules \
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500730 ./src/jtag/drivers/libjaylink/contrib/99-libjaylink.rules \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500731 /etc/udev/rules.d/
732 # Get Udev to load the new rules up
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500733 sudo udevadm control --reload-rules
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500734 # Use the new rules on existing connected devices
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500735 sudo udevadm trigger
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500736
737Step 2: Setup GDB
738^^^^^^^^^^^^^^^^^
739
740Most systems come with gdb-multiarch package.
741
Nishanth Menon740c41c2023-11-02 23:40:25 -0500742.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500743
744 # Install gdb-multiarch package
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500745 sudo apt-get install gdb-multiarch
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500746
747Though using GDB natively is normal, developers with interest in using IDE
748may find a few of these interesting:
749
750* `gdb-dashboard <https://github.com/cyrus-and/gdb-dashboard>`_
751* `gef <https://github.com/hugsy/gef>`_
752* `peda <https://github.com/longld/peda>`_
753* `pwndbg <https://github.com/pwndbg/pwndbg>`_
754* `voltron <https://github.com/snare/voltron>`_
755* `ddd <https://www.gnu.org/software/ddd/>`_
756* `vscode <https://www.justinmklam.com/posts/2017/10/vscode-debugger-setup/>`_
757* `vim conque-gdb <https://github.com/vim-scripts/Conque-GDB>`_
758* `emacs realgud <https://github.com/realgud/realgud/wiki/gdb-notes>`_
759* `Lauterbach IDE <https://www2.lauterbach.com/pdf/backend_gdb.pdf>`_
760
761.. warning::
762 LLDB support for OpenOCD is still a work in progress as of this writing.
763 Using GDB is probably the safest option at this point in time.
764
765Step 3: Connect board to PC
766^^^^^^^^^^^^^^^^^^^^^^^^^^^
767There are few patterns of boards in the ecosystem
768
769.. k3_rst_include_start_openocd_connect_XDS110
770
771**Integrated JTAG adapter/dongle**: The board has a micro-USB connector labelled
772XDS110 USB or JTAG. Connect a USB cable to the board to the mentioned port.
773
774.. note::
775
776 There are multiple USB ports on a typical board, So, ensure you have read
777 the user guide for the board and confirmed the silk screen label to ensure
778 connecting to the correct port.
779
780.. k3_rst_include_end_openocd_connect_XDS110
781
782.. k3_rst_include_start_openocd_connect_cti20
783
784**cTI20 connector**: The TI's `cTI20
785<https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_JTAG_connectors.html#cti-20-pin-header-information>`_ connector
786is probably the most prevelant on TI platforms. Though many
787TI boards have an onboard XDS110, cTI20 connector is usually
788provided as an alternate scheme to connect alternatives such
789as `Lauterbach <https://www.lauterbach.com/>`_ or `XDS560
790<https://www.ti.com/tool/TMDSEMU560V2STM-U>`_.
791
792To debug on these boards, the following combinations is suggested:
793
794* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
795 or `equivalent dongles supported by OpenOCD. <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_
796* Cable such as `Tag-connect ribbon cable <https://www.tag-connect.com/product/20-pin-cortex-ribbon-cable-4-length-with-50-mil-connectors>`_
797* Adapter to convert cTI20 to ARM20 such as those from
798 `Segger <https://www.segger.com/products/debug-probes/j-link/accessories/adapters/ti-cti-20-adapter/>`_
799 or `Lauterbach LA-3780 <https://www.lauterbach.com/ad3780.html>`_
800 Or optionally, if you have manufacturing capability then you could try
801 `BeagleBone JTAG Adapter <https://github.com/mmorawiec/BeagleBone-Black-JTAG-Adapters>`_
802
803.. warning::
804 XDS560 and Lauterbach are proprietary solutions and is not supported by
805 OpenOCD.
806 When purchasing an off the shelf adapter/dongle, you do want to be careful
807 about the signalling though. Please
808 `read for additional info <https://software-dl.ti.com/ccs/esd/xdsdebugprobes/emu_JTAG_connectors.html>`_.
809
810.. k3_rst_include_end_openocd_connect_cti20
811
812.. k3_rst_include_start_openocd_connect_tag_connect
813
814**Tag-Connect**: `Tag-Connect <https://www.tag-connect.com/>`_
815pads on the boards which require special cable. Please check the documentation
816to `identify <https://www.tag-connect.com/info/legs-or-no-legs>`_ if "legged"
817or "no-leg" version of the cable is appropriate for the board.
818
819To debug on these boards, you will need:
820
821* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
822 or `equivalent dongles supported by OpenOCD <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_.
823* Tag-Connect cable appropriate to the board such as
824 `TC2050-IDC-NL <https://www.tag-connect.com/product/TC2050-IDC-NL-10-pin-no-legs-cable-with-ribbon-connector>`_
825* In case of no-leg, version, a
826 `retaining clip <https://www.tag-connect.com/product/tc2050-clip-3pack-retaining-clip>`_
827* Tag-Connect to ARM20
828 `adapter <https://www.tag-connect.com/product/tc2050-arm2010-arm-20-pin-to-tc2050-adapter>`_
829
830.. note::
831 You can optionally use a 3d printed solution such as
832 `Protective cap <https://www.thingiverse.com/thing:3025584>`_ or
833 `clip <https://www.thingiverse.com/thing:3035278>`_ to replace
834 the retaining clip.
835
836.. warning::
837 With the Tag-Connect to ARM20 adapter, Please solder the "Trst" signal for
838 connection to work.
839
840.. k3_rst_include_end_openocd_connect_tag_connect
841
842Debugging with OpenOCD
843^^^^^^^^^^^^^^^^^^^^^^
844
845Debugging U-Boot is different from debugging regular user space
846applications. The bootloader initialization process involves many boot
847media and hardware configuration operations. For K3 devices, there
848are also interactions with security firmware. While reloading the
849"elf" file works through GDB, developers must be mindful of cascading
850initialization's potential consequences.
851
852Consider the following code change:
853
854.. code-block:: diff
855
856 --- a/file.c 2023-07-29 10:55:29.647928811 -0500
857 +++ b/file.c 2023-07-29 10:55:46.091856816 -0500
858 @@ -1,3 +1,3 @@
859 val = readl(reg);
860 -val |= 0x2;
861 +val |= 0x1;
862 writel(val, reg);
863
864Re-running the elf file with the above change will result in the
865register setting 0x3 instead of the intended 0x1. There are other
866hardware blocks which may not behave very well with a re-initialization
867without proper shutdown.
868
869To help narrow the debug down, it is usually simpler to use the
870standard boot media to get to the bootloader and debug only in the area
871of interest.
872
873In general, to debug u-boot spl/u-boot with OpenOCD there are three steps:
874
875* Modify the code adding a loop to allow the debugger to attach
876 near the point of interest. Boot up normally to stop at the loop.
877* Connect with OpenOCD and step out of the loop.
878* Step through the code to find the root of issue.
879
880Typical debugging involves a few iterations of the above sequence.
881Though most bootloader developers like to use printf to debug,
882debug with JTAG tends to be most efficient since it is possible to
883investigate the code flow and inspect hardware registers without
884repeated iterations.
885
886Code modification
887"""""""""""""""""
888
889* **start.S**: Adding an infinite while loop at the very entry of
890 U-Boot. For this, look for the corresponding start.S entry file.
891 This is usually only required when debugging some core SoC or
892 processor related function. For example: arch/arm/cpu/armv8/start.S or
893 arch/arm/cpu/armv7/start.S
894
895.. code-block:: diff
896
897 diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
898 index 69e281b086..744929e825 100644
899 --- a/arch/arm/cpu/armv7/start.S
900 +++ b/arch/arm/cpu/armv7/start.S
901 @@ -37,6 +37,8 @@
902 #endif
903
904 reset:
905 +dead_loop:
906 + b dead_loop
907 /* Allow the board to save important registers */
908 b save_boot_params
909 save_boot_params_ret:
910
911* **board_init_f**: Adding an infinite while loop at the board entry
912 function. In many cases, it is important to debug the boot process if
913 any changes are made for board-specific applications. Below is a step
914 by step process for debugging the boot SPL or Armv8 SPL:
915
916 To debug the boot process in either domain, we will first
917 add a modification to the code we would like to debug.
918 In this example, we will debug ``board_init_f`` inside
919 ``arch/arm/mach-k3/{soc}_init.c``. Since some sections of U-Boot
920 will be executed multiple times during the bootup process of K3
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500921 devices, we will need to include either ``CONFIG_ARM64`` or
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500922 ``CONFIG_CPU_V7R`` to catch the CPU at the desired place during the
923 bootup process (Main or Wakeup domains). For example, modify the
924 file as follows (depending on need):
925
926.. code-block:: c
927
928 void board_init_f(ulong dummy)
929 {
930 .
931 .
932 /* Code to run on the R5F (Wakeup/Boot Domain) */
933 if (IS_ENABLED(CONFIG_CPU_V7R)) {
934 volatile int x = 1;
935 while(x) {};
936 }
937 ...
938 /* Code to run on the ARMV8 (Main Domain) */
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500939 if (IS_ENABLED(CONFIG_ARM64)) {
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500940 volatile int x = 1;
941 while(x) {};
942 }
943 .
944 .
945 }
946
947Connecting with OpenOCD for a debug session
948"""""""""""""""""""""""""""""""""""""""""""
949
950Startup OpenOCD to debug the platform as follows:
951
952* **Integrated JTAG interface**: If the evm has a debugger such as
953 XDS110 inbuilt, there is typically an evm board support added and a
954 cfg file will be available.
955
956.. k3_rst_include_start_openocd_cfg_XDS110
957
Nishanth Menon740c41c2023-11-02 23:40:25 -0500958.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500959
960 openocd -f board/{board_of_choice}.cfg
961
962.. k3_rst_include_end_openocd_cfg_XDS110
963
964.. k3_rst_include_start_openocd_cfg_external_intro
965
966* **External JTAG adapter/interface**: In other cases, where an
967 adapter/dongle is used, a simple cfg file can be created to integrate the
968 SoC and adapter information. See `supported TI K3 SoCs
969 <https://github.com/openocd-org/openocd/blob/master/tcl/target/ti_k3.cfg#L59>`_
970 to decide if the SoC is supported or not.
971
Nishanth Menon740c41c2023-11-02 23:40:25 -0500972.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500973
974 openocd -f openocd_connect.cfg
975
976.. k3_rst_include_end_openocd_cfg_external_intro
977
978 For example, with BeaglePlay (AM62X platform), the openocd_connect.cfg:
979
980.. code-block:: tcl
981
982 # TUMPA example:
983 # http://www.tiaowiki.com/w/TIAO_USB_Multi_Protocol_Adapter_User's_Manual
984 source [find interface/ftdi/tumpa.cfg]
985
986 transport select jtag
987
988 # default JTAG configuration has only SRST and no TRST
989 reset_config srst_only srst_push_pull
990
991 # delay after SRST goes inactive
992 adapter srst delay 20
993
994 if { ![info exists SOC] } {
995 # Set the SoC of interest
996 set SOC am625
997 }
998
999 source [find target/ti_k3.cfg]
1000
1001 ftdi tdo_sample_edge falling
1002
1003 # Speeds for FT2232H are in multiples of 2, and 32MHz is tops
1004 # max speed we seem to achieve is ~20MHz.. so we pick 16MHz
1005 adapter speed 16000
1006
1007Below is an example of the output of this command:
1008
1009.. code-block:: console
1010
1011 Info : Listening on port 6666 for tcl connections
1012 Info : Listening on port 4444 for telnet connections
1013 Info : XDS110: connected
1014 Info : XDS110: vid/pid = 0451/bef3
1015 Info : XDS110: firmware version = 3.0.0.20
1016 Info : XDS110: hardware version = 0x002f
1017 Info : XDS110: connected to target via JTAG
1018 Info : XDS110: TCK set to 2500 kHz
1019 Info : clock speed 2500 kHz
1020 Info : JTAG tap: am625.cpu tap/device found: 0x0bb7e02f (mfg: 0x017 (Texas Instruments), part: 0xbb7e, ver: 0x0)
1021 Info : starting gdb server for am625.cpu.sysctrl on 3333
1022 Info : Listening on port 3333 for gdb connections
1023 Info : starting gdb server for am625.cpu.a53.0 on 3334
1024 Info : Listening on port 3334 for gdb connections
1025 Info : starting gdb server for am625.cpu.a53.1 on 3335
1026 Info : Listening on port 3335 for gdb connections
1027 Info : starting gdb server for am625.cpu.a53.2 on 3336
1028 Info : Listening on port 3336 for gdb connections
1029 Info : starting gdb server for am625.cpu.a53.3 on 3337
1030 Info : Listening on port 3337 for gdb connections
1031 Info : starting gdb server for am625.cpu.main0_r5.0 on 3338
1032 Info : Listening on port 3338 for gdb connections
1033 Info : starting gdb server for am625.cpu.gp_mcu on 3339
1034 Info : Listening on port 3339 for gdb connections
1035
1036.. note::
1037 Notice the default configuration is non-SMP configuration allowing
1038 for each of the core to be attached and debugged simultaneously.
1039 ARMv8 SPL/U-Boot starts up on cpu0 of a53/a72.
1040
1041.. k3_rst_include_start_openocd_cfg_external_gdb
1042
1043To debug using this server, use GDB directly or your preferred
1044GDB-based IDE. To start up GDB in the terminal, run the following
1045command.
1046
Nishanth Menon740c41c2023-11-02 23:40:25 -05001047.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001048
1049 gdb-multiarch
1050
1051To connect to your desired core, run the following command within GDB:
1052
Nishanth Menon740c41c2023-11-02 23:40:25 -05001053.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001054
1055 target extended-remote localhost:{port for desired core}
1056
1057To load symbols:
1058
1059.. warning::
1060
1061 SPL and U-Boot does a re-location of address compared to where it
1062 is loaded originally. This step takes place after the DDR size is
1063 determined from dt parsing. So, debugging can be split into either
1064 "before re-location" or "after re-location". Please refer to the
1065 file ''doc/README.arm-relocation'' to see how to grab the relocation
1066 address.
1067
1068* Prior to relocation:
1069
Nishanth Menon740c41c2023-11-02 23:40:25 -05001070.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001071
1072 symbol-file {path to elf file}
1073
1074* After relocation:
1075
Nishanth Menon740c41c2023-11-02 23:40:25 -05001076.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001077
1078 # Drop old symbol file
1079 symbol-file
1080 # Pick up new relocaddr
1081 add-symbol-file {path to elf file} {relocaddr}
1082
1083.. k3_rst_include_end_openocd_cfg_external_gdb
1084
1085In the above example of AM625,
1086
Nishanth Menon740c41c2023-11-02 23:40:25 -05001087.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001088
1089 target extended-remote localhost:3338 <- R5F (Wakeup Domain)
1090 target extended-remote localhost:3334 <- A53 (Main Domain)
1091
1092The core can now be debugged directly within GDB using GDB commands or
1093if using IDE, as appropriate to the IDE.
1094
1095Stepping through the code
1096"""""""""""""""""""""""""
1097
1098`GDB TUI Commands
1099<https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html>`_ can
1100help set up the display more sensible for debug. Provide the name
1101of the layout that can be used to debug. For example, use the GDB
1102command ``layout src`` after loading the symbols to see the code and
1103breakpoints. To exit the debug loop added above, add any breakpoints
1104needed and run the following GDB commands to step out of the debug
1105loop set in the ``board_init_f`` function.
1106
Nishanth Menon740c41c2023-11-02 23:40:25 -05001107.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001108
1109 set x = 0
1110 continue
1111
1112The platform has now been successfully setup to debug with OpenOCD
1113using GDB commands or a GDB-based IDE. See `OpenOCD documentation for
1114GDB <https://openocd.org/doc/html/GDB-and-OpenOCD.html>`_ for further
1115information.
1116
1117.. warning::
1118
1119 On the K3 family of devices, a watchdog timer within the DMSC is
1120 enabled by default by the ROM bootcode with a timeout of 3 minutes.
1121 The watchdog timer is serviced by System Firmware (SYSFW) or TI
1122 Foundational Security (TIFS) during normal operation. If debugging
1123 the SPL before the SYSFW is loaded, the watchdog timer will not get
1124 serviced automatically and the debug session will reset after 3
1125 minutes. It is recommended to start debugging SPL code only after
1126 the startup of SYSFW to avoid running into the watchdog timer reset.
1127
1128Miscellaneous notes with OpenOCD
1129^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1130
1131Currently, OpenOCD does not support tracing for K3 platforms. Tracing
1132function could be beneficial if the bug in code occurs deep within
1133nested function and can optionally save developers major trouble of
1134stepping through a large quantity of code.