mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Remove NAND offset hardcoding from diskio.c
This commit is contained in:
parent
f920fc47fc
commit
87631e06d1
@ -49,7 +49,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// GodMode9 version
|
// GodMode9 version
|
||||||
#define VERSION "1.1.8"
|
#define VERSION "1.1.9"
|
||||||
|
|
||||||
// Maximum payload size (arbitrary value!)
|
// Maximum payload size (arbitrary value!)
|
||||||
#define SELF_MAX_SIZE (320 * 1024) // 320kB
|
#define SELF_MAX_SIZE (320 * 1024) // 320kB
|
||||||
|
@ -16,10 +16,9 @@
|
|||||||
|
|
||||||
#define FREE_MIN_SECTORS 0x2000 // minimum sectors for the free drive to appear (4MB)
|
#define FREE_MIN_SECTORS 0x2000 // minimum sectors for the free drive to appear (4MB)
|
||||||
|
|
||||||
#define FPDRV(pdrv) (((pdrv >= 7) && !nand_type_img) ? pdrv + 3 : pdrv)
|
#define FPDRV(pdrv) (((pdrv >= 7) && !imgnand_mode) ? pdrv + 3 : pdrv)
|
||||||
|
#define PART_INFO(pdrv) (DriveInfo + FPDRV(pdrv))
|
||||||
#define PART_TYPE(pdrv) (DriveInfo[FPDRV(pdrv)].type)
|
#define PART_TYPE(pdrv) (DriveInfo[FPDRV(pdrv)].type)
|
||||||
#define PART_SUBTYPE(pdrv) (DriveInfo[FPDRV(pdrv)].subtype)
|
|
||||||
#define NAND_TYPE(type) ((type == TYPE_SYSNAND) ? nand_type_sys : (type == TYPE_EMUNAND) ? nand_type_emu : (type == TYPE_IMGNAND) ? nand_type_img : 0)
|
|
||||||
|
|
||||||
#define TYPE_NONE 0
|
#define TYPE_NONE 0
|
||||||
#define TYPE_SYSNAND NAND_SYSNAND
|
#define TYPE_SYSNAND NAND_SYSNAND
|
||||||
@ -41,69 +40,28 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
BYTE type;
|
BYTE type;
|
||||||
BYTE subtype;
|
BYTE subtype;
|
||||||
} FATpartition;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
DWORD offset;
|
DWORD offset;
|
||||||
DWORD size;
|
DWORD size;
|
||||||
BYTE keyslot;
|
BYTE keyslot;
|
||||||
} SubtypeDesc;
|
} FATpartition;
|
||||||
|
|
||||||
FATpartition DriveInfo[13] = {
|
FATpartition DriveInfo[13] = {
|
||||||
{ TYPE_SDCARD, SUBTYPE_NONE }, // 0 - SDCARD
|
{ TYPE_SDCARD, SUBTYPE_NONE, 0, 0, 0xFF }, // 0 - SDCARD
|
||||||
{ TYPE_SYSNAND, SUBTYPE_CTRN }, // 1 - SYSNAND CTRNAND
|
{ TYPE_SYSNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 1 - SYSNAND CTRNAND
|
||||||
{ TYPE_SYSNAND, SUBTYPE_TWLN }, // 2 - SYSNAND TWLN
|
{ TYPE_SYSNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 2 - SYSNAND TWLN
|
||||||
{ TYPE_SYSNAND, SUBTYPE_TWLP }, // 3 - SYSNAND TWLP
|
{ TYPE_SYSNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 3 - SYSNAND TWLP
|
||||||
{ TYPE_EMUNAND, SUBTYPE_CTRN }, // 4 - EMUNAND CTRNAND
|
{ TYPE_EMUNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 4 - EMUNAND CTRNAND
|
||||||
{ TYPE_EMUNAND, SUBTYPE_TWLN }, // 5 - EMUNAND TWLN
|
{ TYPE_EMUNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 5 - EMUNAND TWLN
|
||||||
{ TYPE_EMUNAND, SUBTYPE_TWLP }, // 6 - EMUNAND TWLP
|
{ TYPE_EMUNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 6 - EMUNAND TWLP
|
||||||
{ TYPE_IMGNAND, SUBTYPE_CTRN }, // 7 - IMGNAND CTRNAND
|
{ TYPE_IMGNAND, SUBTYPE_CTRN, 0, 0, 0xFF }, // 7 - IMGNAND CTRNAND
|
||||||
{ TYPE_IMGNAND, SUBTYPE_TWLN }, // 8 - IMGNAND TWLN
|
{ TYPE_IMGNAND, SUBTYPE_TWLN, 0, 0, 0xFF }, // 8 - IMGNAND TWLN
|
||||||
{ TYPE_IMGNAND, SUBTYPE_TWLP }, // 9 - IMGNAND TWLP
|
{ TYPE_IMGNAND, SUBTYPE_TWLP, 0, 0, 0xFF }, // 9 - IMGNAND TWLP
|
||||||
{ TYPE_IMAGE, SUBTYPE_NONE }, // X - IMAGE
|
{ TYPE_IMAGE, SUBTYPE_NONE, 0, 0, 0xFF }, // X - IMAGE
|
||||||
{ TYPE_SYSNAND, SUBTYPE_FREE }, // Y - SYSNAND BONUS
|
{ TYPE_SYSNAND, SUBTYPE_FREE, 0, 0, 0xFF }, // Y - SYSNAND BONUS
|
||||||
{ TYPE_RAMDRV, SUBTYPE_NONE } // Z - RAMDRIVE
|
{ TYPE_RAMDRV, SUBTYPE_NONE, 0, 0, 0xFF } // Z - RAMDRIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
SubtypeDesc SubTypes[7] = {
|
static BYTE imgnand_mode = 0x00;
|
||||||
{ 0x05C980, 0x17AE80, 0x04 }, // O3DS CTRNAND
|
|
||||||
{ 0x05C980, 0x20F680, 0x05 }, // N3DS CTRNAND
|
|
||||||
{ 0x05C980, 0x20F680, 0x04 }, // N3DS CTRNAND (downgraded)
|
|
||||||
{ 0x000097, 0x047DA9, 0x03 }, // TWLN
|
|
||||||
{ 0x04808D, 0x0105B3, 0x03 }, // TWLP
|
|
||||||
{ 0x1D7800, 0x000000, 0xFF }, // O3DS FREE SPACE
|
|
||||||
{ 0x26C000, 0x000000, 0xFF } // N3DS FREE SPACE
|
|
||||||
};
|
|
||||||
|
|
||||||
static BYTE nand_type_sys = 0;
|
|
||||||
static BYTE nand_type_emu = 0;
|
|
||||||
static BYTE nand_type_img = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Get Drive Subtype helper */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static inline SubtypeDesc* get_subtype_desc(
|
|
||||||
__attribute__((unused))
|
|
||||||
BYTE pdrv /* Physical drive number to identify the drive */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
BYTE type = PART_TYPE(pdrv);
|
|
||||||
BYTE subtype = PART_SUBTYPE(pdrv);
|
|
||||||
BYTE nand_type = NAND_TYPE(type);
|
|
||||||
|
|
||||||
if (subtype == SUBTYPE_NONE) {
|
|
||||||
return NULL;
|
|
||||||
} else if ((subtype == SUBTYPE_CTRN) && (nand_type != NAND_TYPE_O3DS)) {
|
|
||||||
subtype = (nand_type == NAND_TYPE_N3DS) ? SUBTYPE_CTRN_N : SUBTYPE_CTRN_NO;
|
|
||||||
} else if ((subtype == SUBTYPE_FREE) && (nand_type != NAND_TYPE_O3DS)) {
|
|
||||||
subtype = SUBTYPE_FREE_N;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &(SubTypes[subtype]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -130,25 +88,46 @@ DSTATUS disk_initialize (
|
|||||||
BYTE pdrv /* Physical drive number to identify the drive */
|
BYTE pdrv /* Physical drive number to identify the drive */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (pdrv == 0) { // a mounted SD card is the preriquisite for everything else
|
imgnand_mode = (GetMountState() & IMG_NAND) ? 0x01 : 0x00;
|
||||||
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
|
fat_info->offset = fat_info->size = 0;
|
||||||
|
fat_info->keyslot = 0xFF;
|
||||||
|
|
||||||
|
if (type == TYPE_SDCARD) {
|
||||||
if (sdmmc_sdcard_init() != 0) return STA_NOINIT|STA_NODISK;
|
if (sdmmc_sdcard_init() != 0) return STA_NOINIT|STA_NODISK;
|
||||||
} else if (pdrv < 4) {
|
fat_info->size = getMMCDevice(1)->total_size;
|
||||||
nand_type_sys = CheckNandType(NAND_SYSNAND);
|
} else if ((type == TYPE_SYSNAND) || (type == TYPE_EMUNAND) || (type == TYPE_IMGNAND)) {
|
||||||
if (!nand_type_sys) return STA_NOINIT|STA_NODISK;
|
NandPartitionInfo nprt_info;
|
||||||
} else if (pdrv < 7) {
|
if ((type == TYPE_EMUNAND) && !GetNandSizeSectors(NAND_EMUNAND)) // size check for EmuNAND
|
||||||
if (!GetNandSizeSectors(NAND_EMUNAND)) return STA_NOINIT|STA_NODISK;
|
return STA_NOINIT|STA_NODISK;
|
||||||
nand_type_emu = CheckNandType(NAND_EMUNAND);
|
if ((fat_info->subtype == SUBTYPE_CTRN) &&
|
||||||
if (!nand_type_emu) return STA_NOINIT|STA_NODISK;
|
(GetNandPartitionInfo(&nprt_info, NP_TYPE_STD, NP_SUBTYPE_CTR, 0, type) != 0) &&
|
||||||
} else if (pdrv < 10) {
|
(GetNandPartitionInfo(&nprt_info, NP_TYPE_STD, NP_SUBTYPE_CTR_N, 0, type) != 0)) {
|
||||||
UINT mount_state = GetMountState();
|
return STA_NOINIT|STA_NODISK;
|
||||||
nand_type_img = (mount_state & IMG_NAND) ? CheckNandType(NAND_IMGNAND) : 0;
|
} else if ((fat_info->subtype == SUBTYPE_TWLN) &&
|
||||||
if (!nand_type_img) {
|
(GetNandPartitionInfo(&nprt_info, NP_TYPE_FAT, NP_SUBTYPE_TWL, 0, type) != 0)) {
|
||||||
if ((pdrv == 7) && !(mount_state & IMG_FAT)) return STA_NOINIT|STA_NODISK;
|
return STA_NOINIT|STA_NODISK;
|
||||||
else if ((pdrv == 8) && (!CheckNandType(NAND_SYSNAND) ||
|
} else if ((fat_info->subtype == SUBTYPE_TWLP) &&
|
||||||
GetNandUnusedSectors(NAND_SYSNAND) < FREE_MIN_SECTORS)) return STA_NOINIT|STA_NODISK;
|
(GetNandPartitionInfo(&nprt_info, NP_TYPE_FAT, NP_SUBTYPE_TWL, 1, type) != 0)) {
|
||||||
else if (pdrv == 9) InitRamDrive();
|
return STA_NOINIT|STA_NODISK;
|
||||||
|
} else if ((fat_info->subtype == SUBTYPE_FREE) &&
|
||||||
|
((GetNandPartitionInfo(&nprt_info, NP_TYPE_BONUS, NP_SUBTYPE_CTR, 0, type) != 0) ||
|
||||||
|
(nprt_info.count < FREE_MIN_SECTORS))) {
|
||||||
|
return STA_NOINIT|STA_NODISK;
|
||||||
}
|
}
|
||||||
|
fat_info->offset = nprt_info.sector;
|
||||||
|
fat_info->size = nprt_info.count;
|
||||||
|
fat_info->keyslot = nprt_info.keyslot;
|
||||||
|
} else if (type == TYPE_IMAGE) {
|
||||||
|
if (!(GetMountState() & IMG_FAT)) return STA_NOINIT|STA_NODISK;
|
||||||
|
fat_info->size = (GetMountSize() + 0x1FF) / 0x200;
|
||||||
|
} else if (type == TYPE_RAMDRV) {
|
||||||
|
InitRamDrive();
|
||||||
|
fat_info->size = (GetRamDriveSize() + 0x1FF) / 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +159,8 @@ DRESULT disk_read (
|
|||||||
if (ReadRamDriveSectors(buff, sector, count))
|
if (ReadRamDriveSectors(buff, sector, count))
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
} else {
|
} else {
|
||||||
SubtypeDesc* subtype = get_subtype_desc(pdrv);
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
BYTE keyslot = subtype->keyslot;
|
if (ReadNandSectors(buff, fat_info->offset + sector, count, fat_info->keyslot, type))
|
||||||
DWORD isector = subtype->offset + sector;
|
|
||||||
|
|
||||||
if (ReadNandSectors(buff, isector, count, keyslot, type))
|
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,11 +196,8 @@ DRESULT disk_write (
|
|||||||
if (WriteRamDriveSectors(buff, sector, count))
|
if (WriteRamDriveSectors(buff, sector, count))
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
} else {
|
} else {
|
||||||
SubtypeDesc* subtype = get_subtype_desc(pdrv);
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
BYTE keyslot = subtype->keyslot;
|
if (WriteNandSectors(buff, fat_info->offset + sector, count, fat_info->keyslot, type))
|
||||||
DWORD isector = subtype->offset + sector;
|
|
||||||
|
|
||||||
if (WriteNandSectors(buff, isector, count, keyslot, type))
|
|
||||||
return RES_PARERR; // unstubbed!
|
return RES_PARERR; // unstubbed!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,23 +222,14 @@ DRESULT disk_ioctl (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = PART_TYPE(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case GET_SECTOR_SIZE:
|
case GET_SECTOR_SIZE:
|
||||||
*((DWORD*) buff) = 0x200;
|
*((DWORD*) buff) = 0x200;
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
case GET_SECTOR_COUNT:
|
case GET_SECTOR_COUNT:
|
||||||
if (type == TYPE_SDCARD) { // SD card
|
*((DWORD*) buff) = fat_info->size;
|
||||||
*((DWORD*) buff) = getMMCDevice(1)->total_size;
|
|
||||||
} else if (type == TYPE_IMAGE) { // FAT image
|
|
||||||
*((DWORD*) buff) = GetMountSize() / 0x200;
|
|
||||||
} else if (type == TYPE_RAMDRV) { // RAM drive
|
|
||||||
*((DWORD*) buff) = GetRamDriveSize() / 0x200;
|
|
||||||
} else if ((type == TYPE_SYSNAND) && (PART_SUBTYPE(pdrv) == SUBTYPE_FREE)) { // SysNAND free area
|
|
||||||
*((DWORD*) buff) = getMMCDevice(0)->total_size - get_subtype_desc(pdrv)->offset;
|
|
||||||
} else if (type != TYPE_NONE) { // NAND
|
|
||||||
*((DWORD*) buff) = get_subtype_desc(pdrv)->size;
|
|
||||||
}
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
case GET_BLOCK_SIZE:
|
case GET_BLOCK_SIZE:
|
||||||
*((DWORD*) buff) = ((type == TYPE_IMAGE) || (type == TYPE_RAMDRV)) ? 0x1 : 0x2000;
|
*((DWORD*) buff) = ((type == TYPE_IMAGE) || (type == TYPE_RAMDRV)) ? 0x1 : 0x2000;
|
||||||
|
@ -43,7 +43,6 @@ bool InitImgFS(const char* path) {
|
|||||||
for (u32 i = NORM_FS - IMGN_FS; i < NORM_FS; i++) {
|
for (u32 i = NORM_FS - IMGN_FS; i < NORM_FS; i++) {
|
||||||
char fsname[8];
|
char fsname[8];
|
||||||
snprintf(fsname, 7, "%lu:", i);
|
snprintf(fsname, 7, "%lu:", i);
|
||||||
if (fs_mounted[i]) continue;
|
|
||||||
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
|
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
|
||||||
}
|
}
|
||||||
return GetMountState();
|
return GetMountState();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user