Skip to content

Commit eba460a

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 4673c82 commit eba460a

16 files changed

Lines changed: 6091 additions & 159 deletions

arch.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,27 @@ endif
563563
## RISCV64 (64-bit)
564564
ifeq ($(ARCH),RISCV64)
565565
CROSS_COMPILE?=riscv64-unknown-elf-
566+
567+
# M-mode vs S-mode configuration
568+
ifeq ($(RISCV_MMODE),1)
569+
# Machine Mode: Running directly from eNVM/L2 SRAM
570+
# Boots from SD card after initializing DDR
571+
CFLAGS+=-DWOLFBOOT_RISCV_MMODE
572+
# Use M-mode specific linker script
573+
LSCRIPT_IN:=hal/$(TARGET)-m.ld
574+
else
575+
# Supervisor Mode (default): Running under HSS with DDR available
576+
endif
577+
566578
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
567579
CFLAGS+=-DWOLFBOOT_UPDATE_DISK -DMAX_DISKS=1
580+
581+
# Disk boot support
568582
UPDATE_OBJS:=src/update_disk.o
569583
OBJS += src/gpt.o
570584
OBJS += src/disk.o
585+
# Note: sdhci.o is added by options.mk when DISK_SDCARD=1
586+
571587
ARCH_FLAGS=-march=rv64imafd -mabi=lp64d -mcmodel=medany
572588
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV -DARCH_RISCV64
573589
CFLAGS+=$(ARCH_FLAGS)
@@ -580,6 +596,7 @@ ifeq ($(ARCH),RISCV64)
580596
# Unified RISC-V boot code (32/64-bit via __riscv_xlen)
581597
OBJS+=src/boot_riscv_start.o src/boot_riscv.o src/vector_riscv.o
582598

599+
# FDT support required
583600
CFLAGS+=-DWOLFBOOT_FDT
584601
OBJS+=src/fdt.o
585602

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
@@ -52,17 +52,17 @@ CFLAGS_EXTRA+=-DBOOT_PART_B=2
5252
# Speed up disk partition read (512KB chunks - max DMA size)
5353
CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
5454

55-
# DTS (Device Tree)
55+
# DTS (Device Tree) load address
5656
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
5757

5858
# Optional Encryption
59-
#CUSTOM_ENCRYPT_KEY=1
60-
#ENCRYPT=1
61-
#ENCRYPT_WITH_AES256=1
62-
#OBJS_EXTRA=src/my_custom_encrypt_key.o
59+
CUSTOM_ENCRYPT_KEY=1
60+
ENCRYPT=1
61+
ENCRYPT_WITH_AES256=1
62+
OBJS_EXTRA=src/my_custom_encrypt_key.o
6363

6464
# Optional EMMC_SD debugging logs
65-
#CFLAGS_EXTRA+=-DDEBUG_MMC
65+
#CFLAGS_EXTRA+=-DDEBUG_SDHCI
6666
# Optional disk debugging logs
6767
#CFLAGS_EXTRA+=-DDEBUG_DISK
6868
#CFLAGS_EXTRA+=-DDISK_TEST

0 commit comments

Comments
 (0)