Skip to content

Commit eb91a6d

Browse files
committed
Support for Microchip PolarFire SoC (MPFS250)
1 parent 97230f5 commit eb91a6d

37 files changed

+2965
-241
lines changed

.github/workflows/test-build-riscv.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
submodules: true
2727

2828
- uses: actions/checkout@v4
29+
if: ${{ inputs.arch == 'riscv' }}
2930
with:
3031
repository: sifive/freedom-e-sdk
3132
path: freedom-e-sdk
@@ -79,12 +80,21 @@ jobs:
7980
- name: Update repository
8081
run: sudo apt-get update -o Acquire::Retries=3
8182

82-
- name: Download and install SiFive RISC-V toolchain
83+
- name: Download and install RISC-V toolchain
84+
if: ${{ inputs.arch == 'riscv' }}
8385
run: |
84-
# Download SiFive prebuilt toolchain with newlib
85-
wget -q https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
86-
tar xzf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
87-
echo "$GITHUB_WORKSPACE/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH
86+
# Download latest prebuilt RISC-V toolchains
87+
wget -q https://github.com/RISCV-Tools/riscv-gnu-toolchain/releases/latest/download/riscv32-elf-ubuntu-24.04-gcc.tar.xz
88+
tar -xf riscv32-elf-ubuntu-24.04-gcc.tar.xz -C $GITHUB_WORKSPACE/riscv
89+
echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
90+
91+
- name: Download and install RISC-V toolchain
92+
if: ${{ inputs.arch == 'riscv64' }}
93+
run: |
94+
# Download latest prebuilt RISC-V toolchains
95+
wget -q https://github.com/RISCV-Tools/riscv-gnu-toolchain/releases/latest/download/riscv64-elf-ubuntu-24.04-gcc.tar.xz
96+
tar -xf riscv64-elf-ubuntu-24.04-gcc.tar.xz -C $GITHUB_WORKSPACE/riscv
97+
echo "$GITHUB_WORKSPACE/riscv/bin" >> $GITHUB_PATH
8898
8999
- name: make clean
90100
run: |
@@ -98,7 +108,12 @@ jobs:
98108
run: |
99109
make -C tools/keytools && make -C tools/bin-assemble
100110
101-
- name: Build wolfboot
111+
- name: Build wolfboot (riscv32)
112+
if: ${{ inputs.arch == 'riscv' }}
102113
run: |
103-
make FREEDOM_E_SDK=$GITHUB_WORKSPACE/freedom-e-sdk CROSS_COMPILE=riscv64-unknown-elf- ${{inputs.make-args}}
114+
make CROSS_COMPILE=riscv32-unknown-elf- FREEDOM_E_SDK=$GITHUB_WORKSPACE/freedom-e-sdk ${{inputs.make-args}}
104115
116+
- name: Build wolfboot (riscv64))
117+
if: ${{ inputs.arch == 'riscv64' }}
118+
run: |
119+
make CROSS_COMPILE=riscv64-unknown-elf- ${{inputs.make-args}}

.github/workflows/test-configs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ jobs:
207207
arch: arm
208208
config-file: ./config/examples/mcxw-tz.config
209209

210+
microchip_mpfs250_test:
211+
uses: ./.github/workflows/test-build-riscv.yml
212+
with:
213+
arch: riscv64
214+
config-file: ./config/examples/polarfire_mpfs250.config
215+
210216
raspi3_test:
211217
uses: ./.github/workflows/test-build.yml
212218
with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ line-count-nrf52:
528528
cloc --force-lang-def cloc_lang_def.txt src/boot_arm.c src/image.c src/libwolfboot.c src/loader.c src/update_flash.c hal/nrf52.c
529529

