Skip to content

Commit da6e1ab

Browse files
dgarskedanielinux
authored andcommitted
Add MPFS250 QSPI support
1 parent 560206c commit da6e1ab

File tree

14 files changed

+1090
-104
lines changed

14 files changed

+1090
-104
lines changed

arch.mk

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,19 @@ endif
582582
ifeq ($(ARCH),RISCV64)
583583
CROSS_COMPILE?=riscv64-unknown-elf-
584584
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
585-
CFLAGS+=-DWOLFBOOT_UPDATE_DISK -DMAX_DISKS=1
586-
UPDATE_OBJS:=src/update_disk.o
587-
OBJS += src/gpt.o
588-
OBJS += src/disk.o
585+
586+
# If SD card or eMMC is enabled use update_disk loader with GPT support
587+
ifneq ($(filter 1,$(DISK_SDCARD) $(DISK_EMMC)),)
588+
CFLAGS+=-DWOLFBOOT_UPDATE_DISK -DMAX_DISKS=1
589+
UPDATE_OBJS:=src/update_disk.o
590+
OBJS += src/gpt.o
591+
OBJS += src/disk.o
592+
else
593+
# Use RAM-based update path for non-memory-mapped flash (SC SPI)
594+
# Images are loaded into RAM before execution
595+
UPDATE_OBJS?=src/update_ram.o
596+
endif
597+
589598
ARCH_FLAGS=-march=rv64imafd -mabi=lp64d -mcmodel=medany
590599
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV -DARCH_RISCV64
591600
CFLAGS+=$(ARCH_FLAGS)
@@ -1522,6 +1531,11 @@ endif
15221531
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)
15231532
BOOT_IMG?=test-app/image.bin
15241533

1534+
# When ELF loading is enabled, sign the ELF file (not the flat binary)
1535+
ifeq ($(ELF),1)
1536+
BOOT_IMG=test-app/image.elf
1537+
endif
1538+
15251539
## Update mechanism
15261540
ifeq ($(ARCH),AARCH64)
15271541
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT

config/examples/polarfire_mpfs250.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ DEBUG?=0
2626
DEBUG_SYMBOLS?=1
2727
DEBUG_UART?=1
2828
VTOR?=1
29+
30+
# Flash Configuration
31+
# EXT_FLASH=0: Use eMMC/SD card for firmware storage (default)
32+
# EXT_FLASH=1: Use QSPI flash (Micron MT25QL01G 128MB)
2933
EXT_FLASH?=0
3034
SPI_FLASH?=0
3135
NO_XIP?=1
@@ -44,8 +48,6 @@ ELF?=1
4448

4549
# Use RISC-V assembly version of ECDSA and SHA
4650
NO_ASM?=0
47-
# Optional: Use smaller SHA512
48-
#CFLAGS_EXTRA+=-DUSE_SLOW_SHA512
4951

5052
# SDCard or eMMC support via SDHCI driver
5153
DISK_SDCARD?=1
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
ARCH?=RISCV64
2+
TARGET?=mpfs250
3+
4+
# ECC P384 + SHA384
5+
SIGN?=ECC384
6+
HASH?=SHA384
7+
IMAGE_HEADER_SIZE=512
8+
9+
# ML-DSA 87 + SHA256
10+
#SIGN=ML_DSA
11+
#HASH=SHA256
12+
#ML_DSA_LEVEL=5
13+
#IMAGE_SIGNATURE_SIZE=4627
14+
#IMAGE_HEADER_SIZE=12288
15+
16+
WOLFBOOT_VERSION?=1
17+
ARMORED?=0
18+
DEBUG?=0
19+
DEBUG_SYMBOLS?=1
20+
DEBUG_UART?=1
21+
VTOR?=1
22+
23+
NO_XIP?=1
24+
25+
NVM_FLASH_WRITEONCE?=0
26+
UART_FLASH?=0
27+
V?=0
28+
NO_MPU?=1
29+
RAM_CODE?=0
30+
SPMATH?=1
31+
DUALBANK_SWAP?=0
32+
PKA?=0
33+
ENCRYPT=0
34+
WOLFTPM?=0
35+
ELF?=1
36+
#DEBUG_ELF?=1
37+
38+
# Use RISC-V assembly version of ECDSA and SHA
39+
NO_ASM?=0
40+
41+
# QSPI Flash Configuration
42+
# Using Micron MT25QL01GBBB (128MB, 64KB sectors)
43+
EXT_FLASH?=1
44+
SPI_FLASH?=0
45+
46+
# SPI Flash Controller Selection:
47+
# MPFS_SC_SPI: Use SC QSPI Controller (0x37020100) for fabric-connected flash.
48+
# Direct register access to System Controller's QSPI instance.
49+
# DEFAULT: Use MSS QSPI Controller (0x21000000) for external flash
50+
# on MSS QSPI pins.
51+
CFLAGS_EXTRA+=-DMPFS_SC_SPI
52+
53+
54+
# Enable SD card temporarily (wolfBoot still loads from SD, apps from QSPI)
55+
# For pure QSPI boot, HSS would need to load wolfBoot from QSPI
56+
DISK_SDCARD?=0
57+
DISK_EMMC?=0
58+
59+
# DDR Address for wolfBoot to start from
60+
# Comes from hal/mpfs.yaml
61+
WOLFBOOT_ORIGIN?=0x80000000
62+
63+
# DDR Address where application image will be loaded from flash
64+
# Used by update_ram.c for non-XIP boot
65+
# Must be well above wolfBoot's memory region
66+
WOLFBOOT_LOAD_ADDRESS?=0x8E000000
67+
68+
# Flash geometry (64 KB sector)
69+
WOLFBOOT_SECTOR_SIZE?=0x10000
70+
71+
# Partition layout for 128MB QSPI flash
72+
# HSS Boot Info: 0x00000000 - 0x00000400 (1KB)
73+
# wolfBoot partition: 0x00000400 - 0x0001FFFF (127KB)
74+
# Boot partition: 0x00020000 - 0x01FFFFFF (~32MB)
75+
# Update partition: 0x02000000 - 0x03FFFFFF (32MB)
76+
# Swap partition: 0x04000000 - 0x0400FFFF (64KB)
77+
# Remaining: 0x04010000 - 0x07FFFFFF (~64MB available)
78+
WOLFBOOT_PARTITION_SIZE?=0x1FE0000
79+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x20000
80+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x2000000
81+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x4000000
82+
83+
# DTS (Device Tree)
84+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
85+
WOLFBOOT_DTS_BOOT_ADDRESS?=0x6000000 # DTS at 96MB (after swap)
86+
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x6010000 # DTS update at 96MB + 64KB
87+
88+
# Speed up reads from flash by using larger blocks
89+
CFLAGS_EXTRA+=-DWOLFBOOT_SHA_BLOCK_SIZE=4096
90+
91+
# Optional Encryption
92+
#CUSTOM_ENCRYPT_KEY=1
93+
#ENCRYPT=1
94+
#ENCRYPT_WITH_AES256=1
95+
#OBJS_EXTRA=src/my_custom_encrypt_key.o
96+
97+
# Optional QSPI debugging
98+
# Uncomment for verbose QSPI debug output
99+
#CFLAGS_EXTRA+=-DDEBUG_QSPI
100+
101+
# Optional QSPI flash test (erase/write/read on update partition)
102+
# Uncomment to run test during hal_init()
103+
#CFLAGS_EXTRA+=-DTEST_EXT_FLASH

