2012-01-21 21:57:41 +01:00
|
|
|
#ifndef _NAND_H_
|
|
|
|
#define _NAND_H_
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
#include "loader/disc.h"
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#define REAL_NAND 0
|
|
|
|
#define EMU_SD 1
|
|
|
|
#define EMU_USB 2
|
|
|
|
|
|
|
|
#define DOWNLOADED_CHANNELS 0x00010001
|
|
|
|
#define SYSTEM_CHANNELS 0x00010002
|
|
|
|
#define RF_NEWS_CHANNEL 0x48414741
|
|
|
|
#define RF_FORECAST_CHANNEL 0x48414641
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
#define SYSCONFPATH "/shared2/sys/SYSCONF"
|
2012-06-07 02:34:47 +02:00
|
|
|
#define MIIPATH "/shared2/menu/FaceLib/RFL_DB.dat"
|
2012-03-17 23:30:16 +01:00
|
|
|
#define TXTPATH "/title/00000001/00000002/data/setting.txt"
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
#define BLOCK 2048
|
2012-03-17 23:30:16 +01:00
|
|
|
|
2012-12-27 21:22:40 +01:00
|
|
|
typedef void (*dump_callback_t)(int dumpstat, int dumpprog, int filestat, int fileprog, int files, int folders, const char *tmess, void *user_data);
|
2012-05-03 01:08:11 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
/* 'NAND Device' structure */
|
|
|
|
typedef struct nandDevice
|
|
|
|
{
|
|
|
|
const char *Name;
|
|
|
|
u32 Mode;
|
|
|
|
u32 Mount;
|
|
|
|
u32 Unmount;
|
|
|
|
} NandDevice;
|
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
typedef struct _config_header
|
|
|
|
{
|
|
|
|
u8 magic[4];
|
|
|
|
u16 ncnt;
|
|
|
|
u16 noff[];
|
|
|
|
} config_header;
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
typedef struct _namelist
|
|
|
|
{
|
|
|
|
char name[ISFS_MAXPATH];
|
|
|
|
int type;
|
|
|
|
} namelist;
|
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
typedef struct _uid
|
|
|
|
{
|
|
|
|
u64 TitleID;
|
2013-07-07 00:35:05 +02:00
|
|
|
u16 padding;
|
|
|
|
u16 uid;
|
2013-01-01 18:42:46 +01:00
|
|
|
} ATTRIBUTE_PACKED uid;
|
2012-12-22 17:47:02 +01:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class Nand
|
|
|
|
{
|
2012-08-21 18:33:44 +02:00
|
|
|
public:
|
2012-10-15 21:16:14 +02:00
|
|
|
void Init();
|
2012-12-25 14:42:53 +01:00
|
|
|
bool LoadDefaultIOS(void);
|
2012-08-21 18:33:44 +02:00
|
|
|
|
|
|
|
/* Prototypes */
|
2012-12-22 17:47:02 +01:00
|
|
|
void SetNANDEmu(u32 partition);
|
2012-08-21 18:33:44 +02:00
|
|
|
s32 Enable_Emu();
|
|
|
|
s32 Disable_Emu();
|
2012-09-10 00:38:42 +02:00
|
|
|
bool EmulationEnabled(void);
|
2012-08-21 18:33:44 +02:00
|
|
|
|
|
|
|
void Set_Partition(u32 partition) { Partition = partition; };
|
|
|
|
void Set_FullMode(bool fullmode) { FullMode = fullmode ? 0x100 : 0; };
|
|
|
|
void Set_RCMode(bool rcmode) { FullMode = rcmode ? 0x40 : 0; };
|
|
|
|
void Set_SSMode(bool ssmode) { FullMode = ssmode ? 0x60 : 0; };
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
void Patch_AHB();
|
2012-08-21 18:33:44 +02:00
|
|
|
void Init_ISFS();
|
2013-01-27 13:12:44 +01:00
|
|
|
void DeInit_ISFS();
|
2012-08-21 18:33:44 +02:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
const char *Get_NandPath(void) { return NandPath; };
|
2012-08-21 18:33:44 +02:00
|
|
|
u32 Get_Partition(void) { return Partition; };
|
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
u64 *GetChannels(u32 *count);
|
|
|
|
u8 *GetTMD(u64 title, u32 *size);
|
|
|
|
u8 *GetEmuFile(const char *path, u32 *size, s32 len = -1);
|
|
|
|
void SetPaths(const char *emuPath, const char *currentPart);
|
2013-07-07 00:35:05 +02:00
|
|
|
const char *GetPath(void) { return FullNANDPath; };
|
2012-12-22 17:47:02 +01:00
|
|
|
|
2012-08-21 18:33:44 +02:00
|
|
|
void CreatePath(const char *path, ...);
|
2012-12-22 17:47:02 +01:00
|
|
|
void CreateTitleTMD(dir_discHdr *hdr);
|
|
|
|
s32 CreateConfig();
|
2012-08-21 18:33:44 +02:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
s32 PreNandCfg(bool miis, bool realconfig);
|
2012-08-21 18:33:44 +02:00
|
|
|
s32 Do_Region_Change(string id);
|
|
|
|
s32 FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data);
|
|
|
|
s32 DoNandDump(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data);
|
|
|
|
s32 CalcFlashSize(const char *source, dump_callback_t i_dumper, void *i_data);
|
|
|
|
s32 CalcDumpSpace(const char *source, dump_callback_t i_dumper, void *i_data);
|
|
|
|
void ResetCounters(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* Prototypes */
|
|
|
|
s32 Nand_Mount(NandDevice *Device);
|
|
|
|
s32 Nand_Unmount(NandDevice *Device);
|
|
|
|
s32 Nand_Enable(NandDevice *Device);
|
2012-09-10 00:38:42 +02:00
|
|
|
s32 Nand_Disable(void);
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-08-21 18:33:44 +02:00
|
|
|
void PatchAHB(void);
|
2012-11-12 21:12:00 +01:00
|
|
|
bool ISFS_Check(void);
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-08-21 18:33:44 +02:00
|
|
|
void __Dec_Enc_TB(void);
|
|
|
|
void __configshifttxt(char *str);
|
|
|
|
void __GetNameList(const char *source, namelist **entries, int *count);
|
|
|
|
s32 __configread(void);
|
|
|
|
s32 __configwrite(void);
|
|
|
|
u32 __configsetbyte(const char *item, u8 val);
|
|
|
|
u32 __configsetbigarray(const char *item, void *val, u32 size);
|
|
|
|
u32 __configsetsetting(const char *item, const char *val);
|
|
|
|
void __NANDify(char *str);
|
|
|
|
void __FATify(char *dst, const char *src);
|
|
|
|
s32 __Unescaped2x(const char *path);
|
|
|
|
s32 __FlashNandFile(const char *source, const char *dest);
|
|
|
|
s32 __FlashNandFolder(const char *source, const char *dest);
|
|
|
|
s32 __DumpNandFile(const char *source, const char *dest);
|
|
|
|
s32 __DumpNandFolder(const char *source, const char *dest);
|
2012-08-26 14:40:34 +02:00
|
|
|
int __makedir(char *newdir);
|
2012-08-21 18:33:44 +02:00
|
|
|
|
|
|
|
u32 MountedDevice;
|
|
|
|
u32 EmuDevice;
|
|
|
|
u32 NandSize;
|
|
|
|
u32 NandDone;
|
|
|
|
u32 FileDone;
|
|
|
|
u32 FilesDone;
|
|
|
|
u32 FoldersDone;
|
|
|
|
bool fake;
|
|
|
|
bool showprogress;
|
2013-01-27 13:12:44 +01:00
|
|
|
bool isfs_inited;
|
2012-11-12 21:12:00 +01:00
|
|
|
|
2012-08-21 18:33:44 +02:00
|
|
|
void *data;
|
|
|
|
dump_callback_t dumper;
|
|
|
|
u32 Partition ATTRIBUTE_ALIGN(32);
|
|
|
|
u32 FullMode ATTRIBUTE_ALIGN(32);
|
|
|
|
char NandPath[32] ATTRIBUTE_ALIGN(32);
|
2012-12-22 17:47:02 +01:00
|
|
|
char FullNANDPath[64] ATTRIBUTE_ALIGN(32);
|
2012-08-21 18:33:44 +02:00
|
|
|
char cfgpath[1024];
|
|
|
|
char settxtpath[1024];
|
2012-01-21 21:57:41 +01:00
|
|
|
};
|
|
|
|
|
2012-10-15 21:16:14 +02:00
|
|
|
extern Nand NandHandle;
|
2012-01-21 21:57:41 +01:00
|
|
|
#endif
|