Skip to content

Commit 5f51e0f

Browse files
dgarskedanielinux
authored andcommitted
Working Secure boot of PolarFire SoC
1 parent d12c79e commit 5f51e0f

File tree

11 files changed

+200
-116
lines changed

11 files changed

+200
-116
lines changed

config/examples/polarfire_mpfs250.config

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DEBUG?=0
99
DEBUG_SYMBOLS?=1
1010
DEBUG_UART?=1
1111
VTOR?=1
12-
EXT_FLASH?=1
12+
EXT_FLASH?=0
1313
SPI_FLASH?=0
1414
NO_XIP?=1
1515
NVM_FLASH_WRITEONCE?=0
@@ -39,7 +39,7 @@ NO_ARM_ASM?=0
3939
WOLFBOOT_SECTOR_SIZE?=0x1000
4040

4141
# Load Partition to RAM Address
42-
WOLFBOOT_LOAD_ADDRESS?=0x80200000
42+
WOLFBOOT_LOAD_ADDRESS?=0x8E000000
4343

4444
# Partition layout for PolarFire SoC MPFS250T
4545
# Using update_disk loader we just need to specify the partition number or A/B
@@ -48,9 +48,12 @@ CFLAGS_EXTRA+=-DBOOT_PART_A=1
4848
CFLAGS_EXTRA+=-DBOOT_PART_B=2
4949

5050
# DTS (Device Tree)
51-
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8a000000
51+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x8A000000
5252

53+
# Optional EMMC_SD debugging logs
5354
#CFLAGS_EXTRA+=-DDEBUG_MMC
55+
# Optional disk debugging logs
56+
#CFLAGS_EXTRA+=-DDEBUG_DISK
5457

5558
# Used by test-application for ELF
5659
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80200000

docs/Targets.md

