emmc bis storage

This commit is contained in:
Christoph Baumann
2025-04-30 11:29:06 +02:00
parent 61e91f79c1
commit 2440318cb5
4 changed files with 16 additions and 11 deletions

View File

@@ -56,6 +56,7 @@ static u32 emu_offset = 0;
static emmc_part_t *system_part = NULL; static emmc_part_t *system_part = NULL;
static u32 *cache_lookup_tbl = (u32 *)NX_BIS_LOOKUP_ADDR; static u32 *cache_lookup_tbl = (u32 *)NX_BIS_LOOKUP_ADDR;
static bis_cache_t *bis_cache = (bis_cache_t *)NX_BIS_CACHE_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) 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. return 1; // Encryption error.
// If not reading from cache, do a regular read and decrypt. // 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); res = emmc_part_write(system_part, sector, count, bis_cache->dma_buff);
else 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) if (!res)
return 1; // R/W error. 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; u32 sector_in_cluster = sector % BIS_CLUSTER_SECTORS;
// If not reading from cache, do a regular read and decrypt. // 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); res = emmc_part_read(system_part, sector, count, bis_cache->dma_buff);
else 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) if (!res)
return 1; // R/W error. 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; cache_lookup_tbl[cluster] = bis_cache->top_idx;
// Read the whole cluster the sector resides in. // 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); res = emmc_part_read(system_part, cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff);
else 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) if (!res)
return 1; // R/W error. return 1; // R/W error.
@@ -292,10 +293,11 @@ int nx_emmc_bis_write(u32 sector, u32 count, void *buff)
return 1; 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; system_part = part;
emu_offset = emummc_offset; emu_offset = emummc_offset;
emu_storage = storage;
_nx_emmc_bis_cluster_cache_init(enable_cache); _nx_emmc_bis_cluster_cache_init(enable_cache);
@@ -322,4 +324,6 @@ void nx_emmc_bis_end()
{ {
_nx_emmc_bis_flush_cache(); _nx_emmc_bis_flush_cache();
system_part = NULL; system_part = NULL;
emu_storage = NULL;
emu_offset = 0;
} }

View File

@@ -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_read(u32 sector, u32 count, void *buff);
int nx_emmc_bis_write(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(); void nx_emmc_bis_end();
#endif #endif

View File

@@ -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_start = user_offset;
user_part.lba_end = user_offset + user_sectors - 1; user_part.lba_end = user_offset + user_sectors - 1;
strcpy(user_part.name, "USER"); 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"); s_printf(gui->txt_buf, "Formatting USER... \n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); 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); LIST_INIT(gpt);
emmc_gpt_parse(&gpt); emmc_gpt_parse(&gpt);
emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null 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_read(0, 0x40, cal0_buff);
nx_emmc_bis_end(); nx_emmc_bis_end();
emmc_gpt_free(&gpt); emmc_gpt_free(&gpt);

View File

@@ -700,7 +700,7 @@ int hos_dump_cal0()
LIST_INIT(gpt); LIST_INIT(gpt);
emmc_gpt_parse(&gpt); emmc_gpt_parse(&gpt);
emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null 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_read(0, 0x40, cal0_buf);
nx_emmc_bis_end(); nx_emmc_bis_end();
emmc_gpt_free(&gpt); emmc_gpt_free(&gpt);