Skip to content

Commit 9b423d5

Browse files
committed
Versal SDCard support
1 parent 810be2d commit 9b423d5

File tree

12 files changed

+1014
-112
lines changed

12 files changed

+1014
-112
lines changed

arch.mk

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,20 @@ BOOT_IMG?=test-app/image.bin
14441444
ifeq ($(ARCH),AARCH64)
14451445
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
14461446
OBJS+=src/fdt.o
1447-
UPDATE_OBJS:=src/update_ram.o
1447+
ifneq ($(filter 1,$(DISK_SDCARD) $(DISK_EMMC)),)
1448+
# Disk-based boot (SD card or eMMC)
1449+
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
1450+
ifeq ($(MAX_DISKS),)
1451+
MAX_DISKS=1
1452+
endif
1453+
CFLAGS+=-DMAX_DISKS=$(MAX_DISKS)
1454+
UPDATE_OBJS:=src/update_disk.o
1455+
OBJS+=src/gpt.o
1456+
OBJS+=src/disk.o
1457+
else
1458+
# RAM-based boot from external flash (default)
1459+
UPDATE_OBJS:=src/update_ram.o
1460+
endif
14481461
else
14491462
ifeq ($(DUALBANK_SWAP),1)
14501463
CFLAGS+=-DWOLFBOOT_DUALBOOT
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# wolfBoot configuration for AMD Versal VMK180 - SD Card Boot
2+
# Versal Prime VM1802 ACAP - Dual ARM Cortex-A72
3+
#
4+
# This configuration enables SD card boot for the Versal:
5+
# PLM -> PSM -> BL31 (EL3) -> wolfBoot (EL2) -> Linux (EL1)
6+
#
7+
# wolfBoot loads firmware images from MBR partitions on SD card.
8+
# Uses the generic SDHCI driver with SD1 controller (external SD slot).
9+
10+
ARCH?=AARCH64
11+
TARGET?=versal
12+
13+
WOLFBOOT_VERSION?=1
14+
15+
# ECC-384 with SHA-384 (good balance of security and performance)
16+
SIGN?=ECC384
17+
HASH?=SHA384
18+
IMAGE_HEADER_SIZE?=512
19+
20+
# Debug options
21+
DEBUG?=1
22+
DEBUG_SYMBOLS=1
23+
DEBUG_UART=1
24+
25+
# SD card support - use SDHCI driver
26+
DISK_SDCARD?=1
27+
DISK_EMMC?=0
28+
29+
# Disable QSPI flash when using SD card
30+
EXT_FLASH?=0
31+
NO_XIP=1
32+
33+
# ELF loading support
34+
ELF?=1
35+
36+
# Boot Benchmarking (optional)
37+
BOOT_BENCHMARK?=1
38+
39+
# General options
40+
VTOR?=1
41+
CORTEX_M0?=0
42+
NO_ASM?=0
43+
ALLOW_DOWNGRADE?=0
44+
NVM_FLASH_WRITEONCE?=0
45+
V?=0
46+
SPMATH?=1
47+
RAM_CODE?=0
48+
DUALBANK_SWAP?=0
49+
PKA?=0
50+
WOLFTPM?=0
51+
52+
# Toolchain
53+
USE_GCC=1
54+
CROSS_COMPILE=aarch64-none-elf-
55+
56+
# ============================================================================
57+
# Partition Layout - MBR (required by Versal boot ROM)
58+
# ============================================================================
59+
# SD Card partition layout (MBR):
60+
# Partition 1: boot (128MB, FAT32 LBA, bootable) - BOOT.BIN
61+
# Partition 2: OFP_A (200MB, Linux) - Primary signed image
62+
# Partition 3: OFP_B (200MB, Linux) - Update signed image
63+
# Partition 4: rootfs (remainder) - Linux root filesystem
64+
#
65+
# Use partition numbers instead of flash addresses
66+
# These are 0-based indices into the parsed partition array:
67+
# part[0]=boot, part[1]=OFP_A, part[2]=OFP_B, part[3]=rootfs
68+
WOLFBOOT_NO_PARTITIONS=1
69+
CFLAGS_EXTRA+=-DBOOT_PART_A=1
70+
CFLAGS_EXTRA+=-DBOOT_PART_B=2
71+
72+
# Disk read chunk size (512KB)
73+
CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
74+
75+
# Disable SDMA for multi-block transfers - use PIO instead.
76+
# The Versal Arasan SDHCI controller does not restart SDMA after
77+
# boundary crossings via SRS22/SRS23 writes (Cadence-specific behavior).
78+
CFLAGS_EXTRA+=-DSDHCI_SDMA_DISABLED
79+
80+
# ============================================================================
81+
# Boot Memory Layout
82+
# ============================================================================
83+
# wolfBoot runs from DDR at 0x8000000 (same address as U-Boot)
84+
WOLFBOOT_ORIGIN=0x8000000
85+
86+
# Load Partition to RAM Address (Linux kernel loads here)
87+
WOLFBOOT_LOAD_ADDRESS?=0x10000000
88+
89+
# DTS (Device Tree) load address
90+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
91+
92+
# ============================================================================
93+
# Required for test-app (even with WOLFBOOT_NO_PARTITIONS=1)
94+
# ============================================================================
95+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80200000
96+
WOLFBOOT_PARTITION_SIZE=0x4000000
97+
WOLFBOOT_SECTOR_SIZE=0x1000
98+
99+
# ============================================================================
100+
# UART Configuration - UART1 for APU console (matches VMK180 board)
101+
# ============================================================================
102+
CFLAGS_EXTRA+=-DDEBUG_UART_NUM=0
103+
104+
# ============================================================================
105+
# Optional Debug Options (uncomment to enable)
106+
# ============================================================================
107+
# SDHCI driver debug logs
108+
CFLAGS_EXTRA+=-DDEBUG_SDHCI
109+
# Disk layer debug logs
110+
CFLAGS_EXTRA+=-DDEBUG_DISK
111+
# GPT partition debug logs
112+
CFLAGS_EXTRA+=-DDEBUG_GPT
113+
# Disk read/write test at boot
114+
#CFLAGS_EXTRA+=-DDISK_TEST

