blob: 927f3976d34827ac7068afe30da3c006a325a2fa [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
Wadim Egorov12722a42023-12-20 10:18:11 +010036 ../phytec/phycore-am62x
Marcel Ziswiler315deb32023-08-04 12:08:08 +020037 ../toradex/verdin-am62
Bryan Brattlofcf2e2b12024-03-12 15:20:30 -050038 am62px_sk
Roger Quadroscd87b1e2023-08-05 11:14:39 +030039 am64x_evm
Neha Malcom Francis507be122023-07-22 00:14:43 +053040 am65x_evm
Nishanth Menone83fe672023-07-27 13:59:01 -050041 j7200_evm
Nishanth Menon756b8782023-11-04 03:11:03 -050042 ../beagle/j721e_beagleboneai64
Nishanth Menone83fe672023-07-27 13:59:01 -050043 j721e_evm
Manorit Chawdhry670a22b2023-10-06 10:16:00 +053044 j721s2_evm
Apurva Nandan2b1c9ff2024-02-24 01:51:53 +053045 j784s4_evm
Bryan Brattlof6d138132022-12-19 14:29:50 -060046
47Boot Flow Overview
48------------------
49
50For all K3 SoCs the first core started will be inside the Security
51Management Subsystem (SMS) which will secure the device and start a core
52in the wakeup domain to run the ROM code. ROM will then initialize the
53boot media needed to load the binaries packaged inside `tiboot3.bin`,
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050054including a 32bit U-Boot SPL, (called the wakeup SPL) that ROM will jump
Bryan Brattlof6d138132022-12-19 14:29:50 -060055to after it has finished loading everything into internal SRAM.
56
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050057.. image:: img/boot_flow_01.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050058 :alt: Boot flow up to wakeup domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060059
60The wakeup SPL, running on a wakeup domain core, will initialize DDR and
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050061any peripherals needed to load the larger binaries inside the `tispl.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -060062into DDR. Once loaded the wakeup SPL will start one of the 'big'
63application cores inside the main domain to initialize the main domain,
Neha Malcom Francis507be122023-07-22 00:14:43 +053064starting with Trusted Firmware-A (TF-A), before moving on to start
65OP-TEE and the main domain's U-Boot SPL.
Bryan Brattlof6d138132022-12-19 14:29:50 -060066
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050067.. image:: img/boot_flow_02.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050068 :alt: Boot flow up to main domain SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060069
70The main domain's SPL, running on a 64bit application core, has
71virtually unlimited space (billions of bytes now that DDR is working) to
72initialize even more peripherals needed to load in the `u-boot.img`
73which loads more firmware into the micro-controller & wakeup domains and
74finally prepare the main domain to run Linux.
75
Nishanth Menon7bdb2d52023-07-27 13:59:02 -050076.. image:: img/boot_flow_03.svg
Heinrich Schuchardtd0894b22023-08-22 11:40:55 -050077 :alt: Complete boot flow up to Linux
Bryan Brattlof6d138132022-12-19 14:29:50 -060078
79This is the typical boot flow for all K3 based SoCs, however this flow
80offers quite a lot in the terms of flexibility, especially on High
81Security (HS) SoCs.
82
83Boot Flow Variations
84^^^^^^^^^^^^^^^^^^^^
85
86All K3 SoCs will generally use the above boot flow with two main
87differences depending on the capabilities of the boot ROM and the number
88of cores inside the device. These differences split the bootflow into
89essentially 4 unique but very similar flows:
90
91* Split binary with a combined firmware: (eg: AM65)
92* Combined binary with a combined firmware: (eg: AM64)
93* Split binary with a split firmware: (eg: J721E)
94* Combined binary with a split firmware: (eg: AM62)
95
96For devices that utilize the split binary approach, ROM is not capable
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -050097of loading the firmware into the SoC, requiring the wakeup domain's
Bryan Brattlof6d138132022-12-19 14:29:50 -060098U-Boot SPL to load the firmware.
99
100Devices with a split firmware will have two firmwares loaded into the
101device at different times during the bootup process. TI's Foundational
102Security (TIFS), needed to operate the Security Management Subsystem,
103will either be loaded by ROM or the WKUP U-Boot SPL, then once the
104wakeup U-Boot SPL has completed, the second Device Management (DM)
105firmware can be loaded on the now free core in the wakeup domain.
106
107For more information on the bootup process of your SoC, consult the
108device specific boot flow documentation.
109
Manorit Chawdhry98346472023-12-29 16:16:33 +0530110Secure Boot
111-----------
112
113K3 HS-SE (High Security - Security Enforced) devices enforce an
114authenticated boot flow for secure boot. HS-FS (High Security - Field
115Securable) is the state of a K3 device before it has been eFused with
116customer security keys. In the HS-FS state the authentication still can
Jonathan Humphreys97fa76a2024-06-14 11:35:29 -0500117function as in HS-SE, but as there are no customer keys to verify the
118signatures against, the authentication will pass for certificates signed
Manorit Chawdhry98346472023-12-29 16:16:33 +0530119with any key.
120
121Chain of trust
122^^^^^^^^^^^^^^
123
1241) Public ROM loads the tiboot3.bin (R5 SPL, TIFS)
1252) R5 SPL loads tispl.bin (ATF, OP-TEE, DM, SPL)
1263) SPL loads u-boot.img (U-Boot)
1274) U-Boot loads fitImage (Linux and DTBs)
128
129Steps 1-3 are all authenticated by either the Secure ROM or TIFS as the
130authenticating entity and step 4 uses U-boot standard mechanism for
131authenticating.
132
133All the authentication that are done for ROM/TIFS are done through x509
134certificates that are signed.
135
136Firewalls
137^^^^^^^^^
138
1391) Secure ROM comes up and sets up firewalls that are needed by itself
1402) TIFS will setup it's own firewalls to protect core system resources
1413) R5 SPL will remove any firewalls that are leftover from the Secure ROM stage
142 that are no longer required.
1434) Each stage beyond this: such as tispl.bin containing TFA/OPTEE uses OIDs to
144 set up firewalls to protect themselves (enforced by TIFS)
1455) TFA/OP-TEE can configure other firewalls at runtime if required as they
146 are already authenticated and firewalled off from illegal access.
1476) All later stages can setup or remove firewalls that have not been already
148 configured by previous stages, such as those created by TIFS, TFA, and OP-TEE.
149
150Futhur, firewalls have a lockdown bit in hardware that enforces the setting
151(and cannot be over-ridden) until the full system is reset.
152
Bryan Brattlof6d138132022-12-19 14:29:50 -0600153Software Sources
154----------------
155
156All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and
157`u-boot.img` for all K3 SoCs can be located at the following places
158online
159
Nishanth Menonee91e482023-07-27 13:58:44 -0500160.. k3_rst_include_start_boot_sources
161
Bryan Brattlof6d138132022-12-19 14:29:50 -0600162* **Das U-Boot**
163
164 | **source:** https://source.denx.de/u-boot/u-boot.git
165 | **branch:** master
166
Neha Malcom Francis507be122023-07-22 00:14:43 +0530167* **Trusted Firmware-A (TF-A)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600168
Neha Malcom Francis507be122023-07-22 00:14:43 +0530169 | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Bryan Brattlof6d138132022-12-19 14:29:50 -0600170 | **branch:** master
171
Neha Malcom Francis507be122023-07-22 00:14:43 +0530172* **Open Portable Trusted Execution Environment (OP-TEE)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600173
174 | **source:** https://github.com/OP-TEE/optee_os.git
175 | **branch:** master
176
Nishanth Menone2a47452023-08-22 11:41:07 -0500177* **TI Firmware (TIFS, DM, SYSFW)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600178
179 | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git
180 | **branch:** ti-linux-firmware
181
Nishanth Menone2a47452023-08-22 11:41:07 -0500182.. note::
183
184 The TI Firmware required for functionality of the system can be
185 one of the following combination (see platform specific boot diagram for
186 further information as to which component runs on which processor):
187
188 * **TIFS** - TI Foundational Security Firmware - Consists of purely firmware
189 meant to run on the security enclave.
190 * **DM** - Device Management firmware also called TI System Control Interface
191 server (TISCI Server) - This component purely plays the role of managing
192 device resources such as power, clock, interrupts, dma etc. This firmware
193 runs on a dedicated or multi-use microcontroller outside the security
194 enclave.
195
196 OR
197
198 * **SYSFW** - System firmware - consists of both TIFS and DM both running on
199 the security enclave.
200
Nishanth Menonee91e482023-07-27 13:58:44 -0500201.. k3_rst_include_end_boot_sources
202
Bryan Brattlof6d138132022-12-19 14:29:50 -0600203Build Procedure
204---------------
205
206Depending on the specifics of your device, you will need three or more
207binaries to boot your SoC.
208
209* `tiboot3.bin` (bootloader for the wakeup domain)
210* `tispl.bin` (bootloader for the main domain)
211* `u-boot.img`
212
213During the bootup process, both the 32bit wakeup domain and the 64bit
214main domains will be involved. This means everything inside the
215`tiboot3.bin` running in the wakeup domain will need to be compiled for
21632bit cores and most binaries in the `tispl.bin` will need to be
217compiled for 64bit main domain CPU cores.
218
219All of that to say you will need both a 32bit and 64bit cross compiler
220(assuming you're using an x86 desktop)
221
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500222.. k3_rst_include_start_common_env_vars_desc
223.. list-table:: Generic environment variables
224 :widths: 25 25 50
225 :header-rows: 1
226
227 * - S/w Component
228 - Env Variable
229 - Description
230 * - All Software
231 - CC32
232 - Cross compiler for ARMv7 (ARM 32bit), typically arm-linux-gnueabihf-
233 * - All Software
234 - CC64
235 - Cross compiler for ARMv8 (ARM 64bit), typically aarch64-linux-gnu-
236 * - All Software
237 - LNX_FW_PATH
238 - Path to TI Linux firmware repository
239 * - All Software
240 - TFA_PATH
241 - Path to source of Trusted Firmware-A
242 * - All Software
243 - OPTEE_PATH
244 - Path to source of OP-TEE
245.. k3_rst_include_end_common_env_vars_desc
246
247.. k3_rst_include_start_common_env_vars_defn
Nishanth Menon740c41c2023-11-02 23:40:25 -0500248.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600249
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500250 export CC32=arm-linux-gnueabihf-
251 export CC64=aarch64-linux-gnu-
252 export LNX_FW_PATH=path/to/ti-linux-firmware
253 export TFA_PATH=path/to/trusted-firmware-a
254 export OPTEE_PATH=path/to/optee_os
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500255.. k3_rst_include_end_common_env_vars_defn
256
257We will also need some common environment variables set up for the various
258other build sources. we shall use the following, in the build descriptions below:
259
260.. k3_rst_include_start_board_env_vars_desc
261.. list-table:: Board specific environment variables
262 :widths: 25 25 50
263 :header-rows: 1
264
265 * - S/w Component
266 - Env Variable
267 - Description
268 * - U-Boot
269 - UBOOT_CFG_CORTEXR
270 - Defconfig for Cortex-R (Boot processor).
271 * - U-Boot
272 - UBOOT_CFG_CORTEXA
273 - Defconfig for Cortex-A (MPU processor).
274 * - Trusted Firmware-A
275 - TFA_BOARD
276 - Platform name used for building TF-A for Cortex-A Processor.
277 * - Trusted Firmware-A
278 - TFA_EXTRA_ARGS
279 - Any extra arguments used for building TF-A.
280 * - OP-TEE
281 - OPTEE_PLATFORM
282 - Platform name used for building OP-TEE for Cortex-A Processor.
283 * - OP-TEE
284 - OPTEE_EXTRA_ARGS
285 - Any extra arguments used for building OP-TEE.
286.. k3_rst_include_end_board_env_vars_desc
Bryan Brattlof6d138132022-12-19 14:29:50 -0600287
288Building tiboot3.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200289^^^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600290
2911. To generate the U-Boot SPL for the wakeup domain, use the following
292 commands, substituting :code:`{SOC}` for the name of your device (eg:
Neha Malcom Francis507be122023-07-22 00:14:43 +0530293 am62x) to package the various firmware and the wakeup UBoot SPL into
294 the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device
295 uses the split binary flow)
Bryan Brattlof6d138132022-12-19 14:29:50 -0600296
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530297.. _k3_rst_include_start_build_steps_spl_r5:
298
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500299.. k3_rst_include_start_build_steps_spl_r5
Nishanth Menon740c41c2023-11-02 23:40:25 -0500300.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600301
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500302 # inside u-boot source
303 make $UBOOT_CFG_CORTEXR
304 make CROSS_COMPILE=$CC32 BINMAN_INDIRS=$LNX_FW_PATH
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500305.. k3_rst_include_end_build_steps_spl_r5
Bryan Brattlof6d138132022-12-19 14:29:50 -0600306
307At this point you should have all the needed binaries to boot the wakeup
308domain of your K3 SoC.
309
310**Combined Binary Boot Flow** (eg: am62x, am64x, ... )
311
Neha Malcom Francis507be122023-07-22 00:14:43 +0530312 `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600313
314**Split Binary Boot Flow** (eg: j721e, am65x)
315
Neha Malcom Francis507be122023-07-22 00:14:43 +0530316 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
317 | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600318
319.. note ::
320
321 It's important to rename the generated `tiboot3.bin` and `sysfw.itb`
322 to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup
323 UBoot SPL will only look for and load the files with these names.
324
325Building tispl.bin
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200326^^^^^^^^^^^^^^^^^^
Bryan Brattlof6d138132022-12-19 14:29:50 -0600327
328The `tispl.bin` is a standard fitImage combining the firmware need for
329the main domain to function properly as well as Device Management (DM)
330firmware if your device using a split firmware.
331
Neha Malcom Francis507be122023-07-22 00:14:43 +05303322. We will first need TF-A, as it's the first thing to run on the 'big'
Bryan Brattlof6d138132022-12-19 14:29:50 -0600333 application cores on the main domain.
334
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500335.. k3_rst_include_start_build_steps_tfa
Nishanth Menon740c41c2023-11-02 23:40:25 -0500336.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600337
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500338 # inside trusted-firmware-a source
339 make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS \
340 TARGET_BOARD=$TFA_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500341.. k3_rst_include_end_build_steps_tfa
Bryan Brattlof6d138132022-12-19 14:29:50 -0600342
Neha Malcom Francis507be122023-07-22 00:14:43 +0530343Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500344=j784s4` (if it is a J784S4 device), while typical Sitara (`am6*`) devices
Neha Malcom Francis507be122023-07-22 00:14:43 +0530345use the `lite` option.
Bryan Brattlof6d138132022-12-19 14:29:50 -0600346
Neha Malcom Francis507be122023-07-22 00:14:43 +05303473. The Open Portable Trusted Execution Environment (OP-TEE) is designed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600348 to run as a companion to a non-secure Linux kernel for Cortex-A cores
349 using the TrustZone technology built into the core.
350
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500351.. k3_rst_include_start_build_steps_optee
Nishanth Menon740c41c2023-11-02 23:40:25 -0500352.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600353
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500354 # inside optee_os source
355 make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 CFG_ARM64_core=y $OPTEE_EXTRA_ARGS \
356 PLATFORM=$OPTEE_PLATFORM
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500357.. k3_rst_include_end_build_steps_optee
Bryan Brattlof6d138132022-12-19 14:29:50 -0600358
Neha Malcom Francis507be122023-07-22 00:14:43 +05303594. Finally, after TF-A has initialized the main domain and OP-TEE has
Bryan Brattlof6d138132022-12-19 14:29:50 -0600360 finished, we can jump back into U-Boot again, this time running on a
361 64bit core in the main domain.
362
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530363.. _k3_rst_include_start_build_steps_uboot:
364
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500365.. k3_rst_include_start_build_steps_uboot
Nishanth Menon740c41c2023-11-02 23:40:25 -0500366.. prompt:: bash $
Bryan Brattlof6d138132022-12-19 14:29:50 -0600367
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500368 # inside u-boot source
369 make $UBOOT_CFG_CORTEXA
370 make CROSS_COMPILE=$CC64 BINMAN_INDIRS=$LNX_FW_PATH \
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500371 BL31=$TFA_PATH/build/k3/$TFA_BOARD/release/bl31.bin \
372 TEE=$OPTEE_PATH/out/arm-plat-k3/core/tee-raw.bin
Neha Malcom Francis2b259f02023-12-05 15:12:20 +0530373
374.. note::
375 It is also possible to pick up a custom DM binary by adding TI_DM argument
376 pointing to the file. If not provided, it defaults to picking up the DM
377 binary from BINMAN_INDIRS. This is only applicable to devices that utilize
378 split firmware.
379
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500380.. k3_rst_include_end_build_steps_uboot
Bryan Brattlof6d138132022-12-19 14:29:50 -0600381
382At this point you should have every binary needed initialize both the
383wakeup and main domain and to boot to the U-Boot prompt
384
385**Main Domain Bootloader**
386
Neha Malcom Francis507be122023-07-22 00:14:43 +0530387 | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices
388 | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530389
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530390FIT signature signing
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530391---------------------
392
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530393K3 platforms have FIT signature signing enabled by default on their primary
394platforms. Here we'll take an example for creating FIT Image for J721E platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530395and the same can be extended to other platforms
396
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530397Pre-requisites:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530398
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530399* U-boot build (:ref:`U-boot build <k3_rst_include_start_build_steps_spl_r5>`)
400* Linux Image and Linux DTB prebuilt
401
402Describing FIT source
403^^^^^^^^^^^^^^^^^^^^^
404
405FIT Image is a packed structure containing binary blobs and configurations.
406The Kernel FIT Image that we have has Kernel Image, DTB and the DTBOs. It
407supports packing multiple images and configurations that allow you to
408choose any configuration at runtime to boot from.
409
410.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530411
412 /dts-v1/;
413
414 / {
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530415 description = "FIT Image description";
416 #address-cells = <1>;
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530417
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530418 images {
419 [image-1]
420 [image-2]
421 [fdt-1]
422 [fdt-2]
423 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530424
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530425 configurations {
426 default = <conf-1>
427 [conf-1: image-1,fdt-1]
428 [conf-2: image-2,fdt-1]
429 }
430 }
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530431
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530432* Sample Images
433
434.. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530435
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530436 kernel-1 {
437 description = "Linux kernel";
438 data = /incbin/("linux.bin");
439 type = "kernel";
440 arch = "arm64";
441 os = "linux";
442 compression = "gzip";
443 load = <0x81000000>;
444 entry = <0x81000000>;
445 hash-1 {
446 algo = "sha512";
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530447 };
448 };
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530449 fdt-ti_k3-j721e-common-proc-board.dtb {
450 description = "Flattened Device Tree blob";
451 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dtb");
452 type = "flat_dt";
453 arch = "arm64";
454 compression = "none";
455 load = <0x83000000>;
456 hash-1 {
457 algo = "sha512";
458 };
459 };
460 # Optional images
461 fdt-ti_k3-j721e-evm-virt-mac-client.dtbo {
462 description = "Flattened Device Tree blob";
463 data = /incbin/("arch/arm64/boot/dts/ti/k3-j721e-evm-virt-mac-client.dtbo");
464 type = "flat_dt";
465 arch = "arm64";
466 compression = "none";
467 load = <0x83080000>;
468 hash-1 {
469 algo = "sha512";
470 };
471 };
472
473.. note::
474
475 Change the path in data variables to point to the respective files in your
476 local machine. For e.g change "linux.bin" to "<path-to-kernel-image>".
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530477
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530478For enabling usage of FIT signature, add the signature node to the
479corresponding configuration node as follows.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530480
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530481* Sample Configurations
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530482
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530483.. code-block::
484
485 conf-ti_k3-j721e-common-proc-board.dtb {
486 description = "Linux kernel, FDT blob";
487 fdt = "fdt-ti_k3-j721e-common-proc-board.dtb";
488 kernel = "kernel-1";
489 signature-1 {
490 algo = "sha512,rsa4096";
491 key-name-hint = "custMpk";
492 sign-images = "kernel", "fdt";
493 };
494 };
495 # Optional configurations
496 conf-ti_k3-j721e-evm-virt-mac-client.dtbo {
497 description = "FDTO blob";
498 fdt = "fdt-ti_k3-j721e-evm-virt-mac-client.dtbo";
499
500 signature-1 {
501 algo = "sha512,rsa4096";
502 key-name-hint = "custMpk";
503 sign-images = "fdt";
504 };
505 };
506
507Specify all images you need the signature to authenticate as a part of
508sign-images. The key-name-hint needs to be changed if you are using some
509other key other than the TI dummy key that we are using for this example.
510It should be the name of the file containing the keys.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530511
Nishanth Menonb7ee22f2023-07-27 13:58:48 -0500512.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530513
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530514 Generating new set of keys:
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530515
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530516 .. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530517
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530518 mkdir keys
519 openssl genpkey -algorithm RSA -out keys/dev.key \
520 -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:65537
521 openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530522
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530523Generating the fitImage
524^^^^^^^^^^^^^^^^^^^^^^^
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530525
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530526.. note::
527
528 For signing a secondary platform like SK boards, you'll require
529 additional steps
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530530
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530531 - Change the CONFIG_DEFAULT_DEVICE_TREE
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530532
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530533 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530534
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530535 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530536
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530537 diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig
538 index a5c1df7e0054..6d0126d955ef 100644
539 --- a/configs/j721e_evm_a72_defconfig
540 +++ b/configs/j721e_evm_a72_defconfig
541 @@ -13,7 +13,7 @@ CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80480000
542 CONFIG_ENV_SIZE=0x20000
543 CONFIG_DM_GPIO=y
544 CONFIG_SPL_DM_SPI=y
545 -CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
546 +CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-sk"
547 CONFIG_SPL_TEXT_BASE=0x80080000
548 CONFIG_DM_RESET=y
549 CONFIG_SPL_MMC=y
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530550
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530551 - Change the binman nodes to package u-boot.dtb for the correct set of platform
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530552
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530553 For e.g
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530554
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530555 .. code-block::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530556
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530557 diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi
558 index 673be646b1e3..752fa805fe8d 100644
559 --- a/arch/arm/dts/k3-j721e-binman.dtsi
560 +++ b/arch/arm/dts/k3-j721e-binman.dtsi
561 @@ -299,8 +299,8 @@
562 #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530563
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530564 #define UBOOT_NODTB "u-boot-nodtb.bin"
565 -#define J721E_EVM_DTB "u-boot.dtb"
566 -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb"
567 +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb"
568 +#define J721E_SK_DTB "u-boot.dtb"
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530569
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530570This step will embed the public key in the u-boot.dtb file that was already
571built during the initial u-boot build.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530572
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530573.. prompt:: bash $
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530574
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530575 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 +0530576
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530577.. note::
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530578
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530579 If you have another set of keys then change the -k argument to point to
580 the folder where your keys are present, the build requires the presence
581 of both .key and .crt file.
582
583Build u-boot again
584^^^^^^^^^^^^^^^^^^
585
586The updated u-boot.dtb needs to be packed in u-boot.img for authentication
587so rebuild U-boot ARMV8 without changing any parameters.
588Refer (:ref:`U-boot ARMV8 build <k3_rst_include_start_build_steps_uboot>`)
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530589
590.. note::
591
Manorit Chawdhryf64b3bd2023-12-29 16:16:32 +0530592 The devices now also have distroboot enabled so if the FIT image doesn't
593 work then the fallback to normal distroboot will be there on HS devices.
594 This will need to be explicitly disabled by changing the boot_targets to
595 disallow fallback during testing.
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530596
597Saving environment
598------------------
599
600SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default
601way for saving the environments. This has been done as Uenv.txt is more granular
602then the saveenv command and can be used across various bootmodes too.
603
604**Writing to MMC/EMMC**
605
Nishanth Menon740c41c2023-11-02 23:40:25 -0500606.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530607
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500608 env export -t $loadaddr <list of variables>
609 fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize}
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530610
611**Reading from MMC/EMMC**
612
613By default run envboot will read it from the MMC/EMMC partition ( based on
614mmcdev) and set the environments.
615
616If manually needs to be done then the environment can be read from the
617filesystem and then imported
618
Nishanth Menon740c41c2023-11-02 23:40:25 -0500619.. prompt:: bash =>
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530620
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500621 fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile}
622 env import -t ${loadaddr} ${filesize}
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500623
624.. _k3_rst_refer_openocd:
625
626Common Debugging environment - OpenOCD
627--------------------------------------
628
629This section will show you how to connect a board to `OpenOCD
630<https://openocd.org/>`_ and load the SPL symbols for debugging with
631a K3 generation device. To follow this guide, you must build custom
632u-boot binaries, start your board from a boot media such as an SD
633card, and use an OpenOCD environment. This section uses generic
634examples, though you can apply these instructions to any supported K3
635generation device.
636
637The overall structure of this setup is in the following figure.
638
639.. image:: img/openocd-overview.svg
Nishanth Menon5746e032023-08-22 11:40:56 -0500640 :alt: Overview of OpenOCD setup.
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500641
642.. note::
643
644 If you find these instructions useful, please consider `donating
645 <https://openocd.org/pages/donations.html>`_ to OpenOCD.
646
647Step 1: Download and install OpenOCD
648^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
649
650To get started, it is more convenient if the distribution you
651use supports OpenOCD by default. Follow the instructions in the
652`getting OpenOCD <https://openocd.org/pages/getting-openocd.html>`_
653documentation to pick the installation steps appropriate to your
654environment. Some references to OpenOCD documentation:
655
656* `OpenOCD User Guide <https://openocd.org/doc/html/index.html>`_
657* `OpenOCD Developer's Guide <https://openocd.org/doc/doxygen/html/index.html>`_
658
659Refer to the release notes corresponding to the `OpenOCD version
660<https://github.com/openocd-org/openocd/releases>`_ to ensure
661
662* Processor support: In general, processor support shouldn't present
663 any difficulties since OpenOCD provides solid support for both ARMv8
664 and ARMv7.
665* SoC support: When working with System-on-a-Chip (SoC), the support
666 usually comes as a TCL config file. It is vital to ensure the correct
667 version of OpenOCD or to use the TCL files from the latest release or
668 the one mentioned.
669* Board or the JTAG adapter support: In most cases, board support is
670 a relatively easy problem if the board has a JTAG pin header. All
671 you need to do is ensure that the adapter you select is compatible
672 with OpenOCD. Some boards come with an onboard JTAG adapter that
673 requires a USB cable to be plugged into the board, in which case, it
674 is vital to ensure that the JTAG adapter is supported. Fortunately,
675 almost all TI K3 SK/EVMs come with TI's XDS110, which has out of the
676 box support by OpenOCD. The board-specific documentation will
677 cover the details and any adapter/dongle recommendations.
678
Nishanth Menon740c41c2023-11-02 23:40:25 -0500679.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500680
681 openocd -v
682
683.. note::
684
685 OpenOCD version 0.12.0 is usually required to connect to most K3
686 devices. If your device is only supported by a newer version than the
687 one provided by your distribution, you may need to build it from the source.
688
689Building OpenOCD from source
690""""""""""""""""""""""""""""
691
692The dependency package installation instructions below are for Debian
693systems, but equivalent instructions should exist for systems with
694other package managers. Please refer to the `OpenOCD Documentation
695<https://openocd.org/>`_ for more recent installation steps.
696
Nishanth Menon740c41c2023-11-02 23:40:25 -0500697.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500698
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500699 # Check the packages to be installed: needs deb-src in sources.list
700 sudo apt build-dep openocd
701 # The following list is NOT complete - please check the latest
702 sudo apt-get install libtool pkg-config texinfo libusb-dev \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500703 libusb-1.0.0-dev libftdi-dev libhidapi-dev autoconf automake
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500704 git clone https://github.com/openocd-org/openocd.git openocd
705 cd openocd
706 git submodule init
707 git submodule update
708 ./bootstrap
709 ./configure --prefix=/usr/local/
710 make -j`nproc`
711 sudo make install
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500712
713.. note::
714
715 The example above uses the GitHub mirror site. See
716 `git repo information <https://openocd.org/doc/html/Developers.html#OpenOCD-Git-Repository>`_
717 information to pick the official git repo.
718 If a specific version is desired, select the version using `git checkout tag`.
719
720Installing OpenOCD udev rules
721"""""""""""""""""""""""""""""
722
723The step is not necessary if the distribution supports the OpenOCD, but
724if building from a source, ensure that the udev rules are installed
725correctly to ensure a sane system.
726
Nishanth Menon740c41c2023-11-02 23:40:25 -0500727.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500728
729 # Go to the OpenOCD source directory
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500730 cd openocd
731 Copy the udev rules to the correct system location
732 sudo cp ./contrib/60-openocd.rules \
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500733 ./src/jtag/drivers/libjaylink/contrib/99-libjaylink.rules \
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500734 /etc/udev/rules.d/
735 # Get Udev to load the new rules up
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500736 sudo udevadm control --reload-rules
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500737 # Use the new rules on existing connected devices
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500738 sudo udevadm trigger
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500739
740Step 2: Setup GDB
741^^^^^^^^^^^^^^^^^
742
743Most systems come with gdb-multiarch package.
744
Nishanth Menon740c41c2023-11-02 23:40:25 -0500745.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500746
747 # Install gdb-multiarch package
Nishanth Menon55fbcae2023-08-24 10:40:36 -0500748 sudo apt-get install gdb-multiarch
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500749
750Though using GDB natively is normal, developers with interest in using IDE
751may find a few of these interesting:
752
753* `gdb-dashboard <https://github.com/cyrus-and/gdb-dashboard>`_
754* `gef <https://github.com/hugsy/gef>`_
755* `peda <https://github.com/longld/peda>`_
756* `pwndbg <https://github.com/pwndbg/pwndbg>`_
757* `voltron <https://github.com/snare/voltron>`_
758* `ddd <https://www.gnu.org/software/ddd/>`_
759* `vscode <https://www.justinmklam.com/posts/2017/10/vscode-debugger-setup/>`_
760* `vim conque-gdb <https://github.com/vim-scripts/Conque-GDB>`_
761* `emacs realgud <https://github.com/realgud/realgud/wiki/gdb-notes>`_
762* `Lauterbach IDE <https://www2.lauterbach.com/pdf/backend_gdb.pdf>`_
763
764.. warning::
765 LLDB support for OpenOCD is still a work in progress as of this writing.
766 Using GDB is probably the safest option at this point in time.
767
768Step 3: Connect board to PC
769^^^^^^^^^^^^^^^^^^^^^^^^^^^
770There are few patterns of boards in the ecosystem
771
772.. k3_rst_include_start_openocd_connect_XDS110
773
774**Integrated JTAG adapter/dongle**: The board has a micro-USB connector labelled
775XDS110 USB or JTAG. Connect a USB cable to the board to the mentioned port.
776
777.. note::
778
779 There are multiple USB ports on a typical board, So, ensure you have read
780 the user guide for the board and confirmed the silk screen label to ensure
781 connecting to the correct port.
782
783.. k3_rst_include_end_openocd_connect_XDS110
784
785.. k3_rst_include_start_openocd_connect_cti20
786
787**cTI20 connector**: The TI's `cTI20
788<https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_JTAG_connectors.html#cti-20-pin-header-information>`_ connector
789is probably the most prevelant on TI platforms. Though many
790TI boards have an onboard XDS110, cTI20 connector is usually
791provided as an alternate scheme to connect alternatives such
792as `Lauterbach <https://www.lauterbach.com/>`_ or `XDS560
793<https://www.ti.com/tool/TMDSEMU560V2STM-U>`_.
794
795To debug on these boards, the following combinations is suggested:
796
797* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
798 or `equivalent dongles supported by OpenOCD. <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_
799* Cable such as `Tag-connect ribbon cable <https://www.tag-connect.com/product/20-pin-cortex-ribbon-cable-4-length-with-50-mil-connectors>`_
800* Adapter to convert cTI20 to ARM20 such as those from
801 `Segger <https://www.segger.com/products/debug-probes/j-link/accessories/adapters/ti-cti-20-adapter/>`_
802 or `Lauterbach LA-3780 <https://www.lauterbach.com/ad3780.html>`_
803 Or optionally, if you have manufacturing capability then you could try
804 `BeagleBone JTAG Adapter <https://github.com/mmorawiec/BeagleBone-Black-JTAG-Adapters>`_
805
806.. warning::
807 XDS560 and Lauterbach are proprietary solutions and is not supported by
808 OpenOCD.
809 When purchasing an off the shelf adapter/dongle, you do want to be careful
810 about the signalling though. Please
811 `read for additional info <https://software-dl.ti.com/ccs/esd/xdsdebugprobes/emu_JTAG_connectors.html>`_.
812
813.. k3_rst_include_end_openocd_connect_cti20
814
815.. k3_rst_include_start_openocd_connect_tag_connect
816
817**Tag-Connect**: `Tag-Connect <https://www.tag-connect.com/>`_
818pads on the boards which require special cable. Please check the documentation
819to `identify <https://www.tag-connect.com/info/legs-or-no-legs>`_ if "legged"
820or "no-leg" version of the cable is appropriate for the board.
821
822To debug on these boards, you will need:
823
824* `TUMPA <https://www.diygadget.com/JTAG-cables-and-microcontroller-programmers/tiao-usb-multi-protocol-adapter-JTAG-spi-i2c-serial>`_
825 or `equivalent dongles supported by OpenOCD <https://openocd.org/doc/html/Debug-Adapter-Hardware.html#Debug-Adapter-Hardware>`_.
826* Tag-Connect cable appropriate to the board such as
827 `TC2050-IDC-NL <https://www.tag-connect.com/product/TC2050-IDC-NL-10-pin-no-legs-cable-with-ribbon-connector>`_
828* In case of no-leg, version, a
829 `retaining clip <https://www.tag-connect.com/product/tc2050-clip-3pack-retaining-clip>`_
830* Tag-Connect to ARM20
831 `adapter <https://www.tag-connect.com/product/tc2050-arm2010-arm-20-pin-to-tc2050-adapter>`_
832
833.. note::
834 You can optionally use a 3d printed solution such as
835 `Protective cap <https://www.thingiverse.com/thing:3025584>`_ or
836 `clip <https://www.thingiverse.com/thing:3035278>`_ to replace
837 the retaining clip.
838
839.. warning::
840 With the Tag-Connect to ARM20 adapter, Please solder the "Trst" signal for
841 connection to work.
842
843.. k3_rst_include_end_openocd_connect_tag_connect
844
845Debugging with OpenOCD
846^^^^^^^^^^^^^^^^^^^^^^
847
848Debugging U-Boot is different from debugging regular user space
849applications. The bootloader initialization process involves many boot
850media and hardware configuration operations. For K3 devices, there
851are also interactions with security firmware. While reloading the
852"elf" file works through GDB, developers must be mindful of cascading
853initialization's potential consequences.
854
855Consider the following code change:
856
857.. code-block:: diff
858
859 --- a/file.c 2023-07-29 10:55:29.647928811 -0500
860 +++ b/file.c 2023-07-29 10:55:46.091856816 -0500
861 @@ -1,3 +1,3 @@
862 val = readl(reg);
863 -val |= 0x2;
864 +val |= 0x1;
865 writel(val, reg);
866
867Re-running the elf file with the above change will result in the
868register setting 0x3 instead of the intended 0x1. There are other
869hardware blocks which may not behave very well with a re-initialization
870without proper shutdown.
871
872To help narrow the debug down, it is usually simpler to use the
873standard boot media to get to the bootloader and debug only in the area
874of interest.
875
876In general, to debug u-boot spl/u-boot with OpenOCD there are three steps:
877
878* Modify the code adding a loop to allow the debugger to attach
879 near the point of interest. Boot up normally to stop at the loop.
880* Connect with OpenOCD and step out of the loop.
881* Step through the code to find the root of issue.
882
883Typical debugging involves a few iterations of the above sequence.
884Though most bootloader developers like to use printf to debug,
885debug with JTAG tends to be most efficient since it is possible to
886investigate the code flow and inspect hardware registers without
887repeated iterations.
888
889Code modification
890"""""""""""""""""
891
892* **start.S**: Adding an infinite while loop at the very entry of
893 U-Boot. For this, look for the corresponding start.S entry file.
894 This is usually only required when debugging some core SoC or
895 processor related function. For example: arch/arm/cpu/armv8/start.S or
896 arch/arm/cpu/armv7/start.S
897
898.. code-block:: diff
899
900 diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
901 index 69e281b086..744929e825 100644
902 --- a/arch/arm/cpu/armv7/start.S
903 +++ b/arch/arm/cpu/armv7/start.S
904 @@ -37,6 +37,8 @@
905 #endif
906
907 reset:
908 +dead_loop:
909 + b dead_loop
910 /* Allow the board to save important registers */
911 b save_boot_params
912 save_boot_params_ret:
913
914* **board_init_f**: Adding an infinite while loop at the board entry
915 function. In many cases, it is important to debug the boot process if
916 any changes are made for board-specific applications. Below is a step
917 by step process for debugging the boot SPL or Armv8 SPL:
918
919 To debug the boot process in either domain, we will first
920 add a modification to the code we would like to debug.
921 In this example, we will debug ``board_init_f`` inside
922 ``arch/arm/mach-k3/{soc}_init.c``. Since some sections of U-Boot
923 will be executed multiple times during the bootup process of K3
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500924 devices, we will need to include either ``CONFIG_ARM64`` or
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500925 ``CONFIG_CPU_V7R`` to catch the CPU at the desired place during the
926 bootup process (Main or Wakeup domains). For example, modify the
927 file as follows (depending on need):
928
929.. code-block:: c
930
931 void board_init_f(ulong dummy)
932 {
933 .
934 .
935 /* Code to run on the R5F (Wakeup/Boot Domain) */
936 if (IS_ENABLED(CONFIG_CPU_V7R)) {
937 volatile int x = 1;
938 while(x) {};
939 }
940 ...
941 /* Code to run on the ARMV8 (Main Domain) */
Jonathan Humphreys27fd4982023-08-22 13:49:03 -0500942 if (IS_ENABLED(CONFIG_ARM64)) {
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500943 volatile int x = 1;
944 while(x) {};
945 }
946 .
947 .
948 }
949
950Connecting with OpenOCD for a debug session
951"""""""""""""""""""""""""""""""""""""""""""
952
953Startup OpenOCD to debug the platform as follows:
954
955* **Integrated JTAG interface**: If the evm has a debugger such as
956 XDS110 inbuilt, there is typically an evm board support added and a
957 cfg file will be available.
958
959.. k3_rst_include_start_openocd_cfg_XDS110
960
Nishanth Menon740c41c2023-11-02 23:40:25 -0500961.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500962
963 openocd -f board/{board_of_choice}.cfg
964
965.. k3_rst_include_end_openocd_cfg_XDS110
966
967.. k3_rst_include_start_openocd_cfg_external_intro
968
969* **External JTAG adapter/interface**: In other cases, where an
970 adapter/dongle is used, a simple cfg file can be created to integrate the
971 SoC and adapter information. See `supported TI K3 SoCs
972 <https://github.com/openocd-org/openocd/blob/master/tcl/target/ti_k3.cfg#L59>`_
973 to decide if the SoC is supported or not.
974
Nishanth Menon740c41c2023-11-02 23:40:25 -0500975.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -0500976
977 openocd -f openocd_connect.cfg
978
979.. k3_rst_include_end_openocd_cfg_external_intro
980
981 For example, with BeaglePlay (AM62X platform), the openocd_connect.cfg:
982
983.. code-block:: tcl
984
985 # TUMPA example:
986 # http://www.tiaowiki.com/w/TIAO_USB_Multi_Protocol_Adapter_User's_Manual
987 source [find interface/ftdi/tumpa.cfg]
988
989 transport select jtag
990
991 # default JTAG configuration has only SRST and no TRST
992 reset_config srst_only srst_push_pull
993
994 # delay after SRST goes inactive
995 adapter srst delay 20
996
997 if { ![info exists SOC] } {
998 # Set the SoC of interest
999 set SOC am625
1000 }
1001
1002 source [find target/ti_k3.cfg]
1003
1004 ftdi tdo_sample_edge falling
1005
1006 # Speeds for FT2232H are in multiples of 2, and 32MHz is tops
1007 # max speed we seem to achieve is ~20MHz.. so we pick 16MHz
1008 adapter speed 16000
1009
1010Below is an example of the output of this command:
1011
1012.. code-block:: console
1013
1014 Info : Listening on port 6666 for tcl connections
1015 Info : Listening on port 4444 for telnet connections
1016 Info : XDS110: connected
1017 Info : XDS110: vid/pid = 0451/bef3
1018 Info : XDS110: firmware version = 3.0.0.20
1019 Info : XDS110: hardware version = 0x002f
1020 Info : XDS110: connected to target via JTAG
1021 Info : XDS110: TCK set to 2500 kHz
1022 Info : clock speed 2500 kHz
1023 Info : JTAG tap: am625.cpu tap/device found: 0x0bb7e02f (mfg: 0x017 (Texas Instruments), part: 0xbb7e, ver: 0x0)
1024 Info : starting gdb server for am625.cpu.sysctrl on 3333
1025 Info : Listening on port 3333 for gdb connections
1026 Info : starting gdb server for am625.cpu.a53.0 on 3334
1027 Info : Listening on port 3334 for gdb connections
1028 Info : starting gdb server for am625.cpu.a53.1 on 3335
1029 Info : Listening on port 3335 for gdb connections
1030 Info : starting gdb server for am625.cpu.a53.2 on 3336
1031 Info : Listening on port 3336 for gdb connections
1032 Info : starting gdb server for am625.cpu.a53.3 on 3337
1033 Info : Listening on port 3337 for gdb connections
1034 Info : starting gdb server for am625.cpu.main0_r5.0 on 3338
1035 Info : Listening on port 3338 for gdb connections
1036 Info : starting gdb server for am625.cpu.gp_mcu on 3339
1037 Info : Listening on port 3339 for gdb connections
1038
1039.. note::
1040 Notice the default configuration is non-SMP configuration allowing
1041 for each of the core to be attached and debugged simultaneously.
1042 ARMv8 SPL/U-Boot starts up on cpu0 of a53/a72.
1043
1044.. k3_rst_include_start_openocd_cfg_external_gdb
1045
1046To debug using this server, use GDB directly or your preferred
1047GDB-based IDE. To start up GDB in the terminal, run the following
1048command.
1049
Nishanth Menon740c41c2023-11-02 23:40:25 -05001050.. prompt:: bash $
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001051
1052 gdb-multiarch
1053
1054To connect to your desired core, run the following command within GDB:
1055
Nishanth Menon740c41c2023-11-02 23:40:25 -05001056.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001057
1058 target extended-remote localhost:{port for desired core}
1059
1060To load symbols:
1061
1062.. warning::
1063
1064 SPL and U-Boot does a re-location of address compared to where it
1065 is loaded originally. This step takes place after the DDR size is
1066 determined from dt parsing. So, debugging can be split into either
1067 "before re-location" or "after re-location". Please refer to the
1068 file ''doc/README.arm-relocation'' to see how to grab the relocation
1069 address.
1070
1071* Prior to relocation:
1072
Nishanth Menon740c41c2023-11-02 23:40:25 -05001073.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001074
1075 symbol-file {path to elf file}
1076
1077* After relocation:
1078
Nishanth Menon740c41c2023-11-02 23:40:25 -05001079.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001080
1081 # Drop old symbol file
1082 symbol-file
1083 # Pick up new relocaddr
1084 add-symbol-file {path to elf file} {relocaddr}
1085
1086.. k3_rst_include_end_openocd_cfg_external_gdb
1087
1088In the above example of AM625,
1089
Nishanth Menon740c41c2023-11-02 23:40:25 -05001090.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001091
1092 target extended-remote localhost:3338 <- R5F (Wakeup Domain)
1093 target extended-remote localhost:3334 <- A53 (Main Domain)
1094
1095The core can now be debugged directly within GDB using GDB commands or
1096if using IDE, as appropriate to the IDE.
1097
1098Stepping through the code
1099"""""""""""""""""""""""""
1100
1101`GDB TUI Commands
1102<https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html>`_ can
1103help set up the display more sensible for debug. Provide the name
1104of the layout that can be used to debug. For example, use the GDB
1105command ``layout src`` after loading the symbols to see the code and
1106breakpoints. To exit the debug loop added above, add any breakpoints
1107needed and run the following GDB commands to step out of the debug
1108loop set in the ``board_init_f`` function.
1109
Nishanth Menon740c41c2023-11-02 23:40:25 -05001110.. prompt:: bash (gdb)
Jason Kacinesb0fdee92023-08-03 01:29:22 -05001111
1112 set x = 0
1113 continue
1114
1115The platform has now been successfully setup to debug with OpenOCD
1116using GDB commands or a GDB-based IDE. See `OpenOCD documentation for
1117GDB <https://openocd.org/doc/html/GDB-and-OpenOCD.html>`_ for further
1118information.
1119
1120.. warning::
1121
1122 On the K3 family of devices, a watchdog timer within the DMSC is
1123 enabled by default by the ROM bootcode with a timeout of 3 minutes.
1124 The watchdog timer is serviced by System Firmware (SYSFW) or TI
1125 Foundational Security (TIFS) during normal operation. If debugging
1126 the SPL before the SYSFW is loaded, the watchdog timer will not get
1127 serviced automatically and the debug session will reset after 3
1128 minutes. It is recommended to start debugging SPL code only after
1129 the startup of SYSFW to avoid running into the watchdog timer reset.
1130
1131Miscellaneous notes with OpenOCD
1132^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1133
1134Currently, OpenOCD does not support tracing for K3 platforms. Tracing
1135function could be beneficial if the bug in code occurs deep within
1136nested function and can optionally save developers major trouble of
1137stepping through a large quantity of code.