530530
line-count-x86:
531-
cloc --force-lang-def cloc_lang_def.txt src/boot_x86_fsp.c src/boot_x86_fsp_payload.c src/boot_x86_fsp_start.S src/image.c src/keystore.c src/libwolfboot.c src/loader.c src/string.c src/update_disk.c src/x86/ahci.c src/x86/ata.c src/x86/common.c src/x86/gpt.c src/x86/hob.c src/pci.c src/x86/tgl_fsp.c hal/x86_fsp_tgl.c hal/x86_uart.c
531+
cloc --force-lang-def cloc_lang_def.txt src/boot_x86_fsp.c src/boot_x86_fsp_payload.c src/boot_x86_fsp_start.S src/image.c src/keystore.c src/libwolfboot.c src/loader.c src/string.c src/update_disk.c src/gpt.c src/x86/ahci.c src/x86/ata.c src/x86/common.c src/x86/disk.c src/x86/hob.c src/pci.c src/x86/tgl_fsp.c hal/x86_fsp_tgl.c hal/x86_uart.c
532532

533533
stack-usage: wolfboot.bin
534534
$(Q)echo $(STACK_USAGE) > .stack_usage

arch.mk

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,39 @@ ifeq ($(ARCH),RISCV)
557557
ARCH_FLASH_OFFSET=0x20010000
558558
endif
559559

560+
## RISCV64
561+
ifeq ($(ARCH),RISCV64)
562+
CROSS_COMPILE?=riscv64-unknown-elf-
563+
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
564+
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
565+
UPDATE_OBJS:=src/update_disk.o
566+
OBJS += src/gpt.o
567+
ARCH_FLAGS=-march=rv64imafdc -mabi=lp64d -mcmodel=medany
568+
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV64
569+
CFLAGS+=$(ARCH_FLAGS)
570+
LDFLAGS+=$(ARCH_FLAGS)
571+
572+
# Prune unused functions and data
573+
CFLAGS +=-ffunction-sections -fdata-sections
574+
LDFLAGS+=-Wl,--gc-sections
575+
576+
OBJS+=src/boot_riscv64_start.o src/boot_riscv64.o src/vector_riscv64.o
577+
578+
CFLAGS+=-DWOLFBOOT_FDT
579+
OBJS+=src/fdt.o
580+
581+
ifeq ($(SPMATH),1)
582+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c64.o
583+
endif
584+
585+
ifneq ($(NO_ASM),1)
586+
MATH_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha256.o \
587+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha512.o \
588+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha3.o \
589+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-aes.o
590+
endif
591+
endif
592+
560593
# powerpc
561594
ifeq ($(ARCH),PPC)
562595
CROSS_COMPILE?=powerpc-linux-gnu-
@@ -815,7 +848,7 @@ ifeq ($(TARGET),nxp_t1024)
815848
ARCH_FLAGS=-mhard-float -mcpu=e5500
816849
CFLAGS+=$(ARCH_FLAGS)
817850
BIG_ENDIAN=1
818-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
851+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
819852
CFLAGS+=-pipe # use pipes instead of temp files
820853
CFLAGS+=-feliminate-unused-debug-types
821854
LDFLAGS+=$(ARCH_FLAGS)
@@ -836,7 +869,7 @@ ifeq ($(TARGET),nxp_t2080)
836869
ARCH_FLAGS=-mhard-float -mcpu=e6500
837870
CFLAGS+=$(ARCH_FLAGS)
838871
BIG_ENDIAN=1
839-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
872+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
840873
CFLAGS+=-pipe # use pipes instead of temp files
841874
CFLAGS+=-feliminate-unused-debug-types
842875
LDFLAGS+=$(ARCH_FLAGS)
@@ -1012,6 +1045,8 @@ ifeq ("${FSP}", "1")
10121045
LD_START_GROUP =
10131046
LD_END_GROUP =
10141047
LD := ld
1048+
# load to address in RAM after wolfBoot (aligned to 16 bytes)
1049+
CFLAGS+=-DWOLFBOOT_NO_LOAD_ADDRESS
10151050
ifeq ($(filter-out $(STAGE1),1),)
10161051
# building stage1
10171052
ifeq ($(FSP_TGL), 1)
@@ -1079,7 +1114,8 @@ ifeq ("${FSP}", "1")
10791114
CFLAGS+=-DWOLFBOOT_USE_PCI
10801115
OBJS += src/x86/ahci.o
10811116
OBJS += src/x86/ata.o
1082-
OBJS += src/x86/gpt.o
1117+
OBJS += src/gpt.o
1118+
OBJS += src/x86/disk.o
10831119
OBJS += src/x86/mptable.o
10841120
OBJS += src/stage2_params.o
10851121
OBJS += src/x86/exceptions.o
@@ -1339,7 +1375,7 @@ BOOT_IMG?=test-app/image.bin
13391375

