Add partition restoring via clipboard

This commit is contained in:
Such Meme, Many Skill 2020-04-04 22:15:13 +02:00
parent a6eaa1ec51
commit 97bbe2a333
7 changed files with 111 additions and 35 deletions

View file

@ -21,7 +21,9 @@ enum utils_err_codes_te_call {
ERR_EMMC_WRITE_FAILED, ERR_EMMC_WRITE_FAILED,
ERR_FILE_TOO_BIG_FOR_DEST, ERR_FILE_TOO_BIG_FOR_DEST,
ERR_SD_EJECTED, ERR_SD_EJECTED,
ERR_PARSE_FAIL ERR_PARSE_FAIL,
ERR_CANNOT_COPY_FILE_TO_FS_PART,
ERR_NO_DESTENATION
}; };
extern const char *utils_err_codes_te[]; extern const char *utils_err_codes_te[];

View file

@ -50,7 +50,9 @@ const char *utils_err_codes_te[] = { // these start at 50
"EMMC WRITE FAILED", "EMMC WRITE FAILED",
"FILE TOO BIG FOR DEST", "FILE TOO BIG FOR DEST",
"SD EJECTED", "SD EJECTED",
"PARSING FAILED" "PARSING FAILED",
"CANNOT COPY FILE TO FS PART",
"NO DESTENATION"
}; };
const char *pkg2names[] = { const char *pkg2names[] = {

View file

@ -81,7 +81,7 @@ gpt_entry_rule gpt_fs_rules[] = {
menu_entry mmcmenu_start[] = { menu_entry mmcmenu_start[] = {
{"Back", COLOR_ORANGE, ISMENU}, {"Back", COLOR_ORANGE, ISMENU},
{"RESERVED\n", COLOR_ORANGE, ISMENU}, {"Clipboard -> Partition\n", COLOR_ORANGE, ISMENU},
{"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU} {"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU}
}; };

View file

@ -33,6 +33,10 @@
#include "../fs/fsutils.h" #include "../fs/fsutils.h"
menu_entry *mmcMenuEntries = NULL; menu_entry *mmcMenuEntries = NULL;
extern sdmmc_storage_t storage;
extern emmc_part_t *system_part;
extern char *clipboard;
extern u8 clipboardhelper;
int checkGptRules(char *in){ int checkGptRules(char *in){
for (int i = 0; gpt_fs_rules[i].name != NULL; i++){ for (int i = 0; gpt_fs_rules[i].name != NULL; i++){
@ -98,6 +102,90 @@ int fillMmcMenu(short mmcType){
return count; return count;
} }
int handleEntries(short mmcType, menu_entry part){
if (part.property & ISDIR){
if (!mount_mmc(part.name, part.storage))
fileexplorer("emmc:/", 1);
}
else {
if (mmcmenu_filemenu[1].name != NULL)
free(mmcmenu_filemenu[1].name);
utils_copystring(part.name, &mmcmenu_filemenu[1].name);
if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3)
return 0;
if (part.property & isBOOT){
dump_emmc_parts(PART_BOOT, (u8)mmcType);
}
else {
f_mkdir("sd:/tegraexplorer");
f_mkdir("sd:/tegraexplorer/partition_dumps");
gfx_clearscreen();
gfx_printf("Dumping %s...\n", part.name);
if (!dump_emmc_specific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name))){
gfx_printf("\nDone!");
btn_wait();
}
}
}
return 0;
}
emmc_part_t *mmcFindPart(char *path, short mmcType){
char *filename, *extention;
emmc_part_t *part;
filename = strrchr(path, '/') + 1;
extention = strrchr(path, '.');
if (extention != NULL)
*extention = '\0';
if (checkGptRules(filename)){
gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1);
return NULL;
}
part = nx_emmc_part_find(selectGpt(mmcType), filename);
if (part != NULL){
emummc_storage_set_mmc_partition(&storage, 0);
return part;
}
if (!strcmp(filename, "BOOT0") || !strcmp(filename, "BOOT1")){
const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17;
part = calloc(1, sizeof(emmc_part_t));
part->lba_start = 0;
part->lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
strcpy(part->name, filename);
emummc_storage_set_mmc_partition(&storage, (!strcmp(filename, "BOOT0")) ? 1 : 2);
return part;
}
//gfx_printf("Path: %s\nFilename: %s", path, filename);
//btn_wait();
gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2);
return NULL;
}
int mmcFlashFile(char *path, short mmcType){
emmc_part_t *part;
part = mmcFindPart(path, mmcType);
if (part != NULL){
return restore_emmc_part(path, &storage, part);
}
clipboardhelper = 0;
return 1;
}
int makeMmcMenu(short mmcType){ int makeMmcMenu(short mmcType){
int count, selection; int count, selection;
count = fillMmcMenu(mmcType); count = fillMmcMenu(mmcType);
@ -109,38 +197,19 @@ int makeMmcMenu(short mmcType){
case 0: case 0:
return 0; return 0;
case 1: case 1:
if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){
gfx_clearscreen();
if (!mmcFlashFile(clipboard, mmcType)){
gfx_printf("\nDone!");
btn_wait();
}
}
else
gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0);
break; //stubbed break; //stubbed
default: default:
if (mmcMenuEntries[selection].property & ISDIR){ handleEntries(mmcType, mmcMenuEntries[selection]);
if (!mount_mmc(mmcMenuEntries[selection].name, mmcMenuEntries[selection].storage)) break;
fileexplorer("emmc:/", 1);
}
else {
if (mmcmenu_filemenu[1].name != NULL)
free(mmcmenu_filemenu[1].name);
utils_copystring(mmcMenuEntries[selection].name, &mmcmenu_filemenu[1].name);
if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3){
break;
}
if (mmcMenuEntries[selection].property & isBOOT){
dump_emmc_parts(PART_BOOT, (u8)mmcType);
}
else {
f_mkdir("sd:/tegraexplorer");
f_mkdir("sd:/tegraexplorer/partition_dumps");
gfx_clearscreen();
gfx_printf("Dumping %s...\n", mmcMenuEntries[selection].name);
if (!dump_emmc_specific(mmcMenuEntries[selection].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[selection].name))){
gfx_printf("\nDone!");
btn_wait();
}
}
}
} }
} }
} }

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
#include "../../utils/types.h" #include "../../utils/types.h"
#include "../../storage/nx_emmc.h"
int dump_emmc_parts(u16 parts, u8 mmctype); int dump_emmc_parts(u16 parts, u8 mmctype);
int restore_bis_using_file(char *path, u8 mmctype); int restore_bis_using_file(char *path, u8 mmctype);
int dump_emmc_specific(char *part, char *path); int dump_emmc_specific(char *part, char *path);
int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);

View file

@ -105,6 +105,7 @@ int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part
return 0; return 0;
} }
// function replaced by new mmc implementation. Will be removed at some point
int restore_emmc_file(char *path, const char *target, u8 partition, u8 mmctype){ int restore_emmc_file(char *path, const char *target, u8 partition, u8 mmctype){
connect_mmc(mmctype); connect_mmc(mmctype);

View file

@ -54,7 +54,7 @@ int gfx_errDisplay(char *src_func, int err, int loc){
if (err < 15) if (err < 15)
gfx_printf("Desc: %s\n", utils_err_codes[err]); gfx_printf("Desc: %s\n", utils_err_codes[err]);
else if (err >= ERR_SAME_LOC && err <= ERR_PARSE_FAIL) else if (err >= ERR_SAME_LOC && err <= ERR_NO_DESTENATION)
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]); gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
if (loc) if (loc)