Repository navigation
eeprom: read the block before a write that ends inside it - #9
Open
vitorjordao wants to merge 1 commit into
Open
vitorjordao wants to merge 1 commit into
vitorjordao wants to merge 1 commit into
Conversation
eeprom_write_bytes fetched the last block of a partial write only when it differed from the first one. A write that starts on a block boundary and ends inside the same block (e.g. eeprom_write_bytes(src, 16, 3)) therefore skipped the read-modify-write: if the block was not cached yet, the rest of it came from the uninitialized cache memory, and the flush wrote that over the EEPROM contents. Fetch the last block whenever the write ends inside it. When it is also the first block, the second fetch is a no-op. Add test_eeprom_read_bytes and test_eeprom_write_bytes, which check spans inside a block, across a boundary and on whole blocks against the hardware contents (they need a ROM with an EEPROM save type).
This was referenced Oct 29, 2026
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.
Fixes #8.
eeprom_write_bytesreads a block back before a partial write only when the write starts inside it, or ends inside a different last block. A write that starts on a block boundary and ends inside the same block skips the read-back. Example:eeprom_write_bytes(src, 136, 3), i.e. block 17, bytes 0..2. If that block isn't cached yet, bytes 3..7 come from uninitialized cache memory, and the flush writes them to the EEPROM.The fix fetches the last block whenever the write ends inside it (
end_offset != 0). When the last block is also the first one,eeprom_cache_ensure_block_validreturns early on the second call because the block is already valid.Tests
Two new testrom tests,
test_eeprom_read_bytesandtest_eeprom_write_bytes. Each one goes through seven spans, written as (offset in the block, length):(5,1),(1,3),(0,3)(3,5)(6,4),(0,11)(0,8)For each span, the tests:
eeprom_read_bytes/eeprom_write_bytes, theneeprom_wait_idle;They check that only the span changed, including the blocks on either side, and that a read writes nothing outside its destination. The tests skip without EEPROM, like
test_eepromfs, so the ROM has to be built with a save type:make -C tests N64_ROM_SAVETYPE=eeprom4k.ares v148,
testrom_emu.z64,N64_ROM_SAVETYPE=eeprom4k.Before the fix (f26e1c1 with the new tests):
After the fix (same result with
eeprom16k):The remaining failure is
test_timer_ticks. It fails the same way before and after this change, and it is unrelated.