13401376
## Update mechanism
13411377
ifeq ($(ARCH),AARCH64)
1342-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
1378+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
13431379
OBJS+=src/fdt.o
13441380
UPDATE_OBJS:=src/update_ram.o
13451381
else
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ARCH?=RISCV64
2+
TARGET?=mpfs250
3+
SIGN?=ECC384
4+
HASH?=SHA384
5+
IMAGE_HEADER_SIZE=512
6+
WOLFBOOT_VERSION?=1
7+
ARMORED?=0
8+
DEBUG?=0
9+
DEBUG_SYMBOLS?=1
10+
DEBUG_UART?=1
11+
VTOR?=1
12+
EXT_FLASH?=1
13+
SPI_FLASH?=0
14+
NO_XIP?=1
15+
NVM_FLASH_WRITEONCE?=0
16+
UART_FLASH?=0
17+
V?=0
18+
NO_MPU?=1
19+
RAM_CODE?=0
20+
SPMATH?=1
21+
DUALBANK_SWAP?=0
22+
PKA?=0
23+
ENCRYPT=0
24+
WOLFTPM?=0
25+
26+
# Optionally allow downgrade to older valid version in update partition
27+
ALLOW_DOWNGRADE?=0
28+
29+
# Use assembly version of ECDSA and SHA
30+
NO_ASM?=0
31+
NO_ARM_ASM?=0
32+
33+
# Optional: Use smaller SHA512
34+
#CFLAGS_EXTRA+=-DUSE_SLOW_SHA512
35+
36+
# Flash sector size (4KB typical)
37+
WOLFBOOT_SECTOR_SIZE?=0x1000
38+
39+
# Load Partition to RAM Address
40+
WOLFBOOT_LOAD_ADDRESS?=0xA0000000
41+
42+
# Partition layout for PolarFire SoC MPFS250T
43+
# TODO: Update with actual flash layout based on your system design
44+
WOLFBOOT_PARTITION_SIZE?=0x10000
45+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08080000
46+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x08090000
47+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x080FF000
48+
49+
# DTS (Device Tree)
50+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x80000000
51+
WOLFBOOT_DTS_BOOT_ADDRESS?=0x20F00000
52+
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x20F00000
53+
54+
#CFLAGS_EXTRA+=-DDEBUG_EXT_FLASH

config/examples/raspi3-encrypted.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS=0xFFFFFFFF
1616
WOLFBOOT_PARTITION_SIZE=0x1000000
1717
WOLFBOOT_SECTOR_SIZE=0x400
1818
EXT_FLASH=0
19-
MMU=1
2019
ENCRYPT=1
2120
NO_XIP=1
2221
ENCRYPT_WITH_AES256=1

