Repository navigation
Conversation
4eb483c to
26320e2
Compare
26320e2 to
13c62bf
Compare
|
What brand of sd card is affected? and will the fix be implemented in 1.5.0? |
Release 1.5.0
|
Happened to me on a Kingston 8GB card that came bundled with Kaico's SD2PSX. Does not seem to happen on recent sandisk, Toshiba/Exercia, Samsung, or Philips cards |
|
@bbsan2k If the issues covered in this PR are confirmed to only occur with low quality cards (as in cards that don't even support all SPI commands, as you said), then it might be trimmed down. The logic to force CMD24 commands and the coalescing of 512-byte sectors into a 8192 bytes buffer before writing could go. However the interleaved reads issue with 128-byte PS1 frames seems to be real, although this is more of an optimization issue. So I'd keep the 128-byte PS1 frames coalescing into 512-byte SD sectors in |
13c62bf to
8fe4b77
Compare
This PR fixes two bugs I had with one of my SD cards on PS1 (PS2 could be affected too but to a lesser extend). These two bugs arise from the same starting point: on dedicated SPI mode, SdFat always writes to the SD card using CMD25 (
WRITE_MULTIPLE_BLOCK) only. In theory this allows to coalesce the writes issued from the memory card into a single CMD25 stream which is closed uponflush(). But the current implementation has a few issues.The save corruption bug
A PS1 sends frames of 128 bytes which is smaller than the SD card base sector (512 bytes). Therefore in SdFat, these 128-byte writes are coalesced in a 512-byte cache, which is prepared by reading the corresponding 512-byte sector from the SD card. That means that every four 128-byte frames, a new sector is read for the SD card. However, like any other command, a read closes any ongoing CMD25 stream (
SharedSpiCard::cardCommandstarts withsyncDevice()). Therefore on PS1 the successive 128-bytes writes turn into an chain that goes open CMD25 - write - close CMD25 - read - open CMD25 - write - close CMD25 - read an so on, ruining the benefits of using CMD25.Now the SD card I had issues with struggles with CMD25 writes that end after only one SD sector, and with the interleaved reads between the writes. As result, it took tens of seconds to write a full save (after the game reports saving finished). Power off the console before this delay is elapsed (very legit since as far as the player can tell the save is done) and the save is corrupted.
The phantom save bug
On PS1 deleting a save takes one 128-byte frame, mutated in one 512-byte SD sector. However like I said earlier, my SD card struggles with CMD25 writes that end after only one SD sector. As a result, sometimes after deleting a save from the PS1 BIOS, the deleted save would reappear after a reboot.
The fixes
ps1_dirty_task(), removing the interleaved reads that were breaking the CMD25 stream. This fixes the save corruption.WRITE_BLOCK), the SD card command dedicated to single block writes. This fixes the phantom save bug.Sidenotes
write()).