diff --git a/Makefile b/Makefile index 9b2b1b9d..00f20cd3 100755 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ mc.o sdram.o minerva.o \ gpio.o pinmux.o pmc.o se.o smmu.o tsec.o uart.o \ fuse.o kfuse.o \ - sdmmc.o sdmmc_driver.o emmc.o sd.o emummc.o emummc_file_based.o \ + sdmmc.o sdmmc_driver.o emmc.o sd.o emummc.o emummc_file_based.o emusd.o \ bq24193.o max17050.o max7762x.o max77620-rtc.o \ hw_init.o boot_storage.o \ ) diff --git a/bdk/storage/boot_storage.c b/bdk/storage/boot_storage.c index 01ad8616..2bbe60a4 100644 --- a/bdk/storage/boot_storage.c +++ b/bdk/storage/boot_storage.c @@ -250,4 +250,18 @@ int boot_storage_save_to_file(const void *buf, u32 size, const char *filename) f_close(&fp); return 0; +} + +FATFS *boot_storage_get_fs() { + switch(drive_cur){ + case DRIVE_BOOT1: + return &boot_storage_fs; + case DRIVE_EMMC: + return &emmc_fs; + case DRIVE_BOOT1_1MB: + return &boot_storage_fs; + case DRIVE_SD: + return &sd_fs; + } + return NULL; } \ No newline at end of file diff --git a/bdk/storage/boot_storage.h b/bdk/storage/boot_storage.h index 1ed95d98..0bd529a2 100644 --- a/bdk/storage/boot_storage.h +++ b/bdk/storage/boot_storage.h @@ -1,6 +1,7 @@ #ifndef _BOOT_STORAGE_H #define _BOOT_STORAGE_H +#include #include // check if boot1 (1mb), boot1, gpp, sd (in that order) have fat32 partition, @@ -16,6 +17,8 @@ bool boot_storage_get_initialized(); void *boot_storage_file_read(const char *path, u32 *fsize); int boot_storage_save_to_file(const void *buf, u32 size, const char *filename); +FATFS *boot_storage_get_fs(); + u8 boot_storage_get_drive(); #endif \ No newline at end of file diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 1fc45e54..2c888fe7 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -28,6 +28,7 @@ #include "../frontend/fe_tools.h" #include "../config.h" #include "../storage/emummc.h" +#include "../storage/emusd.h" #include extern hekate_config h_cfg; @@ -815,7 +816,8 @@ void hos_launch(ini_sec_t *cfg) kb = ctxt.pkg1_id->kb; - bool emummc_enabled = emu_cfg.enabled && !h_cfg.emummc_force_disable; + // TODO: separate force_disable for emuSD? + bool emummc_enabled = (emu_cfg.enabled || emu_sd_cfg.enabled) && !h_cfg.emummc_force_disable; // Enable emummc patching. if (emummc_enabled) diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index 4be5dec9..6a71f5bc 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -28,6 +28,7 @@ #include #include #include "../storage/emummc.h" +#include "../storage/emusd.h" //#define DPRINTF(...) gfx_printf(__VA_ARGS__) #define DPRINTF(...) @@ -668,6 +669,8 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names) if (kip_id_idx > 17) emu_cfg.fs_ver -= 2; + emu_sd_cfg.fs_ver = emu_cfg.fs_ver; + // Inject emuMMC code. gfx_printf("Injecting emuMMC. FS ID: %d\n", emu_cfg.fs_ver); if (_kipm_inject("bootloader/sys/emummc.kipm", "FS", ki)) diff --git a/bootloader/hos/secmon_exo.c b/bootloader/hos/secmon_exo.c index 5b2d9f1f..ea95442b 100644 --- a/bootloader/hos/secmon_exo.c +++ b/bootloader/hos/secmon_exo.c @@ -24,14 +24,17 @@ #include "../config.h" #include #include "../storage/emummc.h" +#include "../storage/emusd.h" extern hekate_config h_cfg; enum emuMMC_Type { - emuMMC_None = 0, - emuMMC_Partition, - emuMMC_File, + EmummcType_None = 0, + EmummcType_Partition_Sd = 1, + EmummcType_File_Sd = 2, + EmummcType_Partition_Emmc = 3, + EmummcType_File_Emmc = 4, emuMMC_MAX }; @@ -66,6 +69,21 @@ typedef struct emummc_file_config_t file_cfg; }; char nintendo_path[EMUMMC_FILE_PATH_MAX]; +} emummc_emmc_config_t; + +typedef struct +{ + emummc_base_config_t base_cfg; + union + { + emummc_partition_config_t partition_cfg; + }; +} emummc_sd_config_t; + +typedef struct +{ + emummc_emmc_config_t emmc_cfg; + emummc_sd_config_t sd_cfg; } exo_emummc_config_t; typedef struct _exo_cfg_t @@ -316,22 +334,55 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) pkg1_warmboot_rsa_mod(warmboot_base); } + // By default, disable emuMMC + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.magic = EMUMMC_MAGIC; + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_None; if (emu_cfg.enabled && !h_cfg.emummc_force_disable) { - exo_cfg->emummc_cfg.base_cfg.magic = EMUMMC_MAGIC; - exo_cfg->emummc_cfg.base_cfg.type = emu_cfg.sector ? emuMMC_Partition : emuMMC_File; - exo_cfg->emummc_cfg.base_cfg.fs_ver = emu_cfg.fs_ver; - exo_cfg->emummc_cfg.base_cfg.id = emu_cfg.id; + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.fs_ver = emu_cfg.fs_ver; + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.id = emu_cfg.id; + if (emu_cfg.enabled == 4 && emu_cfg.sector) { + // emmc partition based + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_Partition_Emmc; + } else if (emu_cfg.enabled == 4 && !emu_cfg.sector) { + // emmc file based + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_File_Emmc; + } else if (emu_cfg.enabled == 1 && emu_cfg.sector) { + // sd partition based + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_Partition_Sd; + } else if (emu_cfg.enabled == 1 && !emu_cfg.sector) { + // sd file based + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_File_Sd; + } else { + // disabled + exo_cfg->emummc_cfg.emmc_cfg.base_cfg.type = EmummcType_None; + } if (emu_cfg.sector) - exo_cfg->emummc_cfg.partition_cfg.start_sector = emu_cfg.sector; + exo_cfg->emummc_cfg.emmc_cfg.partition_cfg.start_sector = emu_cfg.sector; else - strcpy((char *)exo_cfg->emummc_cfg.file_cfg.path, emu_cfg.path); + strcpy((char *)exo_cfg->emummc_cfg.emmc_cfg.file_cfg.path, emu_cfg.path); if (!ctxt->stock && emu_cfg.nintendo_path && emu_cfg.nintendo_path[0]) - strcpy((char *)exo_cfg->emummc_cfg.nintendo_path, emu_cfg.nintendo_path); + strcpy((char *)exo_cfg->emummc_cfg.emmc_cfg.nintendo_path, emu_cfg.nintendo_path); else - strcpy((char *)exo_cfg->emummc_cfg.nintendo_path, "Nintendo"); + strcpy((char *)exo_cfg->emummc_cfg.emmc_cfg.nintendo_path, "Nintendo"); + } + + exo_cfg->emummc_cfg.sd_cfg.base_cfg.magic = EMUMMC_MAGIC; + exo_cfg->emummc_cfg.sd_cfg.base_cfg.id = emu_sd_cfg.id; + if (emu_sd_cfg.enabled) + { + 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) { + exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_Partition_Emmc; + }else { + exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_None; + } + + } else { + exo_cfg->emummc_cfg.sd_cfg.base_cfg.type = EmummcType_None; } // Copy over exosphere fatal for Mariko. diff --git a/bootloader/main.c b/bootloader/main.c index c04954ae..11083e80 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -22,6 +22,7 @@ #include #include "config.h" +#include "gfx/gfx.h" #include "gfx/logos.h" #include "gfx/tui.h" #include "hos/hos.h" @@ -35,6 +36,7 @@ #include "frontend/fe_tools.h" #include "frontend/fe_info.h" +#include "storage/emusd.h" hekate_config h_cfg; boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg; @@ -339,6 +341,7 @@ static void _launch_ini_list() u8 max_entries = 61; char *special_path = NULL; char *emummc_path = NULL; + char *emusd_path = NULL; ment_t *ments = NULL; ini_sec_t *cfg_sec = NULL; @@ -403,13 +406,21 @@ static void _launch_ini_list() h_cfg.emummc_force_disable = atoi(kv->val); else if (!strcmp("emupath", kv->key)) emummc_path = kv->val; + else if (!strcmp("emusdpath", kv->key)) + emusd_path = kv->val; } + // TODO: also check emuSD path if (emummc_path && !emummc_set_path(emummc_path)) { EPRINTF("emupath is wrong!"); goto wrong_emupath; } + + if (emusd_path && !emusd_set_path(emusd_path)){ + EPRINTF("emusdpath is wrong!"); + goto wrong_emupath; + } } if (!cfg_sec) @@ -455,6 +466,12 @@ wrong_emupath: boot_storage_mount(); emummc_load_cfg(); // Reload emuMMC config in case of emupath. } + + if (emusd_path) + { + boot_storage_mount(); + emusd_load_cfg(); + } } out: @@ -468,6 +485,7 @@ static void _launch_config() u8 max_entries = 61; char *special_path = NULL; char *emummc_path = NULL; + char *emusd_path = NULL; ment_t *ments = NULL; ini_sec_t *cfg_sec = NULL; @@ -482,6 +500,7 @@ static void _launch_config() // Load emuMMC configuration. emummc_load_cfg(); + emusd_load_cfg(); // Parse main configuration. ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false); @@ -548,6 +567,8 @@ static void _launch_config() h_cfg.emummc_force_disable = atoi(kv->val); if (!strcmp("emupath", kv->key)) emummc_path = kv->val; + if (!strcmp("emusdpath", kv->key)) + emusd_path = kv->val; } if (emummc_path && !emummc_set_path(emummc_path)) @@ -555,6 +576,12 @@ static void _launch_config() EPRINTF("emupath is wrong!"); goto wrong_emupath; } + + if (emusd_path && !emusd_set_path(emusd_path)) + { + EPRINTF("emusdpath is wrong!"); + goto wrong_emupath; + } } if (!cfg_sec) @@ -600,6 +627,12 @@ wrong_emupath: boot_storage_mount(); emummc_load_cfg(); // Reload emuMMC config in case of emupath. } + + if (emusd_path) + { + boot_storage_mount(); + emusd_load_cfg(); + } } out: @@ -682,7 +715,7 @@ static void _nyx_load_run() (*nyx_ptr)(); } -static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path) +static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path, char **emusd_path) { ini_sec_t *cfg_sec = NULL; @@ -701,10 +734,13 @@ static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustom *bootlogoCustomEntry = kv->val; else if (!strcmp("emummc_force_disable", kv->key)) h_cfg.emummc_force_disable = atoi(kv->val); + else if (!strcmp("emusdpath", kv->key)) + *emusd_path = kv->val; } if (!cfg_sec) { *emummc_path = NULL; + *emusd_path = NULL; *bootlogoCustomEntry = NULL; h_cfg.emummc_force_disable = false; } @@ -759,6 +795,7 @@ static void _auto_launch() u32 boot_entry_id = 0; ini_sec_t *cfg_sec = NULL; char *emummc_path = NULL; + char *emusd_path = NULL; char *bootlogoCustomEntry = NULL; bool config_entry_found = false; @@ -776,6 +813,7 @@ static void _auto_launch() // Load emuMMC configuration. emummc_load_cfg(); + emusd_load_cfg(); // Parse hekate main configuration. if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) @@ -831,7 +869,7 @@ static void _auto_launch() } if (boot_from_id) - cfg_sec = _get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path); + cfg_sec = _get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path, &emusd_path); else if (h_cfg.autoboot == boot_entry_id && config_entry_found) { cfg_sec = ini_sec; @@ -841,6 +879,8 @@ static void _auto_launch() bootlogoCustomEntry = kv->val; else if (!strcmp("emupath", kv->key)) emummc_path = kv->val; + else if (!strcmp("emusdpath", kv->key)) + emusd_path = kv->val; else if (!strcmp("emummc_force_disable", kv->key)) h_cfg.emummc_force_disable = atoi(kv->val); else if (!strcmp("bootwait", kv->key)) @@ -877,7 +917,7 @@ static void _auto_launch() continue; if (boot_from_id) - cfg_sec = _get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path); + cfg_sec = _get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path, &emusd_path); else if (h_cfg.autoboot == boot_entry_id) { h_cfg.emummc_force_disable = false; @@ -888,6 +928,8 @@ static void _auto_launch() bootlogoCustomEntry = kv->val; else if (!strcmp("emupath", kv->key)) emummc_path = kv->val; + else if (!strcmp("emusdpath", kv->key)) + emusd_path = kv->val; else if (!strcmp("emummc_force_disable", kv->key)) h_cfg.emummc_force_disable = atoi(kv->val); else if (!strcmp("bootwait", kv->key)) @@ -1001,6 +1043,7 @@ skip_list: } else { + // TODO: add boot_cfg for emusd if (b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC) emummc_set_path(b_cfg.emummc_path); else if (emummc_path && !emummc_set_path(emummc_path)) @@ -1010,6 +1053,13 @@ skip_list: goto wrong_emupath; } + if (emusd_path && !emusd_set_path(emusd_path)) + { + gfx_con.mute = false; + EPRINTF("emusdpath is wrong!"); + goto wrong_emupath; + } + hos_launch(cfg_sec); wrong_emupath: @@ -1019,6 +1069,12 @@ wrong_emupath: emummc_load_cfg(); // Reload emuMMC config in case of emupath. } + if (emusd_path) + { + boot_storage_mount(); + emusd_load_cfg(); + } + error: gfx_con.mute = false; gfx_printf("\nPress any key...\n"); diff --git a/bootloader/storage/emummc.c b/bootloader/storage/emummc.c index fa23d258..36b192fd 100644 --- a/bootloader/storage/emummc.c +++ b/bootloader/storage/emummc.c @@ -24,6 +24,7 @@ #include "emummc.h" #include "../config.h" +#include "gfx_utils.h" #include #include @@ -173,6 +174,11 @@ 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; @@ -190,11 +196,12 @@ int emummc_storage_init_mmc() if(!emu_cfg.sector){ // file based if(!emmc_mount()){ + gfx_printf("emmc mount fail\n"); return 1; } strcpy(emu_cfg.emummc_file_based_path, "emmc:"); strcat(emu_cfg.emummc_file_based_path, emu_cfg.path); - strcat(emu_cfg.emummc_file_based_path, "/eMMC"); + strcat(emu_cfg.emummc_file_based_path, "/eMMC/"); file_based = true; }else{ // raw based @@ -209,7 +216,7 @@ int emummc_storage_init_mmc() } strcpy(emu_cfg.emummc_file_based_path, "sd:"); strcat(emu_cfg.emummc_file_based_path, emu_cfg.path); - strcat(emu_cfg.emummc_file_based_path, "/eMMC"); + strcat(emu_cfg.emummc_file_based_path, "/eMMC/"); file_based = true; }else{ // raw based @@ -220,6 +227,7 @@ int emummc_storage_init_mmc() } if(file_based){ + gfx_printf("file based\n"); return emummc_storage_file_based_init(emu_cfg.emummc_file_based_path) == 0; } diff --git a/bootloader/storage/emummc.h b/bootloader/storage/emummc.h index 4bb7c3e1..f44dea30 100644 --- a/bootloader/storage/emummc.h +++ b/bootloader/storage/emummc.h @@ -19,19 +19,6 @@ #include -typedef enum -{ - EMUMMC_TYPE_NONE = 0, - EMUMMC_TYPE_PARTITION = 1, - EMUMMC_TYPE_FILES = 2, -} emummc_type_t; - -typedef enum { - EMUMMC_MMC_NAND = 0, - EMUMMC_MMC_SD = 1, - EMUMMC_MMC_GC = 2, -} emummc_mmc_t; - typedef struct _emummc_cfg_t { int enabled;