Skip to content

Commit a0e3442

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

38 files changed

+2993
-249
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
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
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
with:
2020
arch: riscv
2121
config-file: ./config/examples/hifive1.config
22+
# Only building wolfBoot - not test app for now (cross compiler cannot find suitable multilib set for '-march=rv32imafdc_zicsr_zmmul_zaamo_zalrsc_zca_zcd_zcf'/'-mabi=ilp32d')
23+
# Consider building cached RISCV64 toolchain for this target
24+
test-args: wolfboot.bin
2225

2326
sama5d3_test:
2427
uses: ./.github/workflows/test-build.yml
@@ -207,6 +210,15 @@ jobs:
207210
arch: arm
208211
config-file: ./config/examples/mcxw-tz.config
209212

213+
microchip_mpfs250_test:
214+
uses: ./.github/workflows/test-build-riscv.yml
215+
with:
216+
arch: riscv64
217+
config-file: ./config/examples/polarfire_mpfs250.config
218+
# Only building wolfBoot - not test app for now (cross compiler cannot find suitable multilib set for '-march=rv64imafd_zicsr_zmmul_zaamo_zalrsc'/'-mabi=lp64d')
219+
# Consider building cached RISCV64 toolchain for this target
220+
test-args: wolfboot.bin
221+
210222
raspi3_test:
211223
uses: ./.github/workflows/test-build.yml
212224
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: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,10 @@ endif
545545
## RISCV
546546
ifeq ($(ARCH),RISCV)
547547
CROSS_COMPILE?=riscv32-unknown-elf-
548-
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -march=rv32imac -mabi=ilp32 -mcmodel=medany -nostartfiles -DARCH_RISCV
549-
LDFLAGS+=-march=rv32imac -mabi=ilp32 -mcmodel=medany
548+
ARCH_FLAGS=-march=rv32imac -mabi=ilp32 -mcmodel=medany
549+
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV
550+
CFLAGS+=$(ARCH_FLAGS)
551+
LDFLAGS+=$(ARCH_FLAGS)
550552
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
551553

552554
# Prune unused functions and data
@@ -557,6 +559,39 @@ ifeq ($(ARCH),RISCV)
557559
ARCH_FLASH_OFFSET=0x20010000
558560
endif
559561

562+
## RISCV64
563+
ifeq ($(ARCH),RISCV64)
564+
CROSS_COMPILE?=riscv64-unknown-elf-
565+
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
566+
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
567+
UPDATE_OBJS:=src/update_disk.o
568+
OBJS += src/gpt.o
569+
ARCH_FLAGS=-march=rv64imafd -mabi=lp64d -mcmodel=medany
570+
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV64
571+
CFLAGS+=$(ARCH_FLAGS)
572+
LDFLAGS+=$(ARCH_FLAGS)
573+
574+
# Prune unused functions and data
575+
CFLAGS +=-ffunction-sections -fdata-sections
576+
LDFLAGS+=-Wl,--gc-sections
577+
578+
OBJS+=src/boot_riscv64_start.o src/boot_riscv64.o src/vector_riscv64.o
579+
580+
CFLAGS+=-DWOLFBOOT_FDT
581+
OBJS+=src/fdt.o
582+
583+
ifeq ($(SPMATH),1)
584+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c64.o
585+
endif
586+
587+
ifneq ($(NO_ASM),1)
588+
MATH_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha256.o \
589+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha512.o \
590+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-sha3.o \
591+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/riscv/riscv-64-aes.o
592+
endif
593+
endif
594+
560595
# powerpc
561596
ifeq ($(ARCH),PPC)
562597
CROSS_COMPILE?=powerpc-linux-gnu-
@@ -815,7 +850,7 @@ ifeq ($(TARGET),nxp_t1024)
815850
ARCH_FLAGS=-mhard-float -mcpu=e5500
816851
CFLAGS+=$(ARCH_FLAGS)
817852
BIG_ENDIAN=1
818-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
853+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
819854
CFLAGS+=-pipe # use pipes instead of temp files
820855
CFLAGS+=-feliminate-unused-debug-types
821856
LDFLAGS+=$(ARCH_FLAGS)
@@ -836,7 +871,7 @@ ifeq ($(TARGET),nxp_t2080)
836871
ARCH_FLAGS=-mhard-float -mcpu=e6500
837872
CFLAGS+=$(ARCH_FLAGS)
838873
BIG_ENDIAN=1
839-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
874+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
840875
CFLAGS+=-pipe # use pipes instead of temp files
841876
CFLAGS+=-feliminate-unused-debug-types
842877
LDFLAGS+=$(ARCH_FLAGS)
@@ -1012,6 +1047,8 @@ ifeq ("${FSP}", "1")
10121047
LD_START_GROUP =
10131048
LD_END_GROUP =
10141049
LD := ld
1050+
# load to address in RAM after wolfBoot (aligned to 16 bytes)
1051+
CFLAGS+=-DWOLFBOOT_NO_LOAD_ADDRESS
10151052
ifeq ($(filter-out $(STAGE1),1),)
10161053
# building stage1
10171054
ifeq ($(FSP_TGL), 1)
@@ -1079,7 +1116,8 @@ ifeq ("${FSP}", "1")
10791116
CFLAGS+=-DWOLFBOOT_USE_PCI
10801117
OBJS += src/x86/ahci.o
10811118
OBJS += src/x86/ata.o
1082-
OBJS += src/x86/gpt.o
1119+
OBJS += src/gpt.o
1120+
OBJS += src/x86/disk.o
10831121
OBJS += src/x86/mptable.o
10841122
OBJS += src/stage2_params.o
10851123
OBJS += src/x86/exceptions.o
@@ -1339,7 +1377,7 @@ BOOT_IMG?=test-app/image.bin
13391377

13401378
## Update mechanism
13411379
ifeq ($(ARCH),AARCH64)
1342-
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
1380+
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
13431381
OBJS+=src/fdt.o
13441382
UPDATE_OBJS:=src/update_ram.o
13451383
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.

0 commit comments

Comments
 (0)