2021-05-26 01:53:11 +02:00
|
|
|
/*
|
|
|
|
* ISFSHAX
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 rw-r-r-0644 <rwrr0644@gmail.com>
|
|
|
|
*
|
|
|
|
* Based on code from Minute and Mini:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Ash Logan <quarktheawesome@gmail.com>
|
|
|
|
* Copyright (C) 2016 SALT
|
|
|
|
* Copyright (C) 2016 Daz Jones <daz@dazzozo.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008, 2009 Haxx Enterprises <bushing@gmail.com>
|
|
|
|
* Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
|
|
|
|
* Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
|
|
|
* Copyright (C) 2009 Andre Heider "dhewg" <dhewg@wiibrew.org>
|
|
|
|
* Copyright (C) 2009 John Kelley <wiidev@kelley.ca>
|
|
|
|
*
|
|
|
|
* This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
* see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "memory.h"
|
|
|
|
#include "irq.h"
|
|
|
|
#include "crypto.h"
|
|
|
|
#include "smc.h"
|
|
|
|
#include "latte.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "isfs/isfshax.h"
|
|
|
|
#include "sdcard.h"
|
|
|
|
#include "fatfs/ff.h"
|
|
|
|
#include "nand.h"
|
|
|
|
#include "isfs/isfs.h"
|
|
|
|
#include "ancast.h"
|
2021-06-01 13:19:23 +02:00
|
|
|
#include "debug.h"
|
|
|
|
#include "lolserial.h"
|
2021-05-26 01:53:11 +02:00
|
|
|
|
|
|
|
u32 load_payload_sd(void)
|
|
|
|
{
|
|
|
|
static FATFS fatfs;
|
|
|
|
UINT btr, br;
|
|
|
|
FRESULT res;
|
|
|
|
FIL file;
|
|
|
|
u32 vector = 0;
|
|
|
|
|
2021-05-30 20:11:26 +02:00
|
|
|
ancast_iop_clear((u8*)ANCAST_ADDRESS_IOP);
|
|
|
|
|
2021-05-26 01:53:11 +02:00
|
|
|
sdcard_init();
|
|
|
|
|
|
|
|
res = f_mount(&fatfs, "0:", 1);
|
|
|
|
if (res)
|
|
|
|
goto error_mount;
|
|
|
|
|
|
|
|
res = f_open(&file, "isfshax.bin", FA_READ);
|
|
|
|
if (res)
|
|
|
|
goto error_open;
|
|
|
|
|
|
|
|
btr = f_size(&file);
|
|
|
|
if (!btr)
|
|
|
|
goto error_read;
|
|
|
|
|
|
|
|
res = f_read(&file, (u8*)ANCAST_ADDRESS_IOP, btr, &br);
|
|
|
|
if (res || (btr != br))
|
|
|
|
goto error_read;
|
|
|
|
|
|
|
|
vector = ancast_iop_load((u8*)ANCAST_ADDRESS_IOP, btr);
|
|
|
|
|
|
|
|
error_read:
|
|
|
|
f_close(&file);
|
|
|
|
error_open:
|
|
|
|
f_mount(0, "0:", 0);
|
|
|
|
error_mount:
|
|
|
|
sdcard_exit();
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 load_payload_nand(void)
|
|
|
|
{
|
|
|
|
isfs_file file;
|
|
|
|
size_t btr, br;
|
|
|
|
int res;
|
|
|
|
u32 vector = 0;
|
|
|
|
|
2021-05-30 20:11:26 +02:00
|
|
|
ancast_iop_clear((u8*)ANCAST_ADDRESS_IOP);
|
|
|
|
|
2021-05-26 01:53:11 +02:00
|
|
|
res = isfs_init();
|
|
|
|
if (res)
|
|
|
|
return vector;
|
|
|
|
|
2021-06-01 12:36:01 +02:00
|
|
|
res = isfs_open(&file, "slc:/sys/isfshax.bin");
|
2021-05-26 01:53:11 +02:00
|
|
|
if (res)
|
|
|
|
goto error_open;
|
|
|
|
|
|
|
|
btr = file.fst->size;
|
|
|
|
if (!btr)
|
|
|
|
goto error_read;
|
|
|
|
|
|
|
|
res = isfs_read(&file, (u8*)ANCAST_ADDRESS_IOP, btr, &br);
|
|
|
|
if (res || (btr != br))
|
|
|
|
goto error_read;
|
|
|
|
|
|
|
|
vector = ancast_iop_load((u8*)ANCAST_ADDRESS_IOP, btr);
|
|
|
|
|
|
|
|
error_read:
|
|
|
|
isfs_close(&file);
|
|
|
|
error_open:
|
|
|
|
isfs_fini();
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 _main(void)
|
|
|
|
{
|
|
|
|
u32 vector = 0;
|
2021-06-01 13:19:23 +02:00
|
|
|
|
|
|
|
lolserial_init();
|
|
|
|
DEBUG("isfshax start\n");
|
|
|
|
|
2021-05-26 02:21:26 +02:00
|
|
|
//mem_initialize();
|
2021-05-26 01:53:11 +02:00
|
|
|
irq_initialize();
|
|
|
|
crypto_read_otp();
|
|
|
|
nand_initialize();
|
|
|
|
|
|
|
|
/* repair isfshax superblocks ecc errors, if present */
|
2021-06-01 13:19:23 +02:00
|
|
|
DEBUG("isfshax_refresh\n");
|
2021-05-26 01:53:11 +02:00
|
|
|
isfshax_refresh();
|
|
|
|
|
|
|
|
/* attempt to load the payload from SD, then NAND */
|
2021-06-01 13:19:23 +02:00
|
|
|
DEBUG("load_payload_sd\n");
|
|
|
|
lolserial_suspend();
|
2021-05-26 01:53:11 +02:00
|
|
|
vector = load_payload_sd();
|
2021-06-01 13:19:23 +02:00
|
|
|
lolserial_resume();
|
|
|
|
|
|
|
|
if (!vector) {
|
|
|
|
DEBUG("load_payload_nand\n");
|
|
|
|
lolserial_suspend();
|
2021-05-26 01:53:11 +02:00
|
|
|
vector = load_payload_nand();
|
2021-06-01 13:19:23 +02:00
|
|
|
lolserial_resume();
|
|
|
|
}
|
|
|
|
DEBUG("vector: %08lX\n", vector);
|
2021-05-26 01:53:11 +02:00
|
|
|
|
|
|
|
nand_deinitialize();
|
|
|
|
irq_shutdown();
|
2021-05-26 02:21:26 +02:00
|
|
|
//mem_shutdown();
|
2021-05-26 01:53:11 +02:00
|
|
|
|
|
|
|
/* failed to load the payload from SD or NAND -> shutdown */
|
|
|
|
if (!vector)
|
|
|
|
smc_shutdown(false);
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|