Skip to content

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Dec 31, 2025

Summary

This PR adds eMMC support for the PolarFire SoC platform and refactors the SD/eMMC driver code into a reusable generic SDHCI module. Additionally, it introduces support for custom encryption key implementations.

Changes

🆕 New Features

  • eMMC Support: Added full eMMC support for PolarFire SoC alongside existing SD card support
  • Generic SDHCI Driver: Refactored the Cadence SD Host Controller Interface driver into a standalone, reusable module (src/sdhci.c and include/sdhci.h) that can be used by other platforms
  • Custom Encryption Key Support: Added CUSTOM_ENCRYPT_KEY option allowing users to implement their own encryption key storage/retrieval functions

♻️ Refactoring

  • Moved ~1600 lines of SD/eMMC driver code from hal/mpfs250.c to the new generic src/sdhci.c
  • Reduced platform-specific code in hal/mpfs250.c and hal/mpfs250.h significantly
  • Added new RISC-V helper macros to hal/riscv.h

📝 Documentation

  • Updated docs/Targets.md with custom encryption key usage instructions
  • Added comprehensive CUSTOM_ENCRYPT_KEY documentation to docs/encrypted_partitions.md
  • Removed completed TODO item for eMMC support from PolarFire section

New Build Options

Option Description
DISK_SDCARD=1 Enable SD card support via SDHCI driver
DISK_EMMC=1 Enable eMMC support via SDHCI driver
CUSTOM_ENCRYPT_KEY=1 Use custom encryption key implementation

Files Changed

  • src/sdhci.c - New generic SDHCI driver implementation
  • include/sdhci.h - New SDHCI driver header with full register definitions
  • hal/mpfs250.c - Simplified to use the new generic SDHCI driver
  • hal/mpfs250.h - Reduced to platform-specific definitions only
  • hal/riscv.h - Added RISC-V specific helper macros
  • src/boot_riscv.c - Updated for eMMC boot support
  • src/update_disk.c - Enhanced disk update logic
  • src/libwolfboot.c - Conditional compilation for custom encryption keys
  • options.mk - Added new build options
  • config/examples/polarfire_mpfs250.config - Updated with SD/eMMC options
  • docs/Targets.md - Updated documentation
  • docs/encrypted_partitions.md - Added custom encryption key documentation

Usage Example

To enable eMMC instead of SD card in your config:

DISK_SDCARD=0
DISK_EMMC=1

To use custom encryption key storage:

CUSTOM_ENCRYPT_KEY=1
OBJS_EXTRA=src/my_custom_encrypt_key.o

Then implement wolfBoot_get_encrypt_key() in your custom source file.

Testing

  • ✅ eMMC support tested on PolarFire SoC hardware
  • ✅ SD card support verified to continue working

Example eMMC Encrypted Boot output (with DISK_TEST=1)

wolfBoot Version: 2.7.0 (Dec 31 2025 15:04:41)
Disk encryption enabled
disk_test: Starting tests at block 149504 (buf @ 0x8E000000)
  Test 1: size=128 bytes (1 blocks)... PASS
  Test 2: size=512 bytes (1 blocks)... PASS
  Test 3: size=1024 bytes (2 blocks)... PASS
  Test 4: size=524288 bytes (1024 blocks)... PASS
  Test 5: size=1048576 bytes (2048 blocks)... PASS
