blob: 2df57c9850ae3cb1fdb3a7bda39cdbf651e42a0a [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
33 j721e_evm
Udit Kumared92ede2023-05-11 14:47:48 +053034 j7200_evm
Bryan Brattlof6d138132022-12-19 14:29:50 -060035 am62x_sk
Neha Malcom Francis507be122023-07-22 00:14:43 +053036 am65x_evm
Bryan Brattlof6d138132022-12-19 14:29:50 -060037
38Boot Flow Overview
39------------------
40
41For all K3 SoCs the first core started will be inside the Security
42Management Subsystem (SMS) which will secure the device and start a core
43in the wakeup domain to run the ROM code. ROM will then initialize the
44boot media needed to load the binaries packaged inside `tiboot3.bin`,
45including a 32bit U-Boot SPL, (called the wakup SPL) that ROM will jump
46to after it has finished loading everything into internal SRAM.
47
48.. code-block:: text
49
50 | WKUP Domain
51 ROM -> WKUP SPL ->
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,
Neha Malcom Francis507be122023-07-22 00:14:43 +053057starting with Trusted Firmware-A (TF-A), before moving on to start
58OP-TEE and the main domain's U-Boot SPL.
Bryan Brattlof6d138132022-12-19 14:29:50 -060059
60.. code-block:: text
61
62 | WKUP Domain | Main Domain ->
Neha Malcom Francis507be122023-07-22 00:14:43 +053063 ROM -> WKUP SPL -> TF-A -> OP-TEE -> Main SPL
Bryan Brattlof6d138132022-12-19 14:29:50 -060064
65The main domain's SPL, running on a 64bit application core, has
66virtually unlimited space (billions of bytes now that DDR is working) to
67initialize even more peripherals needed to load in the `u-boot.img`
68which loads more firmware into the micro-controller & wakeup domains and
69finally prepare the main domain to run Linux.
70
71.. code-block:: text
72
73 | WKUP Domain | Main Domain ->
Neha Malcom Francis507be122023-07-22 00:14:43 +053074 ROM -> WKUP SPL -> TF-A -> OP-TEE -> Main SPL -> UBoot -> Linux
Bryan Brattlof6d138132022-12-19 14:29:50 -060075
76This is the typical boot flow for all K3 based SoCs, however this flow
77offers quite a lot in the terms of flexibility, especially on High
78Security (HS) SoCs.
79
80Boot Flow Variations
81^^^^^^^^^^^^^^^^^^^^
82
83All K3 SoCs will generally use the above boot flow with two main
84differences depending on the capabilities of the boot ROM and the number
85of cores inside the device. These differences split the bootflow into
86essentially 4 unique but very similar flows:
87
88* Split binary with a combined firmware: (eg: AM65)
89* Combined binary with a combined firmware: (eg: AM64)
90* Split binary with a split firmware: (eg: J721E)
91* Combined binary with a split firmware: (eg: AM62)
92
93For devices that utilize the split binary approach, ROM is not capable
94of loading the firmware into the SoC requiring the wakeup domain's
95U-Boot SPL to load the firmware.
96
97Devices with a split firmware will have two firmwares loaded into the
98device at different times during the bootup process. TI's Foundational
99Security (TIFS), needed to operate the Security Management Subsystem,
100will either be loaded by ROM or the WKUP U-Boot SPL, then once the
101wakeup U-Boot SPL has completed, the second Device Management (DM)
102firmware can be loaded on the now free core in the wakeup domain.
103
104For more information on the bootup process of your SoC, consult the
105device specific boot flow documentation.
106
107Software Sources
108----------------
109
110All scripts and code needed to build the `tiboot3.bin`, `tispl.bin` and
111`u-boot.img` for all K3 SoCs can be located at the following places
112online
113
Nishanth Menonee91e482023-07-27 13:58:44 -0500114.. k3_rst_include_start_boot_sources
115
Bryan Brattlof6d138132022-12-19 14:29:50 -0600116* **Das U-Boot**
117
118 | **source:** https://source.denx.de/u-boot/u-boot.git
119 | **branch:** master
120
Neha Malcom Francis507be122023-07-22 00:14:43 +0530121* **Trusted Firmware-A (TF-A)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600122
Neha Malcom Francis507be122023-07-22 00:14:43 +0530123 | **source:** https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Bryan Brattlof6d138132022-12-19 14:29:50 -0600124 | **branch:** master
125
Neha Malcom Francis507be122023-07-22 00:14:43 +0530126* **Open Portable Trusted Execution Environment (OP-TEE)**
Bryan Brattlof6d138132022-12-19 14:29:50 -0600127
128 | **source:** https://github.com/OP-TEE/optee_os.git
129 | **branch:** master
130
131* **TI Firmware (TIFS, DM, DSMC)**
132
133 | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git
134 | **branch:** ti-linux-firmware
135
Nishanth Menonee91e482023-07-27 13:58:44 -0500136.. k3_rst_include_end_boot_sources
137
Bryan Brattlof6d138132022-12-19 14:29:50 -0600138Build Procedure
139---------------
140
141Depending on the specifics of your device, you will need three or more
142binaries to boot your SoC.
143
144* `tiboot3.bin` (bootloader for the wakeup domain)
145* `tispl.bin` (bootloader for the main domain)
146* `u-boot.img`
147
148During the bootup process, both the 32bit wakeup domain and the 64bit
149main domains will be involved. This means everything inside the
150`tiboot3.bin` running in the wakeup domain will need to be compiled for
15132bit cores and most binaries in the `tispl.bin` will need to be
152compiled for 64bit main domain CPU cores.
153
154All of that to say you will need both a 32bit and 64bit cross compiler
155(assuming you're using an x86 desktop)
156
157.. code-block:: bash
158
Neha Malcom Francis507be122023-07-22 00:14:43 +0530159 $ export CC32=arm-linux-gnueabihf-
160 $ export CC64=aarch64-linux-gnu-
Bryan Brattlof6d138132022-12-19 14:29:50 -0600161
162Building tiboot3.bin
163^^^^^^^^^^^^^^^^^^^^^
164
1651. To generate the U-Boot SPL for the wakeup domain, use the following
166 commands, substituting :code:`{SOC}` for the name of your device (eg:
Neha Malcom Francis507be122023-07-22 00:14:43 +0530167 am62x) to package the various firmware and the wakeup UBoot SPL into
168 the final `tiboot3.bin` binary. (or the `sysfw.itb` if your device
169 uses the split binary flow)
Bryan Brattlof6d138132022-12-19 14:29:50 -0600170
Bryan Brattlof6d138132022-12-19 14:29:50 -0600171
172.. code-block:: bash
173
Neha Malcom Francis507be122023-07-22 00:14:43 +0530174 $ # inside u-boot source
175 $ make ARCH=arm {SOC}_evm_r5_defconfig
176 $ make ARCH=arm CROSS_COMPILE=$CC32 \
177 BINMAN_INDIRS=<path/to/ti-linux-firmware>
Bryan Brattlof6d138132022-12-19 14:29:50 -0600178
179At this point you should have all the needed binaries to boot the wakeup
180domain of your K3 SoC.
181
182**Combined Binary Boot Flow** (eg: am62x, am64x, ... )
183
Neha Malcom Francis507be122023-07-22 00:14:43 +0530184 `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600185
186**Split Binary Boot Flow** (eg: j721e, am65x)
187
Neha Malcom Francis507be122023-07-22 00:14:43 +0530188 | `tiboot3-{SOC}-{gp/hs-fs/hs}.bin`
189 | `sysfw-{SOC}-{gp/hs-fs/hs}-evm.itb`
Bryan Brattlof6d138132022-12-19 14:29:50 -0600190
191.. note ::
192
193 It's important to rename the generated `tiboot3.bin` and `sysfw.itb`
194 to match exactly `tiboot3.bin` and `sysfw.itb` as ROM and the wakeup
195 UBoot SPL will only look for and load the files with these names.
196
197Building tispl.bin
198^^^^^^^^^^^^^^^^^^^
199
200The `tispl.bin` is a standard fitImage combining the firmware need for
201the main domain to function properly as well as Device Management (DM)
202firmware if your device using a split firmware.
203
Neha Malcom Francis507be122023-07-22 00:14:43 +05302042. We will first need TF-A, as it's the first thing to run on the 'big'
Bryan Brattlof6d138132022-12-19 14:29:50 -0600205 application cores on the main domain.
206
207.. code-block:: bash
208
Neha Malcom Francis507be122023-07-22 00:14:43 +0530209 $ # inside trusted-firmware-a source
210 $ make CROSS_COMPILE=$CC64 ARCH=aarch64 PLAT=k3 \
211 TARGET_BOARD={lite|generic|j784s4} \
212 SPD=opteed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600213
Neha Malcom Francis507be122023-07-22 00:14:43 +0530214Typically all `j7*` devices will use `TARGET_BOARD=generic` or `TARGET_BOARD
215=j784s4` (if it is a J784S4 device), while all Sitara (`am6*`) devices
216use the `lite` option.
Bryan Brattlof6d138132022-12-19 14:29:50 -0600217
Neha Malcom Francis507be122023-07-22 00:14:43 +05302183. The Open Portable Trusted Execution Environment (OP-TEE) is designed
Bryan Brattlof6d138132022-12-19 14:29:50 -0600219 to run as a companion to a non-secure Linux kernel for Cortex-A cores
220 using the TrustZone technology built into the core.
221
222.. code-block:: bash
223
Neha Malcom Francis507be122023-07-22 00:14:43 +0530224 $ # inside optee_os source
225 $ make CROSS_COMPILE=$CC32 CROSS_COMPILE64=$CC64 \
Bryan Brattlof6d138132022-12-19 14:29:50 -0600226 PLATFORM=k3 CFG_ARM64_core=y
227
Neha Malcom Francis507be122023-07-22 00:14:43 +05302284. Finally, after TF-A has initialized the main domain and OP-TEE has
Bryan Brattlof6d138132022-12-19 14:29:50 -0600229 finished, we can jump back into U-Boot again, this time running on a
230 64bit core in the main domain.
231
232.. code-block:: bash
233
Neha Malcom Francis507be122023-07-22 00:14:43 +0530234 $ # inside u-boot source
235 $ make ARCH=arm {SOC}_evm_a{53,72}_defconfig
236 $ make ARCH=arm CROSS_COMPILE=$CC64 \
237 BINMAN_INDIRS=<path/to/ti-linux-firmware> \
238 BL31=<path/to/trusted-firmware-a/dir>/build/k3/generic/release/bl31.bin \
239 TEE=<path/to/optee_os/dir>/out/arm-plat-k3/core/tee-raw.bin
Bryan Brattlof6d138132022-12-19 14:29:50 -0600240
241At this point you should have every binary needed initialize both the
242wakeup and main domain and to boot to the U-Boot prompt
243
244**Main Domain Bootloader**
245
Neha Malcom Francis507be122023-07-22 00:14:43 +0530246 | `tispl.bin` for HS devices or `tispl.bin_unsigned` for GP devices
247 | `u-boot.img` for HS devices or `u-boot.img_unsigned` for GP devices
Manorit Chawdhryce7a62f2023-07-14 11:22:29 +0530248
249Fit Signature Signing
250---------------------
251
252K3 Platforms have fit signature signing enabled by default on their primary
253platforms. Here we'll take an example for creating fit image for J721e platform
254and the same can be extended to other platforms
255
2561. Describing FIT source
257
258 .. code-block:: bash
259
260 /dts-v1/;
261
262 / {
263 description = "Kernel fitImage for j721e-hs-evm";
264 #address-cells = <1>;
265
266 images {
267 kernel-1 {
268 description = "Linux kernel";
269 data = /incbin/("Image");
270 type = "kernel";
271 arch = "arm64";
272 os = "linux";
273 compression = "none";
274 load = <0x80080000>;
275 entry = <0x80080000>;
276 hash-1 {
277 algo = "sha512";
278 };
279
280 };
281 fdt-ti_k3-j721e-common-proc-board.dtb {
282 description = "Flattened Device Tree blob";
283 data = /incbin/("k3-j721e-common-proc-board.dtb");
284 type = "flat_dt";
285 arch = "arm64";
286 compression = "none";
287 load = <0x83000000>;
288 hash-1 {
289 algo = "sha512";
290 };
291
292 };
293 };
294
295 configurations {
296 default = "conf-ti_k3-j721e-common-proc-board.dtb";
297 conf-ti_k3-j721e-common-proc-board.dtb {
298 description = "Linux kernel, FDT blob";
299 fdt = "fdt-ti_k3-j721e-common-proc-board.dtb";
300 kernel = "kernel-1";
301 signature-1 {
302 algo = "sha512,rsa4096";
303 key-name-hint = "custMpk";
304 sign-images = "kernel", "fdt";
305 };
306 };
307 };
308 };
309
310 You would require to change the '/incbin/' lines to point to the respective
311 files in your local machine and the key-name-hint also needs to be changed
312 if you are using some other key other than the TI dummy key that we are
313 using for this example.
314
3152. Compile U-boot for the respective board
316
317 .. code-block:: bash
318
319 make O=build/a72 CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=arm
320 BL31=/path/to/bl31.bin TEE=/path/to/bl32.bin
321 BINMAN_INDIRS="/path/to/ti-linux-firmware" -j15
322
323 .. note::
324
325 The changes only affect a72 binaries so the example just builds that
326
3273. Sign the fit image and embed the dtb in uboot
328
329 Now once the build is done, you'll have a dtb for your board that you'll
330 be passing to mkimage for signing the fitImage and embedding the key in
331 the u-boot dtb.
332
333 .. code-block:: bash
334
335 mkimage -r -f fitImage.its -k $UBOOT_PATH/board/ti/keys -K
336 $UBOOT_PATH/build/a72/dts/dt.dtb
337
338 For signing a secondary platform, pass the -K parameter to that DTB
339
340 .. code-block:: bash
341
342 mkimage -f fitImage.its -k $UBOOT_PATH/board/ti/keys -K
343 $UBOOT_PATH/build/a72/arch/arm/dts/k3-j721e-sk.dtb
344
345 .. note::
346
347 If changing `CONFIG_DEFAULT_DEVICE_TREE` to the secondary platform,
348 binman changes would also be required so that correct dtb gets packaged.
349
350 .. code-block:: bash
351
352 diff --git a/arch/arm/dts/k3-j721e-binman.dtsi b/arch/arm/dts/k3-j721e-binman.dtsi
353 index 673be646b1e3..752fa805fe8d 100644
354 --- a/arch/arm/dts/k3-j721e-binman.dtsi
355 +++ b/arch/arm/dts/k3-j721e-binman.dtsi
356 @@ -299,8 +299,8 @@
357 #define SPL_J721E_SK_DTB "spl/dts/k3-j721e-sk.dtb"
358
359 #define UBOOT_NODTB "u-boot-nodtb.bin"
360 -#define J721E_EVM_DTB "u-boot.dtb"
361 -#define J721E_SK_DTB "arch/arm/dts/k3-j721e-sk.dtb"
362 +#define J721E_EVM_DTB "arch/arm/dts/k3-j721e-common-proc-board.dtb"
363 +#define J721E_SK_DTB "u-boot.dtb"
364
3655. Rebuilt u-boot
366
367 This is required so that the modified dtb gets updated in u-boot.img
368
369 .. code-block:: bash
370
371 make O=build/a72 CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=arm
372 BL31=/path/to/bl31.bin TEE=/path/to/bl32.bin
373 BINMAN_INDIRS="/path/to/ti-linux-firmware" -j15
374
3756. (Optional) Enabled FIT_SIGNATURE_ENFORCED
376
377 By default u-boot will boot up the fit image without any authentication as
378 such if the public key is not embedded properly, to check if the public key
379 nodes are proper you can enable FIT_SIGNATURE_ENFORCED that would not rely
380 on the dtb for anything else then the signature node for checking the fit
381 image, rest other things will be enforced such as the property of
382 required-keys. This is not an extensive check so do manual checks also
383
384 This is by default enabled for devices with TI_SECURE_DEVICE enabled.
385
386.. note::
387
388 The devices now also have distroboot enabled so if the fit image doesn't
389 work then the fallback to normal distroboot will be there on hs devices,
390 this will need to be explicitly disabled by changing the boot_targets.
391
392Saving environment
393------------------
394
395SAVEENV is disabled by default and for the new flow uses Uenv.txt as the default
396way for saving the environments. This has been done as Uenv.txt is more granular
397then the saveenv command and can be used across various bootmodes too.
398
399**Writing to MMC/EMMC**
400
401.. code-block::
402
403 => env export -t $loadaddr <list of variables>
404 => fatwrite mmc ${mmcdev} ${loadaddr} ${bootenvfile} ${filesize}
405
406**Reading from MMC/EMMC**
407
408By default run envboot will read it from the MMC/EMMC partition ( based on
409mmcdev) and set the environments.
410
411If manually needs to be done then the environment can be read from the
412filesystem and then imported
413
414.. code-block::
415
416 => fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile}
417 => env import -t ${loadaddr} ${filesize}