diff --git a/bootloader/libs/fatfs/diskio.c b/bootloader/libs/fatfs/diskio.c index 803dc91..8aed635 100644 --- a/bootloader/libs/fatfs/diskio.c +++ b/bootloader/libs/fatfs/diskio.c @@ -46,16 +46,7 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - // Ensure that buffer resides in DRAM and it's DMA aligned. - if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) - return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; - if (sdmmc_storage_read(&sd_storage, sector, count, buf)) - { - memcpy(buff, buf, 512 * count); - return RES_OK; - } - return RES_ERROR; + return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; } /*-----------------------------------------------------------------------*/ @@ -68,14 +59,7 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - // Ensure that buffer resides in DRAM and it's DMA aligned. - if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) - return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; - memcpy(buf, buff, 512 * count); - if (sdmmc_storage_write(&sd_storage, sector, count, buf)) - return RES_OK; - return RES_ERROR; + return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; } /*-----------------------------------------------------------------------*/ diff --git a/bootloader/storage/sdmmc.c b/bootloader/storage/sdmmc.c index 6168784..fc941c8 100644 --- a/bootloader/storage/sdmmc.c +++ b/bootloader/storage/sdmmc.c @@ -202,12 +202,34 @@ DPRINTF("readwrite: %08X\n", blkcnt); int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { - return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buf >= DRAM_START) && !((u32)buf % 8)) + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); + + if (num_sectors > (SDMMC_UP_BUF_SZ / 512)) + return 0; + + u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; + if (_sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 0)) + { + memcpy(buf, tmp_buf, 512 * num_sectors); + return 1; + } + return 0; } int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { - return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buf >= DRAM_START) && !((u32)buf % 8)) + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); + + if (num_sectors > (SDMMC_UP_BUF_SZ / 512)) + return 0; + + u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; + memcpy(tmp_buf, buf, 512 * num_sectors); + return _sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 1); } /* diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index cdeebf9..22cf3fd 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -44,16 +44,7 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - // Ensure that buffer resides in DRAM and it's DMA aligned. - if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) - return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; - if (sdmmc_storage_read(&sd_storage, sector, count, buf)) - { - memcpy(buff, buf, 512 * count); - return RES_OK; - } - return RES_ERROR; + return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; } /*-----------------------------------------------------------------------*/ @@ -66,14 +57,7 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - // Ensure that buffer resides in DRAM and it's DMA aligned. - if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) - return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; - memcpy(buf, buff, 512 * count); - if (sdmmc_storage_write(&sd_storage, sector, count, buf)) - return RES_OK; - return RES_ERROR; + return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; } /*-----------------------------------------------------------------------*/ diff --git a/nyx/nyx_gui/storage/sdmmc.c b/nyx/nyx_gui/storage/sdmmc.c index 6c83d8b..5ce0900 100644 --- a/nyx/nyx_gui/storage/sdmmc.c +++ b/nyx/nyx_gui/storage/sdmmc.c @@ -202,12 +202,34 @@ DPRINTF("readwrite: %08X\n", blkcnt); int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { - return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buf >= DRAM_START) && !((u32)buf % 8)) + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); + + if (num_sectors > (SDMMC_UP_BUF_SZ / 512)) + return 0; + + u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; + if (_sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 0)) + { + memcpy(buf, tmp_buf, 512 * num_sectors); + return 1; + } + return 0; } int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { - return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buf >= DRAM_START) && !((u32)buf % 8)) + return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); + + if (num_sectors > (SDMMC_UP_BUF_SZ / 512)) + return 0; + + u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; + memcpy(tmp_buf, buf, 512 * num_sectors); + return _sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 1); } /*