From af3613b521e990eeb8f3daf43d3904d5b4e817c2 Mon Sep 17 00:00:00 2001 From: NaGa Date: Wed, 8 Apr 2026 16:56:50 +0200 Subject: [PATCH] emuSD/Boot fix --- emummc/source/emuMMC/emummc.c | 21 ++++++++++++++------- emummc/source/main.c | 13 ++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/emummc/source/emuMMC/emummc.c b/emummc/source/emuMMC/emummc.c index aeba5a8ae..967ed192d 100644 --- a/emummc/source/emuMMC/emummc.c +++ b/emummc/source/emuMMC/emummc.c @@ -458,7 +458,7 @@ static void _file_based_sd_initialize(void) if (f_emu_sd.parts == 1) f_emu_sd.parts = 0; - return; + break; } if(!f_expand_cltbl(&f_emu_sd.fp[f_emu_sd.parts], EMUSD_FP_CLMT_COUNT, &f_emu_sd.clmt[f_emu_sd.parts][0], f_size(&f_emu_sd.fp[f_emu_sd.parts]))){ @@ -513,8 +513,13 @@ static void _file_based_emmc_finalize(void) f_close(&f_emu.fp_boot0); f_close(&f_emu.fp_boot1); - for (int i = 0; i < f_emu.parts; i++) - f_close(&f_emu.fp_gpp[i]); + { + int i = 0; + do { + f_close(&f_emu.fp_gpp[i]); + i++; + } while (i < f_emu.parts); + } // Force unmount FAT volume. if (emuMMC_ctx.EMMC_Type == EmummcType_File_Emmc) { @@ -532,9 +537,11 @@ static void _file_based_sd_finalize(void) { if((emuMMC_ctx.SD_Type == EmummcType_File_Emmc || emuMMC_ctx.SD_Type == EmummcType_File_Sd) && file_based_sd_initialized){ _ensure_correct_partition(FS_SDMMC_SD); - for(int i = 0; i < f_emu_sd.parts; i++){ + int i = 0; + do { f_close(&f_emu_sd.fp[i]); - } + i++; + } while(i < f_emu_sd.parts); if(emuMMC_ctx.SD_Type == EmummcType_File_Emmc) { _mount_emmc(false); @@ -716,7 +723,7 @@ static void _file_based_emmc_initialize(void) if (f_emu.parts == 1) f_emu.parts = 0; - return; + break; } if (!f_expand_cltbl(&f_emu.fp_gpp[f_emu.parts], EMUMMC_FP_CLMT_COUNT, @@ -1052,7 +1059,7 @@ static uint64_t emummc_read_write_sd_inner(void *buf, unsigned int sector, unsig goto out; } } else { - fp = &f_emu.fp_gpp[0]; + fp = &f_emu_sd.fp[0]; } diff --git a/emummc/source/main.c b/emummc/source/main.c index eadd5a3a4..ffe1d32fc 100644 --- a/emummc/source/main.c +++ b/emummc/source/main.c @@ -344,7 +344,18 @@ static bool load_emummc_sd_ctx(void) { exo_emummc_config_t config; __attribute__((aligned(0x1000))) exo_emummc_paths_t paths; - load_emummc_cfg(EXO_EMUMMC_MMC_SD, &config, &paths); + // Try to get SD config. Official Atmosphere exosphere does not support + // EXO_EMUMMC_MMC_SD and returns SmcResult::NotSupported. In that case, + // fall through to the default SD behavior (no SD redirection). + int x = smcGetEmummcConfig(EXO_EMUMMC_MMC_SD, &config, &paths); + if(x != 0) { + DEBUG_LOG("GetEmummcConfig SD smc not supported, using defaults\n"); + emuMMC_ctx.SD_Type = EmummcType_Partition_Sd; + emuMMC_ctx.SD_StoragePartitionOffset = 0; + emuMMC_ctx.fs_ver = FS_VER_MAX; + emuMMC_ctx.magic = (u32)-1; + return false; + } if (config.base_cfg.magic == EMUMMC_STORAGE_MAGIC) { emuMMC_ctx.magic = config.base_cfg.magic;