successfully call f_mkfs(). it's a start I guess.
This commit is contained in:
parent
b841f24996
commit
529620a49e
|
@ -52,7 +52,10 @@ bool Init(FILE* nandfile, u8* es_keyY)
|
||||||
if (!nandfile)
|
if (!nandfile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ff_disk_open(FF_ReadNAND, FF_WriteNAND);
|
fseek(nandfile, 0, SEEK_END);
|
||||||
|
u64 nandlen = ftell(nandfile);
|
||||||
|
|
||||||
|
ff_disk_open(FF_ReadNAND, FF_WriteNAND, (LBA_t)(nandlen>>9));
|
||||||
|
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
res = f_mount(&CurFS, "0:", 0);
|
res = f_mount(&CurFS, "0:", 0);
|
||||||
|
|
|
@ -15,3 +15,106 @@
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along
|
||||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "FATStorage.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
|
||||||
|
FATStorage::FATStorage()
|
||||||
|
{
|
||||||
|
printf("FATStorage begin\n");
|
||||||
|
bool res = Build(".", 0x40000000, "melonDLDI.bin");
|
||||||
|
printf("FATStorage result: %d\n", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
FATStorage::~FATStorage()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FILE* FATStorage::FF_File;
|
||||||
|
u64 FATStorage::FF_FileSize;
|
||||||
|
|
||||||
|
UINT FATStorage::FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num)
|
||||||
|
{
|
||||||
|
if (!FF_File) return 0;
|
||||||
|
|
||||||
|
u64 addr = sector * 0x200ULL;
|
||||||
|
u32 len = num * 0x200;
|
||||||
|
|
||||||
|
if ((addr+len) > FF_FileSize)
|
||||||
|
{
|
||||||
|
if (addr >= FF_FileSize) return 0;
|
||||||
|
len = FF_FileSize - addr;
|
||||||
|
num = len >> 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(FF_File, addr, SEEK_SET);
|
||||||
|
|
||||||
|
u32 res = fread(buf, 0x200, num, FF_File);
|
||||||
|
if (res < num)
|
||||||
|
{
|
||||||
|
if (feof(FF_File))
|
||||||
|
{
|
||||||
|
memset(&buf[0x200*res], 0, 0x200*(num-res));
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT FATStorage::FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num)
|
||||||
|
{
|
||||||
|
if (!FF_File) return 0;
|
||||||
|
|
||||||
|
u64 addr = sector * 0x200ULL;
|
||||||
|
u32 len = num * 0x200;
|
||||||
|
|
||||||
|
if ((addr+len) > FF_FileSize)
|
||||||
|
{
|
||||||
|
if (addr >= FF_FileSize) return 0;
|
||||||
|
len = FF_FileSize - addr;
|
||||||
|
num = len >> 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(FF_File, addr, SEEK_SET);
|
||||||
|
|
||||||
|
u32 res = fwrite(buf, 0x200, num, FF_File);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
|
||||||
|
{
|
||||||
|
filesize = size;
|
||||||
|
|
||||||
|
FF_File = Platform::OpenLocalFile(filename, "wb");
|
||||||
|
if (!FF_File)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FF_FileSize = size;
|
||||||
|
ff_disk_open(FF_ReadStorage, FF_WriteStorage, (LBA_t)(size>>9));
|
||||||
|
|
||||||
|
FRESULT res;
|
||||||
|
|
||||||
|
MKFS_PARM fsopt;
|
||||||
|
fsopt.fmt = FM_FAT | FM_FAT32;
|
||||||
|
fsopt.au_size = 0;
|
||||||
|
fsopt.align = 1;
|
||||||
|
fsopt.n_fat = 1;
|
||||||
|
fsopt.n_root = 512;
|
||||||
|
|
||||||
|
BYTE workbuf[FF_MAX_SS];
|
||||||
|
res = f_mkfs("0:", &fsopt, workbuf, sizeof(workbuf));
|
||||||
|
printf("MKFS RES %d\n", res);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
ff_disk_close();
|
||||||
|
fclose(FF_File);
|
||||||
|
FF_File = nullptr;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -19,8 +19,28 @@
|
||||||
#ifndef FATSTORAGE_H
|
#ifndef FATSTORAGE_H
|
||||||
#define FATSTORAGE_H
|
#define FATSTORAGE_H
|
||||||
|
|
||||||
#include "types.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
//
|
#include "types.h"
|
||||||
|
#include "fatfs/ff.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FATStorage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FATStorage();
|
||||||
|
~FATStorage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
FILE* file;
|
||||||
|
u64 filesize;
|
||||||
|
|
||||||
|
static FILE* FF_File;
|
||||||
|
static u64 FF_FileSize;
|
||||||
|
static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num);
|
||||||
|
static UINT FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num);
|
||||||
|
|
||||||
|
bool Build(const char* sourcedir, u64 size, const char* filename);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // FATSTORAGE_H
|
#endif // FATSTORAGE_H
|
||||||
|
|
|
@ -1164,10 +1164,12 @@ u8 CartRetailBT::SPIWrite(u8 val, u32 pos, bool last)
|
||||||
|
|
||||||
CartHomebrew::CartHomebrew(u8* rom, u32 len, u32 chipid) : CartCommon(rom, len, chipid)
|
CartHomebrew::CartHomebrew(u8* rom, u32 len, u32 chipid) : CartCommon(rom, len, chipid)
|
||||||
{
|
{
|
||||||
|
test = nullptr;
|
||||||
if (Config::DLDIEnable)
|
if (Config::DLDIEnable)
|
||||||
{
|
{
|
||||||
ApplyDLDIPatch(melonDLDI, sizeof(melonDLDI));
|
ApplyDLDIPatch(melonDLDI, sizeof(melonDLDI));
|
||||||
SDFile = Platform::OpenLocalFile(Config::DLDISDPath, "r+b");
|
SDFile = Platform::OpenLocalFile(Config::DLDISDPath, "r+b");
|
||||||
|
test = new FATStorage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SDFile = nullptr;
|
SDFile = nullptr;
|
||||||
|
@ -1176,6 +1178,7 @@ CartHomebrew::CartHomebrew(u8* rom, u32 len, u32 chipid) : CartCommon(rom, len,
|
||||||
CartHomebrew::~CartHomebrew()
|
CartHomebrew::~CartHomebrew()
|
||||||
{
|
{
|
||||||
if (SDFile) fclose(SDFile);
|
if (SDFile) fclose(SDFile);
|
||||||
|
if (test) delete test;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CartHomebrew::Reset()
|
void CartHomebrew::Reset()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "NDS_Header.h"
|
#include "NDS_Header.h"
|
||||||
|
#include "FATStorage.h"
|
||||||
|
|
||||||
namespace NDSCart
|
namespace NDSCart
|
||||||
{
|
{
|
||||||
|
@ -182,6 +183,7 @@ private:
|
||||||
void ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset);
|
void ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset);
|
||||||
|
|
||||||
FILE* SDFile;
|
FILE* SDFile;
|
||||||
|
FATStorage* test;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern u16 SPICnt;
|
extern u16 SPICnt;
|
||||||
|
|
|
@ -13,15 +13,17 @@
|
||||||
|
|
||||||
static ff_disk_read_cb ReadCb;
|
static ff_disk_read_cb ReadCb;
|
||||||
static ff_disk_write_cb WriteCb;
|
static ff_disk_write_cb WriteCb;
|
||||||
|
static LBA_t SectorCount;
|
||||||
static DSTATUS Status = STA_NOINIT | STA_NODISK;
|
static DSTATUS Status = STA_NOINIT | STA_NODISK;
|
||||||
|
|
||||||
|
|
||||||
void ff_disk_open(ff_disk_read_cb readcb, ff_disk_write_cb writecb)
|
void ff_disk_open(ff_disk_read_cb readcb, ff_disk_write_cb writecb, LBA_t seccnt)
|
||||||
{
|
{
|
||||||
if (!readcb) return;
|
if (!readcb) return;
|
||||||
|
|
||||||
ReadCb = readcb;
|
ReadCb = readcb;
|
||||||
WriteCb = writecb;
|
WriteCb = writecb;
|
||||||
|
SectorCount = seccnt;
|
||||||
|
|
||||||
Status &= ~STA_NODISK;
|
Status &= ~STA_NODISK;
|
||||||
if (!writecb) Status |= STA_PROTECT;
|
if (!writecb) Status |= STA_PROTECT;
|
||||||
|
@ -32,6 +34,7 @@ void ff_disk_close()
|
||||||
{
|
{
|
||||||
ReadCb = (void*)0;
|
ReadCb = (void*)0;
|
||||||
WriteCb = (void*)0;
|
WriteCb = (void*)0;
|
||||||
|
SectorCount = 0;
|
||||||
|
|
||||||
Status &= ~STA_PROTECT;
|
Status &= ~STA_PROTECT;
|
||||||
Status |= STA_NODISK;
|
Status |= STA_NODISK;
|
||||||
|
@ -123,12 +126,28 @@ DRESULT disk_ioctl (
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case 0: // sync
|
case CTRL_SYNC:
|
||||||
// TODO: fflush?
|
// TODO: fflush?
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_SECTOR_COUNT:
|
||||||
|
*(LBA_t*)buff = SectorCount;
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_SECTOR_SIZE:
|
||||||
|
*(WORD*)buff = 0x200;
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_BLOCK_SIZE:
|
||||||
|
*(DWORD*)buff = 1;
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case CTRL_TRIM:
|
||||||
|
// TODO??
|
||||||
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("disk_ioctl(%02X, %02X, %p)\n", pdrv, cmd, buff);
|
printf("FatFS: unknown disk_ioctl(%02X, %02X, %p)\n", pdrv, cmd, buff);
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||||
typedef UINT (*ff_disk_read_cb)(BYTE* buff, LBA_t sector, UINT count);
|
typedef UINT (*ff_disk_read_cb)(BYTE* buff, LBA_t sector, UINT count);
|
||||||
typedef UINT (*ff_disk_write_cb)(BYTE* buff, LBA_t sector, UINT count);
|
typedef UINT (*ff_disk_write_cb)(BYTE* buff, LBA_t sector, UINT count);
|
||||||
|
|
||||||
void ff_disk_open(ff_disk_read_cb readcb, ff_disk_write_cb writecb);
|
void ff_disk_open(ff_disk_read_cb readcb, ff_disk_write_cb writecb, LBA_t seccnt);
|
||||||
void ff_disk_close();
|
void ff_disk_close();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue