Skip to content

fw/drivers/flash: preserve bootloader XIP setup - #1964

Draft
ericmigi wants to merge 1 commit into
coredevices:mainfrom
ericmigi:codex/firm-1420-flash-init-xip
Draft

fw/drivers/flash: preserve bootloader XIP setup#1964
ericmigi wants to merge 1 commit into
coredevices:mainfrom
ericmigi:codex/firm-1420-flash-init-xip

Conversation

@ericmigi

Copy link
Copy Markdown
Collaborator

Summary

  • avoid calling HAL_FLASH_Init on the live MPI2 controller backing firmware XIP
  • adopt the controller configuration established by pblboot and initialize only the runtime software handles
  • retain DMA, OTP, and coredump behavior while validating the board flash part against the vendor command table

Root cause

Firmware executes directly from FLASH2/MPI2. HAL_FLASH_Init rewrites that controller timing and issues manual flash commands with interrupts enabled. If SysTick or another interrupt fetches XIP code during the command, the controller can wedge and the vendor HAL waits forever for command completion. Repeated resets vary the interrupt phase, matching the rare and apparently random boot freeze in FIRM-1420.

This uses the same adopt-the-bootloader-state approach already hardware-verified in the Zephyr port instead of resetting or reconfiguring a controller while executing from it.

Testing

  • configured obelix@pvt release firmware with CONFIG_FIRMWARE_SLOT=1
  • completed a full obelix release firmware build and link
  • compiled the QSPI driver under the getafix@dvt2 configuration during investigation
  • confirmed the linked qspi_flash_init no longer calls HAL_FLASH_Init
  • git diff --check
  • gitlint

Hardware validation still required

  • run the repeated system_hard_reset reproduction loop for thousands of boots on obelix and getafix
  • exercise flash read, write, erase, PFS, OTP, and coredump paths

Linear: https://linear.app/core-dev/issue/FIRM-1420/the-system-may-occasionally-freeze-in-flash-init

The SF32LB52 firmware executes from the MPI2 flash that pblboot configures before
handing off. HAL_FLASH_Init rewrites the live controller timing and issues manual
commands while interrupts are enabled. An interrupt-driven XIP fetch can then
collide with a command and leave the HAL waiting forever for completion.

Adopt pblboot's controller state and initialize only the software flash and DMA
handles required by the runtime driver. Validate the board part against the vendor
command table while retaining OTP and coredump behavior.

Fixes FIRM-1420

Co-Authored-By: GPT-5.6 Codex <noreply@openai.com>
Signed-off-by: Eric Migicovsky <eric@repebble.com>
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.

1 participant