mirror of
https://github.com/rvtr/TDT.git
synced 2025-10-31 13:51:07 -04:00
Clean up formatting
No code changes outside of a very minor change to arm7/main.c (removes unused functions)
This commit is contained in:
parent
c9267de164
commit
68fc9a6586
@ -29,34 +29,29 @@
|
||||
---------------------------------------------------------------------------------*/
|
||||
#include "my_sdmmc.h"
|
||||
|
||||
//#include <dswifi7.h>
|
||||
//#include <maxmod7.h>
|
||||
#include <nds.h>
|
||||
#include <string.h>
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void VblankHandler(void) {
|
||||
//---------------------------------------------------------------------------------
|
||||
// Wifi_Update();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void VcountHandler() {
|
||||
void VcountHandler()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
inputGetAndSend();
|
||||
}
|
||||
|
||||
volatile bool exitflag = false;
|
||||
volatile bool reboot = false;
|
||||
|
||||
// Custom POWER button handling, based on the default function:
|
||||
// https://github.com/devkitPro/libnds/blob/154a21cc3d57716f773ff2b10f815511c1b8ba9f/source/common/interrupts.c#L51-L69
|
||||
//---------------------------------------------------------------------------------
|
||||
TWL_CODE void i2cIRQHandlerCustom() {
|
||||
TWL_CODE void i2cIRQHandlerCustom()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
int cause = (i2cReadRegister(I2C_PM, I2CREGPM_PWRIF) & 0x3) | (i2cReadRegister(I2C_GPIO, 0x02)<<2);
|
||||
|
||||
switch (cause & 3) {
|
||||
switch (cause & 3)
|
||||
{
|
||||
case 1:
|
||||
reboot = true;
|
||||
exitflag = true;
|
||||
@ -68,14 +63,19 @@ TWL_CODE void i2cIRQHandlerCustom() {
|
||||
}
|
||||
}
|
||||
|
||||
void set_ctr(u32* ctr){
|
||||
void set_ctr(u32* ctr)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) REG_AES_IV[i] = ctr[3-i];
|
||||
}
|
||||
|
||||
// 10 11 22 23 24 25
|
||||
void aes(void* in, void* out, void* iv, u32 method){ //this is sort of a bodged together dsi aes function adapted from this 3ds function
|
||||
REG_AES_CNT = ( AES_CNT_MODE(method) | //https://github.com/TiniVi/AHPCFW/blob/master/source/aes.c#L42
|
||||
AES_WRFIFO_FLUSH | //as long as the output changes when keyslot values change, it's good enough.
|
||||
//this is sort of a bodged together dsi aes function adapted from this 3ds function
|
||||
//https://github.com/TiniVi/AHPCFW/blob/master/source/aes.c#L42
|
||||
//as long as the output changes when keyslot values change, it's good enough.
|
||||
void aes(void* in, void* out, void* iv, u32 method)
|
||||
{
|
||||
REG_AES_CNT = ( AES_CNT_MODE(method) |
|
||||
AES_WRFIFO_FLUSH |
|
||||
AES_RDFIFO_FLUSH |
|
||||
AES_CNT_KEY_APPLY |
|
||||
AES_CNT_KEYSLOT(3) |
|
||||
@ -97,8 +97,9 @@ void aes(void* in, void* out, void* iv, u32 method){ //this is sort of a bodged
|
||||
int my_sdmmc_nand_startup();
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int main() {
|
||||
int main()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
// clear sound registers
|
||||
dmaFillWords(0, (void*)0x04000400, 0x100);
|
||||
|
||||
@ -116,7 +117,8 @@ int main() {
|
||||
fifoInit();
|
||||
touchInit();
|
||||
|
||||
if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/) {
|
||||
if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/)
|
||||
{
|
||||
u8 *out=(u8*)0x02300000;
|
||||
|
||||
#if USENATIVECONSOLEID
|
||||
@ -135,16 +137,18 @@ int main() {
|
||||
u8 *scratch=(u8*)0x02300200;
|
||||
u8 *key3=(u8*)0x40044D0;
|
||||
|
||||
|
||||
aes(in, base, iv, 2);
|
||||
|
||||
//write consecutive 0-255 values to any byte in key3 until we get the same aes output as "base" above - this reveals the hidden byte. this way we can uncover all 16 bytes of the key3 normalkey pretty easily.
|
||||
//greets to Martin Korth for this trick https://problemkaputt.de/gbatek.htm#dsiaesioports (Reading Write-Only Values)
|
||||
for(int i=0;i<16;i++){
|
||||
for(int j=0;j<256;j++){
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
for (int j=0;j<256;j++)
|
||||
{
|
||||
*(key3+i)=j & 0xFF;
|
||||
aes(in, scratch, iv, 2);
|
||||
if(!memcmp(scratch, base, 16)){
|
||||
if (!memcmp(scratch, base, 16))
|
||||
{
|
||||
out[i]=j;
|
||||
//hit++;
|
||||
break;
|
||||
@ -158,25 +162,21 @@ int main() {
|
||||
//sdmmc_nand_cid((u32*)0x2FFD7BC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// mmInstall(FIFO_MAXMOD);
|
||||
|
||||
SetYtrigger(80);
|
||||
|
||||
// installWifiFIFO();
|
||||
installSoundFIFO();
|
||||
|
||||
installSystemFIFO();
|
||||
|
||||
irqSet(IRQ_VCOUNT, VcountHandler);
|
||||
irqSet(IRQ_VBLANK, VblankHandler);
|
||||
|
||||
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
|
||||
|
||||
// Keep the ARM7 mostly idle
|
||||
while (!exitflag) {
|
||||
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
|
||||
while (!exitflag)
|
||||
{
|
||||
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R)))
|
||||
{
|
||||
exitflag = true;
|
||||
}
|
||||
|
||||
@ -195,10 +195,13 @@ int main() {
|
||||
fifoWaitValue32(FIFO_USER_02);
|
||||
fifoCheckValue32(FIFO_USER_02);
|
||||
|
||||
if (reboot) {
|
||||
if (reboot)
|
||||
{
|
||||
i2cWriteRegister(I2C_PM, I2CREGPM_RESETFLAG, 1);
|
||||
i2cWriteRegister(I2C_PM, I2CREGPM_PWRCNT, 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
writePowerManagement(PM_CONTROL_REG,PM_SYSTEM_PWR);
|
||||
}
|
||||
|
||||
|
||||
@ -10,15 +10,17 @@
|
||||
static struct mmcdevice deviceSD;
|
||||
static struct mmcdevice deviceNAND;
|
||||
|
||||
/*mmcdevice *getMMCDevice(int drive) {
|
||||
/*mmcdevice *getMMCDevice(int drive)
|
||||
{
|
||||
if (drive==0) return &deviceNAND;
|
||||
return &deviceSD;
|
||||
}
|
||||
*/
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_geterror(struct mmcdevice *ctx) {
|
||||
int my_geterror(struct mmcdevice *ctx)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
//if (ctx->error == 0x4) return -1;
|
||||
//else return 0;
|
||||
return (ctx->error << 29) >> 31;
|
||||
@ -26,13 +28,17 @@ int my_geterror(struct mmcdevice *ctx) {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_setTarget(struct mmcdevice *ctx) {
|
||||
void my_setTarget(struct mmcdevice *ctx)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
sdmmc_mask16(REG_SDPORTSEL,0x3,(u16)ctx->devicenumber);
|
||||
setckl(ctx->clk);
|
||||
if (ctx->SDOPT == 0) {
|
||||
if (ctx->SDOPT == 0)
|
||||
{
|
||||
sdmmc_mask16(REG_SDOPT, 0, 0x8000);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sdmmc_mask16(REG_SDOPT, 0x8000, 0);
|
||||
}
|
||||
|
||||
@ -40,8 +46,9 @@ void my_setTarget(struct mmcdevice *ctx) {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_sdmmc_send_command(struct mmcdevice *ctx, uint32_t cmd, uint32_t args) {
|
||||
void my_sdmmc_send_command(struct mmcdevice *ctx, uint32_t cmd, uint32_t args)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
const bool getSDRESP = (cmd << 15) >> 31;
|
||||
u16 flags = (cmd << 15) >> 31;
|
||||
const bool readdata = cmd & 0x20000;
|
||||
@ -92,9 +99,9 @@ void my_sdmmc_send_command(struct mmcdevice *ctx, uint32_t cmd, uint32_t args) {
|
||||
volatile u16 status1 = sdmmc_read16(REG_SDSTATUS1);
|
||||
#ifdef DATA32_SUPPORT
|
||||
volatile u16 ctl32 = sdmmc_read16(REG_SDDATACTL32);
|
||||
if((ctl32 & 0x100))
|
||||
if (ctl32 & 0x100)
|
||||
#else
|
||||
if((status1 & TMIO_STAT1_RXRDY))
|
||||
if (status1 & TMIO_STAT1_RXRDY)
|
||||
#endif
|
||||
{
|
||||
if (readdata)
|
||||
@ -243,8 +250,9 @@ void my_sdmmc_send_command(struct mmcdevice *ctx, uint32_t cmd, uint32_t args) {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_cardinserted() {
|
||||
int my_sdmmc_cardinserted()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return 1; //my_sdmmc_cardready;
|
||||
}
|
||||
|
||||
@ -252,8 +260,9 @@ int my_sdmmc_cardinserted() {
|
||||
static bool my_sdmmc_controller_initialised = false;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_sdmmc_controller_init( bool force_init ) {
|
||||
void my_sdmmc_controller_init( bool force_init )
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
if (!force_init && my_sdmmc_controller_initialised) return;
|
||||
|
||||
@ -313,11 +322,13 @@ void my_sdmmc_controller_init( bool force_init ) {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static u32 calcSDSize(u8* csd, int type) {
|
||||
static u32 calcSDSize(u8* csd, int type)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
u32 result = 0;
|
||||
if (type == -1) type = csd[14] >> 6;
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
u32 block_len = csd[9] & 0xf;
|
||||
@ -341,8 +352,9 @@ static u32 calcSDSize(u8* csd, int type) {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_sdcard_init() {
|
||||
int my_sdmmc_sdcard_init()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
// We need to send at least 74 clock pulses.
|
||||
my_setTarget(&deviceSD);
|
||||
swiDelay(0x1980); // ~75-76 clocks
|
||||
@ -362,9 +374,11 @@ int my_sdmmc_sdcard_init() {
|
||||
// ACMD41
|
||||
my_sdmmc_send_command(&deviceSD,0x10769,0x00FF8000 | temp);
|
||||
temp2 = 1;
|
||||
} while ( !(deviceSD.error & 1) );
|
||||
}
|
||||
while ( !(deviceSD.error & 1) );
|
||||
|
||||
} while((deviceSD.ret[0] & 0x80000000) == 0);
|
||||
}
|
||||
while ((deviceSD.ret[0] & 0x80000000) == 0);
|
||||
|
||||
if (!((deviceSD.ret[0] >> 30) & 1) || !temp)
|
||||
temp2 = 0;
|
||||
@ -434,8 +448,9 @@ int my_sdmmc_sdcard_init() {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_nand_init() {
|
||||
int my_sdmmc_nand_init()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
my_setTarget(&deviceNAND);
|
||||
swiDelay(0xF000);
|
||||
|
||||
@ -444,7 +459,8 @@ int my_sdmmc_nand_init() {
|
||||
do {
|
||||
do {
|
||||
my_sdmmc_send_command(&deviceNAND,0x10701,0x100000);
|
||||
} while ( !(deviceNAND.error & 1) );
|
||||
}
|
||||
while ( !(deviceNAND.error & 1) );
|
||||
}
|
||||
while ((deviceNAND.ret[0] & 0x80000000) == 0);
|
||||
|
||||
@ -486,8 +502,9 @@ int my_sdmmc_nand_init() {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_readsectors(struct mmcdevice *device, u32 sector_no, u32 numsectors, void *out) {
|
||||
int my_sdmmc_readsectors(struct mmcdevice *device, u32 sector_no, u32 numsectors, void *out)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
if (device->isSDHC == 0) sector_no <<= 9;
|
||||
my_setTarget(device);
|
||||
sdmmc_write16(REG_SDSTOP,0x100);
|
||||
@ -506,8 +523,9 @@ int my_sdmmc_readsectors(struct mmcdevice *device, u32 sector_no, u32 numsectors
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_writesectors(struct mmcdevice *device, u32 sector_no, u32 numsectors, void *in) {
|
||||
int my_sdmmc_writesectors(struct mmcdevice *device, u32 sector_no, u32 numsectors, void *in)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
if (device->isSDHC == 0)
|
||||
sector_no <<= 9;
|
||||
my_setTarget(device);
|
||||
@ -527,8 +545,9 @@ int my_sdmmc_writesectors(struct mmcdevice *device, u32 sector_no, u32 numsector
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_sdmmc_get_cid(int devicenumber, u32 *cid) {
|
||||
void my_sdmmc_get_cid(int devicenumber, u32 *cid)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
struct mmcdevice *device = (devicenumber == 1 ? &deviceNAND : &deviceSD);
|
||||
|
||||
@ -555,16 +574,17 @@ void my_sdmmc_get_cid(int devicenumber, u32 *cid) {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_sdmmcMsgHandler(int bytes, void *user_data) {
|
||||
void my_sdmmcMsgHandler(int bytes, void *user_data)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
FifoMessage msg;
|
||||
int retval = 0;
|
||||
|
||||
fifoGetDatamsg(FIFO_SDMMC, bytes, (u8*)&msg);
|
||||
|
||||
int oldIME = enterCriticalSection();
|
||||
switch (msg.type) {
|
||||
|
||||
switch (msg.type)
|
||||
{
|
||||
case SDMMC_SD_READ_SECTORS:
|
||||
retval = my_sdmmc_readsectors(&deviceSD, msg.sdParams.startsector, msg.sdParams.numsectors, msg.sdParams.buffer);
|
||||
break;
|
||||
@ -585,28 +605,31 @@ void my_sdmmcMsgHandler(int bytes, void *user_data) {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_nand_startup() {
|
||||
int my_sdmmc_nand_startup()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
my_sdmmc_controller_init(false);
|
||||
return my_sdmmc_nand_init();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_sd_startup() {
|
||||
int my_sdmmc_sd_startup()
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
my_sdmmc_controller_init(false);
|
||||
return my_sdmmc_sdcard_init();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void my_sdmmcValueHandler(u32 value, void* user_data) {
|
||||
void my_sdmmcValueHandler(u32 value, void* user_data)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
int result = 0;
|
||||
int sdflag = 0;
|
||||
int oldIME = enterCriticalSection();
|
||||
|
||||
switch(value) {
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case SDMMC_HAVE_SD:
|
||||
result = sdmmc_read16(REG_SDSTATUS0);
|
||||
break;
|
||||
@ -615,9 +638,12 @@ void my_sdmmcValueHandler(u32 value, void* user_data) {
|
||||
sdflag = 1;
|
||||
/* Falls through. */
|
||||
case SDMMC_NAND_START:
|
||||
if (sdmmc_read16(REG_SDSTATUS0) == 0) {
|
||||
if (sdmmc_read16(REG_SDSTATUS0) == 0)
|
||||
{
|
||||
result = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (sdflag == 1 ) ? my_sdmmc_sd_startup() : my_sdmmc_nand_startup();
|
||||
}
|
||||
break;
|
||||
@ -640,26 +666,30 @@ void my_sdmmcValueHandler(u32 value, void* user_data) {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out) {
|
||||
int my_sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return my_sdmmc_readsectors(&deviceSD, sector_no, numsectors, out);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, void *in) {
|
||||
int my_sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, void *in)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return my_sdmmc_writesectors(&deviceSD, sector_no, numsectors, in);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, void *out) {
|
||||
int my_sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, void *out)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return my_sdmmc_readsectors(&deviceNAND, sector_no, numsectors, out);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
int my_sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, void *in) {
|
||||
int my_sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, void *in)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return my_sdmmc_writesectors(&deviceNAND, sector_no, numsectors, in);
|
||||
}
|
||||
|
||||
|
||||
@ -136,11 +136,13 @@ int my_sdmmc_sdcard_init();
|
||||
int my_sdmmc_nand_init();
|
||||
void my_sdmmc_get_cid(int devicenumber, u32 *cid);
|
||||
|
||||
static inline void sdmmc_nand_cid( u32 *cid) {
|
||||
static inline void sdmmc_nand_cid( u32 *cid)
|
||||
{
|
||||
my_sdmmc_get_cid(MMC_DEVICE_NAND, cid);
|
||||
}
|
||||
|
||||
static inline void sdmmc_sdcard_cid( u32 *cid) {
|
||||
static inline void sdmmc_sdcard_cid( u32 *cid)
|
||||
{
|
||||
my_sdmmc_get_cid(MMC_DEVICE_SDCARD, cid);
|
||||
}
|
||||
|
||||
@ -153,32 +155,37 @@ extern u32 sdmmc_cid[];
|
||||
extern int sdmmc_curdevice;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline u16 sdmmc_read16(u16 reg) {
|
||||
static inline u16 sdmmc_read16(u16 reg)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return *(vu16*)(SDMMC_BASE + reg);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline void sdmmc_write16(u16 reg, u16 val) {
|
||||
static inline void sdmmc_write16(u16 reg, u16 val)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
*(vu16*)(SDMMC_BASE + reg) = val;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline u32 sdmmc_read32(u16 reg) {
|
||||
static inline u32 sdmmc_read32(u16 reg)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
return *(vu32*)(SDMMC_BASE + reg);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline void sdmmc_write32(u16 reg, u32 val) {
|
||||
static inline void sdmmc_write32(u16 reg, u32 val)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
*(vu32*)(SDMMC_BASE + reg) = val;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline void sdmmc_mask16(u16 reg, u16 clear, u16 set) {
|
||||
static inline void sdmmc_mask16(u16 reg, u16 clear, u16 set)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
u16 val = sdmmc_read16(reg);
|
||||
val &= ~clear;
|
||||
val |= set;
|
||||
@ -187,8 +194,9 @@ static inline void sdmmc_mask16(u16 reg, u16 clear, u16 set) {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static inline void setckl(u32 data) {
|
||||
static inline void setckl(u32 data)
|
||||
//---------------------------------------------------------------------------------
|
||||
{
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x2FF, data & 0x2FF);
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x0, 0x100);
|
||||
|
||||
@ -75,7 +75,8 @@ void tmd_create(uint8_t* tmd, FILE* app)
|
||||
|
||||
// Phase 4 - offset 0x1AA (fill-in 0x80 value, 0x10 times)
|
||||
{
|
||||
for(size_t i = 0; i<0x10; i++) {
|
||||
for (size_t i = 0; i<0x10; i++)
|
||||
{
|
||||
tmd[0x1AA + i] = 0x80;
|
||||
}
|
||||
}
|
||||
@ -140,7 +141,8 @@ int maketmd(char* input, char* tmdPath)
|
||||
iprintf("MakeTMD for DSiWare Homebrew\n");
|
||||
iprintf("by Przemyslaw Skryjomski\n\t(Tuxality)\n");
|
||||
|
||||
if(input == NULL || tmdPath == NULL) {
|
||||
if (input == NULL || tmdPath == NULL)
|
||||
{
|
||||
iprintf("\x1B[33m"); //yellow
|
||||
iprintf("\nUsage: %s file.app <file.tmd>\n", "maketmd");
|
||||
iprintf("\x1B[47m"); //white
|
||||
@ -150,7 +152,8 @@ int maketmd(char* input, char* tmdPath)
|
||||
// APP file (input)
|
||||
FILE* app = fopen(input, "rb");
|
||||
|
||||
if(!app) {
|
||||
if (!app)
|
||||
{
|
||||
iprintf("\x1B[31m"); //red
|
||||
iprintf("Error at opening %s for reading.\n", input);
|
||||
iprintf("\x1B[47m"); //white
|
||||
|
||||
@ -16,14 +16,22 @@
|
||||
|
||||
/************************ Constants / Defines *********************************/
|
||||
|
||||
const uint8_t DSi_KEY_MAGIC[16] = { 0x79, 0x3e, 0x4f, 0x1a, 0x5f, 0x0f, 0x68, 0x2a,
|
||||
0x58, 0x02, 0x59, 0x29, 0x4e, 0xfb, 0xfe, 0xff };
|
||||
const uint8_t DSi_NAND_KEY_Y[16] = { 0x76, 0xdc, 0xb9, 0x0a, 0xd3, 0xc4, 0x4d, 0xbd,
|
||||
0x1d, 0xdd, 0x2d, 0x20, 0x05, 0x00, 0xa0, 0xe1 };
|
||||
const uint8_t DSi_ES_KEY_Y[16] = { 0xe5, 0xcc, 0x5a, 0x8b, 0x56, 0xd0, 0xc9,0x72,
|
||||
0x9c, 0x17, 0xe8, 0xdc, 0x39, 0x12, 0x36, 0xa9 };
|
||||
const uint8_t DSi_BOOT2_KEY[16] = { 0x98, 0xee, 0x80, 0x80, 0x00, 0x6c, 0xb4, 0xf6,
|
||||
0x3a, 0xc2, 0x6e, 0x62, 0xf9, 0xec, 0x34, 0xad };
|
||||
const uint8_t DSi_KEY_MAGIC[16] = {
|
||||
0x79, 0x3e, 0x4f, 0x1a, 0x5f, 0x0f, 0x68, 0x2a,
|
||||
0x58, 0x02, 0x59, 0x29, 0x4e, 0xfb, 0xfe, 0xff
|
||||
};
|
||||
const uint8_t DSi_NAND_KEY_Y[16] = {
|
||||
0x76, 0xdc, 0xb9, 0x0a, 0xd3, 0xc4, 0x4d, 0xbd,
|
||||
0x1d, 0xdd, 0x2d, 0x20, 0x05, 0x00, 0xa0, 0xe1
|
||||
};
|
||||
const uint8_t DSi_ES_KEY_Y[16] = {
|
||||
0xe5, 0xcc, 0x5a, 0x8b, 0x56, 0xd0, 0xc9,0x72,
|
||||
0x9c, 0x17, 0xe8, 0xdc, 0x39, 0x12, 0x36, 0xa9
|
||||
};
|
||||
const uint8_t DSi_BOOT2_KEY[16] = {
|
||||
0x98, 0xee, 0x80, 0x80, 0x00, 0x6c, 0xb4, 0xf6,
|
||||
0x3a, 0xc2, 0x6e, 0x62, 0xf9, 0xec, 0x34, 0xad
|
||||
};
|
||||
|
||||
/************************ Functions *******************************************/
|
||||
|
||||
@ -47,4 +55,3 @@ void F_XY_reverse(const uint8_t *key, uint8_t *key_xy)
|
||||
u128_rrot(key_xy, 42);
|
||||
u128_sub(key_xy, DSi_KEY_MAGIC);
|
||||
}
|
||||
|
||||
|
||||
@ -33,4 +33,3 @@ void F_XY_reverse(const uint8_t *key, uint8_t *key_xy);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -127,7 +127,9 @@ static bool read_sectors(sec_t start, sec_t len, void *buffer)
|
||||
((u8*)buffer)[0x38] = 'T';
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -142,7 +144,9 @@ static bool write_sectors(sec_t start, sec_t len, const void *buffer)
|
||||
if (nand_WriteSectors(start, len, crypt_buf))
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,8 @@ int parse_ncsd(const uint8_t sector0[SECTOR_SIZE])
|
||||
{
|
||||
break;
|
||||
}
|
||||
switch (fs_type) {
|
||||
switch (fs_type)
|
||||
{
|
||||
case 1:
|
||||
case 3:
|
||||
case 4:
|
||||
|
||||
@ -42,8 +42,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t offset,
|
||||
length;
|
||||
uint32_t offset, length;
|
||||
} __PACKED ncsd_partition_t;
|
||||
|
||||
typedef struct {
|
||||
@ -52,11 +51,9 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
ncsd_sginature signature;
|
||||
uint32_t magic,
|
||||
size;
|
||||
uint32_t magic, size;
|
||||
uint64_t media_id;
|
||||
uint8_t fs_types[NCSD_PARTITIONS],
|
||||
crypt_types[NCSD_PARTITIONS];
|
||||
uint8_t fs_types[NCSD_PARTITIONS], crypt_types[NCSD_PARTITIONS];
|
||||
ncsd_partition_t partitions[NCSD_PARTITIONS];
|
||||
} __PACKED ncsd_header_t;
|
||||
|
||||
@ -159,10 +156,8 @@ int parse_mbr(const uint8_t sector0[SECTOR_SIZE], const int is3DS);
|
||||
|
||||
/************************ static code verification ****************************/
|
||||
|
||||
static_assert(sizeof(ncsd_header_t) == NCSD_HEADERSIZE,
|
||||
"sizeof(ncsd_header_t) should equal 0x160");
|
||||
static_assert(sizeof(mbr_t) == SECTOR_SIZE,
|
||||
"sizeof(mbr_t) should equal 0x200");
|
||||
static_assert(sizeof(ncsd_header_t) == NCSD_HEADERSIZE, "sizeof(ncsd_header_t) should equal 0x160");
|
||||
static_assert(sizeof(mbr_t) == SECTOR_SIZE, "sizeof(mbr_t) should equal 0x200");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -5,8 +5,7 @@
|
||||
#include <time.h>
|
||||
#include "u128_math.h"
|
||||
|
||||
void dsi_set_key( dsi_context* ctx,
|
||||
const unsigned char key[16] )
|
||||
void dsi_set_key(dsi_context* ctx, const unsigned char key[16])
|
||||
{
|
||||
unsigned char keyswap[16];
|
||||
u128_swap(keyswap, key);
|
||||
@ -14,8 +13,7 @@ void dsi_set_key( dsi_context* ctx,
|
||||
aes_setkey_enc(&ctx->aes, keyswap, 128);
|
||||
}
|
||||
|
||||
void dsi_add_ctr( dsi_context* ctx,
|
||||
unsigned int carry)
|
||||
void dsi_add_ctr(dsi_context* ctx, unsigned int carry)
|
||||
{
|
||||
unsigned int counter[4];
|
||||
unsigned char *outctr = (unsigned char*)ctx->ctr;
|
||||
@ -47,8 +45,7 @@ void dsi_add_ctr( dsi_context* ctx,
|
||||
}
|
||||
}
|
||||
|
||||
void dsi_set_ctr( dsi_context* ctx,
|
||||
const unsigned char ctr[16] )
|
||||
void dsi_set_ctr(dsi_context* ctx, const unsigned char ctr[16])
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -56,18 +53,13 @@ void dsi_set_ctr( dsi_context* ctx,
|
||||
ctx->ctr[i] = ctr[15-i];
|
||||
}
|
||||
|
||||
void dsi_init_ctr( dsi_context* ctx,
|
||||
const unsigned char key[16],
|
||||
const unsigned char ctr[12] )
|
||||
void dsi_init_ctr(dsi_context* ctx, const unsigned char key[16], const unsigned char ctr[12])
|
||||
{
|
||||
dsi_set_key(ctx, key);
|
||||
dsi_set_ctr(ctx, ctr);
|
||||
}
|
||||
|
||||
void dsi_crypt_ctr( dsi_context* ctx,
|
||||
const void* in,
|
||||
void* out,
|
||||
unsigned int len)
|
||||
void dsi_crypt_ctr(dsi_context* ctx, const void* in, void* out, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < len; i += 0x10)
|
||||
@ -76,9 +68,7 @@ void dsi_crypt_ctr( dsi_context* ctx,
|
||||
}
|
||||
}
|
||||
|
||||
void dsi_crypt_ctr_block( dsi_context* ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
void dsi_crypt_ctr_block(dsi_context* ctx, const unsigned char input[16], unsigned char output[16])
|
||||
{
|
||||
int i;
|
||||
unsigned char stream[16];
|
||||
@ -104,12 +94,8 @@ void dsi_crypt_ctr_block( dsi_context* ctx,
|
||||
}
|
||||
|
||||
|
||||
void dsi_init_ccm( dsi_context* ctx,
|
||||
unsigned char key[16],
|
||||
unsigned int maclength,
|
||||
unsigned int payloadlength,
|
||||
unsigned int assoclength,
|
||||
unsigned char nonce[12] )
|
||||
void dsi_init_ccm(dsi_context* ctx, unsigned char key[16], unsigned int maclength,
|
||||
unsigned int payloadlength, unsigned int assoclength, unsigned char nonce[12])
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -148,10 +134,7 @@ void dsi_init_ccm( dsi_context* ctx,
|
||||
dsi_crypt_ctr_block(ctx, 0, ctx->S0);
|
||||
}
|
||||
|
||||
void dsi_encrypt_ccm_block( dsi_context* ctx,
|
||||
unsigned char input[16],
|
||||
unsigned char output[16],
|
||||
unsigned char* mac )
|
||||
void dsi_encrypt_ccm_block(dsi_context* ctx, unsigned char input[16], unsigned char output[16], unsigned char* mac)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -171,10 +154,7 @@ void dsi_encrypt_ccm_block( dsi_context* ctx,
|
||||
}
|
||||
|
||||
|
||||
void dsi_decrypt_ccm_block( dsi_context* ctx,
|
||||
unsigned char input[16],
|
||||
unsigned char output[16],
|
||||
unsigned char* mac )
|
||||
void dsi_decrypt_ccm_block(dsi_context* ctx, unsigned char input[16], unsigned char output[16], unsigned char* mac)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -204,11 +184,7 @@ void dsi_decrypt_ccm_block( dsi_context* ctx,
|
||||
}
|
||||
|
||||
|
||||
void dsi_decrypt_ccm( dsi_context* ctx,
|
||||
unsigned char* input,
|
||||
unsigned char* output,
|
||||
unsigned int size,
|
||||
unsigned char* mac )
|
||||
void dsi_decrypt_ccm(dsi_context* ctx, unsigned char* input, unsigned char* output, unsigned int size, unsigned char* mac)
|
||||
{
|
||||
unsigned char block[16];
|
||||
unsigned char ctr[16];
|
||||
@ -237,11 +213,7 @@ void dsi_decrypt_ccm( dsi_context* ctx,
|
||||
}
|
||||
|
||||
|
||||
void dsi_encrypt_ccm( dsi_context* ctx,
|
||||
unsigned char* input,
|
||||
unsigned char* output,
|
||||
unsigned int size,
|
||||
unsigned char* mac )
|
||||
void dsi_encrypt_ccm(dsi_context* ctx, unsigned char* input, unsigned char* output, unsigned int size, unsigned char* mac)
|
||||
{
|
||||
unsigned char block[16];
|
||||
|
||||
@ -263,15 +235,13 @@ void dsi_encrypt_ccm( dsi_context* ctx,
|
||||
memcpy(output, block, size);
|
||||
}
|
||||
|
||||
void dsi_es_init( dsi_es_context* ctx,
|
||||
unsigned char key[16] )
|
||||
void dsi_es_init(dsi_es_context* ctx, unsigned char key[16])
|
||||
{
|
||||
memcpy(ctx->key, key, 16);
|
||||
ctx->randomnonce = 1;
|
||||
}
|
||||
|
||||
void dsi_es_set_nonce( dsi_es_context* ctx,
|
||||
unsigned char nonce[12] )
|
||||
void dsi_es_set_nonce(dsi_es_context* ctx, unsigned char nonce[12])
|
||||
{
|
||||
memcpy(ctx->nonce, nonce, 12);
|
||||
ctx->randomnonce = 0;
|
||||
@ -283,10 +253,7 @@ void dsi_es_set_random_nonce( dsi_es_context* ctx )
|
||||
}
|
||||
|
||||
|
||||
int dsi_es_decrypt( dsi_es_context* ctx,
|
||||
unsigned char* buffer,
|
||||
unsigned char metablock[32],
|
||||
unsigned int size )
|
||||
int dsi_es_decrypt(dsi_es_context* ctx, unsigned char* buffer, unsigned char metablock[32], unsigned int size)
|
||||
{
|
||||
unsigned char ctr[16];
|
||||
unsigned char nonce[12];
|
||||
@ -334,10 +301,7 @@ int dsi_es_decrypt( dsi_es_context* ctx,
|
||||
}
|
||||
|
||||
|
||||
void dsi_es_encrypt( dsi_es_context* ctx,
|
||||
unsigned char* buffer,
|
||||
unsigned char metablock[32],
|
||||
unsigned int size )
|
||||
void dsi_es_encrypt(dsi_es_context* ctx, unsigned char* buffer, unsigned char metablock[32], unsigned int size)
|
||||
{
|
||||
int i;
|
||||
unsigned char nonce[12];
|
||||
|
||||
@ -27,75 +27,39 @@ typedef struct
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void dsi_set_key( dsi_context* ctx,
|
||||
const unsigned char key[16] );
|
||||
void dsi_set_key(dsi_context* ctx, const unsigned char key[16]);
|
||||
|
||||
void dsi_add_ctr( dsi_context* ctx,
|
||||
unsigned int carry );
|
||||
void dsi_add_ctr(dsi_context* ctx, unsigned int carry);
|
||||
|
||||
void dsi_set_ctr( dsi_context* ctx,
|
||||
const unsigned char ctr[16] );
|
||||
void dsi_set_ctr(dsi_context* ctx, const unsigned char ctr[16]);
|
||||
|
||||
void dsi_init_ctr( dsi_context* ctx,
|
||||
const unsigned char key[16],
|
||||
const unsigned char ctr[12] );
|
||||
void dsi_init_ctr(dsi_context* ctx, const unsigned char key[16], const unsigned char ctr[12]);
|
||||
|
||||
void dsi_crypt_ctr( dsi_context* ctx,
|
||||
const void* in,
|
||||
void* out,
|
||||
unsigned int len);
|
||||
void dsi_crypt_ctr(dsi_context* ctx, const void* in, void* out, unsigned int len);
|
||||
|
||||
void dsi_crypt_ctr_block( dsi_context* ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
void dsi_crypt_ctr_block(dsi_context* ctx, const unsigned char input[16], unsigned char output[16]);
|
||||
|
||||
void dsi_init_ccm( dsi_context* ctx,
|
||||
unsigned char key[16],
|
||||
unsigned int maclength,
|
||||
unsigned int payloadlength,
|
||||
unsigned int assoclength,
|
||||
unsigned char nonce[12] );
|
||||
void dsi_init_ccm(dsi_context* ctx, unsigned char key[16], unsigned int maclength,
|
||||
unsigned int payloadlength, unsigned int assoclength, unsigned char nonce[12]);
|
||||
|
||||
void dsi_encrypt_ccm_block( dsi_context* ctx,
|
||||
unsigned char input[16],
|
||||
unsigned char output[16],
|
||||
unsigned char* mac );
|
||||
void dsi_encrypt_ccm_block(dsi_context* ctx, unsigned char input[16], unsigned char output[16], unsigned char* mac);
|
||||
|
||||
void dsi_decrypt_ccm_block( dsi_context* ctx,
|
||||
unsigned char input[16],
|
||||
unsigned char output[16],
|
||||
unsigned char* mac );
|
||||
void dsi_decrypt_ccm_block(dsi_context* ctx, unsigned char input[16], unsigned char output[16], unsigned char* mac);
|
||||
|
||||
|
||||
void dsi_decrypt_ccm( dsi_context* ctx,
|
||||
unsigned char* input,
|
||||
unsigned char* output,
|
||||
unsigned int size,
|
||||
unsigned char* mac );
|
||||
void dsi_decrypt_ccm(dsi_context* ctx, unsigned char* input, unsigned char* output, unsigned int size, unsigned char* mac);
|
||||
|
||||
void dsi_encrypt_ccm( dsi_context* ctx,
|
||||
unsigned char* input,
|
||||
unsigned char* output,
|
||||
unsigned int size,
|
||||
unsigned char* mac );
|
||||
void dsi_encrypt_ccm(dsi_context* ctx, unsigned char* input, unsigned char* output, unsigned int size, unsigned char* mac);
|
||||
|
||||
void dsi_es_init( dsi_es_context* ctx,
|
||||
unsigned char key[16] );
|
||||
void dsi_es_init(dsi_es_context* ctx, unsigned char key[16]);
|
||||
|
||||
void dsi_es_set_nonce( dsi_es_context* ctx,
|
||||
unsigned char nonce[12] );
|
||||
void dsi_es_set_nonce(dsi_es_context* ctx, unsigned char nonce[12]);
|
||||
|
||||
void dsi_es_set_random_nonce(dsi_es_context* ctx);
|
||||
|
||||
int dsi_es_decrypt( dsi_es_context* ctx,
|
||||
unsigned char* buffer,
|
||||
unsigned char metablock[32],
|
||||
unsigned int size );
|
||||
int dsi_es_decrypt(dsi_es_context* ctx, unsigned char* buffer, unsigned char metablock[32], unsigned int size);
|
||||
|
||||
void dsi_es_encrypt( dsi_es_context* ctx,
|
||||
unsigned char* buffer,
|
||||
unsigned char metablock[32],
|
||||
unsigned int size );
|
||||
void dsi_es_encrypt(dsi_es_context* ctx, unsigned char* buffer, unsigned char metablock[32], unsigned int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user