From 2c46ec9638dabda7bb0ead9d6de6121edaad42c5 Mon Sep 17 00:00:00 2001 From: hexkyz Date: Sun, 16 Jun 2019 20:51:25 +0100 Subject: [PATCH] emummc: fix file based mode --- fusee/fusee-secondary/src/nxboot.c | 12 ++++++------ fusee/fusee-secondary/src/nxfs.c | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index dd8769a9b..e46170c4b 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -239,7 +239,7 @@ static bool nxboot_configure_emummc(exo_emummc_config_t *exo_emummc_config) { exo_emummc_config->emu_dir_path[sizeof(exo_emummc_config->emu_dir_path) - 1] = '\0'; if (emummc_cfg.enabled) { - if (emummc_cfg.sector >= 0) { + if (emummc_cfg.sector != -1) { exo_emummc_config->base_cfg.type = EMUMMC_TYPE_PARTITION; exo_emummc_config->partition_cfg.start_sector = emummc_cfg.sector; @@ -254,13 +254,13 @@ static bool nxboot_configure_emummc(exo_emummc_config_t *exo_emummc_config) { int num_parts = 0; uint64_t part_limit = 0; - char emummc_path[0x300 + 1] = {0}; + char emummc_path[0x100 + 1] = {0}; char emummc_boot0_path[0x300 + 1] = {0}; char emummc_boot1_path[0x300 + 1] = {0}; char emummc_rawnand_path[0x300 + 1] = {0}; /* Prepare base folder path. */ - snprintf(emummc_path, sizeof(emummc_path) - 1, "sdmc:/%s/%s", emummc_cfg.path, "eMMC"); + snprintf(emummc_path, sizeof(emummc_path) - 1, "%s/%s", emummc_cfg.path, "eMMC"); /* Check if eMMC folder is present. */ if (!is_valid_folder(emummc_path)) { @@ -268,8 +268,8 @@ static bool nxboot_configure_emummc(exo_emummc_config_t *exo_emummc_config) { } /* Prepare expected file paths. */ - snprintf(emummc_boot0_path, sizeof(emummc_boot0_path) - 1, "sdmc:/%s/%s", emummc_path, "boot0"); - snprintf(emummc_boot1_path, sizeof(emummc_boot1_path) - 1, "sdmc:/%s/%s", emummc_path, "boot1"); + snprintf(emummc_boot0_path, sizeof(emummc_boot0_path) - 1, "%s/%s", emummc_path, "boot0"); + snprintf(emummc_boot1_path, sizeof(emummc_boot1_path) - 1, "%s/%s", emummc_path, "boot1"); /* Check if boot0 and boot1 image files are present. */ if (!is_valid_file(emummc_boot0_path) || !is_valid_file(emummc_boot1_path)) { @@ -278,7 +278,7 @@ static bool nxboot_configure_emummc(exo_emummc_config_t *exo_emummc_config) { /* Find raw image files (single or multi part). */ for (int i = 0; i < 64; i++) { - snprintf(emummc_rawnand_path, sizeof(emummc_rawnand_path) - 1, "sdmc:/%s/%02d", emummc_path, i); + snprintf(emummc_rawnand_path, sizeof(emummc_rawnand_path) - 1, "%s/%02d", emummc_path, i); if (is_valid_file(emummc_rawnand_path)) { if (i == 0) { /* The size of the first file should tell us the part limit. */ diff --git a/fusee/fusee-secondary/src/nxfs.c b/fusee/fusee-secondary/src/nxfs.c index 51ff312c0..f1462cc49 100644 --- a/fusee/fusee-secondary/src/nxfs.c +++ b/fusee/fusee-secondary/src/nxfs.c @@ -190,7 +190,7 @@ static int emummc_partition_read(device_partition_t *devpart, void *dst, uint64_ /* Read partition data using our backing file. */ int rc = 0; FILE *emummc_file = fopen(devpart->emu_file_path, "rb"); - fseek(emummc_file, sector * devpart->sector_size, SEEK_CUR); + fseek(emummc_file, (devpart->start_sector + sector) * devpart->sector_size, SEEK_CUR); rc = (fread(dst, devpart->sector_size, num_sectors, emummc_file) > 0) ? 0 : -1; fclose(emummc_file); return rc; @@ -205,7 +205,7 @@ static int emummc_partition_write(device_partition_t *devpart, const void *src, /* Write partition data using our backing file. */ int rc = 0; FILE *emummc_file = fopen(devpart->emu_file_path, "wb"); - fseek(emummc_file, sector * devpart->sector_size, SEEK_CUR); + fseek(emummc_file, (devpart->start_sector + sector) * devpart->sector_size, SEEK_CUR); rc = (fwrite(src, devpart->sector_size, num_sectors, emummc_file) > 0) ? 0 : -1; fclose(emummc_file); return rc; @@ -691,7 +691,7 @@ int nxfs_mount_emummc_file(const char *emummc_path, int num_parts, uint64_t part model.emu_use_file = true; /* Prepare boot0 file path. */ - snprintf(emummc_boot0_path, sizeof(emummc_boot0_path) - 1, "sdmc:/%s/%s", emummc_path, "boot0"); + snprintf(emummc_boot0_path, sizeof(emummc_boot0_path) - 1, "%s/%s", emummc_path, "boot0"); /* Mount emulated boot0 device. */ rc = emudev_mount_device("boot0", &model, emummc_boot0_path); @@ -716,7 +716,7 @@ int nxfs_mount_emummc_file(const char *emummc_path, int num_parts, uint64_t part model.emu_use_file = true; /* Prepare boot1 file path. */ - snprintf(emummc_boot1_path, sizeof(emummc_boot1_path) - 1, "sdmc:/%s/%s", emummc_path, "boot1"); + snprintf(emummc_boot1_path, sizeof(emummc_boot1_path) - 1, "%s/%s", emummc_path, "boot1"); /* Mount emulated boot1 device. */ rc = emudev_mount_device("boot1", &model, emummc_boot1_path); @@ -726,7 +726,13 @@ int nxfs_mount_emummc_file(const char *emummc_path, int num_parts, uint64_t part return -1; } - /* Don't register emulated boot1 for now. */ + /* Register emulated boot1 device. */ + rc = emudev_register_device("boot1"); + + /* Failed to register boot1 device. */ + if (rc == -1) { + return -1; + } /* Setup a template for raw NAND. */ model = g_emummc_devpart_template; @@ -735,7 +741,7 @@ int nxfs_mount_emummc_file(const char *emummc_path, int num_parts, uint64_t part model.emu_use_file = true; /* Prepare single raw NAND file path. */ - snprintf(emummc_rawnand_path, sizeof(emummc_rawnand_path) - 1, "sdmc:/%s/%02d", emummc_path, 0); + snprintf(emummc_rawnand_path, sizeof(emummc_rawnand_path) - 1, "%s/%02d", emummc_path, 0); /* Mount emulated raw NAND device from single or multiple parts. */ if (!is_exfat) {