Skip to content

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Dec 31, 2025

Summary

PolarFire SoC improvements: Add CUSTOM_ENCRYPT_KEY option for custom encryption key storage and fix MMC/eMMC write issues in the mpfs250 HAL.


Commits

1. Support for CUSTOM_ENCRYPT_KEY

Adds the CUSTOM_ENCRYPT_KEY build option, allowing customers to supply their own implementation for encryption key storage and retrieval.

Use case: Useful when encryption keys need to be stored in secure hardware (HSM, secure enclave, TPM) or custom non-volatile storage rather than the default flash-based implementation.

How to enable:

  1. Add CUSTOM_ENCRYPT_KEY=1 to your .config
  2. Provide a custom implementation via OBJS_EXTRA=src/custom_encrypt_key.o

Required custom functions:
int wolfBoot_set_encrypt_key(const uint8_t *key, const uint8_t *nonce);
int wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce);
int wolfBoot_erase_encrypt_key(void);
int wolfBoot_initialize_encryption(void);

2. Fixes for mmc_write (mpfs250 HAL)

Fixes reliability issues with MMC/eMMC write operations on PolarFire SoC.

Key changes:

Area Fix
DMA boundary handling Moved DMA address update logic into mmc_irq_handler() for proper interrupt-driven updates
Timeout configuration Split into init timeout (500ms) and data timeout (3000ms) for better reliability
Command error handling Improved error reporting with separate timeout vs error conditions
Device busy checking Moved busy check into mmc_send_cmd_internal() for consistency
Transfer completion Wait for transfer complete before checking status in PIO mode
Multi-block writes Properly wait for idle after CMD12 stop transfer

Test results:

disk_test: Starting tests at block 149504 (buf @ 0x8E000000)
  Test 1: size=128 bytes (1 blocks)... 
disk_write: drv:0, start:76546048, count:128, src:0x8E000000
mmc_read: cmd_index: 17, block_addr: 00024800, dst 0x801FFA60, sz: 512 (1 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
mmc_write: cmd_index: 24, block_addr: 00024800, src 0x801FFA60, sz: 512 (1 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_write: status: 0
disk_read: drv:0, start:76546048, count:128, dst:0x8E000000
mmc_read: cmd_index: 17, block_addr: 00024800, dst 0x801FFA70, sz: 512 (1 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
PASS
  Test 2: size=512 bytes (1 blocks)... 
disk_write: drv:0, start:76546048, count:512, src:0x8E000000
mmc_write: cmd_index: 24, block_addr: 00024800, src 0x8E000000, sz: 512 (1 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_write: status: 0
disk_read: drv:0, start:76546048, count:512, dst:0x8E000000
mmc_read: cmd_index: 17, block_addr: 00024800, dst 0x8E000000, sz: 512 (1 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
PASS
  Test 3: size=1024 bytes (2 blocks)... 
disk_write: drv:0, start:76546048, count:1024, src:0x8E000000
mmc_write: cmd_index: 25, block_addr: 00024800, src 0x8E000000, sz: 1024 (2 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 2
mmc_write: CMD12 stop transfer error
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_write: status: 0
disk_read: drv:0, start:76546048, count:1024, dst:0x8E000000
mmc_read: cmd_index: 18, block_addr: 00024800, dst 0x8E000000, sz: 1024 (2 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
PASS
  Test 4: size=524288 bytes (1024 blocks)... 
disk_write: drv:0, start:76546048, count:524288, src:0x8E000000
mmc_write: cmd_index: 25, block_addr: 00024800, src 0x8E000000, sz: 524288 (1024 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_irq_handler: status=0x00000002, flags=0x02
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 2
mmc_write: CMD12 stop transfer error
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_write: status: 0
disk_read: drv:0, start:76546048, count:524288, dst:0x8E000000
mmc_read: cmd_index: 18, block_addr: 00024800, dst 0x8E000000, sz: 524288 (1024 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_irq_handler: status=0x00000002, flags=0x02
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
PASS
  Test 5: size=1048576 bytes (2048 blocks)... 
disk_write: drv:0, start:76546048, count:1048576, src:0x8E000000
mmc_write: cmd_index: 25, block_addr: 00024800, src 0x8E000000, sz: 1048576 (2048 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_irq_handler: status=0x00000008, flags=0x04
mmc_irq_handler: status=0x00000002, flags=0x06
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 2
mmc_write: CMD12 stop transfer error
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_write: status: 0
disk_read: drv:0, start:76546048, count:1048576, dst:0x8E000000
mmc_read: cmd_index: 18, block_addr: 00024800, dst 0x8E000000, sz: 1048576 (2048 blocks)
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_irq_handler: status=0x00000008, flags=0x04
mmc_irq_handler: status=0x00000002, flags=0x06
mmc_send_cmd: cmd_index: 12, cmd_arg: AAAA0000, resp_type: 1
mmc_send_cmd: cmd_index: 13, cmd_arg: AAAA0000, resp_type: 1
mmc_read: status: 0
PASS
disk_test: Complete

@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.

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