mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 20:06:43 +00:00
re-implement formatting + add firmware dumping
This commit is contained in:
parent
ae225abb75
commit
47df1b9cd1
9 changed files with 135 additions and 27 deletions
|
@ -70,6 +70,14 @@ int mount_emmc(char *partition, int biskeynumb){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short returnpkg1ver(){
|
||||||
|
return pkg1ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disconnect_emmc(){
|
||||||
|
sdmmc_storage_end(&storage);
|
||||||
|
}
|
||||||
|
|
||||||
int dump_biskeys(){
|
int dump_biskeys(){
|
||||||
u8 temp_key[0x10], device_key[0x10] = {0};
|
u8 temp_key[0x10], device_key[0x10] = {0};
|
||||||
tsec_ctxt_t tsec_ctxt;
|
tsec_ctxt_t tsec_ctxt;
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
int dump_biskeys();
|
int dump_biskeys();
|
||||||
void print_biskeys();
|
void print_biskeys();
|
||||||
int mount_emmc(char *partition, int biskeynumb);
|
int mount_emmc(char *partition, int biskeynumb);
|
||||||
|
short returnpkg1ver();
|
||||||
|
void disconnect_emmc();
|
||||||
|
|
||||||
static const u8 zeros[0x10] = {0};
|
static const u8 zeros[0x10] = {0};
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ int readfolder(const char *path){
|
||||||
message(errmes, COLOR_RED);
|
message(errmes, COLOR_RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
while (!f_readdir(&dir, &fno) && fno.fname[0] && folderamount < 500){
|
||||||
addobject(fno.fname, folderamount++, (fno.fattrib & AM_DIR), (fno.fattrib & AM_ARC));
|
addobject(fno.fname, folderamount++, (fno.fattrib & AM_DIR), (fno.fattrib & AM_ARC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,5 @@ enum filemenuoptions {
|
||||||
int readfolder(const char *path);
|
int readfolder(const char *path);
|
||||||
void filemenu();
|
void filemenu();
|
||||||
bool checkfile(char* path);
|
bool checkfile(char* path);
|
||||||
u64 getfilesize(char *path);
|
u64 getfilesize(char *path);
|
||||||
|
int copy(const char *locin, const char *locout, bool print);
|
|
@ -99,7 +99,7 @@ int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer){
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (start + timer > get_tmr_s())
|
if (start + timer > get_tmr_s())
|
||||||
gfx_printf("\r<Wait %d seconds>", timer + start - get_tmr_s());
|
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
|
||||||
|
|
||||||
else if (res & BTN_POWER)
|
else if (res & BTN_POWER)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -37,8 +37,15 @@ menu_item toolsmenu[5] = {
|
||||||
{"-- TOOLS --\n", COLOR_VIOLET, -1, 0},
|
{"-- TOOLS --\n", COLOR_VIOLET, -1, 0},
|
||||||
{"Back", COLOR_WHITE, -1, 1},
|
{"Back", COLOR_WHITE, -1, 1},
|
||||||
{"\nDisplay Console Info", COLOR_GREEN, DISPLAY_INFO, 1},
|
{"\nDisplay Console Info", COLOR_GREEN, DISPLAY_INFO, 1},
|
||||||
{"Display GPIO pins [DEV]", COLOR_RED, DISPLAY_GPIO, 1},
|
{"Display GPIO pins", COLOR_VIOLET, DISPLAY_GPIO, 1},
|
||||||
{"FORMAT TEST", COLOR_RED, FORMATFAT32, 1}
|
{"Dump Firmware", COLOR_BLUE, DUMPFIRMWARE, 1}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_item formatmenu[4] = {
|
||||||
|
{"-- FORMAT SD --\n", COLOR_RED, -1, 0},
|
||||||
|
{"Back\n", COLOR_WHITE, -1, 1},
|
||||||
|
{"Format to FAT32", COLOR_RED, FORMAT_ALL_FAT32, 1},
|
||||||
|
{"Format for EmuMMC setup", COLOR_RED, FORMAT_EMUMMC, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
void fillmainmenu(){
|
void fillmainmenu(){
|
||||||
|
@ -111,17 +118,34 @@ void te_main(){
|
||||||
case TOOLS:
|
case TOOLS:
|
||||||
res = makemenu(toolsmenu, 5);
|
res = makemenu(toolsmenu, 5);
|
||||||
|
|
||||||
if (res == DISPLAY_INFO)
|
switch(res){
|
||||||
displayinfo();
|
case DISPLAY_INFO:
|
||||||
|
displayinfo();
|
||||||
if (res == DISPLAY_GPIO)
|
break;
|
||||||
displaygpio();
|
case DISPLAY_GPIO:
|
||||||
|
displaygpio();
|
||||||
if (res == FORMATFAT32)
|
break;
|
||||||
format();
|
case DUMPFIRMWARE:
|
||||||
|
dumpfirmware();
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SD_FORMAT:
|
||||||
|
res = makemenu(formatmenu, 4);
|
||||||
|
|
||||||
|
switch(res){
|
||||||
|
case FORMAT_ALL_FAT32:
|
||||||
|
if (makewaitmenu("Are you sure you want to format your sd?\nThis action is irreversible!\n\nPress Vol+/- to cancel\n", "Press Power to continue", 10))
|
||||||
|
format(1);
|
||||||
|
break;
|
||||||
|
case FORMAT_EMUMMC:
|
||||||
|
if (makewaitmenu("Are you sure you want to format your sd?\nThis action is irreversible!\n\nPress Vol+/- to cancel\n", "Press Power to continue", 10))
|
||||||
|
format(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case CREDITS:
|
case CREDITS:
|
||||||
message(CREDITS_MESSAGE, COLOR_WHITE);
|
message(CREDITS_MESSAGE, COLOR_WHITE);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -33,7 +33,12 @@ enum shutdownmenu_return {
|
||||||
enum toolsmenu_return {
|
enum toolsmenu_return {
|
||||||
DISPLAY_INFO = 1,
|
DISPLAY_INFO = 1,
|
||||||
DISPLAY_GPIO,
|
DISPLAY_GPIO,
|
||||||
FORMATFAT32
|
DUMPFIRMWARE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum formatmenu_return {
|
||||||
|
FORMAT_ALL_FAT32,
|
||||||
|
FORMAT_EMUMMC
|
||||||
};
|
};
|
||||||
|
|
||||||
//menu_item mainmenu[MAINMENU_AMOUNT];
|
//menu_item mainmenu[MAINMENU_AMOUNT];
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
#include "../utils/types.h"
|
#include "../utils/types.h"
|
||||||
#include "../libs/fatfs/diskio.h"
|
#include "../libs/fatfs/diskio.h"
|
||||||
#include "../storage/sdmmc.h"
|
#include "../storage/sdmmc.h"
|
||||||
|
#include "../utils/sprintf.h"
|
||||||
#include "emmc.h"
|
#include "emmc.h"
|
||||||
|
#include "fs.h"
|
||||||
|
|
||||||
extern bool sd_mount();
|
extern bool sd_mount();
|
||||||
extern void sd_unmount();
|
extern void sd_unmount();
|
||||||
|
@ -17,8 +19,6 @@ extern sdmmc_storage_t sd_storage;
|
||||||
void displayinfo(){
|
void displayinfo(){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FATFS *fs;
|
FATFS *fs;
|
||||||
DWORD fre_clust, fre_sect, tot_sect;
|
DWORD fre_clust, fre_sect, tot_sect;
|
||||||
u32 capacity;
|
u32 capacity;
|
||||||
|
@ -69,31 +69,95 @@ void displaygpio(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(){
|
int dumpfirmware(){
|
||||||
|
DIR dir;
|
||||||
|
FILINFO fno;
|
||||||
|
bool fail = false;
|
||||||
|
int ret, amount = 0;
|
||||||
|
char path[100] = "emmc:/Contents/registered";
|
||||||
|
char sdfolderpath[100] = "";
|
||||||
|
char syspath[100] = "";
|
||||||
|
char sdpath[100] = "";
|
||||||
|
short pkg1ver = returnpkg1ver();
|
||||||
|
u32 timer = get_tmr_s();
|
||||||
|
|
||||||
|
clearscreen();
|
||||||
|
|
||||||
|
gfx_printf("PKG1 version: %d\n", pkg1ver);
|
||||||
|
|
||||||
|
ret = f_mkdir("sd:/tegraexplorer");
|
||||||
|
gfx_printf("Creating making sd:/tegraexplorer %d\n", ret);
|
||||||
|
|
||||||
|
ret = f_mkdir("sd:/tegraexplorer/Firmware");
|
||||||
|
gfx_printf("Creating sd:/tegraexplorer/Firmware %d\n", ret);
|
||||||
|
|
||||||
|
sprintf(sdfolderpath, "sd:/tegraexplorer/Firmware/%d", pkg1ver);
|
||||||
|
ret = f_mkdir(sdfolderpath);
|
||||||
|
gfx_printf("Creating %s %d\n", sdfolderpath, ret);
|
||||||
|
|
||||||
|
ret = f_opendir(&dir, path);
|
||||||
|
gfx_printf("Result opening system:/ %d\n\n%k", ret, COLOR_GREEN);
|
||||||
|
|
||||||
|
while(!f_readdir(&dir, &fno) && fno.fname[0] && !fail){
|
||||||
|
sprintf(sdpath, "%s/%s", sdfolderpath, fno.fname);
|
||||||
|
|
||||||
|
if (fno.fattrib & AM_DIR)
|
||||||
|
sprintf(syspath, "%s/%s/00", path, fno.fname);
|
||||||
|
else
|
||||||
|
sprintf(syspath, "%s/%s", path, fno.fname);
|
||||||
|
|
||||||
|
ret = copy(syspath, sdpath, false);
|
||||||
|
|
||||||
|
gfx_printf("%d %s\r", ++amount, fno.fname);
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fail)
|
||||||
|
gfx_printf("%k\n\nDump failed! Aborting (%d)", COLOR_RED, ret);
|
||||||
|
|
||||||
|
gfx_printf("%k\n\nPress any button to continue...\nTime taken: %ds", COLOR_WHITE, get_tmr_s() - timer);
|
||||||
|
|
||||||
|
btn_wait();
|
||||||
|
|
||||||
|
return fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
void format(int mode){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
int res;
|
int res;
|
||||||
bool fatalerror = false;
|
bool fatalerror = false;
|
||||||
|
DWORD plist[] = {666, 61145088};
|
||||||
u32 timer, totalsectors;
|
u32 timer, totalsectors;
|
||||||
BYTE work[FF_MAX_SS];
|
BYTE work[FF_MAX_SS];
|
||||||
DWORD plist[] = {666, 61145088};
|
|
||||||
DWORD clustsize = 16 * 512;
|
DWORD clustsize = 16 * 512;
|
||||||
BYTE formatoptions = 0;
|
BYTE formatoptions = 0;
|
||||||
formatoptions |= (FM_FAT32);
|
formatoptions |= (FM_FAT32);
|
||||||
//formatoptions |= (FM_SFD);
|
//formatoptions |= (FM_SFD);
|
||||||
|
|
||||||
timer = get_tmr_s();
|
disconnect_emmc();
|
||||||
|
|
||||||
|
timer = get_tmr_s();
|
||||||
totalsectors = sd_storage.csd.capacity;
|
totalsectors = sd_storage.csd.capacity;
|
||||||
|
|
||||||
if (totalsectors < 61145088){
|
if (mode == 0){
|
||||||
gfx_printf("%k\nNot enough free space for emummc!", COLOR_RED);
|
if (totalsectors < 61145088){
|
||||||
fatalerror = true;
|
gfx_printf("%k\nNot enough free space for emummc!", COLOR_RED);
|
||||||
|
fatalerror = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fatalerror){
|
||||||
|
plist[0] = totalsectors - 61145088;
|
||||||
|
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], plist[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
plist[0] = totalsectors;
|
||||||
|
plist[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fatalerror){
|
if (!fatalerror){
|
||||||
plist[0] = totalsectors - 61145088;
|
|
||||||
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], plist[1]);
|
|
||||||
gfx_printf("\nPartitioning SD...\n");
|
gfx_printf("\nPartitioning SD...\n");
|
||||||
res = f_fdisk(0, plist, &work);
|
res = f_fdisk(0, plist, &work);
|
||||||
|
|
||||||
|
@ -127,6 +191,9 @@ void format(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump_biskeys();
|
||||||
|
mount_emmc("SYSTEM", 2);
|
||||||
|
|
||||||
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
||||||
btn_wait();
|
btn_wait();
|
||||||
}
|
}
|
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
void displayinfo();
|
void displayinfo();
|
||||||
void displaygpio();
|
void displaygpio();
|
||||||
void format();
|
void format(int mode);
|
||||||
|
int dumpfirmware();
|
Loading…
Reference in a new issue