From 20a90de55b296184480cc2a2e44b807973fcb727 Mon Sep 17 00:00:00 2001 From: VHANTOMI Date: Tue, 6 Oct 2026 22:46:28 +0200 Subject: [PATCH 1/2] mx4sio: resume partial transfers at the next sector ## Summary Fix the sector position used by MX4SIO when retrying a partially completed multi-sector transfer. After a partial read or write, the driver advances the buffer to the remaining data but previously reused the original starting sector for the next CMD18 or CMD25 attempt. This could cause a retry to process the wrong sectors. Advance the sector position by the number of sectors already transferred. For writes, also pass the remaining sector count to the multi-block write setup so the ACMD23 pre-erase hint matches the remaining request. This does not change the public API or the successful full-transfer path. ## Testing - Built the MX4SIO module with the PS2SDK toolchain. - [Add the PS2/MX4SIO and SD-card tests actually performed, if available.] A deterministic partial-transfer hardware-failure test was not available. --- iop/sio/mx4sio_bd/src/spi_sdcard_driver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iop/sio/mx4sio_bd/src/spi_sdcard_driver.c b/iop/sio/mx4sio_bd/src/spi_sdcard_driver.c index 574cf0626f0b..241c3e814d7e 100644 --- a/iop/sio/mx4sio_bd/src/spi_sdcard_driver.c +++ b/iop/sio/mx4sio_bd/src/spi_sdcard_driver.c @@ -608,6 +608,7 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t /* fail condition */ if (sectors_left > 0) { buffer = (uint8_t *)buffer + (results * 512); + sector += results; M_DEBUG("ERROR: failed to read all sectors, read:%i, abort:%i\n", sectors_left, cmd.abort); if (cmd.abort == CMD_ABORT_NO_READ_TOKEN) { @@ -655,7 +656,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui while (sectors_left > 0 && retries < MAX_RETRIES) { /* issue CMD25 to begin transfer */ - results = spisd_write_multi_begin(sector, count); + results = spisd_write_multi_begin((uint32_t)sector, sectors_left); if (results != SPISD_RESULT_OK) { M_DEBUG("ERROR: failed to start multi-block write\n"); break; @@ -668,6 +669,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui /* fail condition */ if (sectors_left > 0) { write_buffer = (uint8_t *)write_buffer + (results * 512); /* update buffer for next attempt */ + sector += results; M_DEBUG("ERROR: failed to write all sectors, wrote: %i\n", results); } @@ -698,4 +700,4 @@ int spisd_stop(struct block_device *bd) { (void)bd; return 0; -} \ No newline at end of file +} From a67be52bb285dd72998c86aba476d5fa3c516c57 Mon Sep 17 00:00:00 2001 From: VHANTOMI Date: Tue, 6 Oct 2026 22:50:08 +0200 Subject: [PATCH 2/2] Add newline at end of spi_sdcard_driver.c Fix missing newline at the end of the file.