diff --git a/bdk/storage/nx_emmc_bis.c b/bdk/storage/nx_emmc_bis.c index 28bdc6fb..3fbc4d8d 100644 --- a/bdk/storage/nx_emmc_bis.c +++ b/bdk/storage/nx_emmc_bis.c @@ -56,6 +56,7 @@ static u32 emu_offset = 0; static emmc_part_t *system_part = NULL; static u32 *cache_lookup_tbl = (u32 *)NX_BIS_LOOKUP_ADDR; static bis_cache_t *bis_cache = (bis_cache_t *)NX_BIS_CACHE_ADDR; +static sdmmc_storage_t *emu_storage = NULL; static int nx_emmc_bis_write_block(u32 sector, u32 count, void *buff, bool flush) { @@ -95,10 +96,10 @@ static int nx_emmc_bis_write_block(u32 sector, u32 count, void *buff, bool flush return 1; // Encryption error. // If not reading from cache, do a regular read and decrypt. - if (!emu_offset) + if (!emu_storage) res = emmc_part_write(system_part, sector, count, bis_cache->dma_buff); else - res = sdmmc_storage_write(&sd_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); + res = sdmmc_storage_write(emu_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); if (!res) return 1; // R/W error. @@ -155,10 +156,10 @@ static int nx_emmc_bis_read_block_normal(u32 sector, u32 count, void *buff) u32 sector_in_cluster = sector % BIS_CLUSTER_SECTORS; // If not reading from cache, do a regular read and decrypt. - if (!emu_offset) + if (!emu_storage) res = emmc_part_read(system_part, sector, count, bis_cache->dma_buff); else - res = sdmmc_storage_read(&sd_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); + res = sdmmc_storage_read(emu_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); if (!res) return 1; // R/W error. @@ -212,10 +213,10 @@ static int nx_emmc_bis_read_block_cached(u32 sector, u32 count, void *buff) cache_lookup_tbl[cluster] = bis_cache->top_idx; // Read the whole cluster the sector resides in. - if (!emu_offset) + if (!emu_storage) res = emmc_part_read(system_part, cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff); else - res = sdmmc_storage_read(&sd_storage, emu_offset + system_part->lba_start + cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff); + res = sdmmc_storage_read(emu_storage, emu_offset + system_part->lba_start + cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff); if (!res) return 1; // R/W error. @@ -292,10 +293,11 @@ int nx_emmc_bis_write(u32 sector, u32 count, void *buff) return 1; } -void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, u32 emummc_offset) +void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, sdmmc_storage_t *storage, u32 emummc_offset) { system_part = part; emu_offset = emummc_offset; + emu_storage = storage; _nx_emmc_bis_cluster_cache_init(enable_cache); @@ -322,4 +324,6 @@ void nx_emmc_bis_end() { _nx_emmc_bis_flush_cache(); system_part = NULL; + emu_storage = NULL; + emu_offset = 0; } diff --git a/bdk/storage/nx_emmc_bis.h b/bdk/storage/nx_emmc_bis.h index 7cdacfc1..c0bfcdaa 100644 --- a/bdk/storage/nx_emmc_bis.h +++ b/bdk/storage/nx_emmc_bis.h @@ -229,7 +229,8 @@ typedef struct _nx_emmc_cal0_t int nx_emmc_bis_read(u32 sector, u32 count, void *buff); int nx_emmc_bis_write(u32 sector, u32 count, void *buff); -void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, u32 emummc_offset); +// when storage == NULL, use active emummc config, otherwise, access storage at offset +void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, sdmmc_storage_t *storage, u32 emummc_offset); void nx_emmc_bis_end(); #endif diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.c b/nyx/nyx_gui/frontend/fe_emummc_tools.c index 49d44f08..b4034712 100644 --- a/nyx/nyx_gui/frontend/fe_emummc_tools.c +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.c @@ -673,7 +673,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part user_part.lba_start = user_offset; user_part.lba_end = user_offset + user_sectors - 1; strcpy(user_part.name, "USER"); - nx_emmc_bis_init(&user_part, true, sd_sector_off); + nx_emmc_bis_init(&user_part, true, &sd_storage, sd_sector_off); s_printf(gui->txt_buf, "Formatting USER... \n"); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); @@ -787,7 +787,7 @@ static int _emummc_raw_derive_bis_keys(emmc_tool_gui_t *gui, u32 resized_count) LIST_INIT(gpt); emmc_gpt_parse(&gpt); emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null - nx_emmc_bis_init(cal0_part, false, 0); + nx_emmc_bis_init(cal0_part, false, NULL, 0); nx_emmc_bis_read(0, 0x40, cal0_buff); nx_emmc_bis_end(); emmc_gpt_free(&gpt); diff --git a/nyx/nyx_gui/hos/hos.c b/nyx/nyx_gui/hos/hos.c index ba23bdd8..3f5e8bc0 100644 --- a/nyx/nyx_gui/hos/hos.c +++ b/nyx/nyx_gui/hos/hos.c @@ -700,7 +700,7 @@ int hos_dump_cal0() LIST_INIT(gpt); emmc_gpt_parse(&gpt); emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null - nx_emmc_bis_init(cal0_part, false, 0); + nx_emmc_bis_init(cal0_part, false, NULL, 0); nx_emmc_bis_read(0, 0x40, cal0_buf); nx_emmc_bis_end(); emmc_gpt_free(&gpt);