1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-26 19:52:11 +00:00

sdmmc: Restart xfer on Read/Write error

This commit is contained in:
CTCaer 2020-08-28 09:39:06 +03:00
parent 926bd5d2fb
commit d71f6d0b99

View file

@ -175,8 +175,11 @@ int sdmmc_storage_end(sdmmc_storage_t *storage)
static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf, u32 is_write) static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf, u32 is_write)
{ {
u8 *bbuf = (u8 *)buf; u8 *bbuf = (u8 *)buf;
bool first_reinit = false; u32 sct_off = sector;
while (num_sectors) u32 sct_total = num_sectors;
bool first_reinit = true;
while (sct_total)
{ {
u32 blkcnt = 0; u32 blkcnt = 0;
// Retry 5 times if failed. // Retry 5 times if failed.
@ -184,7 +187,7 @@ static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 nu
do do
{ {
reinit_try: reinit_try:
if (_sdmmc_storage_readwrite_ex(storage, &blkcnt, sector, MIN(num_sectors, 0xFFFF), bbuf, is_write)) if (_sdmmc_storage_readwrite_ex(storage, &blkcnt, sct_off, MIN(sct_total, 0xFFFF), bbuf, is_write))
goto out; goto out;
else else
retries--; retries--;
@ -201,7 +204,7 @@ reinit_try:
sd_error_count_increment(SD_ERROR_RW_FAIL); sd_error_count_increment(SD_ERROR_RW_FAIL);
if (!first_reinit) if (first_reinit)
res = sd_initialize(true); res = sd_initialize(true);
else else
{ {
@ -210,19 +213,27 @@ reinit_try:
sd_error_count_increment(SD_ERROR_INIT_FAIL); sd_error_count_increment(SD_ERROR_INIT_FAIL);
} }
// Reset retries to a lower number.
retries = 3; retries = 3;
first_reinit = true; first_reinit = false;
// If succesful reinit, restart xfer.
if (res) if (res)
{
bbuf = (u8 *)buf;
sct_off = sector;
sct_total = num_sectors;
goto reinit_try; goto reinit_try;
} }
}
return 0; return 0;
out: out:
DPRINTF("readwrite: %08X\n", blkcnt); DPRINTF("readwrite: %08X\n", blkcnt);
sector += blkcnt; sct_off += blkcnt;
num_sectors -= blkcnt; sct_total -= blkcnt;
bbuf += 512 * blkcnt; bbuf += 512 * blkcnt;
} }