cleanup of mmc restores/dumps

This commit is contained in:
Such Meme, Many Skill
2020-04-05 16:07:25 +02:00
parent c2a2694baf
commit 6551930233
11 changed files with 110 additions and 100 deletions

View File

@@ -240,4 +240,12 @@ link_t *selectGpt(short mmcType){
return &emu_gpt;
}
return NULL;
}
int checkGptRules(char *in){
for (int i = 0; gpt_fs_rules[i].name != NULL; i++){
if (!strcmp(in, gpt_fs_rules[i].name))
return gpt_fs_rules[i].property;
}
return 0;
}

View File

@@ -18,6 +18,7 @@ void disconnect_mmc();
int connect_part(const char *partition);
void dumpEmuGpt();
link_t *selectGpt(short mmcType);
int checkGptRules(char *in);
static const u8 zeros[0x10] = {0};

View File

@@ -18,7 +18,7 @@
extern sdmmc_storage_t storage;
extern emmc_part_t *system_part;
int dump_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
FIL fp;
u8 *buf;
u32 lba_curr = part->lba_start;
@@ -158,7 +158,7 @@ int emmcDumpBoot(char *basePath){
gfx_printf("Dumping %s\n", bootPart.name);
RESETCOLOR;
dump_emmc_part(path, &storage, &bootPart);
emmcDumpPart(path, &storage, &bootPart);
free(path);
}
emummc_storage_set_mmc_partition(&storage, 0);
@@ -178,7 +178,7 @@ int emmcDumpSpecific(char *part, char *path){
SWAPCOLOR(COLOR_VIOLET);
gfx_printf("Dumping %s\n", part);
RESETCOLOR;
dump_emmc_part(path, &storage, system_part);
emmcDumpPart(path, &storage, system_part);
return 0;
}

View File

@@ -3,21 +3,12 @@
#include "../../mem/heap.h"
#include "../../utils/types.h"
#include "../../libs/fatfs/ff.h"
#include "../../utils/sprintf.h"
#include "../../utils/btn.h"
#include "../../gfx/gfx.h"
#include "../../utils/util.h"
#include "../../hos/pkg1.h"
#include "../../storage/sdmmc.h"
#include "../../storage/nx_emmc.h"
#include "../../sec/tsec.h"
#include "../../soc/t210.h"
#include "../../soc/fuse.h"
#include "../../mem/mc.h"
#include "../../sec/se.h"
#include "../../soc/hw_init.h"
#include "../../mem/emc.h"
#include "../../mem/sdram.h"
#include "../../storage/emummc.h"
#include "../../config/config.h"
#include "../common/common.h"
@@ -38,13 +29,6 @@ extern emmc_part_t *system_part;
extern char *clipboard;
extern u8 clipboardhelper;
int checkGptRules(char *in){
for (int i = 0; gpt_fs_rules[i].name != NULL; i++){
if (!strcmp(in, gpt_fs_rules[i].name))
return gpt_fs_rules[i].property;
}
return 0;
}
void addEntry(emmc_part_t *part, u8 property, int spot){
if (mmcMenuEntries[spot].name != NULL){
@@ -140,61 +124,6 @@ int handleEntries(short mmcType, menu_entry part){
return 0;
}
emmc_part_t *mmcFindPart(char *path, short mmcType){
char *filename, *extention, *path_local;
emmc_part_t *part;
utils_copystring(path, &path_local);
filename = strrchr(path_local, '/') + 1;
extention = strrchr(path_local, '.');
if (extention != NULL)
*extention = '\0';
if (checkGptRules(filename)){
gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1);
free(path_local);
return NULL;
}
part = nx_emmc_part_find(selectGpt(mmcType), filename);
if (part != NULL){
emummc_storage_set_mmc_partition(&storage, 0);
free(path_local);
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);
free(path_local);
return part;
}
//gfx_printf("Path: %s\nFilename: %s", path, filename);
//btn_wait();
gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2);
free(path_local);
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);
}
return 1;
}
int makeMmcMenu(short mmcType){
int count, selection;
count = fillMmcMenu(mmcType);

View File

@@ -1,4 +1,3 @@
#pragma once
int makeMmcMenu(short mmcType);
int mmcFlashFile(char *path, short mmcType);
int makeMmcMenu(short mmcType);

View File

@@ -2,7 +2,9 @@
#include "../../utils/types.h"
#include "../../storage/nx_emmc.h"
int restore_bis_using_file(char *path, u8 mmctype);
int emmcDumpSpecific(char *part, char *path);
int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
int emmcDumpBoot(char *basePath);
int emmcDumpBoot(char *basePath);
int mmcFlashFile(char *path, short mmcType);
int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);

View File

@@ -18,7 +18,7 @@
extern sdmmc_storage_t storage;
extern emmc_part_t *system_part;
int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
FIL fp;
FILINFO fno;
u8 *buf;
@@ -106,6 +106,7 @@ int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part
}
// 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){
connect_mmc(mmctype);
@@ -165,4 +166,64 @@ int restore_bis_using_file(char *path, u8 mmctype){
btn_wait();
return 0;
}
*/
emmc_part_t *mmcFindPart(char *path, short mmcType){
char *filename, *extention, *path_local;
emmc_part_t *part;
utils_copystring(path, &path_local);
filename = strrchr(path_local, '/') + 1;
extention = strrchr(path_local, '.');
if (extention != NULL)
*extention = '\0';
if (checkGptRules(filename)){
gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1);
free(path_local);
return NULL;
}
part = nx_emmc_part_find(selectGpt(mmcType), filename);
if (part != NULL){
emummc_storage_set_mmc_partition(&storage, 0);
free(path_local);
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);
free(path_local);
return part;
}
//gfx_printf("Path: %s\nFilename: %s", path, filename);
//btn_wait();
gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2);
free(path_local);
return NULL;
}
int mmcFlashFile(char *path, short mmcType){
emmc_part_t *part;
int res;
part = mmcFindPart(path, mmcType);
if (part != NULL){
res = emmcRestorePart(path, &storage, part);
emummc_storage_set_mmc_partition(&storage, 0);
return res;
}
return 1;
}