Lines changed: 124 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,15 @@ The PolarFire SoC is a 64-bit RISC-V SoC featuring a five-core CPU cluster (1×
792792
* Low power consumption
793793
* External flash support
794794

795+
### PolarFire SoC Files
796+
797+
`hal/mpfs250.c` - Hardware abstraction layer implementation (UART and uSD)
798+
`hal/mpfs250.h` - Register definitions and hardware interfaces
799+
`hal/mpfs250.ld` - Linker script for the platform
800+
`hal/mpfs.dts` / `hal/mpfs.dtb` - Device tree source and binary
801+
`hal/mpfs.yaml` - HSS payload generator configuration
802+
`hal/mpfs250.its` - For creating new FIT images with Kernel and DTB
803+
795804
### Building PolarFire SoC
796805

797806
All build settings come from .config file. For this platform use `TARGET=mpfs250` and `ARCH=RISCV64`.
@@ -837,18 +846,20 @@ The HSS MMC boot source looks for GPT with GUID "21686148-6449-6E6F-744E-6565644
837846

838847
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:
839848

840-
```
841-
sudo dd if=wolfboot.bin of=/dev/sdc2 bs=512
849+
```sh
850+
sudo dd if=wolfboot.bin of=/dev/sdc1 bs=512 && sudo cmp wolfboot.bin /dev/sdc1
842851
```
843852

844853
### PolarFire testing
845854

846855
This section describes how to build the test-application, create a custom uSD with required partitions and copying signing test-application to uSD partitions.
847856

848-
To use your own application (Linux FIT Image, ELF, etc) just replace test-app/image.elf with your own filename.
857+
To use your own application (Linux FIT Image, ELF, etc) just replace test-app/image.elf with your own file (example "fitImage").
849858

850859
1) Partition uSD card (replace /dev/sdc with your actual media, find using `lsblk`):
851860

861+
Note: adjust +64M for larger OFP A/B
862+
852863
```sh
853864
sudo fdisk /dev/sdc <<EOF
854865
g
@@ -906,17 +917,76 @@ Device Start End Sectors Size Type
906917
```sh
907918
# make test-app
908919
make test-app/image.elf
909-
# Sign image with version 1
920+
921+
# Sign test-app/image with version 1
910922
./tools/keytools/sign --ecc384 --sha384 test-app/image.elf wolfboot_signing_private_key.der 1
911-
# Copy signed image to both OFP partitions
912-
sudo dd if=image_v1_signed.bin of=/dev/sdc2 bs=512
913-
sudo dd if=image_v1_signed.bin of=/dev/sdc3 bs=512
923+
sudo dd if=test-app/image_v1_signed.bin of=/dev/sdc2 bs=512 && sudo cmp test-app/image_v1_signed.bin /dev/sdc2
924+
925+
# OR
914926

915-
# Copy wolfBoot to BIOS boot partition
916-
sudo dd if=wolfboot.bin of=/dev/sdc1 bs=512
927+
# Sign FIT image with version 1
928+
./tools/keytools/sign --ecc384 --sha384 fitImage wolfboot_signing_private_key.der 1
929+
sudo dd if=fitImage_v1_signed.bin of=/dev/sdc2 bs=512 && sudo cmp fitImage_v1_signed.bin /dev/sdc2
930+
931+
# Copy root file system
932+
sudo fdisk -l mchp-base-image-mpfs-video-kit.rootfs-20250725105640.wic
933+
sudo dd if=mchp-base-image-mpfs-video-kit.rootfs-20250725105640.wic skip=155648 of=/dev/sdc4 bs=512 count=944898 status=progress
917934
```
918935

919-
3) Insert SDCARD into PolarFire and let HSS start wolfBoot. You may need to use `boot sdcard` or configure/build HSS to disable MMC / enable SDCARD.
936+
4) Insert SDCARD into PolarFire and let HSS start wolfBoot. You may need to use `boot sdcard` or configure/build HSS to disable MMC / enable SDCARD.
937+
938+
### FIT Image Creation (decompress Linux Kernel Image)
939+
940+
```sh
941+
$ dumpimage -l fitImage
942+
$ dumpimage -T flat_dt -p 0 fitImage -o kernel.gz
943+
Extracted:
944+
Image 0 (kernel-1)
945+
Description: Linux kernel
946+
Created: Tue Jul 22 03:04:20 2025
947+
Type: Kernel Image
948+
Compression: gzip compressed
949+
Data Size: 5831831 Bytes = 5695.15 KiB = 5.56 MiB
950+
Architecture: RISC-V
951+
OS: Linux
952+
Load Address: 0x80200000
953+
Entry Point: 0x80200000
954+
Hash algo: sha256
955+
Hash value: 296034c3100d21e6edc417d2406c9d27ec6578fa03c4e333307d0b0b65e0092b
956+
$ gzip -cdvk kernel.gz > kernel.bin
957+
$ mkimage -f hal/mpfs250.its fitImageNew
958+
FIT description: PolarFire SoC MPFS250T
959+
Created: Mon Dec 22 15:29:32 2025
960+
Image 0 (kernel-1)
961+
Description: Kernel Image
962+
Created: Mon Dec 22 15:29:32 2025
963+
Type: Kernel Image
964+
Compression: uncompressed
965+
Data Size: 19745280 Bytes = 19282.50 KiB = 18.83 MiB
966+
Architecture: RISC-V
967+
OS: Linux
968+
Load Address: 0x80200000
969+
Entry Point: 0x80200000
970+
Hash algo: sha256
971+
Hash value: 800ce147fa91f367ec620936a59a1035c49971ed4b9080c96bdc547471e80487
972+
Image 1 (fdt-1)
973+
Description: Flattened Device Tree blob
974+
Created: Mon Dec 22 15:29:32 2025
975+
Type: Flat Device Tree
976+
Compression: uncompressed
977+
Data Size: 19897 Bytes = 19.43 KiB = 0.02 MiB
978+
Architecture: RISC-V
979+
Load Address: 0x8a000000
980+
Hash algo: sha256
981+
Hash value: 0b4efca8c0607c9a8f4f9a00ccb7691936e019f3181aab45e6d52dae91975039
982+
Default Configuration: 'conf@1'
983+
Configuration 0 (conf@1)
984+
Description: PolarFire SoC MPFS250T
985+
Kernel: kernel-1
986+
FDT: fdt-1
987+
Hash algo: sha256
988+
Hash value: unavailable
989+
```
920990

