support file based/sd partition emusd
This commit is contained in:
@@ -345,6 +345,7 @@ namespace ams::nxboot {
|
|||||||
|
|
||||||
u32 sd_enabled = 0;
|
u32 sd_enabled = 0;
|
||||||
u32 sd_sector = 0;
|
u32 sd_sector = 0;
|
||||||
|
const char *sd_path = "";
|
||||||
|
|
||||||
{
|
{
|
||||||
IniSectionList sections;
|
IniSectionList sections;
|
||||||
@@ -360,17 +361,36 @@ namespace ams::nxboot {
|
|||||||
sd_enabled = ParseDecimalInteger(entry.value);
|
sd_enabled = ParseDecimalInteger(entry.value);
|
||||||
} else if (std::strcmp(entry.key, "sector") == 0) {
|
} else if (std::strcmp(entry.key, "sector") == 0) {
|
||||||
sd_sector = ParseHexInteger(entry.value);
|
sd_sector = ParseHexInteger(entry.value);
|
||||||
|
} else if (std::strcmp(entry.key, "path") ==0) {
|
||||||
|
sd_path = entry.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set parsed values to config */
|
if (sd_enabled == 1) {
|
||||||
if (sd_enabled == 4) {
|
/* SD based */
|
||||||
if (sd_sector > 0) {
|
if (sd_sector > 0) {
|
||||||
|
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_Partition_Sd;
|
||||||
sd_cfg.partition_cfg.start_sector = sd_sector;
|
sd_cfg.partition_cfg.start_sector = sd_sector;
|
||||||
|
} else if (sd_path[0] != '\x00' && IsDirectoryExist(sd_path)) {
|
||||||
|
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_File_Sd;
|
||||||
|
std::strncpy(sd_cfg.file_cfg.path.str, sd_path, sizeof(sd_cfg.file_cfg.path.str));
|
||||||
|
sd_cfg.file_cfg.path.str[sizeof(sd_cfg.file_cfg.path.str) - 1] = '\x00';
|
||||||
|
} else {
|
||||||
|
ShowFatalError(emusd_err_str);
|
||||||
|
}
|
||||||
|
} else if (sd_enabled == 4){
|
||||||
|
/* eMMC based */
|
||||||
|
if (sd_sector > 0) {
|
||||||
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_Partition_Emmc;
|
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_Partition_Emmc;
|
||||||
|
sd_cfg.partition_cfg.start_sector = sd_sector;
|
||||||
|
} else if (sd_path[0] != '\x00' /* && IsDirectoryExist(path) */) {
|
||||||
|
/* TODO: Should check if directory exist on *eMMC* fat partition instead of SD */
|
||||||
|
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_File_Emmc;
|
||||||
|
std::strncpy(sd_cfg.file_cfg.path.str, sd_path, sizeof(sd_cfg.file_cfg.path.str));
|
||||||
|
sd_cfg.file_cfg.path.str[sizeof(sd_cfg.file_cfg.path.str) - 1] = '\x00';
|
||||||
} else {
|
} else {
|
||||||
ShowFatalError(emusd_err_str);
|
ShowFatalError(emusd_err_str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "fusee_malloc.hpp"
|
#include "fusee_malloc.hpp"
|
||||||
#include "fusee_mmc.hpp"
|
#include "fusee_mmc.hpp"
|
||||||
#include <exosphere.hpp>
|
#include <exosphere.hpp>
|
||||||
|
#include <exosphere/secmon/secmon_emummc_context.hpp>
|
||||||
|
|
||||||
namespace ams::nxboot {
|
namespace ams::nxboot {
|
||||||
|
|
||||||
@@ -46,18 +47,25 @@ namespace ams::nxboot {
|
|||||||
|
|
||||||
void InitializeEmuSd(const secmon::EmummcSdConfiguration &emusd_cfg) {
|
void InitializeEmuSd(const secmon::EmummcSdConfiguration &emusd_cfg) {
|
||||||
if (emusd_cfg.IsActive()) {
|
if (emusd_cfg.IsActive()) {
|
||||||
if (emusd_cfg.base_cfg.type == secmon::EmummcSdType_Partition_Emmc) {
|
if (emusd_cfg.base_cfg.type == secmon::EmummcSdType_Partition_Emmc || emusd_cfg.base_cfg.type == secmon::EmummcSdType_Partition_Sd) {
|
||||||
|
/* Partition based */
|
||||||
Result r;
|
Result r;
|
||||||
if (R_FAILED(r = InitializeMmc())) {
|
if (emusd_cfg.base_cfg.type == secmon::EmummcSdType_Partition_Sd) {
|
||||||
ShowFatalError("Failed to initializeMmc: %" PRIx32 "!\n", r.GetValue());
|
if (R_FAILED(r = InitializeSdCard())) {
|
||||||
|
ShowFatalError("Failed to initialize SD Card: %" PRIx32 "!\n", r.GetValue());
|
||||||
|
}
|
||||||
|
g_emusd_base_storage = AllocateObject<fs::SdCardStorage>();
|
||||||
|
} else {
|
||||||
|
if (R_FAILED(r = InitializeMmc())) {
|
||||||
|
ShowFatalError("Failed to initialize eMMC: %" PRIx32 "!\n", r.GetValue());
|
||||||
|
}
|
||||||
|
g_emusd_base_storage = AllocateObject<fs::MmcPartitionStorage<sdmmc::MmcPartition_UserData>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_emusd_base_storage = AllocateObject<fs::MmcPartitionStorage<sdmmc::MmcPartition_UserData>>();
|
|
||||||
|
|
||||||
/* Get base storage size */
|
/* Get base storage size */
|
||||||
s64 size;
|
s64 size;
|
||||||
if(R_FAILED(g_emusd_base_storage->GetSize(std::addressof(size)))) {
|
if(R_FAILED(g_emusd_base_storage->GetSize(std::addressof(size)))) {
|
||||||
ShowFatalError("Failed to get eMMC size!");
|
ShowFatalError("Failed to get size!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read emuSD size from mbr */
|
/* Read emuSD size from mbr */
|
||||||
@@ -76,8 +84,43 @@ namespace ams::nxboot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_emusd_storage = AllocateObject<fs::SubStorage>(*g_emusd_base_storage, offset, emusd_size);
|
g_emusd_storage = AllocateObject<fs::SubStorage>(*g_emusd_base_storage, offset, emusd_size);
|
||||||
|
} else if(emusd_cfg.base_cfg.type == secmon::EmummcSdType_File_Emmc || emusd_cfg.base_cfg.type == secmon::EmummcSdType_File_Sd) {
|
||||||
|
/* File based */
|
||||||
|
Result r;
|
||||||
|
if(emusd_cfg.base_cfg.type == secmon::EmummcSdType_File_Emmc) {
|
||||||
|
/* When emmc based, init eMMC */
|
||||||
|
if (R_FAILED((r = InitializeMmc()))) {
|
||||||
|
ShowFatalError("Failed to initialize mmc: 0x%08" PRIx32 "\n", r.GetValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::MountSys()) {
|
||||||
|
ShowFatalError("Failed to mount mmc!\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* When sd based, init sd */
|
||||||
|
if (R_FAILED((r = InitializeSdCard ()))) {
|
||||||
|
ShowFatalError("Failed to initialize sd: 0x%08" PRIx32 "\n", r.GetValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::MountSdCard()) {
|
||||||
|
ShowFatalError("Failed to mount sd!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char path[0xa0];
|
||||||
|
if (emusd_cfg.base_cfg.type == secmon::EmummcSdType_File_Emmc) {
|
||||||
|
memcpy(path, "sys:", 5);
|
||||||
|
} else {
|
||||||
|
memcpy(path, "sdmc:", 6);
|
||||||
|
}
|
||||||
|
memcpy(path + strlen(path), emusd_cfg.file_cfg.path.str, sizeof(emusd_cfg.file_cfg.path.str));
|
||||||
|
memcpy(path + strlen(path), "/SD/", 5);
|
||||||
|
path[sizeof(path) - 1] = '\x00';
|
||||||
|
|
||||||
|
g_emusd_storage = AllocateObject<fs::MultiFileStorage>(path);
|
||||||
|
} else {
|
||||||
|
ShowFatalError("Invalid emuSD config!\n");
|
||||||
}
|
}
|
||||||
/* TODO: support other emusd types */
|
|
||||||
} else {
|
} else {
|
||||||
const Result r = InitializeSdCard();
|
const Result r = InitializeSdCard();
|
||||||
if (R_FAILED(r)) {
|
if (R_FAILED(r)) {
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ namespace ams::nxboot {
|
|||||||
/* UnmountBootStorage(); */
|
/* UnmountBootStorage(); */
|
||||||
FinalizeBootStorage();
|
FinalizeBootStorage();
|
||||||
InitializeEmuSd(GetEmummcConfig().sd_cfg);
|
InitializeEmuSd(GetEmummcConfig().sd_cfg);
|
||||||
fs::ChangeDrive("emusd:");
|
Result r = fs::ChangeDrive("emusd:");
|
||||||
if (!fs::MountEmuSD()) {
|
if (!fs::MountEmuSD()) {
|
||||||
ShowFatalError("Failed to mount emuSD");
|
ShowFatalError("Failed to mount emuSD 0x%" PRIx32 "\n", r.GetValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user