docs/Targets.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,108 @@ Typical boot timing with ECC384/SHA384 signing:
23062306
| **Total wolfBoot overhead** | **~870ms** |
23072307

23082308

2309+
### SD Card Boot
2310+
2311+
wolfBoot supports booting from SD card on the VMK180 using the Cadence SDHCI controller. This enables A/B partition-based firmware updates from GPT partitions on the SD card.
2312+
2313+
#### SD Card Partition Layout
2314+
2315+
The SD card uses MBR partitioning to match the stock Versal SD card format:
2316+
2317+
| Partition | Name | Size | Type | Contents |
2318+
|-----------|------|------|------|----------|
2319+
| 1 | boot | 128MB | FAT32 LBA (0x0c), bootable | BOOT.BIN (PLM + PSM + BL31 + wolfBoot) |
2320+
| 2 | OFP_A | 200MB | Linux (0x83) | Primary signed firmware image |
2321+
| 3 | OFP_B | 200MB | Linux (0x83) | Update signed firmware image |
2322+
| 4 | rootfs | remainder | Linux (0x83) | Linux root filesystem |
2323+
2324+
#### Configuration
2325+
2326+
Use the SD card configuration file:
2327+
2328+
```sh
2329+
cp config/examples/versal_vmk180_sdcard.config .config
2330+
make clean
2331+
make
2332+
```
2333+
2334+
Key differences from QSPI configuration:
2335+
- `DISK_SDCARD=1` - Enable SD card support via SDHCI driver
2336+
- `EXT_FLASH=0` - Disable QSPI flash
2337+
- `BOOT_PART_A=2` - Primary firmware on partition 2
2338+
- `BOOT_PART_B=3` - Update firmware on partition 3
2339+
2340+
#### Building and Provisioning
2341+
2342+
1. **Build wolfBoot and create SD card image:**
2343+
2344+
```sh
2345+
./tools/scripts/versal_test.sh --sdcard
2346+
```
2347+
2348+
This creates:
2349+
- `wolfboot.elf` - wolfBoot bootloader
2350+
- `BOOT.BIN` - Complete boot image for partition 1
2351+
- `sdcard.img` - GPT-partitioned SD card image with signed test apps
2352+
- `test-app/image_v1_signed.bin` - Signed primary firmware
2353+
- `test-app/image_v2_signed.bin` - Signed update firmware
2354+
2355+
2. **Provision the SD card:**
2356+
2357+
```sh
2358+
sudo ./tools/scripts/versal_sdcard_provision.sh /dev/sdX
2359+
```
2360+
2361+
Or manually:
2362+
2363+
```sh
2364+
# Write partition image
2365+
sudo dd if=sdcard.img of=/dev/sdX bs=4M status=progress conv=fsync
2366+
sync
2367+
2368+
# Format boot partition and copy BOOT.BIN
2369+
sudo mkfs.vfat -F 32 -n BOOT /dev/sdX1
2370+
sudo mount /dev/sdX1 /mnt
2371+
sudo cp BOOT.BIN /mnt/
2372+
sudo umount /mnt
2373+
```
2374+
2375+
3. **Verify partitions:**
2376+
2377+
```sh
2378+
sudo sgdisk -p /dev/sdX
2379+
```
2380+
2381+
#### Boot Mode Selection
2382+
2383+
Set the VMK180 boot mode switches for SD card boot:
2384+
- MODE[3:0] = 0b1110 (SD1 boot)
2385+
2386+
#### Expected Boot Output
2387+
2388+
```
2389+
========================================
2390+
wolfBoot Secure Boot - AMD Versal
2391+
========================================
2392+
Current EL: 2
2393+
SDHCI: SDCard mode
2394+
...
2395+
Boot partition: A (2)
2396+
Firmware Valid
2397+
Booting at 0x10000000
2398+
```
2399+
2400+
#### Firmware Updates
2401+
2402+
To test A/B updates:
2403+
2404+
1. Boot from partition A (OFP_A) with version 1
2405+
2. Write new signed image to partition B (OFP_B)
2406+
3. Trigger update via wolfBoot API
2407+
4. On next boot, wolfBoot verifies and boots from partition B
2408+
5. If verification fails, wolfBoot falls back to partition A
2409+
2410+
23092411
## Cypress PSoC-6
23102412

23112413
The Cypress PSoC 62S2 is a dual-core Cortex-M4 & Cortex-M0+ MCU. The secure boot process is managed by the M0+.

0 commit comments

Comments
 (0)