docs/Targets.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This README describes configuration of supported targets.
1212
* [Kontron VX3060-S2](#kontron-vx3060-s2)
1313
* [Microchip PIC32CK](#microchip-pic32ck)
1414
* [Microchip PIC32CZ](#microchip-pic32cz)
15+
* [Microchip PolarFire SoC](#microchip-polarfire-soc)
1516
* [Microchip SAMA5D3](#microchip-sama5d3)
1617
* [Microchip SAME51](#microchip-same51)
1718
* [Nordic nRF52840](#nordic-nrf52840)
@@ -778,6 +779,110 @@ add-symbol-file test-app/image.elf 0x20020100
778779
```
779780

780781

782+
## Microchip PolarFire SoC
783+
784+
The PolarFire SoC is a 64-bit RISC-V SoC featuring a five-core CPU cluster (1× E51 monitor core and 4× U54 application cores) and FPGA fabric. Tested with MPFS250.
785+
786+
### Features
787+
* RISC-V 64-bit architecture (rv64imac)
788+
* Five-core CPU: 1× E51 monitor + 4× U54 application cores
789+
* Integrated DDR3/4, LPDDR3/4 controller and PHY
790+
* PCIe Gen2, USB 2.0, and Gigabit Ethernet interfaces
791+
* Secure boot capabilities
792+
* Low power consumption
793+
* External flash support
794+
795+
### Building PolarFire SoC
796+
797+
All build settings come from .config file. For this platform use `TARGET=mpfs250` and `ARCH=RISCV64`.
798+
799+
See example configuration at `config/examples/polarfire_mpfs250.config`.
800+
801+
```sh
802+
cp config/examples/polarfire_mpfs250.config .config
803+
make wolfboot.elf
804+
```
805+
806+
To assemble this as a flashable image you need the 0x100 byte HART header added:
807+
808+
```sh
809+
git clone https://github.com/polarfire-soc/hart-software-services.git
810+
cd hart-software-services
811+
cd tools/hss-payload-generator
812+
make
813+
# install tool
814+
sudo cp hss-payload-generator /usr/local/bin/
815+
```
816+
817+
Use this command to assemble a bootable wolfboot image:
818+
819+
```sh
820+
hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin
821+
```
822+
823+
Any customizations to the Device Tree can be made in mpfs.dts and it can be recompiled using: `dtc -I dts -O dtb mpfs.dts -o mpfs.dtb`
824+
825+
826+
Example one-shot command:
827+
828+
```sh
829+
cp ./config/examples/polarfire_mpfs250.config .config && make clean && make wolfboot.elf && size wolfboot.elf && hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin && file wolfboot.bin && ls -la wolfboot.bin
830+
```
831+
832+
### Flashing PolarFire SoC
833+
834+
835+
The HSS MMC boot source looks for GPT with GUID "21686148-6449-6E6F-744E-656564454649" or sector "0" if no GPT found. That GUID is the default "BIOS" boot partition.
836+
837+
The resulting image from `hss-payload-generator` can be directly placed into GPT BIOS partition. The HSS tinyCLI supports the `USBDMSC` command to mount the eMMC or SD card as a USB device. You can then use "dd" to copy the boot image to the BOOT partition 2. Example:
838+
839+
```
840+
sudo dd if=wolfboot.bin of=/dev/sde2 bs=1024
841+
```
842+
843+
Flashing to eNVM:
844+
845+
The boot rom expects a 0x100 byte secure boot header added. It also requires the .ld is offset by 0x100 to leave room for this. The mpfsBootmodeProgrammer adds 0x100 of meta information for secure boot.
846+
847+
```sh
848+
$SC_INSTALL_DIR/eclipse/jre/bin/java -jar \
849+
$SC_INSTALL_DIR/extras/mpfs/mpfsBootmodeProgrammer.jar \
850+
--bootmode 1 --die MPFS250T --package FCVG484 --workdir $PWD wolfboot.elf
851+
```
852+
Note: wolfBoot does not support running from eNVM in machine mode yet.
853+
854+
### Debugging PolarFire Soc
855+
856+
Start GDB server:
857+
858+
```sh
859+
$SC_INSTALL_DIR/openocd/bin/openocd --command "set DEVICE MPFS" --file board/microsemi-riscv.cfg
860+
```
861+
862+
Start GDB Client: `riscv64-unknown-elf-gdb`
863+
864+
```
865+
file wolfboot.elf
866+
tar rem:3333
867+
add-symbol-file ../hart-software-services/build/hss-l2scratch.elf
868+
set pagination off
869+
foc c
870+
871+
set $target_riscv=1
872+
set mem inaccessible-by-default off
873+
set architecture riscv:rv64
874+
#load wolfboot.elf
875+
#thread apply 2 set $pc=_reset
876+
#thread apply all set $pc=_start
877+
```
878+
879+
### PolarFire TODO
880+
881+
1) Add support for full HSS replacement using wolfboot.
882+
2) Add support for eMMC and QSPI NOR flash
883+
884+
885+
781886
## STM32F7
782887

783888
The STM32-F76x and F77x offer dual-bank hardware-assisted swapping.

hal/mpfs.dtb

19.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)