support for file based and sd partition based emusd

This commit is contained in:
Christoph Baumann
2025-05-20 00:40:48 +02:00
parent 865b9dc1a4
commit 9b95d026f3
25 changed files with 1691 additions and 294 deletions

View File

@@ -782,9 +782,15 @@ void hos_launch(ini_sec_t *cfg)
goto error;
}
gfx_con.mute = false;
if (emusd_storage_init_mmc() || !emusd_mount()) {
_hos_crit_error("error: Failed to init emuSD.");
goto error;
}
// Check if SD Card is GPT.
// TODO: not relevant with emuSD
if (sd_is_gpt())
if (emusd_is_gpt())
{
_hos_crit_error("SD has GPT only! Run Fix Hybrid MBR!");
goto error;
@@ -804,6 +810,8 @@ void hos_launch(ini_sec_t *cfg)
if (ctxt.stock && (h_cfg.t210b01 || !tools_autorcm_enabled()))
{
sdram_src_pllc(false);
emummc_storage_end();
emusd_storage_end();
emmc_end();
WPRINTF("\nRebooting to OFW in 5s...");
@@ -1053,7 +1061,7 @@ void hos_launch(ini_sec_t *cfg)
{
bool exfat_compat = _get_fs_exfat_compatible(&kip1_info, &ctxt.exo_ctx.hos_revision);
if (sd_fs.fs_type == FS_EXFAT && !exfat_compat)
if (emusd_get_fs_type() == FS_EXFAT && !exfat_compat)
{
_hos_crit_error("SD Card is exFAT but installed HOS driver\nonly supports FAT32!");
@@ -1086,6 +1094,8 @@ void hos_launch(ini_sec_t *cfg)
config_exosphere(&ctxt, warmboot_base);
// Unmount SD card and eMMC.
emummc_storage_end();
emusd_storage_end();
boot_storage_end();
sd_end();
emmc_end();
@@ -1201,6 +1211,8 @@ void hos_launch(ini_sec_t *cfg)
error:
_free_launch_components(&ctxt);
sdram_src_pllc(false);
emummc_storage_end();
emusd_storage_end();
emmc_end();
EPRINTF("\nFailed to launch HOS!");

View File

@@ -16,6 +16,7 @@
*/
#include <storage/boot_storage.h>
#include "../storage/emusd.h"
#include <string.h>
#include <bdk.h>
@@ -30,7 +31,7 @@
static int _config_warmboot(launch_ctxt_t *ctxt, const char *value)
{
ctxt->warmboot = boot_storage_file_read(value, &ctxt->warmboot_size);
ctxt->warmboot = emusd_file_read(value, &ctxt->warmboot_size);
if (!ctxt->warmboot)
return 0;
@@ -39,7 +40,7 @@ static int _config_warmboot(launch_ctxt_t *ctxt, const char *value)
static int _config_secmon(launch_ctxt_t *ctxt, const char *value)
{
ctxt->secmon = boot_storage_file_read(value, &ctxt->secmon_size);
ctxt->secmon = emusd_file_read(value, &ctxt->secmon_size);
if (!ctxt->secmon)
return 0;
@@ -48,7 +49,7 @@ static int _config_secmon(launch_ctxt_t *ctxt, const char *value)
static int _config_kernel(launch_ctxt_t *ctxt, const char *value)
{
ctxt->kernel = boot_storage_file_read(value, &ctxt->kernel_size);
ctxt->kernel = emusd_file_read(value, &ctxt->kernel_size);
if (!ctxt->kernel)
return 0;
@@ -62,7 +63,8 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
if (value[strlen(value) - 1] == '*')
{
char *dir = (char *)malloc(256);
strcpy(dir, value);
strcpy(dir, "emusd:");
strcat(dir, value);
u32 dirlen = 0;
dir[strlen(dir) - 2] = 0;
@@ -82,7 +84,7 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
strcpy(dir + dirlen, filelist->name[i]);
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
mkip1->kip1 = boot_storage_file_read(dir, &size);
mkip1->kip1 = emusd_file_read(dir + 6, &size);
if (!mkip1->kip1)
{
free(mkip1);
@@ -104,7 +106,7 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
else
{
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
mkip1->kip1 = boot_storage_file_read(value, &size);
mkip1->kip1 = emusd_file_read(value, &size);
if (!mkip1->kip1)
{
free(mkip1);
@@ -263,7 +265,7 @@ static int _config_pkg3(launch_ctxt_t *ctxt, const char *value)
static int _config_exo_fatal_payload(launch_ctxt_t *ctxt, const char *value)
{
ctxt->exofatal = boot_storage_file_read(value, &ctxt->exofatal_size);
ctxt->exofatal = emusd_file_read(value, &ctxt->exofatal_size);
if (!ctxt->exofatal)
return 0;

View File

@@ -18,6 +18,7 @@
*/
#include <storage/boot_storage.h>
#include "../storage/emusd.h"
#include <string.h>
#include <stdlib.h>
@@ -370,13 +371,13 @@ int pkg1_warmboot_config(void *hos_ctxt, u32 warmboot_base, u32 fuses_fw, u8 kb)
if (!ctxt->warmboot)
{
char path[128];
strcpy(path, "warmboot_mariko/wb_");
strcpy(path, "emusd:warmboot_mariko/wb_");
_warmboot_filename(path, fuses_fw);
// Check if warmboot fw exists and save it.
if (ctxt->warmboot_size && f_stat(path, NULL))
{
f_mkdir("warmboot_mariko");
f_mkdir("emusd:warmboot_mariko");
sd_save_to_file((void *)warmboot_base, ctxt->warmboot_size, path);
}
@@ -389,7 +390,7 @@ int pkg1_warmboot_config(void *hos_ctxt, u32 warmboot_base, u32 fuses_fw, u8 kb)
_warmboot_filename(path, burnt_fuses);
if (!f_stat(path, NULL))
{
ctxt->warmboot = boot_storage_file_read(path, &ctxt->warmboot_size);
ctxt->warmboot = emusd_file_read(path + 6, &ctxt->warmboot_size);
burnt_fuses = tmp_fuses;
break;
}

View File

@@ -77,6 +77,7 @@ static void parse_external_kip_patches()
return;
LIST_INIT(ini_kip_sections);
// TODO: load frome emusd?
if (ini_patch_parse(&ini_kip_sections, "bootloader/patches.ini"))
{
// Copy ids into a new patchset.

View File

@@ -17,6 +17,7 @@
*/
#include <storage/boot_storage.h>
#include "../storage/emusd.h"
#include <string.h>
#include <bdk.h>
@@ -87,9 +88,9 @@ typedef struct _pkg3_content_t
static void _pkg3_update_r2p()
{
u8 *r2p_payload = boot_storage_file_read("atmosphere/reboot_payload.bin", NULL);
u8 *r2p_payload = emusd_file_read("atmosphere/reboot_payload.bin", NULL);
is_ipl_updated(r2p_payload, "atmosphere/reboot_payload.bin", h_cfg.updater2p ? true : false);
is_ipl_updated(r2p_payload, "emusd:atmosphere/reboot_payload.bin", h_cfg.updater2p ? true : false);
free(r2p_payload);
}
@@ -127,6 +128,10 @@ static int _pkg3_kip1_skip(char ***pkg3_kip1_skip, u32 *pkg3_kip1_skip_num, char
int parse_pkg3(launch_ctxt_t *ctxt, const char *path)
{
char *path1 = (char *)malloc(256);
strcpy(path1, "emusd:");
strcat(path1, path);
FIL fp;
char **pkg3_kip1_skip = NULL;
@@ -154,16 +159,25 @@ int parse_pkg3(launch_ctxt_t *ctxt, const char *path)
}
#ifdef HOS_MARIKO_STOCK_SECMON
if (stock && emummc_disabled && (pkg1_old || h_cfg.t210b01))
if (stock && emummc_disabled && (pkg1_old || h_cfg.t210b01)) {
free(path1);
return 1;
}
#else
if (stock && emummc_disabled && pkg1_old)
if (stock && emummc_disabled && pkg1_old) {
free(path1);
return 1;
}
#endif
// Try to open PKG3.
if (f_open(&fp, path, FA_READ) != FR_OK)
if (f_open(&fp, path1, FA_READ) != FR_OK) {
free(path1);
return 0;
}
void *pkg3 = malloc(f_size(&fp));
@@ -269,6 +283,7 @@ int parse_pkg3(launch_ctxt_t *ctxt, const char *path)
_pkg3_update_r2p();
free(pkg3_kip1_skip);
free(path1);
return 1;
}

View File

@@ -77,6 +77,7 @@ typedef struct
union
{
emummc_partition_config_t partition_cfg;
emummc_file_config_t file_cfg;
};
} emummc_sd_config_t;
@@ -226,7 +227,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base)
if (!ctxt->stock)
{
LIST_INIT(ini_exo_sections);
if (ini_parse(&ini_exo_sections, "exosphere.ini", false))
if (ini_parse(&ini_exo_sections, "emusd:exosphere.ini", false))
{
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_exo_sections, link)
{
@@ -265,7 +266,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base)
if (!ctxt->exo_ctx.usb3_force)
{
LIST_INIT(ini_sys_sections);
if (ini_parse(&ini_sys_sections, "atmosphere/config/system_settings.ini", false))
if (ini_parse(&ini_sys_sections, "emusd:atmosphere/config/system_settings.ini", false))
{
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sys_sections, link)
{
@@ -375,12 +376,27 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base)
{
exo_cfg->emummc_cfg.sd_cfg.base_cfg.fs_ver = emu_sd_cfg.fs_ver;
exo_cfg->emummc_cfg.sd_cfg.partition_cfg.start_sector = emu_sd_cfg.sector;
if(emu_sd_cfg.enabled == 4 && emu_sd_cfg.sector) {
if (emu_sd_cfg.enabled == 4 && emu_sd_cfg.sector) {
// emmc partition based
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_Partition_Emmc;
}else {
} else if (emu_sd_cfg.enabled == 4 && !emu_sd_cfg.sector) {
// emmc file based
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_File_Emmc;
} else if (emu_sd_cfg.enabled == 1 && emu_sd_cfg.sector) {
// sd partition based
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_Partition_Sd;
} else if (emu_sd_cfg.enabled == 1 && !emu_sd_cfg.sector) {
// sd file based
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_File_Sd;
} else {
// disabled
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_None;
}
if (emu_sd_cfg.sector)
exo_cfg->emummc_cfg.sd_cfg.partition_cfg.start_sector = emu_sd_cfg.sector;
else
strcpy((char *)exo_cfg->emummc_cfg.sd_cfg.file_cfg.path, emu_sd_cfg.path);
} else {
exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_None;
}

View File

@@ -7,9 +7,9 @@
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "../../storage/emusd.h"
#include <storage/sd.h>
#include <storage/sdmmc.h>
#include <string.h>
#include <bdk.h>
@@ -28,6 +28,8 @@ static bool ensure_partition(BYTE pdrv){
case DRIVE_EMMC:
part = EMMC_GPP;
break;
case DRIVE_EMUSD:
return true;
default:
return false;
}
@@ -86,6 +88,9 @@ DRESULT disk_read (
storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512);
break;
case DRIVE_EMUSD:
return emusd_storage_read(sector, count, buff) ? RES_OK : RES_ERROR;
break;
default:
return RES_ERROR;
@@ -122,6 +127,8 @@ DRESULT disk_write (
storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512);
break;
case DRIVE_EMUSD:
return emusd_storage_write(sector, count, (void*)buff) ? RES_OK : RES_ERROR;
default:
return RES_ERROR;

View File

@@ -179,12 +179,12 @@
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
#define FF_VOLUMES 4
#define FF_VOLUMES 5
/* Number of volumes (logical drives) to be used. (1-10) */
#define FF_STR_VOLUME_ID 1
#define FF_VOLUME_STRS "sd", "boot1", "boot1_1mb", "emmc"
#define FF_VOLUME_STRS "sd", "boot1", "boot1_1mb", "emmc", "emusd"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
@@ -306,6 +306,7 @@ typedef enum {
DRIVE_BOOT1 = 1,
DRIVE_BOOT1_1MB = 2,
DRIVE_EMMC = 3,
DRIVE_EMUSD = 4,
} DDRIVE;
/*--- End of configuration options ---*/

View File

@@ -418,7 +418,8 @@ static void _launch_ini_list()
}
if (emusd_path && !emusd_set_path(emusd_path)){
EPRINTF("emusdpath is wrong!");
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}
}
@@ -579,7 +580,8 @@ static void _launch_config()
if (emusd_path && !emusd_set_path(emusd_path))
{
EPRINTF("emusdpath is wrong!");
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}
}
@@ -1056,7 +1058,8 @@ skip_list:
if (emusd_path && !emusd_set_path(emusd_path))
{
gfx_con.mute = false;
EPRINTF("emusdpath is wrong!");
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}

View File

@@ -24,7 +24,6 @@
#include "emummc.h"
#include "../config.h"
#include "gfx_utils.h"
#include <libs/fatfs/ff.h>
#include <storage/emummc_file_based.h>
@@ -174,11 +173,6 @@ static int emummc_raw_get_part_off(int part_idx)
int emummc_storage_init_mmc()
{
gfx_con.mute = false;
gfx_printf("en %d path %s\n", emu_cfg.enabled, emu_cfg.path);
// FILINFO fno;
emu_cfg.active_part = 0;
@@ -263,33 +257,6 @@ int emummc_storage_read(u32 sector, u32 num_sectors, void *buf)
else
{
return emummc_storage_file_based_read(sector, num_sectors, buf);
// if (!emu_cfg.active_part)
// {
// u32 file_part = sector / emu_cfg.file_based_part_size;
// sector = sector % emu_cfg.file_based_part_size;
// if (file_part >= 10)
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
// else
// {
// emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
// 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_READ))
// {
// EPRINTF("Failed to open emuMMC image.");
// return 0;
// }
// f_lseek(&fp, (u64)sector << 9);
// if (f_read(&fp, buf, (u64)num_sectors << 9, NULL))
// {
// EPRINTF("Failed to read emuMMC image.");
// f_close(&fp);
// return 0;
// }
// f_close(&fp);
// return 1;
}
return 1;
@@ -310,31 +277,6 @@ int emummc_storage_write(u32 sector, u32 num_sectors, void *buf)
else
{
return emummc_storage_file_based_write(sector, num_sectors, buf);
// if (!emu_cfg.active_part)
// {
// u32 file_part = sector / emu_cfg.file_based_part_size;
// sector = sector % emu_cfg.file_based_part_size;
// if (file_part >= 10)
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
// else
// {
// emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
// 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))
// return 0;
// f_lseek(&fp, (u64)sector << 9);
// if (f_write(&fp, buf, (u64)num_sectors << 9, NULL))
// {
// f_close(&fp);
// return 0;
// }
// f_close(&fp);
// return 1;
}
}

View File

@@ -1,9 +1,26 @@
#include "emusd.h"
#include <bdk.h>
#include <storage/boot_storage.h>
#include <storage/emmc.h>
#include <storage/file_based_storage.h>
#include <storage/sd.h>
#include <storage/sdmmc.h>
#include <string.h>
#include <utils/ini.h>
#include <libs/fatfs/ff.h>
#include "../config.h"
#include "gfx_utils.h"
FATFS emusd_fs;
bool emusd_mounted = false;
bool emusd_initialized = false;
emusd_cfg_t emu_sd_cfg = {0};
extern hekate_config h_cfg;
static bool emusd_get_mounted() {
return emusd_mounted;
}
void emusd_load_cfg()
{
@@ -14,7 +31,7 @@ void emusd_load_cfg()
if(!emu_sd_cfg.path) {
emu_sd_cfg.path = (char*)malloc(0x200);
}
if(emu_sd_cfg.emummc_file_based_path){
if(!emu_sd_cfg.emummc_file_based_path){
emu_sd_cfg.emummc_file_based_path = (char*)malloc(0x200);
}
@@ -35,6 +52,8 @@ void emusd_load_cfg()
emu_sd_cfg.enabled = atoi(kv->val);
} else if(!strcmp(kv->key, "sector")){
emu_sd_cfg.sector = strtol(kv->val, NULL, 16);
} else if(!strcmp(kv->key, "path")){
emu_sd_cfg.path = kv->val;
}
}
break;
@@ -43,19 +62,46 @@ void emusd_load_cfg()
}
}
bool emusd_mount() {
if (emusd_mounted) {
return true;
}
if (emusd_storage_init_mmc()){
return false;
}
int res = f_mount(&emusd_fs, "emusd:", 1);
if(res) {
EPRINTFARGS("emusd mount fail %d", res);
return false;
}
return true;
}
bool emusd_unmount() {
f_mount(NULL, "emusd:", 1);
emusd_mounted = false;
return true;
}
bool emusd_set_path(char *path) {
gfx_con.mute = false;
FIL fp;
bool found = false;
char sd_path[0x80];
// TODO: use emu_sd.file_path instead
strcpy(sd_path, path);
strcat(sd_path, "/raw_emmc_based");
if(!f_open(&fp, sd_path, FA_READ))
strcat(emu_sd_cfg.emummc_file_based_path, "");
strcpy(emu_sd_cfg.emummc_file_based_path, path);
strcat(emu_sd_cfg.emummc_file_based_path, "/raw_emmc_based");
gfx_printf("1 %s \n", emu_sd_cfg.emummc_file_based_path);
if(!f_open(&fp, emu_sd_cfg.emummc_file_based_path, FA_READ))
{
gfx_printf("open done\n");
if(!f_read(&fp, &emu_sd_cfg.sector, 4, NULL)){
gfx_printf("found sct\n");
if(emu_sd_cfg.sector){
gfx_printf("!=0\n");
found = true;
emu_sd_cfg.enabled = 4;
goto out;
@@ -63,8 +109,198 @@ bool emusd_set_path(char *path) {
}
}
// TODO: file based / SD partition based support
strcpy(emu_sd_cfg.emummc_file_based_path, "");
strcat(emu_sd_cfg.emummc_file_based_path, path);
strcat(emu_sd_cfg.emummc_file_based_path, "/raw_emmc_based");
gfx_printf("1 %s \n", emu_sd_cfg.emummc_file_based_path);
if (!f_open(&fp, emu_sd_cfg.emummc_file_based_path, FA_READ))
{
gfx_printf("open done\n");
if (!f_read(&fp, &emu_sd_cfg.sector, 4, NULL)){
gfx_printf("found sct\n");
if (emu_sd_cfg.sector){
gfx_printf("!=0\n");
found = true;
emu_sd_cfg.enabled = 4;
goto out;
}
}
}
out:
// strcpy(emu_sd_cfg.emummc_file_based_path, "sd:");
strcpy(emu_sd_cfg.emummc_file_based_path, "");
strcat(emu_sd_cfg.emummc_file_based_path, path);
strcat(emu_sd_cfg.emummc_file_based_path, "/file_based");
gfx_printf("1 %s \n", emu_sd_cfg.emummc_file_based_path);
if (!f_stat(emu_sd_cfg.emummc_file_based_path, NULL))
{
gfx_printf("open done\n");
emu_sd_cfg.sector = 0;
emu_sd_cfg.path = path;
emu_sd_cfg.enabled = 1;
gfx_printf("path %s\n", emu_sd_cfg.path);
found = true;
goto out;
}
// strcpy(emu_sd_cfg.emummc_file_based_path, "sd:");
strcpy(emu_sd_cfg.emummc_file_based_path, "");
strcat(emu_sd_cfg.emummc_file_based_path, path);
strcat(emu_sd_cfg.emummc_file_based_path, "/file_emmc_based");
gfx_printf("1 %s \n", emu_sd_cfg.emummc_file_based_path);
if (!f_stat(emu_sd_cfg.emummc_file_based_path, NULL))
{
gfx_printf("open done\n");
emu_sd_cfg.sector = 0;
emu_sd_cfg.path = path;
emu_sd_cfg.enabled = 4;
gfx_printf("path %s\n", emu_sd_cfg.path);
found = true;
goto out;
}
out:
return found;
}
int emusd_storage_init_mmc() {
if(!emusd_initialized) {
if (!emu_sd_cfg.enabled || h_cfg.emummc_force_disable) {
return 0;
}
bool file_based = false;
if(emu_sd_cfg.enabled == 4){
if(!emu_sd_cfg.sector){
//file based
if(!emmc_mount()){
return 1;
}
strcpy(emu_sd_cfg.emummc_file_based_path, "emmc:");
strcat(emu_sd_cfg.emummc_file_based_path, emu_sd_cfg.path);
strcat(emu_sd_cfg.emummc_file_based_path, "/SD/");
file_based = true;
}else{
if(!emmc_initialize(false)){
return 1;
}
}
}else{
if(!emu_sd_cfg.sector){
//file based
if(!sd_mount()){
return 1;
}
strcpy(emu_sd_cfg.emummc_file_based_path, "sd:");
strcat(emu_sd_cfg.emummc_file_based_path, emu_sd_cfg.path);
strcat(emu_sd_cfg.emummc_file_based_path, "/SD/");
file_based = true;
}else{
if(!sd_initialize(false)){
return 1;
}
}
}
if(file_based){
return file_based_storage_init(emu_sd_cfg.emummc_file_based_path) == 0;
}
emusd_initialized = true;
}
return 0;
}
int emusd_storage_end() {
if(!h_cfg.emummc_force_disable && emu_sd_cfg.enabled && !emu_sd_cfg.sector){
file_based_storage_end();
}
if(!emu_sd_cfg.enabled || h_cfg.emummc_force_disable || emu_sd_cfg.enabled == 1){
sd_unmount();
}else{
emmc_unmount();
}
emusd_initialized = false;
return 0;
}
int emusd_storage_write(u32 sector, u32 num_sectors, void *buf) {
if(!emu_sd_cfg.enabled || h_cfg.emummc_force_disable){
return sdmmc_storage_write(&sd_storage, sector, num_sectors, buf);
}else if(emu_sd_cfg.sector){
sdmmc_storage_t *storage = emu_sd_cfg.enabled == 1 ? &sd_storage : &emmc_storage;
sector += emu_sd_cfg.sector;
return sdmmc_storage_write(storage, sector, num_sectors, buf);
}else{
return file_based_storage_write(sector, num_sectors, buf);
}
}
int emusd_storage_read(u32 sector, u32 num_sectors, void *buf) {
if(!emu_sd_cfg.enabled || h_cfg.emummc_force_disable){
return sdmmc_storage_read(&sd_storage, sector, num_sectors, buf);
}else if(emu_sd_cfg.sector){
sdmmc_storage_t *storage = emu_sd_cfg.enabled == 1 ? &sd_storage : &emmc_storage;
sector += emu_sd_cfg.sector;
return sdmmc_storage_read(storage, sector, num_sectors, buf);
}else{
return file_based_storage_read(sector, num_sectors, buf);
}
}
sdmmc_storage_t *emusd_get_storage() {
return emu_sd_cfg.enabled == 4 ? &emmc_storage : &sd_storage;
}
bool emusd_is_gpt() {
if(emu_sd_cfg.enabled) {
return emusd_fs.part_type;
} else {
return sd_fs.part_type;
}
}
int emusd_get_fs_type() {
if(emu_sd_cfg.enabled) {
return emusd_fs.fs_type;
} else {
return sd_fs.fs_type;
}
}
void *emusd_file_read(const char *path, u32 *fsize) {
if(emu_sd_cfg.enabled) {
char *path1 = malloc(0x100);
strcpy(path1, "emusd:");
strcat(path1, path);
FIL fp;
if (!emusd_get_mounted())
return NULL;
if (f_open(&fp, path, FA_READ) != FR_OK)
return NULL;
u32 size = f_size(&fp);
if (fsize)
*fsize = size;
void *buf = malloc(size);
if (f_read(&fp, buf, size, NULL) != FR_OK)
{
free(buf);
f_close(&fp);
return NULL;
}
f_close(&fp);
return buf;
} else {
return boot_storage_file_read(path, fsize);
}
}

View File

@@ -40,5 +40,10 @@ int emusd_storage_end();
int emusd_storage_read(u32 sector, u32 num_sectors, void *buf);
int emusd_storage_write(u32 sector, u32 num_sectors, void *buf);
sdmmc_storage_t *emusd_get_storage();
bool emusd_is_gpt();
int emusd_get_fs_type();
bool emusd_mount();
bool emusd_unmount();
void *emusd_file_read(const char *path, u32 *fsize);
#endif