921991
### Debugging PolarFire Soc
922992

@@ -946,117 +1016,66 @@ set architecture riscv:rv64
9461016
### PolarFire Example Boot Output
9471017

9481018
```
949-
wolfBoot Version: 2.7.0 (Dec 17 2025 17:03:55)
950-
mmc_set_timeout: timeout_val 500000 (12)
951-
mmc_set_clock: requested khz: 400, actual khz: 400
952-
mmc_send_cmd: cmd_index: 0, cmd_arg: 00000000, resp_type: 0
953-
mmc_send_cmd: cmd_index: 8, cmd_arg: 00000100, resp_type: 9
954-
mmc_init: xpc:0, si8r:1, max_ma (3.3v:128 1.8v:128)
955-
mmc_send_cmd: cmd_index: 55, cmd_arg: 00000000, resp_type: 1
956-
mmc_send_cmd: cmd_index: 41, cmd_arg: 00000000, resp_type: 4
957-
ocr_reg: 0x40FF8000
958-
mmc_init: sending OCR arg: 0x41200000
959-
mmc_send_cmd: cmd_index: 55, cmd_arg: 00000000, resp_type: 1
960-
mmc_send_cmd: cmd_index: 41, cmd_arg: 41200000, resp_type: 4
961-
ocr_reg: 0x40FF8000
962-
mmc_send_cmd: cmd_index: 55, cmd_arg: 00000000, resp_type: 1
963-
mmc_send_cmd: cmd_index: 41, cmd_arg: 41200000, resp_type: 4
964-
ocr_reg: 0xC1FF8000
965-
mmc_send_cmd: cmd_index: 2, cmd_arg: 00000000, resp_type: 3
966-
mmc_send_cmd: cmd_index: 3, cmd_arg: 00000000, resp_type: 8
967-
mmc_init: rca: 43690
968-
mmc_send_cmd: cmd_index: 9, cmd_arg: AAAA0000, resp_type: 3
969-
mmc_init: sector size: 512
970-
mmc_init: sector count: 62333952
971-
mmc_send_cmd: cmd_index: 7, cmd_arg: AAAA0000, resp_type: 2
972-
mmc_send_cmd: cmd_index: 55, cmd_arg: AAAA0000, resp_type: 1
973-
mmc_send_cmd: cmd_index: 6, cmd_arg: 00000002, resp_type: 1
974-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
975-
mmc_send_cmd: cmd_index: 16, cmd_arg: 00000008, resp_type: 1
976-
mmc_send_cmd: cmd_index: 55, cmd_arg: AAAA0000, resp_type: 1
977-
mmc_read: cmd_index: 51, block_addr: 00000000, dst 0x801FFCD0, sz: 8
978-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
979-
mmc_read: status: 0
980-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
981-
mmc_read: cmd_index: 6, block_addr: 00000001, dst 0x801FFC38, sz: 64
982-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
983-
mmc_read: status: 0
984-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
985-
mmc_read: cmd_index: 6, block_addr: 80000001, dst 0x801FFC38, sz: 64
986-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
987-
mmc_read: status: 0
988-
mmc_set_clock: requested khz: 50000, actual khz: 50000
1019+
wolfBoot Version: 2.7.0 (Dec 22 2025 14:14:37)
9891020
Reading MBR...
990-
disk_read: drv:0, start:0, count:512, dst:0x801FF918
991-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
992-
mmc_read: cmd_index: 17, block_addr: 00000000, dst 0x801FF918, sz: 512
993-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
994-
mmc_read: status: 0
9951021
Found GPT PTE at sector 1
9961022
Found valid boot signature in MBR
997-
disk_read: drv:0, start:512, count:512, dst:0x801FF918
998-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
999-
mmc_read: cmd_index: 17, block_addr: 00000001, dst 0x801FF918, sz: 512
1000-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1001-
mmc_read: status: 0
10021023
Valid GPT partition table
10031024
Current LBA: 0x1
10041025
Backup LBA: 0x3B723FF
10051026
Max number of partitions: 128
10061027
Software limited: only allowing up to 16 partitions per disk.
1007-
Disk size: 1850178048
1008-
disk_read: drv:0, start:1024, count:128, dst:0x801FF818
1009-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1010-
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
1011-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1012-
mmc_read: status: 0
1013-
disk0.p0 (0_3FFFE00h@ 0_400000)
1014-
disk_read: drv:0, start:1152, count:128, dst:0x801FF818
1015-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1016-
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
1017-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1018-
mmc_read: status: 0
1019-
disk0.p1 (0_3FFFE00h@ 0_400000)
1020-
disk_read: drv:0, start:1280, count:128, dst:0x801FF818
1021-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1022-
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
1023-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1024-
mmc_read: status: 0
1025-
disk0.p2 (0_3FFFE00h@ 0_400000)
1026-
disk_read: drv:0, start:1408, count:128, dst:0x801FF818
1027-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1028-
mmc_read: cmd_index: 17, block_addr: 00000002, dst 0x801FF588, sz: 512
1029-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1030-
mmc_read: status: 0
1031-
disk0.p3 (0_3FFFE00h@ 0_400000)
1032-
disk_read: drv:0, start:1536, count:128, dst:0x801FF818
1033-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1034-
mmc_read: cmd_index: 17, block_addr: 00000003, dst 0x801FF588, sz: 512
1035-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1036-
mmc_read: status: 0
1028+
Disk size: 1849146880
1029+
disk0.p0 (0_7FFE00h@ 0_100000)
1030+
disk0.p1 (0_3FFFE00h@ 0_900000)
1031+
disk0.p2 (0_3FFFE00h@ 0_4900000)
1032+
disk0.p3 (7_65AFFE00h@ 0_8900000)
10371033
Total partitions on disk0: 4
10381034
Checking primary OS image in 0,1...
1039-
disk_read: drv:0, start:4194304, count:512, dst:0x801FFDA0
1040-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1041-
mmc_read: cmd_index: 17, block_addr: 00002000, dst 0x801FFDA0, sz: 512
1042-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1043-
mmc_read: status: 0
10441035
Checking secondary OS image in 0,2...
1045-
disk_read: drv:0, start:4194304, count:512, dst:0x801FFDA0
1046-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1047-
mmc_read: cmd_index: 17, block_addr: 00002000, dst 0x801FFDA0, sz: 512
1048-
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
1049-
mmc_read: status: 0
1050-
No valid OS image found in either partition 1 or 2
1051-
wolfBoot: PANIC!
1036+
Versions, A:1 B:1
1037+
Load address 0x8E000000
1038+
Attempting boot from P:A
1039+
Boot partition: 0x801FFDA0 (sz 19767000, ver 0x1, type 0x601)
1040+
Loading image from disk...done.
1041+
Boot partition: 0x8E000000 (sz 19767000, ver 0x1, type 0x601)
1042+
Checking image integrity...done.
1043+
Verifying image signature...done.
1044+
Firmware Valid.
1045+
Flattened uImage Tree: Version 17, Size 19767000
1046+
Loading Image kernel-1: 0x8E0002C8 -> 0x80200000 (19745280 bytes)
1047+
Image kernel-1: 0x80200000 (19745280 bytes)
1048+
Loading Image fdt-1: 0x8F2D4DCC -> 0x8A000000 (19897 bytes)
1049+
Image fdt-1: 0x8A000000 (19897 bytes)
1050+
Loading DTS: 0x8A000000 -> 0x8A000000 (19897 bytes)
1051+
Loading elf at 0x80200000
1052+
Invalid elf, falling back to raw binary
1053+
Booting at 80200000
1054+
[ 0.000000] Linux version 6.12.22-linux4microchip+fpga-2025.07-g032a7095303a (oe-user@oe-host) (riscv64-oe-linux-gcc (GCC) 13.3.0, GNU ld (GNU Binutils) 2.42.0.20240723) #1 SMP Tue Jul 22 10:04:20 UTC 2025
1055+
[ 0.000000] Machine model: Microchip PolarFire-SoC VIDEO Kit
1056+
[ 0.000000] SBI specification v1.0 detected
1057+
[ 0.000000] SBI implementation ID=0x8 Version=0x10002
1058+
[ 0.000000] SBI TIME extension detected
1059+
[ 0.000000] SBI IPI extension detected
1060+
[ 0.000000] SBI RFENCE extension detected
1061+
[ 0.000000] SBI SRST extension detected
1062+
[ 0.000000] earlycon: ns16550a0 at MMIO32 0x0000000020100000 (options '115200n8')
1063+
...
10521064
```
10531065

