PolarFire SoC M-Mode: Fix L2 scratchpad init, QSPI programmer and WDT support#747
Open
dgarske wants to merge 2 commits intowolfSSL:masterfrom
Open
PolarFire SoC M-Mode: Fix L2 scratchpad init, QSPI programmer and WDT support#747dgarske wants to merge 2 commits intowolfSSL:masterfrom
dgarske wants to merge 2 commits intowolfSSL:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes PolarFire SoC MPFS250 M-mode boot stability and robustness by correcting L2 scratchpad initialization, hardening the UART QSPI programmer path, and adding optional watchdog support with safer boot handoff.
Changes:
- Fix L2 scratchpad copy on E51 by routing D-cache stores to scratchpad ways and adding appropriate fences.
- Make UART QSPI programmer more reliable on USB-UART bridges and reduce protocol corruption risks by using direct UART output.
- Add WATCHDOG build option plus build/runtime safety checks (linker ASSERT + RAM overlap guard) and documentation updates.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/scripts/mpfs_qspi_prog.py | Throttles UART writes to avoid USB-UART bulk-write stalls. |
| src/update_ram.c | Adds runtime guard to prevent RAM image load overlapping wolfBoot region. |
| src/boot_riscv_start.S | Fixes MPFS250 L2 scratchpad initialization (D-cache way mask + fences). |
| src/boot_riscv.c | Ensures synchronous traps always print and halt; adds optional stack overflow diagnostics. |
| hal/mpfs250.h | Adds MPFS watchdog register definitions and a QSPI reset bit define. |
| hal/mpfs250.c | Implements watchdog handling, QSPI programmer UART output changes, and RTS assertion. |
| hal/mpfs250-m.ld | Reduces stack size and adds linker-time overlap ASSERT using WOLFBOOT_LOAD_ADDRESS. |
| docs/Targets.md | Documents M-mode optional flags and stack overflow detection. |
| config/examples/polarfire_mpfs250_m_qspi.config | Enables UART QSPI programmer by default; adds STRIP_ELF and WATCHDOG flag docs; adjusts load address/stack settings. |
| Makefile | Adds optional ELF stripping before signing; wires WOLFBOOT_LOAD_ADDRESS into linker script templating. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PolarFire SoC M-Mode: Fix L2 scratchpad init, QSPI programmer, and add WDT support
Summary
L2 Scratchpad Fix (root cause of TRAP cause=2)
The eNVM→L2 Scratchpad copy in
boot_riscv_start.Swrote through the D-cache withWAY_MASK_E51_DCACHE = 0xFF(cache ways 0-7). Stores landed in cache and never reached the scratchpad SRAM (ways 8-11). The I-cache later fetched from the uninitialized scratchpad and got zeros, causing non-deterministic illegal-instruction traps during SHA384/ECDSA verification.Fix: set
WAY_MASK_E51_DCACHE = 0xF00(scratchpad ways) before the copy, restore to0xFFafter. This follows the HSSmss_l2_cache.cconfig_l2_cache()pattern.Also added
fence rw,rwbeforefence.iafter the copy — the standard RISC-V pattern for ensuring store visibility before I-cache invalidation.QSPI Programmer Fix
The USB-UART bridge on the PolarFire Video Kit stalls when receiving bulk serial writes (256 bytes at once). The fix sends data in 8-byte pieces with 10ms inter-piece delays in
mpfs_qspi_prog.py.Additionally, the QSPI programmer now uses
uart_qspi_puts()(direct UART register writes) instead ofwolfBoot_printf()/uart_write()for all protocol messages. Theuart_write()function inserts\rbefore\n, which can corrupt the binary ACK/data protocol.QSPI transfer block error messages are now guarded by
#ifdef DEBUG_QSPIto prevent them from leaking into the UART during the binary protocol phase.Watchdog Timer Support
New
WATCHDOGbuild option (follows the s32k1xx pattern):hal_init(), restored to boot ROM defaults inhal_prepare_boot()beforedo_boot()-DWATCHDOG): WDT kept running with configurable timeout (WATCHDOG_TIMEOUT_MS, default 30s) — large enough to cover ECDSA P-384 verify (~5s) without needing per-operation refreshEither way,
hal_prepare_boot()restores the boot ROM WDT default so the application receives a normal watchdog.Trap Handler Improvements
DEBUG_BOOT, causing silent infinite mret loops without it)DEBUG_BOOT: prints SP value and detects stack overflow by comparing against_main_hart_stack_bottomlinker symbolBuild Safety
STRIP_ELF=1: Makefile strips debug symbols before signing (149KB → 5KB for M-mode L2 Scratch fit)wolfBoot_ramboot()checks image destination against_endSTACK_PAINTINGdiagnostic: paints stack with sentinel at boot, reports peak usage after verificationConfig Changes (
polarfire_mpfs250_m_qspi.config)UART_QSPI_PROGRAM=1(enabled by default for M-mode)STRIP_ELF=1(required for L2 Scratch fit)STACK_SIZE_PER_HART=0(secondary harts unused in M-mode)WOLFBOOT_LOAD_ADDRESS=0x0A020200(128KB reserved for wolfBoot growth)DEBUG_BOOTcommented out (production default)