support file based/sd partition emusd

This commit is contained in:
Christoph Baumann
2025-05-20 20:57:35 +02:00
parent 178c833862
commit b301bba5e7
3 changed files with 74 additions and 11 deletions

View File

@@ -345,6 +345,7 @@ namespace ams::nxboot {
u32 sd_enabled = 0;
u32 sd_sector = 0;
const char *sd_path = "";
{
IniSectionList sections;
@@ -360,17 +361,36 @@ namespace ams::nxboot {
sd_enabled = ParseDecimalInteger(entry.value);
} else if (std::strcmp(entry.key, "sector") == 0) {
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 == 4) {
if (sd_enabled == 1) {
/* SD based */
if (sd_sector > 0) {
sd_cfg.base_cfg.type = secmon::EmummcSdType::EmummcSdType_Partition_Sd;
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.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 {
ShowFatalError(emusd_err_str);
}

View File

@@ -19,6 +19,7 @@
#include "fusee_malloc.hpp"
#include "fusee_mmc.hpp"
#include <exosphere.hpp>
#include <exosphere/secmon/secmon_emummc_context.hpp>
namespace ams::nxboot {
@@ -46,18 +47,25 @@ namespace ams::nxboot {
void InitializeEmuSd(const secmon::EmummcSdConfiguration &emusd_cfg) {
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;
if (R_FAILED(r = InitializeMmc())) {
ShowFatalError("Failed to initializeMmc: %" PRIx32 "!\n", r.GetValue());
if (emusd_cfg.base_cfg.type == secmon::EmummcSdType_Partition_Sd) {
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 */
s64 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 */
@@ -76,8 +84,43 @@ namespace ams::nxboot {
}
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 {
const Result r = InitializeSdCard();
if (R_FAILED(r)) {

View File

@@ -75,9 +75,9 @@ namespace ams::nxboot {
/* UnmountBootStorage(); */
FinalizeBootStorage();
InitializeEmuSd(GetEmummcConfig().sd_cfg);
fs::ChangeDrive("emusd:");
Result r = fs::ChangeDrive("emusd:");
if (!fs::MountEmuSD()) {
ShowFatalError("Failed to mount emuSD");
ShowFatalError("Failed to mount emuSD 0x%" PRIx32 "\n", r.GetValue());
}
}
}