Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear SP flash errors we should never see #1905

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions drv/stm32h7-update-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ impl<'a> ServerImpl<'a> {
fn bank2_status(&self) -> Result<(), RequestError<UpdateError>> {
let err = self.flash.bank2().sr.read();

// We purposely omit checking `rdserr` and `rdperr` as
// speculative access may trigger those bits

if err.dbeccerr().bit() {
return Err(UpdateError::EccDoubleErr.into());
}
Expand All @@ -133,14 +136,6 @@ impl<'a> ServerImpl<'a> {
return Err(UpdateError::EccSingleErr.into());
}

if err.rdserr().bit() {
return Err(UpdateError::SecureErr.into());
}

if err.rdperr().bit() {
return Err(UpdateError::ReadProtErr.into());
}

if err.operr().bit() {
return Err(UpdateError::WriteEraseErr.into());
}
Expand Down Expand Up @@ -172,6 +167,7 @@ impl<'a> ServerImpl<'a> {
words: &[u32; FLASH_WORD_WORDS],
) -> Result<(), RequestError<UpdateError>> {
ringbuf_entry!(Trace::WriteStart);
self.clear_errors();

// These variables are _philosophically_ constants, but since they're
// generated by taking the address of a linker-generated symbol, we
Expand Down Expand Up @@ -243,9 +239,24 @@ impl<'a> ServerImpl<'a> {
.write(|w| unsafe { w.optkeyr().bits(FLASH_OPT_KEY2) });
}

fn clear_errors(&mut self) {
// https://github.com/zephyrproject-rtos/zephyr/issues/60449
// https://community.st.com/t5/stm32-mcus-products/spurious-rdperr-and-rdserr-when-all-protection-and-security/td-p/279852
// There are issue with the CPU speculating into unknown
// areas. One workaround is to explicitly mark the reigon as NX
// via MPU but that's expensive/costs an MPU region
// Another workaround is to just clear errors we don't
// expect to see
self.flash
.bank2()
.ccr
.modify(|_, w| w.clr_rdperr().set_bit().clr_rdserr().set_bit());
}

fn bank_erase(&mut self) -> Result<(), RequestError<UpdateError>> {
ringbuf_entry!(Trace::EraseStart);

self.clear_errors();
// Enable relevant interrupts for completion (or failure) of erasing
// bank2.
sys_irq_control(notifications::FLASH_IRQ_MASK, true);
Expand Down