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