fix indicators, add emmc_mount, various fixes

This commit is contained in:
Christoph Baumann
2025-04-29 12:36:32 +02:00
parent 31c8ad0d88
commit 28796b417b
6 changed files with 792 additions and 423 deletions

View File

@@ -27,7 +27,16 @@ static bool _is_eligible(){
}
bool boot_storage_get_mounted(){
return drive != DEV_INVALID;
switch(drive){
case DRIVE_SD:
return sd_get_card_mounted();
case DRIVE_EMMC:
return emmc_get_mounted();
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
return drive != DEV_INVALID;
}
return false;
}
bool boot_storage_get_initialized(){
@@ -51,23 +60,36 @@ static bool _boot_storage_initialize(){
case DRIVE_SD:
return sd_initialize(false);
}
return false;
}
static void _boot_storage_end(bool deinit){
if(boot_storage_get_mounted()){
if(drive == DRIVE_SD){
switch(drive){
case DRIVE_SD:
sd_unmount();
}else{
f_mount(NULL, drive_base_paths[drive], false);
break;
case DRIVE_EMMC:
emmc_unmount();
break;
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
f_mount(NULL, drive_base_paths[drive], 0);
}
drive = DEV_INVALID;
}
if(deinit){
if(drive == DRIVE_SD){
switch(drive){
case DRIVE_SD:
sd_end();
}else{
break;
case DRIVE_EMMC:
case DRIVE_BOOT1:
case DRIVE_BOOT1_1MB:
emmc_end();
break;
}
}
}
@@ -93,7 +115,7 @@ static bool _boot_storage_mount(){
goto emmc_init_fail;
}
static const BYTE emmc_drives[] = {DRIVE_BOOT1_1MB, DRIVE_BOOT1, DRIVE_EMMC};
static const BYTE emmc_drives[] = {DRIVE_BOOT1_1MB, DRIVE_BOOT1};
for(BYTE i = 0; i < ARRAY_SIZE(emmc_drives); i++){
res = f_mount(&boot_storage_fs, drive_base_paths[emmc_drives[i]], true);
@@ -121,14 +143,28 @@ static bool _boot_storage_mount(){
}
emmc_init_fail:
gfx_printf("trying %s\n", drive_base_paths[DRIVE_SD]);
if(!emmc_initialize(false)){
goto emmc_init_fail2;
}
if(!emmc_mount()){
emmc_end();
goto emmc_init_fail2;
}
res = f_chdrive(drive_base_paths[DRIVE_EMMC]);
if(res == FR_OK && _is_eligible()){
drive = DRIVE_EMMC;
return true;
}
emmc_init_fail2:
if(!sd_initialize(false)){
gfx_printf("%s fail\n", drive_base_paths[DRIVE_SD]);
goto out;
}
if(!sd_mount()){
gfx_printf("%s fail\n", drive_base_paths[DRIVE_SD]);
sd_end();
goto out;
}
@@ -136,7 +172,6 @@ emmc_init_fail:
res = f_chdrive(drive_base_paths[DRIVE_SD]);
if(res == FR_OK && _is_eligible()){
gfx_printf("%s ok\n", drive_base_paths[DRIVE_SD]);
drive = DRIVE_SD;
return true;
}

View File

@@ -21,11 +21,13 @@
#include <mem/heap.h>
#include <soc/fuse.h>
#include <storage/mbr_gpt.h>
#include <gfx_utils.h>
#include <utils/list.h>
static u16 emmc_errors[3] = { 0 }; // Init and Read/Write errors.
static u32 emmc_mode = EMMC_MMC_HS400;
static bool emmc_init_done = false;
static bool emmc_mounted = false;
sdmmc_t emmc_sdmmc;
sdmmc_storage_t emmc_storage;
@@ -62,14 +64,22 @@ u32 emmc_get_mode()
return emmc_mode;
}
static void _emmc_deinit(){
static void _emmc_deinit(bool deinit){
if(emmc_init_done){
sdmmc_storage_end(&emmc_storage);
emmc_init_done = false;
// TODO: Allow unmount even when not init'd?
if(emmc_mounted){
f_mount(NULL, "emmc:", 0);
}
if(deinit){
sdmmc_storage_end(&emmc_storage);
emmc_init_done = false;
}
}
emmc_mounted = false;
}
void emmc_end() { _emmc_deinit(); }
void emmc_end() { _emmc_deinit(true); }
bool emmc_get_initialized(){
return emmc_init_done;
@@ -243,3 +253,44 @@ void nx_emmc_get_autorcm_masks(u8 *mod0, u8 *mod1)
*mod1 = 0x84;
}
}
bool emmc_mount()
{
if (emmc_init_done && emmc_mounted)
return true;
int res = 0;
if (!emmc_init_done)
res = !emmc_initialize(false);
if (res)
{
gfx_con.mute = false;
EPRINTF("Failed to init eMMC.");
}
else
{
if (!emmc_mounted)
res = f_mount(&emmc_fs, "emmc:", 1); // Volume 0 is SD.
if (res == FR_OK)
{
emmc_mounted = true;
return true;
}
else
{
gfx_con.mute = false;
EPRINTFARGS("Failed to mount eMMC (FatFS Error %d).\nMake sure that a FAT partition exists..", res);
}
}
return false;
}
bool emmc_get_mounted(){
return emmc_mounted;
}
void emmc_unmount() { _emmc_deinit(false); }

View File

@@ -65,7 +65,10 @@ int emmc_init_retry(bool power_cycle);
bool emmc_initialize(bool power_cycle);
int emmc_set_partition(u32 partition);
void emmc_end();
bool emmc_mount();
void emmc_unmount();
bool emmc_get_initialized();
bool emmc_get_mounted();
void emmc_gpt_parse(link_t *gpt);
void emmc_gpt_free(link_t *gpt);