Skip to content

akiko: keep CD32 NVRAM dirty when the backing-file write fails#266

Merged
LinuxJedi merged 2 commits into
mainfrom
fix/cd32-nvram-write-retry
Jul 23, 2026
Merged

akiko: keep CD32 NVRAM dirty when the backing-file write fails#266
LinuxJedi merged 2 commits into
mainfrom
fix/cd32-nvram-write-retry

Conversation

@LinuxJedi

Copy link
Copy Markdown
Collaborator

Summary

The CD32 NVRAM flush (Nvram::stop) cleared its dirty bit before attempting the backing-file write, so a transient host error -- full disk, missing directory, permissions -- silently dropped the EEPROM contents: no later I2C STOP would retry, and nothing persisted until the guest happened to write the NVRAM again. Save games are exactly what lives here, so a one-off failure could quietly lose them.

The dirty bit is now cleared only after std::fs::write succeeds; on failure it stays armed and the flush retries at the next STOP. Retries are naturally rate-limited because only a STOP with dirty contents attempts a write.

This is the same durability fix Copilot flagged on the RP5C01 battmem flush in #265 -- that code had inherited the clear-before-write pattern from here, so this brings the original in line.

Testing

  • New unit test nvram_retries_the_backing_file_write_after_a_failure: points the backing file into a not-yet-created directory, drives a page write over the bit-banged I2C lines, and checks the failed STOP leaves the state dirty, a later STOP lands the file once the directory exists, and the contents match the written byte.
  • Full suite passes; cargo clippy and cargo fmt --check clean.

Clearing the dirty bit before the write meant a transient host error
(full disk, missing directory, permissions) silently dropped the
EEPROM contents: no later I2C STOP would retry, so nothing persisted
until the guest wrote the NVRAM again. Clear it only after the write
lands; a failure leaves it armed and the flush retries at the next
STOP. Retries stay naturally rate-limited because only a STOP with
dirty contents attempts a write.

Same fix as the RP5C01 battmem flush in #265, which inherited the
pattern from here.
Copilot AI review requested due to automatic review settings July 23, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes CD32 Akiko NVRAM durability by ensuring the dirty bit is only cleared after a successful backing-file write, so transient host filesystem errors don’t silently drop EEPROM contents (e.g., save games) and a later I2C STOP will retry the flush.

Changes:

  • Update Nvram::stop to keep dirty set when std::fs::write fails, clearing it only after a successful write.
  • Add a unit test that simulates a failed write (missing parent directory) and verifies a later STOP retries and persists the data once the directory exists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/akiko.rs
Match the temp-naming convention the other filesystem-touching tests
in this module use (pid + atomic counter). The pid-only name could
not collide today -- only this one test uses it and the harness runs
it once per process -- but the suffix keeps the name safe if another
test ever reuses the pattern.
@LinuxJedi
LinuxJedi merged commit 0551ff9 into main Jul 23, 2026
13 checks passed
@LinuxJedi
LinuxJedi deleted the fix/cd32-nvram-write-retry branch July 23, 2026 15:37
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.

2 participants