Skip to content

Commit c9486a9

Browse files
committed
PolarFire SoC M-Mode Support with DDR Initialization
This PR adds comprehensive support for running wolfBoot in M-mode (Machine mode) on the PolarFire SoC MPFS250T, including DDR controller initialization for LPDDR4 memory. This enables wolfBoot to run directly from eNVM without requiring HSS (Hart Software Services), providing a standalone boot solution.
1 parent 7b871c6 commit c9486a9

16 files changed

+6132
-798
lines changed

arch.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ endif
581581
## RISCV64 (64-bit)
582582
ifeq ($(ARCH),RISCV64)
583583
CROSS_COMPILE?=riscv64-unknown-elf-
584+
585+
# M-mode vs S-mode configuration
586+
ifeq ($(RISCV_MMODE),1)
587+
# Machine Mode: Running directly from eNVM/L2 SRAM
588+
# Boots from SD card after initializing DDR
589+
CFLAGS+=-DWOLFBOOT_RISCV_MMODE
590+
# Use M-mode specific linker script
591+
LSCRIPT_IN:=hal/$(TARGET)-m.ld
592+
else
593+
# Supervisor Mode (default): Running under HSS with DDR available
594+
endif
595+
584596
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
585597

586598
# If SD card or eMMC is enabled use update_disk loader with GPT support
@@ -607,6 +619,7 @@ ifeq ($(ARCH),RISCV64)
607619
# Unified RISC-V boot code (32/64-bit via __riscv_xlen)
608620
OBJS+=src/boot_riscv_start.o src/boot_riscv.o src/vector_riscv.o
609621

622+
# FDT support required
610623
CFLAGS+=-DWOLFBOOT_FDT
611624
OBJS+=src/fdt.o
612625

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# PolarFire SoC MPFS250T M-Mode (Machine Mode) Configuration
2+
#
3+
# This configuration runs wolfBoot directly from eNVM in M-mode (Machine Mode),
4+
# initializes DDR memory, and boots Linux from SD card.
5+
#
6+
# Boot flow:
7+
# 1. eNVM (0x20220100) -> L2_SCRATCH (0x0A000000) - wolfBoot starts
8+
# 2. DDR initialization (PLLs, controller, training)
9+
# 3. Load signed OS image from SD card partition to DDR
10+
# 4. Verify signature and boot
11+
#
12+
# Flash using mpfsBootmodeProgrammer (bootmode 1):
13+
# java -jar mpfsBootmodeProgrammer.jar --bootmode 1 --die MPFS250T \
14+
# --package FCG1152 --workdir $PWD wolfboot.elf
15+
16+
ARCH?=RISCV64
17+
TARGET?=mpfs250
18+
SIGN?=ECC384
19+
HASH?=SHA384
20+
IMAGE_HEADER_SIZE=512
21+
WOLFBOOT_VERSION?=1
22+
ARMORED?=0
23+
DEBUG?=0
24+
DEBUG_SYMBOLS?=1
25+
DEBUG_UART?=1
26+
VTOR?=1
27+
EXT_FLASH?=0
28+
SPI_FLASH?=0
29+
NO_XIP?=1
30+
NVM_FLASH_WRITEONCE?=0
31+
UART_FLASH?=0
32+
V?=0
33+
NO_MPU?=1
34+
RAM_CODE?=0
35+
SPMATH?=1
36+
DUALBANK_SWAP?=0
37+
PKA?=0
38+
ENCRYPT=0
39+
WOLFTPM?=0
40+
ELF?=1
41+
#DEBUG_ELF?=1
42+
43+
# M-Mode Configuration
44+
# Runs on E51 core in Machine Mode from L2 SRAM
45+
RISCV_MMODE?=1
46+
47+
# Stack size per hart (reduced for L2 SRAM constraints)
48+
CFLAGS_EXTRA+=-DSTACK_SIZE_PER_HART=8192
49+
50+
# Use RISC-V assembly version of ECDSA and SHA
51+
NO_ASM?=0
52+
NO_ARM_ASM?=0
53+
54+
# Enable SD card for loading application
55+
DISK_SDCARD?=1
56+
DISK_EMMC?=0
57+
# L2 SRAM Address for wolfBoot (256KB available)
58+
# Stack grows down from end of L2_SCRATCH
59+
WOLFBOOT_ORIGIN?=0x0A000000
60+
61+
# Flash sector size (4KB typical)
62+
WOLFBOOT_SECTOR_SIZE?=0x1000
63+
64+
# Load Partition to RAM Address
65+
WOLFBOOT_LOAD_ADDRESS?=0x8E000000
66+
67+
# Partition layout for PolarFire SoC MPFS250T
68+
# Using update_disk loader we just need to specify the partition number (A/B)
69+
WOLFBOOT_NO_PARTITIONS=1
70+
CFLAGS_EXTRA+=-DBOOT_PART_A=1
71+
CFLAGS_EXTRA+=-DBOOT_PART_B=2
72+
# Speed up disk partition read (512KB chunks - max DMA size)
73+
CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
74+
75+
# DTS (Device Tree) load address
76+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
77+
78+
# Optional Encryption
79+
CUSTOM_ENCRYPT_KEY=1
80+
ENCRYPT=1
81+
ENCRYPT_WITH_AES256=1
82+
OBJS_EXTRA=src/my_custom_encrypt_key.o
83+
84+
# Debug options (useful for initial M-mode bring-up)
85+
#CFLAGS_EXTRA+=-DDEBUG_BOOT
86+
87+
# Optional EMMC_SD debugging logs
88+
#CFLAGS_EXTRA+=-DDEBUG_SDHCI
89+
# Optional disk debugging logs
90+
#CFLAGS_EXTRA+=-DDEBUG_DISK
91+
#CFLAGS_EXTRA+=-DDISK_TEST
92+
93+
# Used by test-application for ELF
94+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80200000
95+
WOLFBOOT_PARTITION_SIZE=0x4000000
96+
97+
98+

config/examples/polarfire_mpfs250.config

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ CFLAGS_EXTRA+=-DBOOT_PART_B=2
6767
# Speed up disk partition read (512KB chunks - max DMA size)
6868
CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
6969

70-
# DTS (Device Tree)
70+
# DTS (Device Tree) load address
7171
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
7272

7373
# Optional Encryption
74-
#CUSTOM_ENCRYPT_KEY=1
75-
#ENCRYPT=1
76-
#ENCRYPT_WITH_AES256=1
77-
#OBJS_EXTRA=src/my_custom_encrypt_key.o
74+
CUSTOM_ENCRYPT_KEY=1
75+
ENCRYPT=1
76+
ENCRYPT_WITH_AES256=1
77+
OBJS_EXTRA=src/my_custom_encrypt_key.o
7878

7979
# Optional EMMC_SD debugging logs
80-
#CFLAGS_EXTRA+=-DDEBUG_MMC
80+
#CFLAGS_EXTRA+=-DDEBUG_SDHCI
8181
# Optional disk debugging logs
8282
#CFLAGS_EXTRA+=-DDEBUG_DISK
8383
#CFLAGS_EXTRA+=-DDISK_TEST

0 commit comments

Comments
 (0)