From e5689cfe5782c8b168a73e1f7a450641005bfe01 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sat, 6 Feb 2021 17:11:32 +0200 Subject: [PATCH] fatfs: Add raw emuMMC support for USER partition --- bdk/libs/fatfs/diskio.h | 3 ++- nyx/nyx_gui/libs/fatfs/diskio.c | 22 +++++++++++++++++++++- nyx/nyx_gui/libs/fatfs/ffconf.h | 4 ++-- nyx/nyx_gui/storage/nx_emmc_bis.h | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bdk/libs/fatfs/diskio.h b/bdk/libs/fatfs/diskio.h index 5b23027..b5299c6 100644 --- a/bdk/libs/fatfs/diskio.h +++ b/bdk/libs/fatfs/diskio.h @@ -27,7 +27,8 @@ typedef enum { DRIVE_SD = 0, DRIVE_RAM = 1, DRIVE_EMMC = 2, - DRIVE_BIS = 3 + DRIVE_BIS = 3, + DRIVE_EMU = 4 } DDRIVE; diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index 5e3a47b..3d37f7d 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -18,6 +18,8 @@ static u32 sd_rsvd_sectors = 0; static u32 ramdisk_sectors = 0; +static u32 emummc_sectors = 0; + /*-----------------------------------------------------------------------*/ /* Get Drive Status */ /*-----------------------------------------------------------------------*/ @@ -57,7 +59,8 @@ DRESULT disk_read ( case DRIVE_EMMC: return sdmmc_storage_read(&emmc_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; case DRIVE_BIS: - return nx_emmc_bis_read(sector, count, (void *)buff); + case DRIVE_EMU: + return nx_emmc_bis_read(sector, count, (void *)buff) ? RES_OK : RES_ERROR; } return RES_ERROR; @@ -82,6 +85,8 @@ DRESULT disk_write ( case DRIVE_EMMC: case DRIVE_BIS: return RES_WRPRT; + case DRIVE_EMU: + return nx_emmc_bis_write(sector, count, (void *)buff) ? RES_OK : RES_ERROR; } return RES_ERROR; @@ -122,6 +127,18 @@ DRESULT disk_ioctl ( break; } } + else if (pdrv == DRIVE_EMU) + { + switch (cmd) + { + case GET_SECTOR_COUNT: + *buf = emummc_sectors; + break; + case GET_BLOCK_SIZE: + *buf = 32768; // Align to 16MB. + break; + } + } return RES_OK; } @@ -144,6 +161,9 @@ DRESULT disk_set_info ( case DRIVE_RAM: ramdisk_sectors = *buf; break; + case DRIVE_EMU: + emummc_sectors = *buf; + break; } } diff --git a/nyx/nyx_gui/libs/fatfs/ffconf.h b/nyx/nyx_gui/libs/fatfs/ffconf.h index 08bee44..8e417ad 100644 --- a/nyx/nyx_gui/libs/fatfs/ffconf.h +++ b/nyx/nyx_gui/libs/fatfs/ffconf.h @@ -179,13 +179,13 @@ / Drive/Volume Configurations /---------------------------------------------------------------------------*/ -#define FF_VOLUMES 4 +#define FF_VOLUMES 5 /* Number of volumes (logical drives) to be used. (1-10) */ #define FF_STR_VOLUME_ID 1 // Order is important. Any change to order, must also be reflected to diskio drive enum. -#define FF_VOLUME_STRS "sd","ram","emmc","bis" +#define FF_VOLUME_STRS "sd","ram","emmc","bis","emu" /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each diff --git a/nyx/nyx_gui/storage/nx_emmc_bis.h b/nyx/nyx_gui/storage/nx_emmc_bis.h index f1783b3..1a137fa 100644 --- a/nyx/nyx_gui/storage/nx_emmc_bis.h +++ b/nyx/nyx_gui/storage/nx_emmc_bis.h @@ -224,6 +224,7 @@ typedef struct _nx_emmc_cal0_t } __attribute__((packed)) nx_emmc_cal0_t; int nx_emmc_bis_read(u32 sector, u32 count, void *buff); +int nx_emmc_bis_write(u32 sector, u32 count, void *buff); void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, u32 emummc_offset); void nx_emmc_bis_end();