Skip to content

Commit 16497fc

Browse files
dgarskedanielinux
authored andcommitted
Documentation and fixes for booting full PetaLinux with wolfBoot on Versal VMK180
1 parent ae63f60 commit 16497fc

4 files changed

Lines changed: 509 additions & 486 deletions

File tree

docs/Targets.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,154 @@ Application running successfully!
21562156
Entering idle loop...
21572157
```
21582158

2159+
### Booting PetaLinux
2160+
2161+
wolfBoot can boot a signed Linux kernel on the Versal VMK180. This replaces U-Boot entirely for a secure boot chain.
2162+
2163+
#### Prerequisites
2164+
2165+
1. **PetaLinux 2024.2** (or compatible version) built for VMK180
2166+
2. **Pre-built Linux images** from your PetaLinux build:
2167+
- `Image` - Uncompressed Linux kernel (ARM64)
2168+
- `system-default.dtb` - Device tree blob for VMK180
2169+
- `bl31.elf` - ARM Trusted Firmware
2170+
- `plm.elf` - Platform Loader & Manager
2171+
- `psmfw.elf` - PSM firmware
2172+
2173+
3. **SD card** with root filesystem (PetaLinux rootfs.ext4 written to partition 2)
2174+
2175+
#### Boot Flow
2176+
2177+
```
2178+
PLM -> PSM -> BL31 (EL3) -> wolfBoot (EL2) -> Linux (EL1)
2179+
```
2180+
2181+
wolfBoot:
2182+
1. Loads the signed FIT image from QSPI flash
2183+
2. Verifies the cryptographic signature (ECC384/SHA384)
2184+
3. Parses the FIT image to extract kernel and DTB
2185+
4. Applies DTB fixups (bootargs for root filesystem)
2186+
5. Transitions from EL2 to EL1 and jumps to the kernel
2187+
2188+
#### Creating the FIT Image
2189+
2190+
wolfBoot uses a FIT (Flattened Image Tree) image containing the kernel and device tree. Create the FIT image using the provided ITS file:
2191+
2192+
```sh
2193+
# Copy Linux images to wolfBoot root directory
2194+
cp /path/to/petalinux/images/linux/Image .
2195+
cp /path/to/petalinux/images/linux/system-default.dtb .
2196+
2197+
# Create FIT image using mkimage
2198+
mkimage -f hal/versal.its fitImage
2199+
```
2200+
2201+
The ITS file (`hal/versal.its`) specifies:
2202+
- Kernel load address: `0x00200000`
2203+
- DTB load address: `0x00001000`
2204+
- SHA256 hashes for integrity
2205+
2206+
#### Signing the FIT Image
2207+
2208+
Sign the FIT image with wolfBoot tools:
2209+
2210+
```sh
2211+
# Sign with ECC384 (default for Versal config)
2212+
./tools/keytools/sign --ecc384 --sha384 fitImage wolfboot_signing_private_key.der 1
2213+
```
2214+
2215+
This creates `fitImage_v1_signed.bin`.
2216+
2217+
#### DTB Fixup for Root Filesystem
2218+
2219+
wolfBoot automatically modifies the device tree to set the kernel command line (`bootargs`). The default configuration mounts the root filesystem from SD card partition 2:
2220+
2221+
```
2222+
earlycon root=/dev/mmcblk0p2 rootwait
2223+
```
2224+
2225+
To customize the root device, add to your config:
2226+
2227+
```makefile
2228+
# Mount root from SD card partition 4
2229+
CFLAGS_EXTRA+=-DLINUX_BOOTARGS_ROOT=\"/dev/mmcblk0p4\"
2230+
```
2231+
2232+
#### Flashing to QSPI
2233+
2234+
Flash the signed FIT image to the boot partition at `0x800000`:
2235+
2236+
```sh
2237+
# From U-Boot (via SD card boot)
2238+
tftp ${loadaddr} fitImage_v1_signed.bin
2239+
sf probe 0
2240+
sf erase 0x800000 +${filesize}
2241+
sf write ${loadaddr} 0x800000 ${filesize}
2242+
```
2243+
2244+
#### Automated Testing
2245+
2246+
The test script supports Linux boot testing:
2247+
2248+
```sh
2249+
# Set path to PetaLinux images
2250+
export LINUX_IMAGES_DIR=/path/to/petalinux/images/linux
2251+
2252+
# Build wolfBoot, create signed FIT, flash to QSPI, and boot
2253+
./tools/scripts/versal_test.sh --linux
2254+
```
2255+
2256+
#### Example Linux Boot Output
2257+
2258+
```
2259+
========================================
2260+
wolfBoot Secure Boot - AMD Versal
2261+
========================================
2262+
Current EL: 2
2263+
QSPI: Lower ID: 20 BB 21
2264+
QSPI: Upper ID: 20 BB 21
2265+
QSPI: 75MHz, Quad mode, DMA
2266+
Versions: Boot 1, Update 0
2267+
Trying Boot partition at 0x800000
2268+
Loading header 512 bytes from 0x800000 to 0xFFFFE00
2269+
Loading image 24658696 bytes from 0x800200 to 0x10000000...done (701 ms)
2270+
Boot partition: 0xFFFFE00 (sz 24658696, ver 0x1, type 0x601)
2271+
Checking integrity...done (167 ms)
2272+
Verifying signature...done (3 ms)
2273+
Successfully selected image in part: 0
2274+
Firmware Valid
2275+
Loading elf at 0x10000000
2276+
Invalid elf, falling back to raw binary
2277+
Flattened uImage Tree: Version 17, Size 24658696
2278+
Loading Image kernel-1: 0x100000D8 -> 0x200000 (24617472 bytes)
2279+
Image kernel-1: 0x200000 (24617472 bytes)
2280+
Loading Image fdt-1: 0x1177A3DC -> 0x1000 (39384 bytes)
2281+
Image fdt-1: 0x1000 (39384 bytes)
2282+
Loading DTS: 0x1000 -> 0x1000 (39384 bytes)
2283+
FDT: Version 17, Size 39384
2284+
FDT: Setting bootargs: earlycon root=/dev/mmcblk0p2 rootwait
2285+
FDT: Set chosen (28076), bootargs=earlycon root=/dev/mmcblk0p2 rootwait
2286+
Booting at 0x200000
2287+
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd083]
2288+
[ 0.000000] Linux version 6.6.40-xilinx-g2b7f6f70a62a ...
2289+
[ 0.000000] Machine model: Xilinx Versal vmk180 Eval board revA
2290+
...
2291+
PetaLinux 2024.2 xilinx-vmk180 ttyAMA0
2292+
2293+
xilinx-vmk180 login:
2294+
```
2295+
2296+
#### Boot Performance
2297+
2298+
Typical boot timing with ECC384/SHA384 signing:
2299+
2300+
| Operation | Time |
2301+
|-----------|------|
2302+
| Load 24MB FIT from QSPI | ~700ms |
2303+
| SHA384 integrity check | ~167ms |
2304+
| ECC384 signature verify | ~3ms |
2305+
| **Total wolfBoot overhead** | **~870ms** |
2306+
21592307

21602308
## Cypress PSoC-6
21612309

hal/versal.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,29 @@
5050
#include "hal/versal.h"
5151
#include "image.h"
5252
#include "printf.h"
53+
#include "fdt.h"
5354

5455
#ifndef ARCH_AARCH64
5556
# error "wolfBoot versal HAL: wrong architecture. Please compile with ARCH=AARCH64."
5657
#endif
5758

59+
/* ============================================================================
60+
* Linux Boot Arguments
61+
* ============================================================================
62+
* DTB fixup for kernel command line. Override LINUX_BOOTARGS or
63+
* LINUX_BOOTARGS_ROOT in your config to customize.
64+
*/
65+
66+
/* Linux kernel command line arguments */
67+
#ifndef LINUX_BOOTARGS
68+
#ifndef LINUX_BOOTARGS_ROOT
69+
#define LINUX_BOOTARGS_ROOT "/dev/mmcblk0p2"
70+
#endif
71+
72+
#define LINUX_BOOTARGS \
73+
"earlycon root=" LINUX_BOOTARGS_ROOT " rootwait"
74+
#endif
75+
5876

5977
/* ============================================================================
6078
* UART Driver
@@ -1297,6 +1315,54 @@ void* hal_get_dts_update_address(void)
12971315
return NULL;
12981316
#endif
12991317
}
1318+
1319+
#ifdef __WOLFBOOT
1320+
/**
1321+
* Fixup Device Tree before booting Linux
1322+
*
1323+
* This function modifies the DTB to set bootargs for the kernel.
1324+
* Called from do_boot() before jumping to the kernel.
1325+
*
1326+
* @param dts_addr: Pointer to the device tree blob in memory
1327+
* @return: 0 on success, negative error code on failure
1328+
*/
1329+
int hal_dts_fixup(void* dts_addr)
1330+
{
1331+
int off, ret;
1332+
struct fdt_header *fdt = (struct fdt_header *)dts_addr;
1333+
1334+
/* Verify FDT header */
1335+
ret = fdt_check_header(dts_addr);
1336+
if (ret != 0) {
1337+
wolfBoot_printf("FDT: Invalid header! %d\n", ret);
1338+
return ret;
1339+
}
1340+
1341+
wolfBoot_printf("FDT: Version %d, Size %d\n",
1342+
fdt_version(fdt), fdt_totalsize(fdt));
1343+
1344+
/* Expand total size to allow adding/modifying properties */
1345+
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 512);
1346+
1347+
/* Find /chosen node */
1348+
off = fdt_find_node_offset(fdt, -1, "chosen");
1349+
if (off < 0) {
1350+
/* Create /chosen node if it doesn't exist */
1351+
off = fdt_add_subnode(fdt, 0, "chosen");
1352+
}
1353+
1354+
if (off >= 0) {
1355+
/* Set bootargs property */
1356+
wolfBoot_printf("FDT: Setting bootargs: %s\n", LINUX_BOOTARGS);
1357+
fdt_fixup_str(fdt, off, "chosen", "bootargs", LINUX_BOOTARGS);
1358+
} else {
1359+
wolfBoot_printf("FDT: Failed to find/create chosen node (%d)\n", off);
1360+
return off;
1361+
}
1362+
1363+
return 0;
1364+
}
1365+
#endif /* __WOLFBOOT */
13001366
#endif /* MMU */
13011367

13021368
#ifdef WOLFBOOT_DUALBOOT

hal/versal.its

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/dts-v1/;
2+
3+
/ {
4+
description = "Xilinx Versal VMK180 - wolfBoot Linux";
5+
#address-cells = <1>;
6+
7+
images {
8+
kernel-1 {
9+
description = "Linux Kernel";
10+
data = /incbin/("../Image");
11+
type = "kernel";
12+
arch = "arm64";
13+
os = "linux";
14+
compression = "none";
15+
load = <0x00200000>;
16+
entry = <0x00200000>;
17+
hash-1 {
18+
algo = "sha256";
19+
};
20+
};
21+
fdt-1 {
22+
description = "Flattened Device Tree blob";
23+
data = /incbin/("../system-default.dtb");
24+
type = "flat_dt";
25+
arch = "arm64";
26+
compression = "none";
27+
load = <0x00001000>;
28+
hash-1 {
29+
algo = "sha256";
30+
};
31+
};
32+
};
33+
configurations {
34+
default = "conf1";
35+
conf1 {
36+
description = "Linux kernel and FDT blob";
37+
kernel = "kernel-1";
38+
fdt = "fdt-1";
39+
hash-1 {
40+
algo = "sha256";
41+
};
42+
};
43+
};
44+
};

0 commit comments

Comments
 (0)