Step 1: Compile
This commit is contained in:
@@ -18,17 +18,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include <utils/ini.h>
|
||||
#include <gfx_utils.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <soc/fuse.h>
|
||||
#include <soc/hw_init.h>
|
||||
#include <soc/t210.h>
|
||||
#include <storage/nx_sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/btn.h>
|
||||
#include <utils/list.h>
|
||||
#include <utils/util.h>
|
||||
#include <bdk.h>
|
||||
|
||||
extern hekate_config h_cfg;
|
||||
|
||||
@@ -37,19 +27,13 @@ void set_default_configuration()
|
||||
h_cfg.autoboot = 0;
|
||||
h_cfg.autoboot_list = 0;
|
||||
h_cfg.bootwait = 3;
|
||||
h_cfg.se_keygen_done = 0;
|
||||
h_cfg.backlight = 100;
|
||||
h_cfg.autohosoff = 0;
|
||||
h_cfg.autonogc = 1;
|
||||
h_cfg.updater2p = 0;
|
||||
h_cfg.bootprotect = 0;
|
||||
h_cfg.errors = 0;
|
||||
h_cfg.eks = NULL;
|
||||
h_cfg.sept_run = EMC(EMC_SCRATCH0) & EMC_SEPT_RUN;
|
||||
h_cfg.aes_slots_new = false;
|
||||
h_cfg.rcm_patched = fuse_check_patched_rcm();
|
||||
h_cfg.emummc_force_disable = false;
|
||||
h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01;
|
||||
|
||||
sd_power_cycle_time_start = 0;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include "hos/hos.h"
|
||||
#include <utils/types.h>
|
||||
|
||||
typedef struct _hekate_config
|
||||
@@ -39,7 +38,6 @@ typedef struct _hekate_config
|
||||
bool emummc_force_disable;
|
||||
bool rcm_patched;
|
||||
u32 errors;
|
||||
hos_eks_mbr_t *eks;
|
||||
} hekate_config;
|
||||
|
||||
void set_default_configuration();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "fscopy.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <utils/btn.h>
|
||||
#include <bdk.h>
|
||||
#include <string.h>
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "../gfx/gfx.h"
|
||||
#include <mem/heap.h>
|
||||
#include <string.h>
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "fsutils.h"
|
||||
#include "readers/folderReader.h"
|
||||
|
||||
|
||||
ErrCode_t FileCopy(const char *locin, const char *locout, u8 options){
|
||||
FIL in, out;
|
||||
FILINFO in_info;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include <mem/heap.h>
|
||||
#include <string.h>
|
||||
#include "fsutils.h"
|
||||
#include "../utils/utils.h"
|
||||
#include <utils/sprintf.h>
|
||||
#include <bdk.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "readers/folderReader.h"
|
||||
|
||||
|
||||
@@ -3,19 +3,17 @@
|
||||
#include "../../gfx/menu.h"
|
||||
#include "../../gfx/gfxutils.h"
|
||||
#include "../fsutils.h"
|
||||
#include <mem/heap.h>
|
||||
#include <string.h>
|
||||
#include <utils/sprintf.h>
|
||||
#include "../../tegraexplorer/tconf.h"
|
||||
#include "../../hid/hid.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../utils/utils.h"
|
||||
#include "../../keys/nca.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../../storage/emummc.h"
|
||||
#include "../../script/eval.h"
|
||||
#include "../../script/parser.h"
|
||||
#include "../../script/garbageCollector.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <string.h>
|
||||
#include <bdk.h>
|
||||
|
||||
|
||||
MenuEntry_t FileMenuEntries[] = {
|
||||
@@ -73,6 +71,7 @@ void DeleteFile(char *path, FSEntry_t entry){
|
||||
}
|
||||
|
||||
void RunScriptString(char *str, u32 size){
|
||||
return;
|
||||
TConf.scriptCWD = "sd:/";
|
||||
gfx_clearscreen();
|
||||
ParserRet_t ret = parseScript(str, size);
|
||||
@@ -87,6 +86,7 @@ void RunScriptString(char *str, u32 size){
|
||||
}
|
||||
|
||||
void RunScript(char *path, FSEntry_t entry){
|
||||
return;
|
||||
char *thing = CombinePaths(path, entry.name);
|
||||
u32 size;
|
||||
char *script = sd_file_read(thing, &size);
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
#include "../../gfx/menu.h"
|
||||
#include "../../gfx/gfxutils.h"
|
||||
#include "../fsutils.h"
|
||||
#include <mem/heap.h>
|
||||
#include <string.h>
|
||||
#include <utils/sprintf.h>
|
||||
#include "../../tegraexplorer/tconf.h"
|
||||
#include "../../hid/hid.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../utils/utils.h"
|
||||
#include "../../keys/nca.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <bdk.h>
|
||||
#include "../fscopy.h"
|
||||
|
||||
MenuEntry_t FolderMenuEntries[] = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "folderReader.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../utils/utils.h"
|
||||
#include <mem/heap.h>
|
||||
#include <bdk.h>
|
||||
|
||||
void clearFileVector(Vector_t *v){
|
||||
vecPDefArray(FSEntry_t*, entries, v);
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
#include "fss.h"
|
||||
#include "hos.h"
|
||||
#include "../config.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../storage/emummc.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <bdk.h>
|
||||
|
||||
#include <gfx_utils.h>
|
||||
#define DPRINTF(...)
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "hos.h"
|
||||
#include "fss.h"
|
||||
#include "sept.h"
|
||||
#include "../config.h"
|
||||
#include <utils/ini.h>
|
||||
#include <display/di.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include <soc/hw_init.h>
|
||||
#include <soc/pmc.h>
|
||||
#include <soc/t210.h>
|
||||
#include "../storage/nx_emmc.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/btn.h>
|
||||
#include <utils/list.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
#include <gfx_utils.h>
|
||||
|
||||
#define PATCHED_RELOC_SZ 0x94
|
||||
|
||||
#define WB_RST_ADDR 0x40010ED0
|
||||
#define WB_RST_SIZE 0x30
|
||||
|
||||
u8 warmboot_reboot[] = {
|
||||
0x14, 0x00, 0x9F, 0xE5, // LDR R0, =0x7000E450
|
||||
0x01, 0x10, 0xB0, 0xE3, // MOVS R1, #1
|
||||
0x00, 0x10, 0x80, 0xE5, // STR R1, [R0]
|
||||
0x0C, 0x00, 0x9F, 0xE5, // LDR R0, =0x7000E400
|
||||
0x10, 0x10, 0xB0, 0xE3, // MOVS R1, #0x10
|
||||
0x00, 0x10, 0x80, 0xE5, // STR R1, [R0]
|
||||
0xFE, 0xFF, 0xFF, 0xEA, // LOOP
|
||||
0x50, 0xE4, 0x00, 0x70, // #0x7000E450
|
||||
0x00, 0xE4, 0x00, 0x70 // #0x7000E400
|
||||
};
|
||||
|
||||
#define SEPT_PRI_ADDR 0x4003F000
|
||||
|
||||
#define SEPT_PK1T_ADDR 0xC0400000
|
||||
#define SEPT_PK1T_STACK 0x40008000
|
||||
#define SEPT_TCSZ_ADDR (SEPT_PK1T_ADDR - 0x4)
|
||||
#define SEPT_STG1_ADDR (SEPT_PK1T_ADDR + 0x2E100)
|
||||
#define SEPT_STG2_ADDR (SEPT_PK1T_ADDR + 0x60E0)
|
||||
#define SEPT_PKG_SZ (0x2F100 + WB_RST_SIZE)
|
||||
|
||||
extern u32 color_idx;
|
||||
extern boot_cfg_t b_cfg;
|
||||
extern void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size);
|
||||
|
||||
int reboot_to_sept(const u8 *tsec_fw, const u32 tsec_size, const u32 kb)
|
||||
{
|
||||
FIL fp;
|
||||
bool fss0_sept_used = false;
|
||||
|
||||
// Copy warmboot reboot code and TSEC fw.
|
||||
memcpy((u8 *)(SEPT_PK1T_ADDR - WB_RST_SIZE), (u8 *)warmboot_reboot, sizeof(warmboot_reboot));
|
||||
memcpy((void *)SEPT_PK1T_ADDR, tsec_fw, tsec_size);
|
||||
*(vu32 *)SEPT_TCSZ_ADDR = tsec_size;
|
||||
|
||||
LIST_INIT(ini_sections);
|
||||
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
||||
{
|
||||
bool found = false;
|
||||
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
||||
{
|
||||
// Only parse non config sections.
|
||||
if (ini_sec->type == INI_CHOICE && strcmp(ini_sec->name, "config"))
|
||||
{
|
||||
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
||||
{
|
||||
if (!strcmp("fss0", kv->key))
|
||||
{
|
||||
fss0_sept_t sept_ctxt;
|
||||
sept_ctxt.kb = kb;
|
||||
sept_ctxt.sept_primary = (void *)SEPT_STG1_ADDR;
|
||||
sept_ctxt.sept_secondary = (void *)SEPT_STG2_ADDR;
|
||||
fss0_sept_used = parse_fss(NULL, kv->val, &sept_ctxt);
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fss0_sept_used)
|
||||
{
|
||||
// Copy sept-primary.
|
||||
if (f_open(&fp, "sd:/sept/sept-primary.bin", FA_READ))
|
||||
goto error;
|
||||
|
||||
if (f_read(&fp, (u8 *)SEPT_STG1_ADDR, f_size(&fp), NULL))
|
||||
{
|
||||
f_close(&fp);
|
||||
goto error;
|
||||
}
|
||||
f_close(&fp);
|
||||
|
||||
// Copy sept-secondary.
|
||||
if (kb < KB_FIRMWARE_VERSION_810)
|
||||
{
|
||||
if (f_open(&fp, "sd:/sept/sept-secondary_00.enc", FA_READ))
|
||||
if (f_open(&fp, "sd:/sept/sept-secondary.enc", FA_READ)) // Try the deprecated version.
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f_open(&fp, "sd:/sept/sept-secondary_01.enc", FA_READ))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (f_read(&fp, (u8 *)SEPT_STG2_ADDR, f_size(&fp), NULL))
|
||||
{
|
||||
f_close(&fp);
|
||||
goto error;
|
||||
}
|
||||
f_close(&fp);
|
||||
}
|
||||
|
||||
// Save auto boot config to sept payload, if any.
|
||||
boot_cfg_t *tmp_cfg = malloc(sizeof(boot_cfg_t));
|
||||
memcpy(tmp_cfg, &b_cfg, sizeof(boot_cfg_t));
|
||||
|
||||
tmp_cfg->boot_cfg |= BOOT_CFG_SEPT_RUN;
|
||||
|
||||
if (f_open(&fp, "sd:/sept/payload.bin", FA_READ | FA_WRITE))
|
||||
{
|
||||
free(tmp_cfg);
|
||||
goto error;
|
||||
}
|
||||
|
||||
f_lseek(&fp, PATCHED_RELOC_SZ);
|
||||
f_write(&fp, tmp_cfg, sizeof(boot_cfg_t), NULL);
|
||||
|
||||
f_close(&fp);
|
||||
|
||||
sd_unmount();
|
||||
gfx_printf("\n%kPress Power or Vol +/-\n to Reboot to Sept...", colors[(color_idx++) % 6]);
|
||||
|
||||
u32 pk1t_sept = SEPT_PK1T_ADDR - (ALIGN(PATCHED_RELOC_SZ, 0x10) + WB_RST_SIZE);
|
||||
|
||||
void (*sept)() = (void *)pk1t_sept;
|
||||
|
||||
reloc_patcher(WB_RST_ADDR, pk1t_sept, SEPT_PKG_SZ);
|
||||
|
||||
// Patch SDRAM init to perform an SVC immediately after second write.
|
||||
PMC(APBDEV_PMC_SCRATCH45) = 0x2E38DFFF;
|
||||
PMC(APBDEV_PMC_SCRATCH46) = 0x6001DC28;
|
||||
// Set SVC handler to jump to sept-primary in IRAM.
|
||||
PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR;
|
||||
PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208;
|
||||
|
||||
hw_reinit_workaround(false, 0);
|
||||
|
||||
(*sept)();
|
||||
|
||||
error:
|
||||
EPRINTF("\nSept files not found in sd:/sept!\nPlace appropriate files and try again.");
|
||||
display_backlight_brightness(100, 1000);
|
||||
|
||||
btn_wait();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SEPT_H_
|
||||
#define _SEPT_H_
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
int reboot_to_sept(const u8 *tsec_fw, const u32 tsec_size, const u32 kb);
|
||||
|
||||
#endif
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
|
||||
// Sha256 hash of the null string.
|
||||
#include <bdk.h>
|
||||
#include "../hos/hos.h"
|
||||
|
||||
static const u8 null_hash[0x20] __attribute__((aligned(4))) = {
|
||||
0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
||||
0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "keys.h"
|
||||
#include "keyfile.h"
|
||||
#include <utils/types.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <string.h>
|
||||
#include <utils/ini.h>
|
||||
#include <bdk.h>
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../gfx/gfx.h"
|
||||
|
||||
#define GetHexFromChar(c) ((c & 0x0F) + (c >= 'A' ? 9 : 0))
|
||||
|
||||
@@ -1,31 +1,10 @@
|
||||
#include "keys.h"
|
||||
|
||||
#include "../config.h"
|
||||
#include <display/di.h>
|
||||
#include <gfx_utils.h>
|
||||
#include "../hos/pkg1.h"
|
||||
#include "../hos/pkg2.h"
|
||||
#include "../hos/sept.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include <mem/mc.h>
|
||||
#include <mem/minerva.h>
|
||||
#include <mem/sdram.h>
|
||||
#include <sec/se.h>
|
||||
#include <sec/se_t210.h>
|
||||
#include <sec/tsec.h>
|
||||
#include <soc/fuse.h>
|
||||
#include <mem/smmu.h>
|
||||
#include <soc/t210.h>
|
||||
#include <bdk.h>
|
||||
#include "../config.h"
|
||||
#include "../hos/pkg1.h"
|
||||
#include "../storage/emummc.h"
|
||||
#include "../storage/nx_emmc.h"
|
||||
#include "../storage/nx_emmc_bis.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/btn.h>
|
||||
#include <utils/list.h>
|
||||
#include <utils/sprintf.h>
|
||||
#include <utils/util.h>
|
||||
#include "../gfx/gfx.h"
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "../storage/mountmanager.h"
|
||||
@@ -37,6 +16,7 @@
|
||||
extern hekate_config h_cfg;
|
||||
|
||||
#define DPRINTF(x)
|
||||
#define TSEC_KEY_DATA_OFFSET 0x300
|
||||
|
||||
static int _key_exists(const void *data) { return memcmp(data, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) != 0; };
|
||||
|
||||
@@ -125,7 +105,7 @@ static void _derive_bis_keys(key_derivation_ctx_t *keys) {
|
||||
}
|
||||
|
||||
static int _derive_master_keys_from_keyblobs(key_derivation_ctx_t *keys) {
|
||||
u8 *keyblob_block = (u8 *)calloc(KB_FIRMWARE_VERSION_600 + 1, NX_EMMC_BLOCKSIZE);
|
||||
u8 *keyblob_block = (u8 *)calloc(KB_FIRMWARE_VERSION_600 + 1, EMMC_BLOCKSIZE);
|
||||
encrypted_keyblob_t *current_keyblob = (encrypted_keyblob_t *)keyblob_block;
|
||||
u32 keyblob_mac[AES_128_KEY_SIZE / 4] = {0};
|
||||
|
||||
@@ -144,7 +124,7 @@ static int _derive_master_keys_from_keyblobs(key_derivation_ctx_t *keys) {
|
||||
se_aes_key_set(8, keys->tsec_keys, sizeof(keys->tsec_keys) / 2);
|
||||
se_aes_key_set(9, keys->sbk, 0x10);
|
||||
|
||||
if (!emummc_storage_read(&emmc_storage, KEYBLOB_OFFSET / NX_EMMC_BLOCKSIZE, KB_FIRMWARE_VERSION_600 + 1, keyblob_block)) {
|
||||
if (!emummc_storage_read(KEYBLOB_OFFSET / EMMC_BLOCKSIZE, KB_FIRMWARE_VERSION_600 + 1, keyblob_block)) {
|
||||
DPRINTF("Unable to read keyblobs.");
|
||||
}
|
||||
|
||||
@@ -195,7 +175,7 @@ static bool _derive_tsec_keys(tsec_ctxt_t *tsec_ctxt, u32 kb, key_derivation_ctx
|
||||
|
||||
mc_disable_ahb_redirect();
|
||||
|
||||
while (tsec_query(keys->tsec_keys, kb, tsec_ctxt) < 0) {
|
||||
while (tsec_query(keys->tsec_keys, tsec_ctxt) < 0) {
|
||||
memset(keys->tsec_keys, 0, sizeof(keys->tsec_keys));
|
||||
retries++;
|
||||
if (retries > 15) {
|
||||
@@ -204,7 +184,7 @@ static bool _derive_tsec_keys(tsec_ctxt_t *tsec_ctxt, u32 kb, key_derivation_ctx
|
||||
}
|
||||
}
|
||||
|
||||
mc_enable_ahb_redirect();
|
||||
mc_enable_ahb_redirect(false);
|
||||
|
||||
if (res < 0) {
|
||||
//EPRINTFARGS("ERROR %x dumping TSEC.\n", res);
|
||||
@@ -227,11 +207,11 @@ static ALWAYS_INLINE u8 *_read_pkg1(const pkg1_id_t **pkg1_id) {
|
||||
|
||||
// Read package1.
|
||||
u8 *pkg1 = (u8 *)malloc(PKG1_MAX_SIZE);
|
||||
if (!emummc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0)) {
|
||||
if (!emummc_storage_set_mmc_partition(EMMC_BOOT0)) {
|
||||
DPRINTF("Unable to set partition.");
|
||||
return NULL;
|
||||
}
|
||||
if (!emummc_storage_read(&emmc_storage, PKG1_OFFSET / NX_EMMC_BLOCKSIZE, PKG1_MAX_SIZE / NX_EMMC_BLOCKSIZE, pkg1)) {
|
||||
if (!emummc_storage_read(PKG1_OFFSET / EMMC_BLOCKSIZE, PKG1_MAX_SIZE / EMMC_BLOCKSIZE, pkg1)) {
|
||||
DPRINTF("Unable to read pkg1.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <utils/types.h>
|
||||
#include "../hos/hos.h"
|
||||
|
||||
#define HOS_PKG11_MAGIC 0x31314B50
|
||||
#define HOS_EKS_MAGIC 0x30534B45
|
||||
|
||||
#define AES_128_KEY_SIZE 16
|
||||
#define RSA_2048_KEY_SIZE 256
|
||||
@@ -86,6 +88,23 @@ typedef struct {
|
||||
keyblob_t keyblob;
|
||||
} key_derivation_ctx_t;
|
||||
|
||||
typedef struct _tsec_key_data_t
|
||||
{
|
||||
u8 debug_key[0x10];
|
||||
u8 blob0_auth_hash[0x10];
|
||||
u8 blob1_auth_hash[0x10];
|
||||
u8 blob2_auth_hash[0x10];
|
||||
u8 blob2_aes_iv[0x10];
|
||||
u8 hovi_eks_seed[0x10];
|
||||
u8 hovi_common_seed[0x10];
|
||||
u32 blob0_size;
|
||||
u32 blob1_size;
|
||||
u32 blob2_size;
|
||||
u32 blob3_size;
|
||||
u32 blob4_size;
|
||||
u8 reserved[0x7C];
|
||||
} tsec_key_data_t;
|
||||
|
||||
int DumpKeys();
|
||||
void PrintKey(u8 *key, u32 len);
|
||||
|
||||
|
||||
@@ -24,12 +24,8 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <bdk.h>
|
||||
#include <libs/fatfs/diskio.h> /* FatFs lower layer API */
|
||||
#include <memory_map.h>
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../../storage/nx_emmc_bis.h"
|
||||
#include <storage/sdmmc.h>
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
|
||||
@@ -41,15 +41,26 @@
|
||||
#define FF_USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
#define FF_FASTFS 0
|
||||
|
||||
#if FF_FASTFS
|
||||
#define FF_USE_FASTSEEK 1
|
||||
#else
|
||||
#define FF_USE_FASTSEEK 0
|
||||
#if FF_USE_MKFS
|
||||
#define FF_MKFS_LABEL "SWITCH SD "
|
||||
#endif
|
||||
/* This sets FAT/FAT32 label. Exactly 11 characters, all caps. */
|
||||
|
||||
|
||||
#define FF_USE_FASTSEEK 0
|
||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||
|
||||
#define FF_FASTFS 0
|
||||
#if FF_FASTFS
|
||||
#undef FF_USE_FASTSEEK
|
||||
#define FF_USE_FASTSEEK 1
|
||||
#endif
|
||||
/* This option switches fast access to chained clusters. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_SIMPLE_GPT 1
|
||||
/* This option switches support for the first GPT partition. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_EXPAND 0
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
@@ -245,7 +256,7 @@
|
||||
#define FF_FS_NORTC 1
|
||||
#define FF_NORTC_MON 1
|
||||
#define FF_NORTC_MDAY 1
|
||||
#define FF_NORTC_YEAR 2020
|
||||
#define FF_NORTC_YEAR 2022
|
||||
/* The option FF_FS_NORTC switches timestamp function. If the system does not have
|
||||
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||
|
||||
@@ -20,35 +20,15 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
#include <display/di.h>
|
||||
#include <gfx_utils.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include <mem/minerva.h>
|
||||
#include <power/bq24193.h>
|
||||
#include <power/max17050.h>
|
||||
#include <power/max77620.h>
|
||||
#include <rtc/max77620-rtc.h>
|
||||
#include <soc/bpmp.h>
|
||||
#include <soc/hw_init.h>
|
||||
#include <bdk.h>
|
||||
#include "storage/emummc.h"
|
||||
#include "storage/nx_emmc.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/btn.h>
|
||||
#include <utils/dirlist.h>
|
||||
#include <utils/ini.h>
|
||||
#include <utils/sprintf.h>
|
||||
#include <utils/util.h>
|
||||
#include "hid/hid.h"
|
||||
#include <input/joycon.h>
|
||||
#include "gfx/menu.h"
|
||||
#include "utils/vector.h"
|
||||
#include "gfx/gfxutils.h"
|
||||
#include "tegraexplorer/mainmenu.h"
|
||||
#include "tegraexplorer/tconf.h"
|
||||
#include "err.h"
|
||||
#include <soc/pmc.h>
|
||||
#include "keys/keys.h"
|
||||
#include "keys/keyfile.h"
|
||||
#include "storage/mountmanager.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#ifndef WIN32
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <bdk.h>
|
||||
#endif
|
||||
|
||||
static inline int isValidWord(char c) {
|
||||
|
||||
@@ -15,18 +15,15 @@
|
||||
#include "../keys/keys.h"
|
||||
#include "../fs/readers/folderReader.h"
|
||||
#include "../fs/fscopy.h"
|
||||
#include <mem/heap.h>
|
||||
#include "../keys/nca.h"
|
||||
#include "../hid/hid.h"
|
||||
#include "../gfx/menu.h"
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "../storage/emummc.h"
|
||||
#include <utils/util.h>
|
||||
#include "../fs/fsutils.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../storage/emmcfile.h"
|
||||
#include <soc/fuse.h>
|
||||
#include <bdk.h>
|
||||
#endif
|
||||
// Takes [int, function]. Returns elseable.
|
||||
ClassFunction(stdIf) {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
#include "emmcfile.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../gfx/gfx.h"
|
||||
#include "emummc.h"
|
||||
#include "mountmanager.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "nx_emmc.h"
|
||||
#include <mem/heap.h>
|
||||
#include "../err.h"
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../hid/hid.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <string.h>
|
||||
#include "../fs/fsutils.h"
|
||||
#include "nx_emmc_bis.h"
|
||||
#include <bdk.h>
|
||||
|
||||
// Uses default storage in nx_emmc.c
|
||||
// Expects the correct mmc & partition to be set
|
||||
@@ -41,20 +38,20 @@ ErrCode_t EmmcDumpToFile(const char *path, u32 lba_start, u32 lba_end, u8 force,
|
||||
gfx_con_getpos(&x, &y);
|
||||
|
||||
while (totalSectors > 0){
|
||||
u32 num = MIN(totalSectors, TConf.FSBuffSize / NX_EMMC_BLOCKSIZE);
|
||||
u32 num = MIN(totalSectors, TConf.FSBuffSize / EMMC_BLOCKSIZE);
|
||||
|
||||
int readRes = 0;
|
||||
if (crypt)
|
||||
readRes = !nx_emmc_bis_read(curLba, num, buff);
|
||||
else
|
||||
readRes = emummc_storage_read(&emmc_storage, curLba, num, buff);
|
||||
readRes = emummc_storage_read(curLba, num, buff);
|
||||
|
||||
if (!readRes){
|
||||
err = newErrCode(TE_ERR_EMMC_READ_FAIL);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((res = f_write(&fp, buff, num * NX_EMMC_BLOCKSIZE, NULL))){
|
||||
if ((res = f_write(&fp, buff, num * EMMC_BLOCKSIZE, NULL))){
|
||||
err = newErrCode(res);
|
||||
break;
|
||||
}
|
||||
@@ -82,7 +79,7 @@ ErrCode_t EmmcRestoreFromFile(const char *path, u32 lba_start, u32 lba_end, u8 f
|
||||
return newErrCode(res);
|
||||
|
||||
u64 totalSizeSrc = f_size(&fp);
|
||||
u32 totalSectorsSrc = totalSizeSrc / NX_EMMC_BLOCKSIZE;
|
||||
u32 totalSectorsSrc = totalSizeSrc / EMMC_BLOCKSIZE;
|
||||
|
||||
if (totalSectorsSrc > totalSectorsDest) // We don't close the file here, oh well
|
||||
return newErrCode(TE_ERR_FILE_TOO_BIG_FOR_DEST);
|
||||
@@ -100,9 +97,9 @@ ErrCode_t EmmcRestoreFromFile(const char *path, u32 lba_start, u32 lba_end, u8 f
|
||||
gfx_con_getpos(&x, &y);
|
||||
|
||||
while (totalSectorsSrc > 0){
|
||||
u32 num = MIN(totalSectorsSrc, TConf.FSBuffSize / NX_EMMC_BLOCKSIZE);
|
||||
u32 num = MIN(totalSectorsSrc, TConf.FSBuffSize / EMMC_BLOCKSIZE);
|
||||
|
||||
if ((res = f_read(&fp, buff, num * NX_EMMC_BLOCKSIZE, NULL))){
|
||||
if ((res = f_read(&fp, buff, num * EMMC_BLOCKSIZE, NULL))){
|
||||
err = newErrCode(res);
|
||||
break;
|
||||
}
|
||||
@@ -111,7 +108,7 @@ ErrCode_t EmmcRestoreFromFile(const char *path, u32 lba_start, u32 lba_end, u8 f
|
||||
if (crypt)
|
||||
writeRes = !nx_emmc_bis_write(curLba, num, buff);
|
||||
else
|
||||
writeRes = emummc_storage_write(&emmc_storage, curLba, num, buff);
|
||||
writeRes = emummc_storage_write(curLba, num, buff);
|
||||
|
||||
if (!writeRes){
|
||||
err = newErrCode(TE_ERR_EMMC_WRITE_FAIL);
|
||||
@@ -121,7 +118,7 @@ ErrCode_t EmmcRestoreFromFile(const char *path, u32 lba_start, u32 lba_end, u8 f
|
||||
curLba += num;
|
||||
totalSectorsSrc -= num;
|
||||
|
||||
u32 percent = ((curLba - lba_start) * 100) / ((totalSizeSrc / NX_EMMC_BLOCKSIZE));
|
||||
u32 percent = ((curLba - lba_start) * 100) / ((totalSizeSrc / EMMC_BLOCKSIZE));
|
||||
gfx_printf("[%3d%%]", percent);
|
||||
gfx_con_setpos(x, y);
|
||||
}
|
||||
@@ -157,22 +154,22 @@ ErrCode_t DumpOrWriteEmmcPart(const char *path, const char *part, u8 write, u8 f
|
||||
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
|
||||
|
||||
if (!memcmp(part, "BOOT0", 5)){
|
||||
emummc_storage_set_mmc_partition(&emmc_storage, 1);
|
||||
lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||
emummc_storage_set_mmc_partition(1);
|
||||
lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
|
||||
}
|
||||
else if (!memcmp(part, "BOOT1", 5)){
|
||||
emummc_storage_set_mmc_partition(&emmc_storage, 2);
|
||||
lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||
emummc_storage_set_mmc_partition(2);
|
||||
lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
|
||||
}
|
||||
else {
|
||||
emummc_storage_set_mmc_partition(&emmc_storage, 0);
|
||||
emummc_storage_set_mmc_partition(0);
|
||||
|
||||
emmc_part_t *system_part = nx_emmc_part_find(GetCurGPT(), part);
|
||||
emmc_part_t *system_part = emmc_part_find(GetCurGPT(), part);
|
||||
if (!system_part)
|
||||
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
|
||||
|
||||
if (isSystemPartCrypt(system_part) && TConf.keysDumped){
|
||||
nx_emmc_bis_init(system_part);
|
||||
nx_emmc_bis_init(system_part, true, 0);
|
||||
crypt = true;
|
||||
lba_start = 0;
|
||||
lba_end = system_part->lba_end - system_part->lba_start;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
* Copyright (c) 2019-2022 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -17,17 +17,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <bdk.h>
|
||||
|
||||
#include "emummc.h"
|
||||
#include <storage/sdmmc.h>
|
||||
#include "../config.h"
|
||||
#include <utils/ini.h>
|
||||
#include <gfx_utils.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../storage/nx_emmc.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include <utils/list.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
extern hekate_config h_cfg;
|
||||
emummc_cfg_t emu_cfg = { 0 };
|
||||
@@ -42,9 +36,9 @@ void emummc_load_cfg()
|
||||
emu_cfg.active_part = 0;
|
||||
emu_cfg.fs_ver = 0;
|
||||
if (!emu_cfg.nintendo_path)
|
||||
emu_cfg.nintendo_path = (char *)malloc(0x80);
|
||||
emu_cfg.nintendo_path = (char *)malloc(0x200);
|
||||
if (!emu_cfg.emummc_file_based_path)
|
||||
emu_cfg.emummc_file_based_path = (char *)malloc(0x80);
|
||||
emu_cfg.emummc_file_based_path = (char *)malloc(0x200);
|
||||
|
||||
emu_cfg.nintendo_path[0] = 0;
|
||||
emu_cfg.emummc_file_based_path[0] = 0;
|
||||
@@ -109,7 +103,14 @@ bool emummc_set_path(char *path)
|
||||
if (found)
|
||||
{
|
||||
emu_cfg.enabled = 1;
|
||||
emu_cfg.id = 0;
|
||||
|
||||
// Get ID from path.
|
||||
u32 id_from_path = 0;
|
||||
u32 path_size = strlen(path);
|
||||
if (path_size >= 4)
|
||||
memcpy(&id_from_path, path + path_size - 4, 4);
|
||||
emu_cfg.id = id_from_path;
|
||||
|
||||
strcpy(emu_cfg.nintendo_path, path);
|
||||
strcat(emu_cfg.nintendo_path, "/Nintendo");
|
||||
}
|
||||
@@ -131,13 +132,13 @@ static int emummc_raw_get_part_off(int part_idx)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int emummc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc)
|
||||
int emummc_storage_init_mmc()
|
||||
{
|
||||
FILINFO fno;
|
||||
emu_cfg.active_part = 0;
|
||||
|
||||
// Always init eMMC even when in emuMMC. eMMC is needed from the emuMMC driver anyway.
|
||||
if (!sdmmc_storage_init_mmc(storage, sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
|
||||
if (!emmc_initialize(false))
|
||||
return 2;
|
||||
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
@@ -173,18 +174,21 @@ out:
|
||||
return 1;
|
||||
}
|
||||
|
||||
int emummc_storage_end(sdmmc_storage_t *storage)
|
||||
int emummc_storage_end()
|
||||
{
|
||||
sdmmc_storage_end(storage);
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
sdmmc_storage_end(&emmc_storage);
|
||||
else
|
||||
sd_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int emummc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf)
|
||||
int emummc_storage_read(u32 sector, u32 num_sectors, void *buf)
|
||||
{
|
||||
FIL fp;
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
return sdmmc_storage_read(storage, sector, num_sectors, buf);
|
||||
return sdmmc_storage_read(&emmc_storage, sector, num_sectors, buf);
|
||||
else if (emu_cfg.sector)
|
||||
{
|
||||
sector += emu_cfg.sector;
|
||||
@@ -225,11 +229,11 @@ int emummc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, v
|
||||
return 1;
|
||||
}
|
||||
|
||||
int emummc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf)
|
||||
int emummc_storage_write(u32 sector, u32 num_sectors, void *buf)
|
||||
{
|
||||
FIL fp;
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
return sdmmc_storage_write(storage, sector, num_sectors, buf);
|
||||
return sdmmc_storage_write(&emmc_storage, sector, num_sectors, buf);
|
||||
else if (emu_cfg.sector)
|
||||
{
|
||||
sector += emu_cfg.sector;
|
||||
@@ -250,15 +254,13 @@ int emummc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors,
|
||||
itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 1, 10);
|
||||
}
|
||||
}
|
||||
|
||||
if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_WRITE))
|
||||
{
|
||||
gfx_printf("e5\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
f_lseek(&fp, (u64)sector << 9);
|
||||
if (f_write(&fp, buf, (u64)num_sectors << 9, NULL))
|
||||
{
|
||||
gfx_printf("e6\n");
|
||||
f_close(&fp);
|
||||
return 0;
|
||||
}
|
||||
@@ -268,13 +270,12 @@ int emummc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors,
|
||||
}
|
||||
}
|
||||
|
||||
int emummc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition)
|
||||
int emummc_storage_set_mmc_partition(u32 partition)
|
||||
{
|
||||
emu_cfg.active_part = partition;
|
||||
sdmmc_storage_set_mmc_partition(&emmc_storage, partition);
|
||||
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
sdmmc_storage_set_mmc_partition(storage, partition);
|
||||
else if (emu_cfg.sector)
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable || emu_cfg.sector)
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
* Copyright (c) 2019-2021 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -17,8 +17,7 @@
|
||||
#ifndef EMUMMC_H
|
||||
#define EMUMMC_H
|
||||
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/types.h>
|
||||
#include <bdk.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -37,7 +36,7 @@ typedef struct _emummc_cfg_t
|
||||
{
|
||||
int enabled;
|
||||
u64 sector;
|
||||
u16 id;
|
||||
u32 id;
|
||||
char *path;
|
||||
char *nintendo_path;
|
||||
// Internal.
|
||||
@@ -51,10 +50,10 @@ extern emummc_cfg_t emu_cfg;
|
||||
|
||||
void emummc_load_cfg();
|
||||
bool emummc_set_path(char *path);
|
||||
int emummc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc);
|
||||
int emummc_storage_end(sdmmc_storage_t *storage);
|
||||
int emummc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
|
||||
int emummc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
|
||||
int emummc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition);
|
||||
int emummc_storage_init_mmc();
|
||||
int emummc_storage_end();
|
||||
int emummc_storage_read(u32 sector, u32 num_sectors, void *buf);
|
||||
int emummc_storage_write(u32 sector, u32 num_sectors, void *buf);
|
||||
int emummc_storage_set_mmc_partition(u32 partition);
|
||||
|
||||
#endif
|
||||
@@ -1,18 +1,15 @@
|
||||
#include "gptmenu.h"
|
||||
#include <string.h>
|
||||
#include <bdk.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"
|
||||
#include "emmcfile.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../fs/fsutils.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "mountmanager.h"
|
||||
#include "emummc.h"
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "nx_emmc.h"
|
||||
#include "../keys/keys.h"
|
||||
#include <sec/se.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "nx_emmc_bis.h"
|
||||
#include <bdk.h>
|
||||
#include "../config.h"
|
||||
|
||||
extern hekate_config h_cfg;
|
||||
@@ -39,8 +37,8 @@ void disconnectMMC(){
|
||||
|
||||
if (TConf.currentMMCConnected != MMC_CONN_None){
|
||||
TConf.currentMMCConnected = MMC_CONN_None;
|
||||
emummc_storage_end(&emmc_storage);
|
||||
nx_emmc_gpt_free(&curGpt);
|
||||
emummc_storage_end();
|
||||
emmc_gpt_free(&curGpt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +49,11 @@ int connectMMC(u8 mmcType){
|
||||
|
||||
disconnectMMC();
|
||||
h_cfg.emummc_force_disable = (mmcType == MMC_CONN_EMMC) ? 1 : 0;
|
||||
int res = emummc_storage_init_mmc(&emmc_storage, &emmc_sdmmc);
|
||||
int res = emummc_storage_init_mmc(&emmc_sdmmc);
|
||||
if (!res){
|
||||
TConf.currentMMCConnected = mmcType;
|
||||
emummc_storage_set_mmc_partition(&emmc_storage, 0);
|
||||
nx_emmc_gpt_parse(&curGpt, &emmc_storage);
|
||||
emummc_storage_set_mmc_partition(0);
|
||||
emmc_gpt_parse(&curGpt);
|
||||
}
|
||||
|
||||
return res; // deal with the errors later lol
|
||||
@@ -67,13 +65,13 @@ ErrCode_t mountMMCPart(const char *partition){
|
||||
|
||||
unmountMMCPart();
|
||||
|
||||
emummc_storage_set_mmc_partition(&emmc_storage, 0); // why i have to do this twice beats me
|
||||
emummc_storage_set_mmc_partition(0); // why i have to do this twice beats me
|
||||
|
||||
emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition);
|
||||
emmc_part_t *system_part = emmc_part_find(&curGpt, partition);
|
||||
if (!system_part)
|
||||
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
|
||||
|
||||
nx_emmc_bis_init(system_part);
|
||||
nx_emmc_bis_init(system_part, true, 0);
|
||||
|
||||
int res = 0;
|
||||
if ((res = f_mount(&emmc_fs, "bis:", 1)))
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "nx_emmc.h"
|
||||
#include "emummc.h"
|
||||
#include <mem/heap.h>
|
||||
#include <storage/mbr_gpt.h>
|
||||
#include <utils/list.h>
|
||||
|
||||
sdmmc_t emmc_sdmmc;
|
||||
sdmmc_storage_t emmc_storage;
|
||||
FATFS emmc_fs;
|
||||
|
||||
void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage)
|
||||
{
|
||||
gpt_t *gpt_buf = (gpt_t *)calloc(NX_GPT_NUM_BLOCKS, NX_EMMC_BLOCKSIZE);
|
||||
|
||||
emummc_storage_read(storage, NX_GPT_FIRST_LBA, NX_GPT_NUM_BLOCKS, gpt_buf);
|
||||
|
||||
for (u32 i = 0; i < gpt_buf->header.num_part_ents; i++)
|
||||
{
|
||||
emmc_part_t *part = (emmc_part_t *)calloc(sizeof(emmc_part_t), 1);
|
||||
|
||||
if (gpt_buf->entries[i].lba_start < gpt_buf->header.first_use_lba)
|
||||
continue;
|
||||
|
||||
part->index = i;
|
||||
part->lba_start = gpt_buf->entries[i].lba_start;
|
||||
part->lba_end = gpt_buf->entries[i].lba_end;
|
||||
part->attrs = gpt_buf->entries[i].attrs;
|
||||
|
||||
// ASCII conversion. Copy only the LSByte of the UTF-16LE name.
|
||||
for (u32 j = 0; j < 36; j++)
|
||||
part->name[j] = gpt_buf->entries[i].name[j];
|
||||
part->name[35] = 0;
|
||||
|
||||
list_append(gpt, &part->link);
|
||||
}
|
||||
|
||||
free(gpt_buf);
|
||||
}
|
||||
|
||||
void nx_emmc_gpt_free(link_t *gpt)
|
||||
{
|
||||
LIST_FOREACH_SAFE(iter, gpt)
|
||||
free(CONTAINER_OF(iter, emmc_part_t, link));
|
||||
}
|
||||
|
||||
emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name)
|
||||
{
|
||||
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link)
|
||||
if (!strcmp(part->name, name))
|
||||
return part;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf)
|
||||
{
|
||||
// The last LBA is inclusive.
|
||||
if (part->lba_start + sector_off > part->lba_end)
|
||||
return 0;
|
||||
return emummc_storage_read(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||
}
|
||||
|
||||
int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf)
|
||||
{
|
||||
// The last LBA is inclusive.
|
||||
if (part->lba_start + sector_off > part->lba_end)
|
||||
return 0;
|
||||
return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _NX_EMMC_H_
|
||||
#define _NX_EMMC_H_
|
||||
|
||||
#include <storage/sdmmc.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <utils/types.h>
|
||||
#include <utils/list.h>
|
||||
|
||||
#define NX_GPT_FIRST_LBA 1
|
||||
#define NX_GPT_NUM_BLOCKS 33
|
||||
#define NX_EMMC_BLOCKSIZE 512
|
||||
|
||||
typedef struct _emmc_part_t
|
||||
{
|
||||
u32 index;
|
||||
u32 lba_start;
|
||||
u32 lba_end;
|
||||
u64 attrs;
|
||||
char name[37];
|
||||
link_t link;
|
||||
} emmc_part_t;
|
||||
|
||||
extern sdmmc_t emmc_sdmmc;
|
||||
extern sdmmc_storage_t emmc_storage;
|
||||
extern FATFS emmc_fs;
|
||||
|
||||
void nx_emmc_gpt_parse(link_t *gpt, sdmmc_storage_t *storage);
|
||||
void nx_emmc_gpt_free(link_t *gpt);
|
||||
emmc_part_t *nx_emmc_part_find(link_t *gpt, const char *name);
|
||||
int nx_emmc_part_read(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf);
|
||||
int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf);
|
||||
|
||||
#endif
|
||||
@@ -1,387 +0,0 @@
|
||||
/*
|
||||
* eMMC BIS driver for Nintendo Switch
|
||||
*
|
||||
* Copyright (c) 2019 shchmue
|
||||
* Copyright (c) 2019-2020 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#include <mem/heap.h>
|
||||
#include <sec/se.h>
|
||||
#include "../storage/nx_emmc.h"
|
||||
#include "nx_emmc_bis.h"
|
||||
#include <storage/sdmmc.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
#define MAX_CLUSTER_CACHE_ENTRIES 32768
|
||||
#define CLUSTER_LOOKUP_EMPTY_ENTRY 0xFFFFFFFF
|
||||
#define SECTORS_PER_CLUSTER 0x20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 cluster_num; // index of the cluster in the partition
|
||||
u32 visit_count; // used for debugging/access analysis
|
||||
u8 dirty; // has been modified without writeback flag
|
||||
u8 align[7];
|
||||
u8 cluster[XTS_CLUSTER_SIZE]; // the cached cluster itself
|
||||
} cluster_cache_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 emmc_buffer[XTS_CLUSTER_SIZE];
|
||||
cluster_cache_t cluster_cache[];
|
||||
} bis_cache_t;
|
||||
|
||||
static u8 ks_crypt = 0;
|
||||
static u8 ks_tweak = 0;
|
||||
static u8 cache_filled = 0;
|
||||
static u32 dirty_cluster_count = 0;
|
||||
static u32 cluster_cache_end_index = 0;
|
||||
static emmc_part_t *system_part = NULL;
|
||||
static bis_cache_t *bis_cache = (bis_cache_t *)NX_BIS_CACHE_ADDR;
|
||||
static u32 *cluster_lookup_buf = NULL;
|
||||
static u32 *cluster_lookup = NULL;
|
||||
static bool lock_cluster_cache = false;
|
||||
|
||||
static void _gf256_mul_x_le(void *block)
|
||||
{
|
||||
u32 *pdata = (u32 *)block;
|
||||
u32 carry = 0;
|
||||
|
||||
for (u32 i = 0; i < 4; i++)
|
||||
{
|
||||
u32 b = pdata[i];
|
||||
pdata[i] = (b << 1) | carry;
|
||||
carry = b >> 31;
|
||||
}
|
||||
|
||||
if (carry)
|
||||
pdata[0x0] ^= 0x87;
|
||||
}
|
||||
|
||||
static int _nx_aes_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u8 *tweak, bool regen_tweak, u32 tweak_exp, u32 sec, void *dst, const void *src, u32 sec_size)
|
||||
{
|
||||
u32 *pdst = (u32 *)dst;
|
||||
u32 *psrc = (u32 *)src;
|
||||
u32 *ptweak = (u32 *)tweak;
|
||||
|
||||
if (regen_tweak)
|
||||
{
|
||||
for (int i = 0xF; i >= 0; i--)
|
||||
{
|
||||
tweak[i] = sec & 0xFF;
|
||||
sec >>= 8;
|
||||
}
|
||||
if (!se_aes_crypt_block_ecb(tweak_ks, 1, tweak, tweak))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tweak_exp allows us to use a saved tweak to reduce _gf256_mul_x_le calls.
|
||||
for (u32 i = 0; i < (tweak_exp << 5); i++)
|
||||
_gf256_mul_x_le(tweak);
|
||||
|
||||
u8 orig_tweak[0x10] __attribute__((aligned(4)));
|
||||
memcpy(orig_tweak, tweak, 0x10);
|
||||
|
||||
// We are assuming a 0x10-aligned sector size in this implementation.
|
||||
for (u32 i = 0; i < (sec_size >> 4); i++)
|
||||
{
|
||||
for (u32 j = 0; j < 4; j++)
|
||||
pdst[j] = psrc[j] ^ ptweak[j];
|
||||
|
||||
_gf256_mul_x_le(tweak);
|
||||
psrc += 4;
|
||||
pdst += 4;
|
||||
}
|
||||
|
||||
if (!se_aes_crypt_ecb(crypt_ks, enc, dst, sec_size, dst, sec_size))
|
||||
return 0;
|
||||
|
||||
pdst = (u32 *)dst;
|
||||
ptweak = (u32 *)orig_tweak;
|
||||
for (u32 i = 0; i < (sec_size >> 4); i++)
|
||||
{
|
||||
for (u32 j = 0; j < 4; j++)
|
||||
pdst[j] = pdst[j] ^ ptweak[j];
|
||||
|
||||
_gf256_mul_x_le(orig_tweak);
|
||||
pdst += 4;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nx_emmc_bis_write_block(u32 sector, u32 count, void *buff, bool force_flush)
|
||||
{
|
||||
if (!system_part)
|
||||
return 3; // Not ready.
|
||||
|
||||
u8 tweak[0x10] __attribute__((aligned(4)));
|
||||
u32 cluster = sector / SECTORS_PER_CLUSTER;
|
||||
u32 aligned_sector = cluster * SECTORS_PER_CLUSTER;
|
||||
u32 sector_index_in_cluster = sector % SECTORS_PER_CLUSTER;
|
||||
u32 cluster_lookup_index = cluster_lookup[cluster];
|
||||
bool is_cached = cluster_lookup_index != CLUSTER_LOOKUP_EMPTY_ENTRY;
|
||||
|
||||
// Write to cached cluster.
|
||||
if (is_cached)
|
||||
{
|
||||
if (buff)
|
||||
memcpy(bis_cache->cluster_cache[cluster_lookup_index].cluster + sector_index_in_cluster * NX_EMMC_BLOCKSIZE, buff, count * NX_EMMC_BLOCKSIZE);
|
||||
else
|
||||
buff = bis_cache->cluster_cache[cluster_lookup_index].cluster;
|
||||
bis_cache->cluster_cache[cluster_lookup_index].visit_count++;
|
||||
if (bis_cache->cluster_cache[cluster_lookup_index].dirty == 0)
|
||||
dirty_cluster_count++;
|
||||
bis_cache->cluster_cache[cluster_lookup_index].dirty = 1;
|
||||
if (!force_flush)
|
||||
return 0; // Success.
|
||||
|
||||
// Reset args to trigger a full cluster flush to emmc.
|
||||
sector_index_in_cluster = 0;
|
||||
sector = aligned_sector;
|
||||
count = SECTORS_PER_CLUSTER;
|
||||
}
|
||||
|
||||
// Encrypt and write.
|
||||
if (!_nx_aes_xts_crypt_sec(ks_tweak, ks_crypt, 1, tweak, true, sector_index_in_cluster, cluster, bis_cache->emmc_buffer, buff, count * NX_EMMC_BLOCKSIZE) ||
|
||||
!nx_emmc_part_write(&emmc_storage, system_part, sector, count, bis_cache->emmc_buffer)
|
||||
)
|
||||
return 1; // R/W error.
|
||||
|
||||
// Mark cache entry not dirty if write succeeds.
|
||||
if (is_cached)
|
||||
{
|
||||
bis_cache->cluster_cache[cluster_lookup_index].dirty = 0;
|
||||
dirty_cluster_count--;
|
||||
}
|
||||
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
static void _nx_emmc_bis_flush_cluster(cluster_cache_t *cache_entry)
|
||||
{
|
||||
nx_emmc_bis_write_block(cache_entry->cluster_num * SECTORS_PER_CLUSTER, SECTORS_PER_CLUSTER, NULL, true);
|
||||
}
|
||||
|
||||
static int nx_emmc_bis_read_block(u32 sector, u32 count, void *buff)
|
||||
{
|
||||
if (!system_part)
|
||||
return 3; // Not ready.
|
||||
|
||||
static u32 prev_cluster = -1;
|
||||
static u32 prev_sector = 0;
|
||||
static u8 tweak[0x10] __attribute__((aligned(4)));
|
||||
u8 cache_tweak[0x10] __attribute__((aligned(4)));
|
||||
|
||||
u32 tweak_exp = 0;
|
||||
bool regen_tweak = true;
|
||||
|
||||
u32 cluster = sector / SECTORS_PER_CLUSTER;
|
||||
u32 aligned_sector = cluster * SECTORS_PER_CLUSTER;
|
||||
u32 sector_index_in_cluster = sector % SECTORS_PER_CLUSTER;
|
||||
u32 cluster_lookup_index = cluster_lookup[cluster];
|
||||
|
||||
// Read from cached cluster.
|
||||
if (cluster_lookup_index != CLUSTER_LOOKUP_EMPTY_ENTRY)
|
||||
{
|
||||
memcpy(buff, bis_cache->cluster_cache[cluster_lookup_index].cluster + sector_index_in_cluster * NX_EMMC_BLOCKSIZE, count * NX_EMMC_BLOCKSIZE);
|
||||
bis_cache->cluster_cache[cluster_lookup_index].visit_count++;
|
||||
prev_sector = sector + count - 1;
|
||||
prev_cluster = cluster;
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
// Cache cluster.
|
||||
if (!lock_cluster_cache)
|
||||
{
|
||||
// Roll the cache index over and flush if full.
|
||||
if (cluster_cache_end_index >= MAX_CLUSTER_CACHE_ENTRIES)
|
||||
{
|
||||
cluster_cache_end_index = 0;
|
||||
cache_filled = 1;
|
||||
}
|
||||
// Check if cache entry was previously in use in case of cache loop.
|
||||
if (cache_filled == 1 && bis_cache->cluster_cache[cluster_cache_end_index].dirty == 1)
|
||||
_nx_emmc_bis_flush_cluster(&bis_cache->cluster_cache[cluster_cache_end_index]);
|
||||
|
||||
if (cache_filled == 1)
|
||||
cluster_lookup[bis_cache->cluster_cache[cluster_cache_end_index].cluster_num] = -1;
|
||||
|
||||
bis_cache->cluster_cache[cluster_cache_end_index].cluster_num = cluster;
|
||||
bis_cache->cluster_cache[cluster_cache_end_index].visit_count = 1;
|
||||
bis_cache->cluster_cache[cluster_cache_end_index].dirty = 0;
|
||||
cluster_lookup[cluster] = cluster_cache_end_index;
|
||||
|
||||
// Read and decrypt the whole cluster the sector resides in.
|
||||
if (!nx_emmc_part_read(&emmc_storage, system_part, aligned_sector, SECTORS_PER_CLUSTER, bis_cache->emmc_buffer) ||
|
||||
!_nx_aes_xts_crypt_sec(ks_tweak, ks_crypt, 0, cache_tweak, true, 0, cluster, bis_cache->emmc_buffer, bis_cache->emmc_buffer, XTS_CLUSTER_SIZE)
|
||||
)
|
||||
return 1; // R/W error.
|
||||
|
||||
// Copy to cluster cache.
|
||||
memcpy(bis_cache->cluster_cache[cluster_cache_end_index].cluster, bis_cache->emmc_buffer, XTS_CLUSTER_SIZE);
|
||||
memcpy(buff, bis_cache->emmc_buffer + sector_index_in_cluster * NX_EMMC_BLOCKSIZE, count * NX_EMMC_BLOCKSIZE);
|
||||
cluster_cache_end_index++;
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
// If not reading from or writing to cache, do a regular read and decrypt.
|
||||
if (!nx_emmc_part_read(&emmc_storage, system_part, sector, count, bis_cache->emmc_buffer))
|
||||
return 1; // R/W error.
|
||||
|
||||
if (prev_cluster != cluster) // Sector in different cluster than last read.
|
||||
{
|
||||
prev_cluster = cluster;
|
||||
tweak_exp = sector_index_in_cluster;
|
||||
}
|
||||
else if (sector > prev_sector) // Sector in same cluster and past last sector.
|
||||
{
|
||||
// Calculates the new tweak using the saved one, reducing expensive _gf256_mul_x_le calls.
|
||||
tweak_exp = sector - prev_sector - 1;
|
||||
regen_tweak = false;
|
||||
}
|
||||
else // Sector in same cluster and before or same as last sector.
|
||||
tweak_exp = sector_index_in_cluster;
|
||||
|
||||
// Maximum one cluster (1 XTS crypto block 16KB).
|
||||
if (!_nx_aes_xts_crypt_sec(ks_tweak, ks_crypt, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, bis_cache->emmc_buffer, count * NX_EMMC_BLOCKSIZE))
|
||||
return 1; // R/W error.
|
||||
prev_sector = sector + count - 1;
|
||||
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
int nx_emmc_bis_read(u32 sector, u32 count, void *buff)
|
||||
{
|
||||
int res = 1;
|
||||
u8 *buf = (u8 *)buff;
|
||||
u32 curr_sct = sector;
|
||||
|
||||
while (count)
|
||||
{
|
||||
u32 sct_cnt = MIN(count, 0x20);
|
||||
res = nx_emmc_bis_read_block(curr_sct, sct_cnt, buf);
|
||||
if (res)
|
||||
return 1;
|
||||
|
||||
count -= sct_cnt;
|
||||
curr_sct += sct_cnt;
|
||||
buf += NX_EMMC_BLOCKSIZE * sct_cnt;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int nx_emmc_bis_write(u32 sector, u32 count, void *buff)
|
||||
{
|
||||
int res = 1;
|
||||
u8 *buf = (u8 *)buff;
|
||||
u32 curr_sct = sector;
|
||||
|
||||
while (count)
|
||||
{
|
||||
u32 sct_cnt = MIN(count, 0x20);
|
||||
res = nx_emmc_bis_write_block(curr_sct, sct_cnt, buf, false);
|
||||
if (res)
|
||||
return 1;
|
||||
|
||||
count -= sct_cnt;
|
||||
curr_sct += sct_cnt;
|
||||
buf += NX_EMMC_BLOCKSIZE * sct_cnt;
|
||||
}
|
||||
|
||||
nx_emmc_bis_finalize();
|
||||
return res;
|
||||
}
|
||||
|
||||
void nx_emmc_bis_cluster_cache_init()
|
||||
{
|
||||
u32 cluster_lookup_size = (system_part->lba_end - system_part->lba_start + 1) / SECTORS_PER_CLUSTER * sizeof(*cluster_lookup);
|
||||
|
||||
if (cluster_lookup_buf)
|
||||
free(cluster_lookup_buf);
|
||||
|
||||
// Check if carveout protected, in case of old hwinit (pre 4.0.0) chainload.
|
||||
*(vu32 *)NX_BIS_LOOKUP_ADR = 0;
|
||||
if (*(vu32 *)NX_BIS_LOOKUP_ADR != 0)
|
||||
{
|
||||
cluster_lookup_buf = (u32 *)malloc(cluster_lookup_size + 0x2000);
|
||||
cluster_lookup = (u32 *)ALIGN((u32)cluster_lookup_buf, 0x1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster_lookup_buf = NULL;
|
||||
cluster_lookup = (u32 *)NX_BIS_LOOKUP_ADR;
|
||||
}
|
||||
|
||||
// Clear cluster lookup table and reset end index.
|
||||
memset(cluster_lookup, -1, cluster_lookup_size);
|
||||
cluster_cache_end_index = 0;
|
||||
lock_cluster_cache = false;
|
||||
|
||||
dirty_cluster_count = 0;
|
||||
cache_filled = 0;
|
||||
}
|
||||
|
||||
void nx_emmc_bis_init(emmc_part_t *part)
|
||||
{
|
||||
system_part = part;
|
||||
|
||||
nx_emmc_bis_cluster_cache_init();
|
||||
|
||||
switch (part->index)
|
||||
{
|
||||
case 0: // PRODINFO.
|
||||
case 1: // PRODINFOF.
|
||||
ks_crypt = 0;
|
||||
ks_tweak = 1;
|
||||
break;
|
||||
case 8: // SAFE.
|
||||
ks_crypt = 2;
|
||||
ks_tweak = 3;
|
||||
break;
|
||||
case 9: // SYSTEM.
|
||||
case 10: // USER.
|
||||
ks_crypt = 4;
|
||||
ks_tweak = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void nx_emmc_bis_finalize()
|
||||
{
|
||||
if (dirty_cluster_count == 0)
|
||||
return;
|
||||
|
||||
u32 limit = cache_filled == 1 ? MAX_CLUSTER_CACHE_ENTRIES : cluster_cache_end_index;
|
||||
u32 clusters_to_flush = dirty_cluster_count;
|
||||
for (u32 i = 0; i < limit && clusters_to_flush; i++)
|
||||
{
|
||||
if (bis_cache->cluster_cache[i].dirty) {
|
||||
_nx_emmc_bis_flush_cluster(&bis_cache->cluster_cache[i]);
|
||||
clusters_to_flush--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set cluster cache lock according to arg.
|
||||
void nx_emmc_bis_cache_lock(bool lock)
|
||||
{
|
||||
lock_cluster_cache = lock;
|
||||
}
|
||||
@@ -1,240 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 shchmue
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NX_EMMC_BIS_H
|
||||
#define NX_EMMC_BIS_H
|
||||
|
||||
#include "../storage/nx_emmc.h"
|
||||
#include <storage/sdmmc.h>
|
||||
|
||||
typedef struct _nx_emmc_cal0_spk_t
|
||||
{
|
||||
u16 unk0;
|
||||
u16 unk1;
|
||||
u16 eq_bw_lop;
|
||||
u16 eq_gn_lop;
|
||||
u16 eq_fc_bp1;
|
||||
u16 eq_bw_bp1;
|
||||
u16 eq_gn_bp1;
|
||||
u16 eq_fc_bp2;
|
||||
u16 eq_bw_bp2;
|
||||
u16 eq_gn_bp2;
|
||||
u16 eq_fc_bp3;
|
||||
u16 eq_bw_bp3;
|
||||
u16 eq_gn_bp3;
|
||||
u16 eq_fc_bp4;
|
||||
u16 eq_bw_bp4;
|
||||
u16 eq_gn_bp4;
|
||||
u16 eq_fc_hip1;
|
||||
u16 eq_gn_hip1;
|
||||
u16 eq_fc_hip2;
|
||||
u16 eq_bw_hip2;
|
||||
u16 eq_gn_hip2;
|
||||
u16 eq_pre_vol;
|
||||
u16 eq_pst_vol;
|
||||
u16 eq_ctrl2;
|
||||
u16 eq_ctrl1;
|
||||
u16 drc_agc_2;
|
||||
u16 drc_agc_3;
|
||||
u16 drc_agc_1;
|
||||
u16 spk_vol;
|
||||
u16 hp_vol;
|
||||
u16 dac1_min_vol_spk;
|
||||
u16 dac1_max_vol_spk;
|
||||
u16 dac1_min_vol_hp;
|
||||
u16 dac1_max_vol_hp;
|
||||
u16 in1_in2;
|
||||
u16 adc_vol_min;
|
||||
u16 adc_vol_max;
|
||||
u8 unk4[16];
|
||||
} __attribute__((packed)) nx_emmc_cal0_spk_t;
|
||||
|
||||
typedef struct _nx_emmc_cal0_t
|
||||
{
|
||||
u32 magic; // 'CAL0'.
|
||||
u32 version;
|
||||
u32 body_size;
|
||||
u16 model;
|
||||
u16 update_cnt;
|
||||
u8 pad_crc16_0[0x10];
|
||||
u8 body_sha256[0x20];
|
||||
char cfg_id1[0x1E];
|
||||
u8 crc16_pad1[2];
|
||||
u8 rsvd0[0x20];
|
||||
u32 wlan_cc_num;
|
||||
u32 wlan_cc_last;
|
||||
char wlan_cc[128][3];
|
||||
u8 crc16_pad2[8];
|
||||
u8 wlan_mac[6];
|
||||
u8 crc16_pad3[2];
|
||||
u8 rsvd1[8];
|
||||
u8 bd_mac[6];
|
||||
u8 crc16_pad4[2];
|
||||
u8 rsvd2[8];
|
||||
u8 acc_offset[6];
|
||||
u8 crc16_pad5[2];
|
||||
u8 acc_scale[6];
|
||||
u8 crc16_pad6[2];
|
||||
u8 gyro_offset[6];
|
||||
u8 crc16_pad7[2];
|
||||
u8 gyro_scale[6];
|
||||
u8 crc16_pad8[2];
|
||||
char serial_number[0x18];
|
||||
u8 crc16_pad9[8];
|
||||
|
||||
u8 ecc_p256_device_key[0x30];
|
||||
u8 crc16_pad10[0x10];
|
||||
u8 ecc_p256_device_cert[0x180];
|
||||
u8 crc16_pad11[0x10];
|
||||
u8 ecc_p233_device_key[0x30];
|
||||
u8 crc16_pad12[0x10];
|
||||
u8 ecc_p33_device_cert[0x180];
|
||||
u8 crc16_pad13[0x10];
|
||||
u8 ecc_p256_ticket_key[0x30];
|
||||
u8 crc16_pad14[0x10];
|
||||
u8 ecc_p256_ticket_cert[0x180];
|
||||
u8 crc16_pad15[0x10];
|
||||
u8 ecc_p233_ticket_key[0x30];
|
||||
u8 crc16_pad16[0x10];
|
||||
u8 ecc_p33_ticket_cert[0x180];
|
||||
u8 crc16_pad17[0x10];
|
||||
u8 ssl_key[0x110];
|
||||
u8 crc16_pad18[0x10];
|
||||
u32 ssl_cert_size;
|
||||
u8 crc16_pad19[0xC];
|
||||
u8 ssl_cert[0x800];
|
||||
u8 ssl_sha256[0x20];
|
||||
u8 random_number[0x1000];
|
||||
u8 random_number_sha256[0x20];
|
||||
u8 gc_key[0x110];
|
||||
u8 crc16_pad20[0x10];
|
||||
u8 gc_cert[0x400];
|
||||
u8 gc_cert_sha256[0x20];
|
||||
u8 rsa2048_eticket_key[0x220];
|
||||
u8 crc16_pad21[0x10];
|
||||
u8 rsa2048_eticket_cert[0x240];
|
||||
u8 crc16_pad22[0x10];
|
||||
|
||||
char battery_lot[0x1E];
|
||||
u8 crc16_pad23[2];
|
||||
nx_emmc_cal0_spk_t spk_cal;
|
||||
u8 spk_cal_rsvd[0x800 - sizeof(nx_emmc_cal0_spk_t)];
|
||||
u8 crc16_pad24[0x10];
|
||||
u32 region_code;
|
||||
u8 crc16_pad25[0xC];
|
||||
|
||||
u8 amiibo_key[0x50];
|
||||
u8 crc16_pad26[0x10];
|
||||
u8 amiibo_ecqv_cert[0x14];
|
||||
u8 crc16_pad27[0xC];
|
||||
u8 amiibo_ecqdsa_cert[0x70];
|
||||
u8 crc16_pad28[0x10];
|
||||
u8 amiibo_ecqv_bls_key[0x40];
|
||||
u8 crc16_pad29[0x10];
|
||||
u8 amiibo_ecqv_bls_cert[0x20];
|
||||
u8 crc16_pad30[0x10];
|
||||
u8 amiibo_ecqv_bls_root_cert[0x90];
|
||||
u8 crc16_pad31[0x10];
|
||||
|
||||
u32 product_model; // 1: Nx, 2: Copper, 4: Hoag.
|
||||
u8 crc16_pad32[0xC];
|
||||
u8 home_menu_scheme_main_color[6];
|
||||
u8 crc16_pad33[0xA];
|
||||
u32 lcd_bl_brightness_mapping[3]; // Floats. Normally 100%, 0% and 2%.
|
||||
u8 crc16_pad34[0x4];
|
||||
|
||||
u8 ext_ecc_b233_device_key[0x50];
|
||||
u8 crc16_pad35[0x10];
|
||||
u8 ext_ecc_p256_eticket_key[0x50];
|
||||
u8 crc16_pad36[0x10];
|
||||
u8 ext_ecc_b233_eticket_key[0x50];
|
||||
u8 crc16_pad37[0x10];
|
||||
u8 ext_ecc_rsa2048_eticket_key_iv[0x10];
|
||||
u8 ext_ecc_rsa2048_eticket_key[0x230];
|
||||
u32 ext_ecc_rsa2048_eticket_key_ver;
|
||||
u8 crc16_pad38[0xC];
|
||||
u8 ext_ssl_key[0x130];
|
||||
u8 crc16_pad39[0x10];
|
||||
u8 ext_gc_key[0x130];
|
||||
u8 crc16_pad40[0x10];
|
||||
|
||||
u32 lcd_vendor;
|
||||
u8 crc16_pad41[0xC];
|
||||
|
||||
// 5.0.0 and up.
|
||||
u8 ext_rsa2048_device_key[0x240];
|
||||
u8 crc16_pad42[0x10];
|
||||
u8 rsa2048_device_cert[0x240];
|
||||
u8 crc16_pad43[0x10];
|
||||
|
||||
u8 usbc_pwr_src_circuit_ver;
|
||||
u8 crc16_pad44[0xF];
|
||||
|
||||
// 9.0.0 and up.
|
||||
u32 home_menu_scheme_sub_color;
|
||||
u8 crc16_pad45[0xC];
|
||||
u32 home_menu_scheme_bezel_color;
|
||||
u8 crc16_pad46[0xC];
|
||||
u32 home_menu_scheme_main_color1;
|
||||
u8 crc16_pad47[0xC];
|
||||
u32 home_menu_scheme_main_color2;
|
||||
u8 crc16_pad48[0xC];
|
||||
u32 home_menu_scheme_main_color3;
|
||||
u8 crc16_pad49[0xC];
|
||||
|
||||
u8 analog_stick_type_l;
|
||||
u8 crc16_pad50[0xF];
|
||||
u8 analog_stick_param_l[0x12];
|
||||
u8 crc16_pad51[0xE];
|
||||
u8 analog_stick_cal_l[0x9];
|
||||
u8 crc16_pad52[0x7];
|
||||
u8 analog_stick_type_r;
|
||||
u8 crc16_pad53[0xF];
|
||||
u8 analog_stick_param_r[0x12];
|
||||
u8 crc16_pad54[0xE];
|
||||
u8 analog_stick_cal_r[0x9];
|
||||
u8 crc16_pad55[0x7];
|
||||
u8 console_6axis_sensor_type;
|
||||
u8 crc16_pad56[0xF];
|
||||
u8 console_6axis_sensor_hor_off[0x6];
|
||||
u8 crc16_pad57[0xA];
|
||||
|
||||
// 6.0.0 and up.
|
||||
u8 battery_ver;
|
||||
u8 crc16_pad58[0x1F];
|
||||
|
||||
// 9.0.0 and up.
|
||||
u32 home_menu_scheme_model;
|
||||
u8 crc16_pad59[0xC];
|
||||
|
||||
// 10.0.0 and up.
|
||||
u8 console_6axis_sensor_mount_type;
|
||||
} __attribute__((packed)) nx_emmc_cal0_t;
|
||||
|
||||
#define MAGIC_CAL0 0x304C4143
|
||||
#define NX_EMMC_CALIBRATION_OFFSET 0x4400
|
||||
#define NX_EMMC_CALIBRATION_SIZE 0x8000
|
||||
#define XTS_CLUSTER_SIZE 0x4000
|
||||
|
||||
int nx_emmc_bis_read(u32 sector, u32 count, void *buff);
|
||||
int nx_emmc_bis_write(u32 sector, u32 count, void *buff);
|
||||
void nx_emmc_bis_cluster_cache_init();
|
||||
void nx_emmc_bis_init(emmc_part_t *part);
|
||||
void nx_emmc_bis_finalize();
|
||||
void nx_emmc_bis_cache_lock(bool lock);
|
||||
|
||||
#endif
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
* Copyright (c) 2018-2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <storage/nx_sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <storage/sdmmc_driver.h>
|
||||
#include <gfx_utils.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
|
||||
bool sd_mounted = false;
|
||||
static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
|
||||
static u32 sd_mode = SD_UHS_SDR82;
|
||||
|
||||
sdmmc_t sd_sdmmc;
|
||||
sdmmc_storage_t sd_storage;
|
||||
FATFS sd_fs;
|
||||
|
||||
void sd_error_count_increment(u8 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SD_ERROR_INIT_FAIL:
|
||||
sd_errors[0]++;
|
||||
break;
|
||||
case SD_ERROR_RW_FAIL:
|
||||
sd_errors[1]++;
|
||||
break;
|
||||
case SD_ERROR_RW_RETRY:
|
||||
sd_errors[2]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
u16 *sd_get_error_count()
|
||||
{
|
||||
return sd_errors;
|
||||
}
|
||||
|
||||
bool sd_get_card_removed()
|
||||
{
|
||||
if (!sdmmc_get_sd_inserted())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 sd_get_mode()
|
||||
{
|
||||
return sd_mode;
|
||||
}
|
||||
|
||||
int sd_init_retry(bool power_cycle)
|
||||
{
|
||||
u32 bus_width = SDMMC_BUS_WIDTH_4;
|
||||
u32 type = SDHCI_TIMING_UHS_SDR82;
|
||||
|
||||
// Power cycle SD card.
|
||||
if (power_cycle)
|
||||
{
|
||||
sd_mode--;
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
}
|
||||
|
||||
// Get init parameters.
|
||||
switch (sd_mode)
|
||||
{
|
||||
case SD_INIT_FAIL: // Reset to max.
|
||||
return 0;
|
||||
case SD_1BIT_HS25:
|
||||
bus_width = SDMMC_BUS_WIDTH_1;
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
case SD_4BIT_HS25:
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
case SD_UHS_SDR82:
|
||||
type = SDHCI_TIMING_UHS_SDR82;
|
||||
break;
|
||||
default:
|
||||
sd_mode = SD_UHS_SDR82;
|
||||
}
|
||||
|
||||
return sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, bus_width, type);
|
||||
}
|
||||
|
||||
bool sd_initialize(bool power_cycle)
|
||||
{
|
||||
if (power_cycle)
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
|
||||
int res = !sd_init_retry(false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!res)
|
||||
return true;
|
||||
else if (!sdmmc_get_sd_inserted()) // SD Card is not inserted.
|
||||
{
|
||||
sd_mode = SD_UHS_SDR82;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sd_errors[SD_ERROR_INIT_FAIL]++;
|
||||
|
||||
if (sd_mode == SD_INIT_FAIL)
|
||||
break;
|
||||
else
|
||||
res = !sd_init_retry(true);
|
||||
}
|
||||
}
|
||||
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_sd_inited = false;
|
||||
|
||||
bool sd_mount()
|
||||
{
|
||||
if (sd_mounted)
|
||||
return true;
|
||||
|
||||
int res = !sd_initialize(false);
|
||||
is_sd_inited = !res;
|
||||
|
||||
if (res)
|
||||
{
|
||||
gfx_con.mute = false;
|
||||
EPRINTF("Failed to init SD card.");
|
||||
if (!sdmmc_get_sd_inserted())
|
||||
EPRINTF("Make sure that it is inserted.");
|
||||
else
|
||||
EPRINTF("SD Card Reader is not properly seated!");
|
||||
}
|
||||
else
|
||||
{
|
||||
res = f_mount(&sd_fs, "", 1);
|
||||
if (res == FR_OK)
|
||||
{
|
||||
sd_mounted = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx_con.mute = false;
|
||||
EPRINTFARGS("Failed to mount SD card (FatFS Error %d).\nMake sure that a FAT partition exists..", res);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void _sd_deinit()
|
||||
{
|
||||
if (sd_mode == SD_INIT_FAIL)
|
||||
sd_mode = SD_UHS_SDR82;
|
||||
|
||||
if (sd_mounted)
|
||||
{
|
||||
f_mount(NULL, "", 1);
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
sd_mounted = false;
|
||||
is_sd_inited = false;
|
||||
}
|
||||
}
|
||||
|
||||
void sd_unmount() { _sd_deinit(); }
|
||||
void sd_end() { _sd_deinit(); }
|
||||
|
||||
void *sd_file_read(const char *path, u32 *fsize)
|
||||
{
|
||||
FIL fp;
|
||||
if (f_open(&fp, path, FA_READ) != FR_OK)
|
||||
return NULL;
|
||||
|
||||
u32 size = f_size(&fp);
|
||||
if (fsize)
|
||||
*fsize = size;
|
||||
|
||||
char *buf = malloc(size + 1);
|
||||
buf[size] = '\0';
|
||||
|
||||
if (f_read(&fp, buf, size, NULL) != FR_OK)
|
||||
{
|
||||
free(buf);
|
||||
f_close(&fp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f_close(&fp);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int sd_save_to_file(void *buf, u32 size, const char *filename)
|
||||
{
|
||||
FIL fp;
|
||||
u32 res = 0;
|
||||
res = f_open(&fp, filename, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (res)
|
||||
{
|
||||
EPRINTFARGS("Error (%d) creating file\n%s.\n", res, filename);
|
||||
return res;
|
||||
}
|
||||
|
||||
f_write(&fp, buf, size, NULL);
|
||||
f_close(&fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -5,22 +5,18 @@
|
||||
#include "tools.h"
|
||||
#include "../hid/hid.h"
|
||||
#include "../fs/menus/explorer.h"
|
||||
#include <utils/btn.h>
|
||||
#include <storage/nx_sd.h>
|
||||
#include "tconf.h"
|
||||
#include "../keys/keys.h"
|
||||
#include "../storage/mountmanager.h"
|
||||
#include "../storage/gptmenu.h"
|
||||
#include "../storage/emummc.h"
|
||||
#include <utils/util.h>
|
||||
#include "../fs/fsutils.h"
|
||||
#include <soc/fuse.h>
|
||||
#include "../utils/utils.h"
|
||||
#include "../config.h"
|
||||
#include "../fs/readers/folderReader.h"
|
||||
#include <string.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../fs/menus/filemenu.h"
|
||||
#include <bdk.h>
|
||||
|
||||
#define INCLUDE_BUILTIN_SCRIPTS 1
|
||||
//#define SCRIPT_ONLY 1
|
||||
@@ -131,8 +127,6 @@ void ViewCredits(){
|
||||
hidWait();
|
||||
}
|
||||
|
||||
extern bool sd_mounted;
|
||||
extern bool is_sd_inited;
|
||||
extern int launch_payload(char *path);
|
||||
|
||||
void RebootToAMS(){
|
||||
@@ -145,7 +139,7 @@ void RebootToHekate(){
|
||||
|
||||
void MountOrUnmountSD(){
|
||||
gfx_clearscreen();
|
||||
if (sd_mounted)
|
||||
if (sd_get_card_mounted())
|
||||
sd_unmount();
|
||||
else if (!sd_mount())
|
||||
hidWait();
|
||||
@@ -176,24 +170,24 @@ void EnterMainMenu(){
|
||||
|
||||
#ifndef SCRIPT_ONLY
|
||||
// -- Explore --
|
||||
mainMenuEntries[MainBrowseSd].hide = !sd_mounted;
|
||||
mainMenuEntries[MainMountSd].name = (sd_mounted) ? "Unmount SD" : "Mount SD";
|
||||
mainMenuEntries[MainBrowseEmummc].hide = (!emu_cfg.enabled || !sd_mounted);
|
||||
mainMenuEntries[MainBrowseSd].hide = !sd_get_card_mounted();
|
||||
mainMenuEntries[MainMountSd].name = (sd_get_card_mounted()) ? "Unmount SD" : "Mount SD";
|
||||
mainMenuEntries[MainBrowseEmummc].hide = (!emu_cfg.enabled || !sd_get_card_mounted());
|
||||
|
||||
// -- Tools --
|
||||
mainMenuEntries[MainPartitionSd].hide = (!is_sd_inited || sd_get_card_removed());
|
||||
mainMenuEntries[MainPartitionSd].hide = (!sd_get_card_initialized() || sd_get_card_removed());
|
||||
mainMenuEntries[MainViewKeys].hide = !TConf.keysDumped;
|
||||
|
||||
// -- Exit --
|
||||
mainMenuEntries[MainRebootAMS].hide = (!sd_mounted || !FileExists("sd:/atmosphere/reboot_payload.bin"));
|
||||
mainMenuEntries[MainRebootHekate].hide = (!sd_mounted || !FileExists("sd:/bootloader/update.bin"));
|
||||
mainMenuEntries[MainRebootAMS].hide = (!sd_get_card_mounted() || !FileExists("sd:/atmosphere/reboot_payload.bin"));
|
||||
mainMenuEntries[MainRebootHekate].hide = (!sd_get_card_mounted() || !FileExists("sd:/bootloader/update.bin"));
|
||||
mainMenuEntries[MainRebootRCM].hide = h_cfg.t210b01;
|
||||
#endif
|
||||
// -- Scripts --
|
||||
#ifndef INCLUDE_BUILTIN_SCRIPTS
|
||||
mainMenuEntries[MainScripts].hide = (!sd_mounted || !FileExists("sd:/tegraexplorer/scripts"));
|
||||
mainMenuEntries[MainScripts].hide = (!sd_get_card_mounted() || !FileExists("sd:/tegraexplorer/scripts"));
|
||||
#else
|
||||
mainMenuEntries[MainScripts].hide = ((!sd_mounted || !FileExists("sd:/tegraexplorer/scripts")) && !EMBEDDED_SCRIPTS_LEN);
|
||||
mainMenuEntries[MainScripts].hide = ((!sd_get_card_mounted() || !FileExists("sd:/tegraexplorer/scripts")) && !EMBEDDED_SCRIPTS_LEN);
|
||||
#endif
|
||||
|
||||
Vector_t ent = newVec(sizeof(MenuEntry_t), ARRAY_SIZE(mainMenuEntries));
|
||||
@@ -209,7 +203,7 @@ void EnterMainMenu(){
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sd_mounted && FileExists("sd:/tegraexplorer/scripts")){
|
||||
if (sd_get_card_mounted() && FileExists("sd:/tegraexplorer/scripts")){
|
||||
scriptFiles = ReadFolder("sd:/tegraexplorer/scripts", &res);
|
||||
if (!res){
|
||||
if (!scriptFiles.count){
|
||||
|
||||
@@ -3,21 +3,18 @@
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../gfx/menu.h"
|
||||
#include "../hid/hid.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../keys/keys.h"
|
||||
#include "../keys/nca.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../fs/fsutils.h"
|
||||
#include <utils/util.h>
|
||||
#include "../storage/mountmanager.h"
|
||||
#include "../err.h"
|
||||
#include <utils/sprintf.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
#include "../fs/readers/folderReader.h"
|
||||
#include <string.h>
|
||||
#include "../fs/fscopy.h"
|
||||
#include "../utils/utils.h"
|
||||
#include <bdk.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
|
||||
void DumpSysFw(){
|
||||
char sysPath[25 + 36 + 3 + 1]; // 24 for "bis:/Contents/registered", 36 for ncaName.nca, 3 for /00, and 1 to make sure :)
|
||||
@@ -118,7 +115,6 @@ void DumpSysFw(){
|
||||
}
|
||||
|
||||
extern sdmmc_storage_t sd_storage;
|
||||
extern bool is_sd_inited;
|
||||
|
||||
MenuEntry_t FatAndEmu[] = {
|
||||
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back to main menu"},
|
||||
@@ -133,7 +129,7 @@ void FormatSD(){
|
||||
bool emummc = 0;
|
||||
int res;
|
||||
|
||||
if (!is_sd_inited || sd_get_card_removed())
|
||||
if (!sd_get_card_initialized() || sd_get_card_removed())
|
||||
return;
|
||||
|
||||
gfx_printf("\nDo you want to partition for an emummc?\n");
|
||||
@@ -198,12 +194,10 @@ void FormatSD(){
|
||||
hidWait();
|
||||
}
|
||||
|
||||
extern bool sd_mounted;
|
||||
|
||||
void TakeScreenshot(){
|
||||
static u32 timer = 0;
|
||||
|
||||
if (!TConf.minervaEnabled || !sd_mounted)
|
||||
if (!TConf.minervaEnabled || !sd_get_card_mounted())
|
||||
return;
|
||||
|
||||
if (timer + 3 < get_tmr_s())
|
||||
|
||||
Reference in New Issue
Block a user