mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-12-26 11:26:05 +00:00
Add emummc support
This commit is contained in:
parent
1410fa185f
commit
9885308bce
9 changed files with 98 additions and 58 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "../../sec/se.h"
|
||||
#include "../../storage/nx_emmc.h"
|
||||
#include "../../storage/sdmmc.h"
|
||||
#include "../../storage/emummc.h"
|
||||
|
||||
extern sdmmc_storage_t sd_storage;
|
||||
extern sdmmc_storage_t storage;
|
||||
|
|
|
@ -52,10 +52,10 @@ boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
|||
|
||||
bool return_sd_mounted(int value){
|
||||
switch(value){
|
||||
case 1:
|
||||
return sd_mounted;
|
||||
case 7:
|
||||
case 10:
|
||||
return sd_inited;
|
||||
default:
|
||||
return sd_mounted;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,6 @@ out:
|
|||
|
||||
int emummc_storage_end(sdmmc_storage_t *storage)
|
||||
{
|
||||
sd_unmount();
|
||||
sdmmc_storage_end(storage);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -74,5 +74,5 @@ int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_o
|
|||
// The last LBA is inclusive.
|
||||
if (part->lba_start + sector_off > part->lba_end)
|
||||
return 0;
|
||||
return sdmmc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||
return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "../soc/hw_init.h"
|
||||
#include "../mem/emc.h"
|
||||
#include "../mem/sdram.h"
|
||||
#include "../storage/emummc.h"
|
||||
|
||||
sdmmc_storage_t storage;
|
||||
emmc_part_t *system_part;
|
||||
|
@ -29,6 +30,8 @@ LIST_INIT(gpt);
|
|||
|
||||
u8 bis_key[4][32];
|
||||
short pkg1ver = -1;
|
||||
short currentlyMounted = -1;
|
||||
|
||||
|
||||
static bool _key_exists(const void *data) { return memcmp(data, zeros, 0x10); };
|
||||
|
||||
|
@ -52,7 +55,11 @@ void print_biskeys(){
|
|||
gfx_hexdump(0, bis_key[2], 32);
|
||||
}
|
||||
|
||||
int mount_emmc(char *partition, int biskeynumb){
|
||||
short returnpkg1ver(){
|
||||
return pkg1ver;
|
||||
}
|
||||
|
||||
int mount_mmc(char *partition, int biskeynumb){
|
||||
f_unmount("emmc:");
|
||||
|
||||
se_aes_key_set(8, bis_key[biskeynumb] + 0x00, 0x10);
|
||||
|
@ -72,13 +79,36 @@ int mount_emmc(char *partition, int biskeynumb){
|
|||
return 0;
|
||||
}
|
||||
|
||||
short returnpkg1ver(){
|
||||
return pkg1ver;
|
||||
void connect_mmc(short mmctype){
|
||||
if (mmctype != currentlyMounted){
|
||||
disconnect_mmc();
|
||||
switch (mmctype){
|
||||
case SYSMMC:
|
||||
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4);
|
||||
emu_cfg.enabled = 0;
|
||||
currentlyMounted = SYSMMC;
|
||||
break;
|
||||
case EMUMMC:
|
||||
emummc_storage_init_mmc(&storage, &sdmmc);
|
||||
emu_cfg.enabled = 1;
|
||||
currentlyMounted = EMUMMC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect_emmc(){
|
||||
void disconnect_mmc(){
|
||||
f_unmount("emmc:");
|
||||
sdmmc_storage_end(&storage);
|
||||
switch (currentlyMounted){
|
||||
case SYSMMC:
|
||||
sdmmc_storage_end(&storage);
|
||||
currentlyMounted = -1;
|
||||
break;
|
||||
case EMUMMC:
|
||||
emummc_storage_end(&storage);
|
||||
currentlyMounted = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int dump_biskeys(){
|
||||
|
@ -87,7 +117,7 @@ int dump_biskeys(){
|
|||
|
||||
int retries = 0;
|
||||
|
||||
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4);
|
||||
connect_mmc(SYSMMC);
|
||||
|
||||
// Read package1.
|
||||
u8 *pkg1 = (u8 *)malloc(0x40000);
|
||||
|
@ -172,41 +202,10 @@ int dump_biskeys(){
|
|||
sdmmc_storage_set_mmc_partition(&storage, 0);
|
||||
// Parse eMMC GPT.
|
||||
nx_emmc_gpt_parse(&gpt, &storage);
|
||||
/*
|
||||
char part_name[37] = "SYSTEM";
|
||||
|
||||
// todo: menu selection for this
|
||||
|
||||
u32 bis_key_index = 0;
|
||||
if (strcmp(part_name, "PRODINFOF") == 0)
|
||||
bis_key_index = 0;
|
||||
else if (strcmp(part_name, "SAFE") == 0)
|
||||
bis_key_index = 1;
|
||||
else if (strcmp(part_name, "SYSTEM") == 0)
|
||||
bis_key_index = 2;
|
||||
else if (strcmp(part_name, "USER") == 0)
|
||||
bis_key_index = 3;
|
||||
else {
|
||||
gfx_printf("Partition name %s unrecognized.", part_name);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
se_aes_key_set(8, bis_key[2] + 0x00, 0x10);
|
||||
se_aes_key_set(9, bis_key[2] + 0x10, 0x10);
|
||||
|
||||
/*
|
||||
system_part = nx_emmc_part_find(&gpt, "SYSTEM");
|
||||
if (!system_part) {
|
||||
gfx_printf("Failed to locate SYSTEM partition.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (f_mount(&emmc_sys, "system:", 1)) {
|
||||
gfx_printf("Mount failed of SYSTEM.");
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
pkg1ver = pkg1_id->kb;
|
||||
return 0;
|
||||
}
|
|
@ -3,9 +3,12 @@
|
|||
//int mount_emmc_partition(const char *part, int logicnumb);
|
||||
int dump_biskeys();
|
||||
void print_biskeys();
|
||||
int mount_emmc(char *partition, int biskeynumb);
|
||||
short returnpkg1ver();
|
||||
void disconnect_emmc();
|
||||
|
||||
int mount_mmc(char *partition, int biskeynumb);
|
||||
void connect_mmc(short mmctype);
|
||||
void disconnect_mmc();
|
||||
|
||||
|
||||
static const u8 zeros[0x10] = {0};
|
||||
|
||||
|
@ -40,4 +43,9 @@ static const u8 bis_key_source[3][0x20] = {
|
|||
{
|
||||
0x52, 0xC2, 0xE9, 0xEB, 0x09, 0xE3, 0xEE, 0x29, 0x32, 0xA1, 0x0C, 0x1F, 0xB6, 0xA0, 0x92, 0x6C,
|
||||
0x4D, 0x12, 0xE1, 0x4B, 0x2A, 0x47, 0x4C, 0x1C, 0x09, 0xCB, 0x03, 0x59, 0xF0, 0x15, 0xF4, 0xE4}
|
||||
};
|
||||
|
||||
enum mmc_types {
|
||||
SYSMMC = 0,
|
||||
EMUMMC
|
||||
};
|
|
@ -8,6 +8,7 @@
|
|||
#include "io.h"
|
||||
#include "../utils/btn.h"
|
||||
#include "emmc.h"
|
||||
#include "../storage/emummc.h"
|
||||
|
||||
extern bool sd_mount();
|
||||
extern void sd_unmount();
|
||||
|
@ -19,6 +20,9 @@ menu_item mainmenu[MAINMENU_AMOUNT] = {
|
|||
{"[SYSTEM:/] EMMC", COLOR_ORANGE, EMMC_SYS, 1},
|
||||
{"[USER:/] EMMC", COLOR_ORANGE, EMMC_USR, 1},
|
||||
{"[SAFE:/] EMMC", COLOR_ORANGE, EMMC_SAF, 1},
|
||||
{"\n[SYSTEM:/] EMUMMC", COLOR_BLUE, EMUMMC_SYS, 1},
|
||||
{"[USER:/] EMUMMC", COLOR_BLUE, EMUMMC_USR, 1},
|
||||
{"[SAFE:/] EMUMMC", COLOR_BLUE, EMUMMC_SAF, 1},
|
||||
{"\nMount/Unmount SD", COLOR_WHITE, MOUNT_SD, 1},
|
||||
{"Tools", COLOR_VIOLET, TOOLS, 1},
|
||||
{"SD format", COLOR_VIOLET, SD_FORMAT, 1},
|
||||
|
@ -63,14 +67,19 @@ void fillmainmenu(){
|
|||
|
||||
for (i = 0; i < MAINMENU_AMOUNT; i++){
|
||||
switch (i + 1) {
|
||||
case 1:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
if (mainmenu[i].property == -2)
|
||||
continue;
|
||||
case 1:
|
||||
case 10:
|
||||
if (return_sd_mounted(i + 1))
|
||||
mainmenu[i].property = 1;
|
||||
else
|
||||
mainmenu[i].property = -1;
|
||||
break;
|
||||
case 5:
|
||||
case 8:
|
||||
if (return_sd_mounted(1)){
|
||||
mainmenu[i].property = 2;
|
||||
strcpy(mainmenu[i].name, "\nUnmount SD");
|
||||
|
@ -94,6 +103,12 @@ void te_main(){
|
|||
mainmenu[3].property = -1;
|
||||
}
|
||||
|
||||
if (emummc_load_cfg()){
|
||||
mainmenu[4].property = -2;
|
||||
mainmenu[5].property = -2;
|
||||
mainmenu[6].property = -2;
|
||||
}
|
||||
|
||||
while (1){
|
||||
fillmainmenu();
|
||||
res = makemenu(mainmenu, MAINMENU_AMOUNT);
|
||||
|
@ -107,15 +122,29 @@ void te_main(){
|
|||
case EMMC_SYS:
|
||||
case EMMC_USR:
|
||||
|
||||
if (makewaitmenu("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress Vol+/- to return\n", "Press Power to enter", 4)){
|
||||
if (!mount_emmc(emmc_entries[res - 2], res - 1)){
|
||||
if (makewaitmenu("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress Vol+/- to return\n", "Press Power to enter", 4)){
|
||||
connect_mmc(SYSMMC);
|
||||
if (!mount_mmc(emmc_entries[res - 2], res - 1)){
|
||||
fileexplorer("emmc:/");
|
||||
}
|
||||
else
|
||||
message(COLOR_RED, "EMMC failed to mount!");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EMUMMC_SAF:
|
||||
case EMUMMC_SYS:
|
||||
case EMUMMC_USR:
|
||||
|
||||
connect_mmc(EMUMMC);
|
||||
if (!mount_mmc(emmc_entries[res - 5], res - 4)){
|
||||
fileexplorer("emmc:/");
|
||||
}
|
||||
else
|
||||
message(COLOR_RED, "EMMC failed to mount!");
|
||||
}
|
||||
|
||||
break;
|
||||
message(COLOR_RED, "EMUMMC failed to mount!");
|
||||
|
||||
break;
|
||||
|
||||
case MOUNT_SD:
|
||||
if (return_sd_mounted(1))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "../utils/types.h"
|
||||
|
||||
#define MAINMENU_AMOUNT 9
|
||||
#define MAINMENU_AMOUNT 12
|
||||
#define CREDITS_MESSAGE "\nTegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax"
|
||||
|
||||
typedef struct _menu_item {
|
||||
|
@ -16,6 +16,9 @@ enum mainmenu_return {
|
|||
EMMC_SAF,
|
||||
EMMC_SYS,
|
||||
EMMC_USR,
|
||||
EMUMMC_SAF,
|
||||
EMUMMC_SYS,
|
||||
EMUMMC_USR,
|
||||
MOUNT_SD,
|
||||
TOOLS,
|
||||
SD_FORMAT,
|
||||
|
|
|
@ -98,7 +98,8 @@ int dumpfirmware(){
|
|||
u32 timer = get_tmr_s();
|
||||
|
||||
clearscreen();
|
||||
mount_emmc("SYSTEM", 2);
|
||||
connect_mmc(SYSMMC);
|
||||
mount_mmc("SYSTEM", 2);
|
||||
|
||||
gfx_printf("PKG1 version: %d\n", pkg1ver);
|
||||
|
||||
|
@ -144,7 +145,8 @@ int dumpfirmware(){
|
|||
void dumpusersaves(){
|
||||
int res;
|
||||
|
||||
mount_emmc("USER", 2);
|
||||
connect_mmc(SYSMMC);
|
||||
mount_mmc("USER", 2);
|
||||
clearscreen();
|
||||
|
||||
res = f_mkdir("sd:/tegraexplorer");
|
||||
|
@ -180,7 +182,7 @@ int format(int mode){
|
|||
formatoptions |= (FM_FAT32);
|
||||
//formatoptions |= (FM_SFD);
|
||||
|
||||
disconnect_emmc();
|
||||
disconnect_mmc();
|
||||
|
||||
timer = get_tmr_s();
|
||||
totalsectors = sd_storage.csd.capacity;
|
||||
|
@ -238,8 +240,7 @@ int format(int mode){
|
|||
}
|
||||
}
|
||||
|
||||
dump_biskeys();
|
||||
mount_emmc("SYSTEM", 2);
|
||||
connect_mmc(SYSMMC);
|
||||
|
||||
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
||||
btn_wait();
|
||||
|
|
Loading…
Reference in a new issue