disk_test: Complete
Reading MBR...
Found GPT PTE at sector 1
Found valid boot signature in MBR
Valid GPT partition table
Current LBA: 0x1 
Backup LBA: 0xE90E7F 
Max number of partitions: 128
Software limited: only allowing up to 16 partitions per disk.
Disk size: -770916864
disk0.p0 (0_7FFE00h@ 0_100000)
disk0.p1 (0_3FFFE00h@ 0_900000)
disk0.p2 (0_3FFFE00h@ 0_4900000)
disk0.p3 (1_C97FFE00h@ 0_8900000)
Total partitions on disk0: 4
Checking primary OS image in 0,1...
Checking secondary OS image in 0,2...
Versions, A:1 B:0
Load address 0x8E000000
Attempting boot from P:A
Boot partition: 0x801FFD90 (sz 19767004, ver 0x0, type 0x0)
Loading image from disk...done. (1642 ms)
Decrypting image...done. (2894 ms)
Boot partition: 0x8E000000 (sz 19767004, ver 0x0, type 0x0)
Checking image integrity...done. (1507 ms)
Verifying image signature...done. (68 ms)
Firmware Valid.
Flattened uImage Tree: Version 17, Size 19767004
Loading Image kernel-1: 0x8E0002C8 -> 0x80200000 (19745280 bytes)
Image kernel-1: 0x80200000 (19745280 bytes)
Loading Image fdt-1: 0x8F2D4DCC -> 0x8A000000 (19897 bytes)
Image fdt-1: 0x8A000000 (19897 bytes)
Loading DTS: 0x8A000000 -> 0x8A000000 (19897 bytes)
Invalid elf, falling back to raw binary
Booting at 80200000
FDT: Version 17, Size 19897
FDT: Set chosen (13840), bootargs=earlycon root=/dev/mmcblk0p4 rootwait uio_pdrv_genirq.of_id=generic-uio
[    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
[    0.000000] Machine model: Microchip PolarFire-SoC VIDEO Kit
[    0.000000] SBI specification v1.0 detected
[    0.000000] SBI implementation ID=0x8 Version=0x10002
[    0.000000] SBI TIME extension detected
[    0.000000] SBI IPI extension detected
[    0.000000] SBI RFENCE extension detected
[    0.000000] SBI SRST extension detected
[    0.000000] earlycon: ns16550a0 at MMIO32 0x0000000020100000 (options '115200n8')
[    0.000000] printk: legacy bootconsole [ns16550a0] enabled

Example SDCARD Encrypted Boot output (with DISK_TEST=1)

wolfBoot Version: 2.7.0 (Dec 31 2025 15:08:00)
Disk encryption enabled
disk_test: Starting tests at block 149504 (buf @ 0x8E000000)
  Test 1: size=128 bytes (1 blocks)... PASS
  Test 2: size=512 bytes (1 blocks)... PASS
  Test 3: size=1024 bytes (2 blocks)... PASS
  Test 4: size=524288 bytes (1024 blocks)... PASS
  Test 5: size=1048576 bytes (2048 blocks)... PASS
disk_test: Complete
Reading MBR...
Found GPT PTE at sector 1
Found valid boot signature in MBR
Valid GPT partition table
Current LBA: 0x1 
Backup LBA: 0x3B723FF 
Max number of partitions: 128
Software limited: only allowing up to 16 partitions per disk.
Disk size: 1849146880
disk0.p0 (0_7FFE00h@ 0_100000)
disk0.p1 (0_3FFFE00h@ 0_900000)
disk0.p2 (0_3FFFE00h@ 0_4900000)
disk0.p3 (7_65AFFE00h@ 0_8900000)
Total partitions on disk0: 4
Checking primary OS image in 0,1...
Checking secondary OS image in 0,2...
Versions, A:1 B:0
Load address 0x8E000000
Attempting boot from P:A
Boot partition: 0x801FFD90 (sz 19767004, ver 0x0, type 0x0)
Loading image from disk...done. (879 ms)
Decrypting image...done. (2894 ms)
Boot partition: 0x8E000000 (sz 19767004, ver 0x0, type 0x0)
Checking image integrity...done. (1507 ms)
Verifying image signature...done. (68 ms)
Firmware Valid.
Flattened uImage Tree: Version 17, Size 19767004
Loading Image kernel-1: 0x8E0002C8 -> 0x80200000 (19745280 bytes)
Image kernel-1: 0x80200000 (19745280 bytes)
Loading Image fdt-1: 0x8F2D4DCC -> 0x8A000000 (19897 bytes)
Image fdt-1: 0x8A000000 (19897 bytes)
Loading DTS: 0x8A000000 -> 0x8A000000 (19897 bytes)
Invalid elf, falling back to raw binary
Booting at 80200000
FDT: Version 17, Size 19897
FDT: Set chosen (13840), bootargs=earlycon root=/dev/mmcblk0p4 rootwait uio_pdrv_genirq.of_id=generic-uio
[    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
[    0.000000] Machine model: Microchip PolarFire-SoC VIDEO Kit
[    0.000000] SBI specification v1.0 detected
[    0.000000] SBI implementation ID=0x8 Version=0x10002
[    0.000000] SBI TIME extension detected
[    0.000000] SBI IPI extension detected
[    0.000000] SBI RFENCE extension detected
[    0.000000] SBI SRST extension detected
[    0.000000] earlycon: ns16550a0 at MMIO32 0x0000000020100000 (options '115200n8')
[    0.000000] printk: legacy bootconsole [ns16550a0] enabled

@dgarske dgarske self-assigned this Dec 31, 2025
@dgarske dgarske requested a review from danielinux December 31, 2025 00:54
@dgarske
Copy link
Contributor Author

dgarske commented Dec 31, 2025

@danielinux Please don’t merge yet. I need to do a bit more testing with custom encryption key with update_disk loader. The SD card driver changes are good to merge, but the customer doesn’t need them for testing.

@dgarske dgarske changed the title Add CUSTOM_ENCRYPT_KEY option and Fixes for PolarFire SDCard edge cases PolarFire eMMC Support, SDHCI Driver Refactor and add CUSTOM_ENCRYPT_KEY support Dec 31, 2025
…to generic module that can be used by other platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants