2020-04-04 15:49:47 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include "emmc.h"
|
|
|
|
#include "../../mem/heap.h"
|
|
|
|
#include "../../utils/types.h"
|
|
|
|
#include "../../libs/fatfs/ff.h"
|
2020-05-02 01:05:37 +01:00
|
|
|
#include "../../hid/hid.h"
|
2020-04-04 15:49:47 +01:00
|
|
|
#include "../../gfx/gfx.h"
|
|
|
|
#include "../../utils/util.h"
|
|
|
|
#include "../../storage/nx_emmc.h"
|
|
|
|
#include "../../mem/mc.h"
|
|
|
|
#include "../../mem/emc.h"
|
|
|
|
#include "../../storage/emummc.h"
|
|
|
|
#include "../../config/config.h"
|
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../gfx/gfxutils.h"
|
|
|
|
#include "../../utils/list.h"
|
|
|
|
#include "../../mem/heap.h"
|
|
|
|
#include "emmcmenu.h"
|
|
|
|
#include "../utils/utils.h"
|
|
|
|
#include "../gfx/menu.h"
|
|
|
|
#include "../fs/fsmenu.h"
|
2020-04-04 17:40:27 +01:00
|
|
|
#include "emmcoperations.h"
|
|
|
|
#include "../fs/fsutils.h"
|
2020-05-04 12:55:26 +01:00
|
|
|
#include "../utils/menuUtils.h"
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
menu_entry *mmcMenuEntries = NULL;
|
2020-04-04 21:15:13 +01:00
|
|
|
extern sdmmc_storage_t storage;
|
|
|
|
extern emmc_part_t *system_part;
|
|
|
|
extern char *clipboard;
|
|
|
|
extern u8 clipboardhelper;
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
void addEntry(emmc_part_t *part, u8 property_GPT, int spot){
|
|
|
|
u32 storage = 0;
|
|
|
|
u8 property = 0;
|
2020-04-04 15:49:47 +01:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
if (property_GPT & isFS){
|
|
|
|
storage = (u32)(property_GPT & 0x7F);
|
|
|
|
property = ISDIR;
|
2020-04-04 15:49:47 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
u64 size = 0;
|
2020-05-04 12:55:26 +01:00
|
|
|
u32 sizes = 0;
|
|
|
|
|
2020-04-22 11:23:18 +01:00
|
|
|
size = (u64)(part->lba_end + 1 - part->lba_start);
|
|
|
|
size *= (u64)NX_EMMC_BLOCKSIZE;
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
while (size > 1024){
|
|
|
|
size /= 1024;
|
|
|
|
sizes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizes > 3)
|
2020-05-04 12:55:26 +01:00
|
|
|
sizes = 3;
|
2020-04-04 15:49:47 +01:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
property |= SETSIZE(sizes);
|
|
|
|
storage = (u32)size;
|
2020-04-04 15:49:47 +01:00
|
|
|
}
|
2020-05-04 12:55:26 +01:00
|
|
|
|
|
|
|
mu_copySingle(part->name, storage, property, &mmcMenuEntries[spot]);
|
2020-04-04 15:49:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int fillMmcMenu(short mmcType){
|
2020-04-04 23:22:23 +01:00
|
|
|
int count = 4, i;
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
if (mmcMenuEntries != NULL)
|
2020-05-04 12:55:26 +01:00
|
|
|
mu_clearObjects(&mmcMenuEntries);
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
link_t *gpt = selectGpt(mmcType);
|
|
|
|
|
|
|
|
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link)
|
|
|
|
count++;
|
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
mu_createObjects(count, &mmcMenuEntries);
|
2020-04-04 15:49:47 +01:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
mu_copySingle(mmcmenu_start[i].name, mmcmenu_start[i].storage, mmcmenu_start[i].property, &mmcMenuEntries[i]);
|
2020-04-04 15:49:47 +01:00
|
|
|
|
|
|
|
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link){
|
|
|
|
addEntry(part, checkGptRules(part->name), i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-04-04 21:15:13 +01:00
|
|
|
int handleEntries(short mmcType, menu_entry part){
|
2020-04-04 22:41:09 +01:00
|
|
|
int res = 0;
|
|
|
|
|
2020-04-04 21:15:13 +01:00
|
|
|
if (part.property & ISDIR){
|
2020-04-14 08:40:37 +01:00
|
|
|
if (returnpkg1info().ver < 0){
|
|
|
|
gfx_errDisplay("emmcMakeMenu", ERR_BISKEY_DUMP_FAILED, 0);
|
|
|
|
return -1;
|
|
|
|
}
|
2020-04-04 21:15:13 +01:00
|
|
|
if (!mount_mmc(part.name, part.storage))
|
|
|
|
fileexplorer("emmc:/", 1);
|
|
|
|
}
|
|
|
|
else {
|
2020-05-04 12:55:26 +01:00
|
|
|
/*
|
2020-04-04 21:15:13 +01:00
|
|
|
if (mmcmenu_filemenu[1].name != NULL)
|
|
|
|
free(mmcmenu_filemenu[1].name);
|
|
|
|
|
|
|
|
utils_copystring(part.name, &mmcmenu_filemenu[1].name);
|
2020-05-04 12:55:26 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
mu_copySingle(part.name, mmcmenu_filemenu[1].storage, mmcmenu_filemenu[1].property, &mmcmenu_filemenu[1]);
|
2020-04-04 21:15:13 +01:00
|
|
|
|
|
|
|
if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3)
|
|
|
|
return 0;
|
|
|
|
|
2020-04-04 22:41:09 +01:00
|
|
|
f_mkdir("sd:/tegraexplorer");
|
|
|
|
f_mkdir("sd:/tegraexplorer/partition_dumps");
|
|
|
|
|
|
|
|
gfx_clearscreen();
|
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
if (part.isNull){
|
2020-04-04 22:41:09 +01:00
|
|
|
res = emmcDumpBoot("sd:/tegraexplorer/partition_dumps");
|
2020-04-04 21:15:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-04-04 23:22:23 +01:00
|
|
|
//gfx_printf("Dumping %s...\n", part.name);
|
2020-04-04 22:41:09 +01:00
|
|
|
res = emmcDumpSpecific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name));
|
|
|
|
}
|
2020-04-04 21:15:13 +01:00
|
|
|
|
2020-04-04 22:41:09 +01:00
|
|
|
if (!res){
|
|
|
|
gfx_printf("\nDone!");
|
2020-05-02 01:05:37 +01:00
|
|
|
hidWait();
|
2020-04-04 21:15:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-04 15:49:47 +01:00
|
|
|
int makeMmcMenu(short mmcType){
|
|
|
|
int count, selection;
|
|
|
|
count = fillMmcMenu(mmcType);
|
|
|
|
connect_mmc(mmcType);
|
|
|
|
while (1){
|
|
|
|
selection = menu_make(mmcMenuEntries, count, (mmcType == SYSMMC) ? "-- SYSMMC --" : "-- EMUMMC --");
|
|
|
|
|
|
|
|
switch(selection){
|
2020-04-04 22:41:09 +01:00
|
|
|
case -1:
|
2020-04-04 15:49:47 +01:00
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
2020-04-04 23:22:23 +01:00
|
|
|
gfx_clearscreen();
|
|
|
|
f_mkdir("sd:/tegraexplorer");
|
|
|
|
f_mkdir("sd:/tegraexplorer/partition_dumps");
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++){
|
2020-05-04 12:55:26 +01:00
|
|
|
if (mmcMenuEntries[i].property & (ISMENU | ISDIR))
|
2020-04-04 23:22:23 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
//gfx_printf("Dumping %s...\n", mmcMenuEntries[i].name);
|
|
|
|
emmcDumpSpecific(mmcMenuEntries[i].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[i].name));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_printf("\nDone!");
|
2020-05-02 01:05:37 +01:00
|
|
|
hidWait();
|
2020-04-04 23:22:23 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-04-04 21:15:13 +01:00
|
|
|
if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){
|
|
|
|
gfx_clearscreen();
|
2020-05-08 19:57:26 +01:00
|
|
|
if (!mmcFlashFile(clipboard, mmcType, true)){
|
2020-04-04 21:15:13 +01:00
|
|
|
gfx_printf("\nDone!");
|
2020-05-02 01:05:37 +01:00
|
|
|
hidWait();
|
2020-04-04 21:15:13 +01:00
|
|
|
}
|
2020-04-04 22:41:09 +01:00
|
|
|
clipboardhelper = 0;
|
2020-04-04 21:15:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0);
|
2020-04-04 23:22:23 +01:00
|
|
|
break;
|
2020-04-04 15:49:47 +01:00
|
|
|
default:
|
2020-04-04 21:15:13 +01:00
|
|
|
handleEntries(mmcType, mmcMenuEntries[selection]);
|
|
|
|
break;
|
2020-04-04 15:49:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|