2016-03-03 13:27:51 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2017-02-17 15:54:37 +01:00
|
|
|
#define NAND_SYSNAND (1UL<<0)
|
|
|
|
#define NAND_EMUNAND (1UL<<1)
|
|
|
|
#define NAND_IMGNAND (1UL<<2)
|
|
|
|
#define NAND_ZERONAND (1UL<<3)
|
|
|
|
#define NAND_TYPE_O3DS (1UL<<4)
|
|
|
|
#define NAND_TYPE_N3DS (1UL<<5)
|
|
|
|
#define NAND_TYPE_NO3DS (1UL<<6)
|
2016-03-15 16:25:27 +01:00
|
|
|
|
2017-01-05 02:50:41 +01:00
|
|
|
// minimum size of NAND memory
|
2017-01-02 17:37:08 +01:00
|
|
|
#define NAND_MIN_SECTORS_O3DS 0x1D7800
|
|
|
|
#define NAND_MIN_SECTORS_N3DS 0x26C000
|
|
|
|
|
2017-01-05 02:50:41 +01:00
|
|
|
// start sectors of partitions
|
|
|
|
#define SECTOR_TWL 0x000000
|
|
|
|
#define SECTOR_SECRET 0x000096
|
|
|
|
#define SECTOR_TWLN 0x000097
|
|
|
|
#define SECTOR_TWLP 0x04808D
|
|
|
|
#define SECTOR_AGBSAVE 0x058800
|
|
|
|
#define SECTOR_FIRM0 0x058980
|
|
|
|
#define SECTOR_FIRM1 0x05A980
|
|
|
|
#define SECTOR_CTR 0x05C980
|
|
|
|
|
|
|
|
// sizes of partitions (in sectors)
|
|
|
|
#define SIZE_TWL 0x058800
|
|
|
|
#define SIZE_TWLN 0x047DA9
|
|
|
|
#define SIZE_TWLP 0x0105B3
|
|
|
|
#define SIZE_AGBSAVE 0x000180
|
|
|
|
#define SIZE_FIRM0 0x002000
|
|
|
|
#define SIZE_FIRM1 0x002000
|
|
|
|
#define SIZE_CTR_O3DS 0x17AE80
|
|
|
|
#define SIZE_CTR_N3DS 0x20F680
|
|
|
|
|
2016-03-03 13:27:51 +01:00
|
|
|
bool InitNandCrypto(void);
|
2016-03-22 19:24:21 +01:00
|
|
|
bool CheckSlot0x05Crypto(void);
|
2016-05-15 18:16:45 +02:00
|
|
|
bool CheckSector0x96Crypto(void);
|
2016-03-03 13:27:51 +01:00
|
|
|
|
2016-03-22 19:24:21 +01:00
|
|
|
void CryptNand(u8* buffer, u32 sector, u32 count, u32 keyslot);
|
2016-05-15 18:16:45 +02:00
|
|
|
void CryptSector0x96(u8* buffer, bool encrypt);
|
2017-02-17 04:01:25 +01:00
|
|
|
int ReadNandBytes(u8* buffer, u64 offset, u64 count, u32 keyslot, u32 nand_src);
|
|
|
|
int WriteNandBytes(const u8* buffer, u64 offset, u64 count, u32 keyslot, u32 nand_dst);
|
2016-04-04 22:45:49 +02:00
|
|
|
int ReadNandSectors(u8* buffer, u32 sector, u32 count, u32 keyslot, u32 src);
|
|
|
|
int WriteNandSectors(const u8* buffer, u32 sector, u32 count, u32 keyslot, u32 dest);
|
2016-03-03 13:27:51 +01:00
|
|
|
|
2016-04-04 22:45:49 +02:00
|
|
|
u64 GetNandSizeSectors(u32 src);
|
2017-02-20 22:59:03 +01:00
|
|
|
u64 GetNandUnusedSectors(u32 src);
|
2017-01-02 17:37:08 +01:00
|
|
|
u32 CheckNandHeader(u8* header);
|
2016-04-09 21:50:50 +02:00
|
|
|
u32 CheckNandType(u32 src);
|
2016-03-15 16:25:27 +01:00
|
|
|
|
2017-01-17 21:44:16 +01:00
|
|
|
bool CheckMultiEmuNand(void);
|
|
|
|
u32 InitEmuNandBase(bool reset);
|
|
|
|
u32 GetEmuNandBase(void);
|