mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 19:14:44 +00:00
[stage1] refactor diskio.c
This commit is contained in:
parent
00f08321c7
commit
9dce3b05ba
1 changed files with 44 additions and 21 deletions
|
@ -13,16 +13,55 @@
|
||||||
#include "../../sdmmc.h"
|
#include "../../sdmmc.h"
|
||||||
#include "../../hwinit.h"
|
#include "../../hwinit.h"
|
||||||
|
|
||||||
|
static bool g_ahb_redirect_enabled = false;
|
||||||
|
|
||||||
/* Global sd struct. */
|
/* Global sd struct. */
|
||||||
struct mmc g_sd_mmc = {0};
|
static struct mmc g_sd_mmc = {0};
|
||||||
static bool g_sd_initialized = false;
|
static bool g_sd_initialized = false;
|
||||||
|
|
||||||
static bool g_ahb_redirect_enabled = false;
|
int initialize_sd_mmc(void) {
|
||||||
|
if (!g_ahb_redirect_enabled) {
|
||||||
|
mc_enable_ahb_redirect();
|
||||||
|
g_ahb_redirect_enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_sd_initialized) {
|
||||||
|
int rc = sdmmc_init(&g_sd_mmc, SWITCH_MICROSD);
|
||||||
|
if (rc == 0) {
|
||||||
|
g_sd_initialized = true;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Uncomment if needed:
|
Uncomment if needed:
|
||||||
struct mmc nand_mmc = {0};
|
static struct mmc nand_mmc = {0};
|
||||||
static bool g_nand_initialized = false;
|
static bool g_nand_initialized = false;
|
||||||
|
|
||||||
|
int initialize_nand_mmc(void) {
|
||||||
|
if (!g_ahb_redirect_enabled) {
|
||||||
|
mc_enable_ahb_redirect();
|
||||||
|
g_ahb_redirect_enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_nand_initialized) {
|
||||||
|
int rc = sdmmc_init(&g_sd_mmc, SWITCH_EMMC);
|
||||||
|
if (rc == 0) {
|
||||||
|
g_nand_initialized = true;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
@ -46,25 +85,9 @@ DSTATUS disk_initialize (
|
||||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!g_ahb_redirect_enabled) {
|
|
||||||
mc_enable_ahb_redirect();
|
|
||||||
g_ahb_redirect_enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (pdrv) {
|
switch (pdrv) {
|
||||||
case 0: {
|
case 0:
|
||||||
if (!g_sd_initialized) {
|
return initialize_sd_mmc() == 0 ? 0 : STA_NOINIT;
|
||||||
int rc = sdmmc_init(&g_sd_mmc, SWITCH_MICROSD);
|
|
||||||
if (rc == 0) {
|
|
||||||
g_sd_initialized = true;
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return STA_NODISK;
|
return STA_NODISK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue