diff --git a/fusee/program/source/fusee_emummc.cpp b/fusee/program/source/fusee_emummc.cpp index cc1e9d7d6..9b71a787c 100644 --- a/fusee/program/source/fusee_emummc.cpp +++ b/fusee/program/source/fusee_emummc.cpp @@ -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); } diff --git a/fusee/program/source/fusee_emusd.cpp b/fusee/program/source/fusee_emusd.cpp index b5304b55e..87ac396ea 100644 --- a/fusee/program/source/fusee_emusd.cpp +++ b/fusee/program/source/fusee_emusd.cpp @@ -19,6 +19,7 @@ #include "fusee_malloc.hpp" #include "fusee_mmc.hpp" #include +#include 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(); + } else { + if (R_FAILED(r = InitializeMmc())) { + ShowFatalError("Failed to initialize eMMC: %" PRIx32 "!\n", r.GetValue()); + } + g_emusd_base_storage = AllocateObject>(); } - g_emusd_base_storage = AllocateObject>(); - /* 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(*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(path); + } else { + ShowFatalError("Invalid emuSD config!\n"); } - /* TODO: support other emusd types */ } else { const Result r = InitializeSdCard(); if (R_FAILED(r)) { diff --git a/fusee/program/source/fusee_main.cpp b/fusee/program/source/fusee_main.cpp index df119a976..ccf02d5cd 100644 --- a/fusee/program/source/fusee_main.cpp +++ b/fusee/program/source/fusee_main.cpp @@ -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()); } } }