Show EMMC/EMUMMC GPT

This commit is contained in:
suchmememanyskill
2020-12-27 23:33:23 +01:00
parent 3307e975c9
commit 859ad2cc4c
7 changed files with 157 additions and 36 deletions

95
source/storage/gptmenu.c Normal file
View File

@@ -0,0 +1,95 @@
#include "gptmenu.h"
#include "../gfx/gfx.h"
#include "../gfx/menu.h"
#include "../gfx/gfxutils.h"
#include "../utils/vector.h"
#include "mountmanager.h"
#include <utils/list.h>
#include <string.h>
#include "nx_emmc.h"
#include <mem/heap.h>
#include "../fs/menus/explorer.h"
#include "../err.h"
#include "../tegraexplorer/tconf.h"
MenuEntry_t GptMenuHeader[] = {
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "<- Back"},
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Partition"},
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "\nBoot0/1"} // Should be blue when implemented
};
const char *GptFSEntries[] = {
"PRODINFOF",
"SAFE",
"SYSTEM",
"USER"
};
void GptMenu(u8 MMCType){
if (connectMMC(MMCType))
return;
Vector_t GptMenu = newVec(sizeof(MenuEntry_t), 15);
GptMenu.count = 3;
memcpy(GptMenu.data, GptMenuHeader, sizeof(MenuEntry_t) * ARR_LEN(GptMenuHeader));
link_t *gpt = GetCurGPT();
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) {
MenuEntry_t entry = {.optionUnion = COLORTORGB(COLOR_VIOLET), .icon = 128, .name = part->name};
u64 total = (part->lba_end - part->lba_start) / 2 + 1;
u8 type = 1;
while (total > 1024){
total /= 1024;
type++;
}
if (type > 3)
type = 3;
entry.showSize = 1;
entry.size = total;
entry.sizeDef = type;
for (int i = 0; i < ARR_LEN(GptFSEntries); i++){
if (!strcmp(part->name, GptFSEntries[i])){
entry.optionUnion = COLORTORGB(COLOR_WHITE);
entry.icon = 127;
break;
}
}
vecAddElem(&GptMenu, entry);
}
vecDefArray(MenuEntry_t*, entries, GptMenu);
int res = 0;
while (1){
gfx_clearscreen();
gfx_printf((MMCType == MMC_CONN_EMMC) ? "-- Emmc --\n\n" : "-- Emummc --\n\n");
res = newMenu(&GptMenu, res, 40, 20, ALWAYSREDRAW | ENABLEB, GptMenu.count);
if (res < 3){
break;
}
else if (entries[res].icon == 127){
unmountMMCPart();
ErrCode_t err = mountMMCPart(entries[res].name);
if (err.err){
DrawError(err);
}
else {
if (TConf.curExplorerLoc > LOC_SD)
ResetCopyParams();
TConf.curExplorerLoc = LOC_EMMC;
FileExplorer("bis:/");
}
}
else {
DrawError(newErrCode(TE_ERR_UNIMPLEMENTED));
}
}
free(GptMenu.data);
}

5
source/storage/gptmenu.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#include <utils/types.h>
void GptMenu(u8 MMCType);

View File

@@ -6,6 +6,9 @@
#include <sec/se.h>
#include <libs/fatfs/ff.h>
#include "nx_emmc_bis.h"
#include "../config.h"
extern hekate_config h_cfg;
void SetKeySlots(){
if (TConf.keysDumped){
@@ -39,31 +42,45 @@ int connectMMC(u8 mmcType){
return 0;
disconnectMMC();
emu_cfg.enabled = (mmcType == MMC_CONN_EMMC) ? 0 : 1;
h_cfg.emummc_force_disable = (mmcType == MMC_CONN_EMMC) ? 1 : 0;
int res = emummc_storage_init_mmc(&emmc_storage, &emmc_sdmmc);
if (!res)
if (!res){
TConf.currentMMCConnected = mmcType;
emummc_storage_set_mmc_partition(&emmc_storage, 0);
nx_emmc_gpt_parse(&curGpt, &emmc_storage);
}
return res; // deal with the errors later lol
}
ErrCode_t mountMMCPart(const char *partition){
if (TConf.connectedMMCMounted)
return newErrCode(0);
if (!TConf.connectedMMCMounted){
emummc_storage_set_mmc_partition(&emmc_storage, 0); // why i have to do this twice beats me
emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition);
if (!system_part)
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
nx_emmc_bis_init(system_part);
emummc_storage_set_mmc_partition(&emmc_storage, 0);
nx_emmc_gpt_parse(&curGpt, &emmc_storage);
emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition);
if (!system_part)
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
nx_emmc_bis_init(system_part);
int res = 0;
if ((res = f_mount(&emmc_fs, "bis:", 1)))
return newErrCode(res);
int res = 0;
if ((res = f_mount(&emmc_fs, "bis:", 1)))
return newErrCode(res);
TConf.connectedMMCMounted = 1;
}
TConf.connectedMMCMounted = 1;
return newErrCode(0);
}
link_t *GetCurGPT(){
if (TConf.currentMMCConnected != MMC_CONN_None)
return &curGpt;
return NULL;
}
void unmountMMCPart(){
if (TConf.connectedMMCMounted)
f_unmount("bis:");
TConf.connectedMMCMounted = 0;
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <utils/types.h>
#include <utils/list.h>
#include "../err.h"
enum {
@@ -10,4 +11,6 @@ enum {
int connectMMC(u8 mmcType);
ErrCode_t mountMMCPart(const char *partition);
void SetKeySlots();
void SetKeySlots();
void unmountMMCPart();
link_t *GetCurGPT();