docs/Targets.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,51 @@ The HSS tinyCLI supports the `USBDMSC` command to mount the eMMC or SD card as a
857857
sudo dd if=wolfboot.bin of=/dev/sdc1 bs=512 && sudo cmp wolfboot.bin /dev/sdc1
858858
```
859859

860-
Note:
860+
### PolarFire SoC QSPI
861+
862+
PolarFire SoC has two CoreQSPI v2 controllers with identical register layouts. The selection
863+
is made at build time via `MPFS_SC_SPI` and affects which QSPI base address wolfBoot uses:
864+
865+
```text
866+
+-------------------+ +----------------------+
867+
| U54 cores | | U54 cores |
868+
| (wolfBoot) | | (wolfBoot) |
869+
+---------+---------+ +----------+-----------+
870+
| |
871+
| direct register access | direct register access
872+
| (MSS QSPI @ 0x2100_0000) | (SC QSPI @ 0x3702_0100)
873+
v v
874+
+-------------------+ +----------------------+
875+
| MSS QSPI IP | | SC QSPI IP |
876+
| (CoreQSPI v2) | | (CoreQSPI v2) |
877+
+---------+---------+ +----------+-----------+
878+
| |
879+
v v
880+
External QSPI flash Fabric-connected flash
881+
```
882+
883+
Build options:
884+
885+
- MSS QSPI controller (direct register access at 0x21000000, read/write/erase)
886+
- `EXT_FLASH=1`
887+
- Do not set `MPFS_SC_SPI`
888+
- Example config: `config/examples/polarfire_mpfs250_qspi.config` with `CFLAGS_EXTRA` line removed.
889+
890+
- SC QSPI controller (direct register access at 0x37020100, read/write/erase)
891+
- `EXT_FLASH=1`
892+
- `CFLAGS_EXTRA+=-DMPFS_SC_SPI`
893+
- Example config: `config/examples/polarfire_mpfs250_qspi.config` as-is.
894+
- Both controllers share the same CoreQSPI v2 register interface.
895+
The only difference is that SC QSPI does not need MSS clock/reset setup.
896+
897+
Example single-shot build: `cp config/examples/polarfire_mpfs250_qspi.config .config && make clean && make wolfboot.bin && hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin && make test-app/image.elf && ./tools/keytools/sign --ecc384 --sha384 test-app/image.elf wolfboot_signing_private_key.der 1`
898+
899+
Notes:
900+
- Both modes support full read, write, and erase operations.
901+
- For QSPI-based boot flows, disable SD/eMMC in the config (`DISK_SDCARD=0`, `DISK_EMMC=0`) unless you
902+
explicitly want wolfBoot to load from disk and the application from QSPI.
903+
- The MSS QSPI path expects external flash on the MSS QSPI pins; the SC QSPI path is for
904+
fabric-connected flash (design flash) accessed via the System Controller's QSPI instance.
861905
862906
### PolarFire testing
863907
@@ -1321,7 +1365,6 @@ Benchmark complete
13211365
13221366
### PolarFire TODO
13231367
1324-
* Add support for QSPI NOR flash
13251368
* Add support for full HSS replacement using wolfboot
13261369
- Machine level assembly startup
13271370
- DDR driver

0 commit comments

Comments
 (0)