10541066

10551067
### PolarFire TODO
10561068

1057-
1) Add support for full HSS replacement using wolfboot.
1058-
2) Add support for eMMC and QSPI NOR flash
1059-
1069+
* Add eMMC/SD features:
1070+
- Multi-block read (CMD18 support)
1071+
- DMA read support
1072+
- Write support
1073+
- eMMC support (not just SD)
1074+
* Add support for reading serial number and modifying ethernet MAC in device tree
1075+
* Add support for QSPI NOR flash
1076+
* Add support for full HSS replacement using wolfboot
1077+
- Machine level assembly startup
1078+
- DDR driver
10601079

10611080

10621081
## STM32F7

hal/mpfs.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
set-name: 'PolarFire-SoC-HSS::wolfBoot'
66
hart-entry-points: {
7-
u54_1: '0x80200000',
8-
u54_2: '0x80200000',
9-
u54_3: '0x80200000',
10-
u54_4: '0x80200000'
7+
u54_1: '0x80000000',
8+
u54_2: '0x80000000',
9+
u54_3: '0x80000000',
10+
u54_4: '0x80000000'
1111
}
1212
payloads:
1313
wolfboot.elf: {
14-
exec-addr: '0x80200000',
1514
owner-hart: u54_1,
1615
secondary-hart: u54_2,
1716
secondary-hart: u54_3,

hal/mpfs250.its

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/dts-v1/;
2+
3+
/ {
4+
description = "PolarFire SoC MPFS250T";
5+
#address-cells = <1>;
6+
7+
images {
8+
kernel-1 {
9+
description = "Kernel Image";
10+
data = /incbin/("../kernel.bin");
11+
type = "kernel";
12+
arch = "riscv";
13+
os = "linux";
14+
compression = "none";
15+
load = <0x80200000>;
16+
entry = <0x80200000>;
17+
hash {
18+
algo = "sha256";
19+
};
20+
};
21+
fdt-1 {
22+
description = "Flattened Device Tree blob";
23+
data = /incbin/("mpfs.dtb");
24+
type = "flat_dt";
25+
arch = "riscv";
26+
compression = "none";
27+
load = <0x8a000000>;
28+
hash {
29+
algo = "sha256";
30+
};
31+
};
32+
};
33+
configurations {
34+
default = "conf@1";
35+
conf@1 {
36+
description = "PolarFire SoC MPFS250T";
37+
kernel = "kernel-1";
38+
fdt = "fdt-1";
39+
hash {
40+
algo = "sha256";
41+
};
42+
};
43+
};
44+
};

hal/mpfs250.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MEMORY
99
{
1010
/* The first 0x100 bytes of eNVM are used for boot ROM secure boot meta information */
1111
FLASH_ENVM (rx) : ORIGIN = 0x20220100, LENGTH = 128k - 0x100
12-
DDR (rx) : ORIGIN = 0x80200000, LENGTH = 1028k
12+
DDR (rx) : ORIGIN = 0x80000000, LENGTH = 1028k
1313
L2_SCRATCH (rwx) : ORIGIN = 0x0A000000, LENGTH = 256k
1414
}
1515

0 commit comments

Comments
 (0)