From 7a771f48554b024b42cb431cb34f65e7a8e88ad7 Mon Sep 17 00:00:00 2001 From: Kostas Missos Date: Tue, 29 May 2018 02:28:07 +0300 Subject: [PATCH] [sdmmc] Change internal read/write retries This can fix busy errors when writing to sd cards. Additionally it now returns properly on success --- ipl/main.c | 4 ++-- ipl/sdmmc.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ipl/main.c b/ipl/main.c index 83c7bb8..d99f1f0 100755 --- a/ipl/main.c +++ b/ipl/main.c @@ -850,8 +850,8 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part) EPRINTFARGS("Error reading %d blocks @ LBA %08X from eMMC (try %d), retrying...", num, lba_curr, ++retryCount); - sleep(500000); - if (retryCount >= 10) + sleep(150000); + if (retryCount >= 3) { EPRINTFARGS("\nFailed to read %d blocks @ LBA %08X from eMMC. Aborting..\n", num, lba_curr); diff --git a/ipl/sdmmc.c b/ipl/sdmmc.c index eec6054..5362187 100755 --- a/ipl/sdmmc.c +++ b/ipl/sdmmc.c @@ -165,15 +165,27 @@ static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 nu while (num_sectors) { u32 blkcnt = 0; - //Retry once on error. - if (!_sdmmc_storage_readwrite_ex(storage, &blkcnt, sector, MIN(num_sectors, 0xFFFF), bbuf, is_write)) - if (!_sdmmc_storage_readwrite_ex(storage, &blkcnt, sector, MIN(num_sectors, 0xFFFF), bbuf, is_write)) - return 0; + //Retry 9 times on error. + u32 retries = 10; + do + { + if (_sdmmc_storage_readwrite_ex(storage, &blkcnt, sector, MIN(num_sectors, 0xFFFF), bbuf, is_write)) + goto out; + else + retries--; + + sleep(500000); + + } while (retries); + return 0; + +out:; DPRINTF("readwrite: %08X\n", blkcnt); sector += blkcnt; num_sectors -= blkcnt; bbuf += 512 * blkcnt; } + return 1; } int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf)