forked from CTCaer/hekate
redirect sd card to eMMC
This commit is contained in:
parent
9e1b2ee573
commit
2d2433031c
117
bdk/storage/sd.c
117
bdk/storage/sd.c
@ -35,42 +35,29 @@ static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
|
||||
static u32 sd_mode = SD_DEFAULT_SPEED;
|
||||
|
||||
|
||||
sdmmc_t sd_sdmmc;
|
||||
sdmmc_storage_t sd_storage;
|
||||
FATFS sd_fs;
|
||||
|
||||
void sd_error_count_increment(u8 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SD_ERROR_INIT_FAIL:
|
||||
sd_errors[0]++;
|
||||
break;
|
||||
case SD_ERROR_RW_FAIL:
|
||||
sd_errors[1]++;
|
||||
break;
|
||||
case SD_ERROR_RW_RETRY:
|
||||
sd_errors[2]++;
|
||||
break;
|
||||
}
|
||||
emmc_error_count_increment(type);
|
||||
}
|
||||
|
||||
u16 *sd_get_error_count()
|
||||
{
|
||||
return sd_errors;
|
||||
return emmc_get_error_count();
|
||||
}
|
||||
|
||||
bool sd_get_card_removed()
|
||||
{
|
||||
if (insertion_event && !sdmmc_get_sd_inserted())
|
||||
return true;
|
||||
// if (insertion_event && !sdmmc_get_sd_inserted())
|
||||
// return true;
|
||||
|
||||
// you probably wouldn't want to remove the nand while the system is powered on anyways.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sd_get_card_initialized()
|
||||
{
|
||||
return sd_init_done;
|
||||
// return sd_init_done;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sd_get_card_mounted()
|
||||
@ -85,96 +72,12 @@ u32 sd_get_mode()
|
||||
|
||||
int sd_init_retry(bool power_cycle)
|
||||
{
|
||||
u32 bus_width = SDMMC_BUS_WIDTH_4;
|
||||
#ifndef BDK_SDMMC_UHS_DDR200_SUPPORT
|
||||
u32 type = SDHCI_TIMING_UHS_SDR104;
|
||||
#else
|
||||
u32 type = SDHCI_TIMING_UHS_DDR200;
|
||||
#endif
|
||||
|
||||
// Power cycle SD card.
|
||||
if (power_cycle)
|
||||
{
|
||||
sd_mode--;
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
}
|
||||
|
||||
// Get init parameters.
|
||||
switch (sd_mode)
|
||||
{
|
||||
case SD_INIT_FAIL: // Reset to max.
|
||||
return 0;
|
||||
|
||||
case SD_1BIT_HS25:
|
||||
bus_width = SDMMC_BUS_WIDTH_1;
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
|
||||
case SD_4BIT_HS25:
|
||||
type = SDHCI_TIMING_SD_HS25;
|
||||
break;
|
||||
|
||||
case SD_UHS_SDR82:
|
||||
type = SDHCI_TIMING_UHS_SDR82;
|
||||
break;
|
||||
|
||||
case SD_UHS_SDR104:
|
||||
type = SDHCI_TIMING_UHS_SDR104;
|
||||
break;
|
||||
|
||||
#ifdef BDK_SDMMC_UHS_DDR200_SUPPORT
|
||||
case SD_UHS_DDR208:
|
||||
type = SDHCI_TIMING_UHS_DDR200;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
sd_mode = SD_DEFAULT_SPEED;
|
||||
break;
|
||||
}
|
||||
|
||||
int res = sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, bus_width, type);
|
||||
if (res)
|
||||
{
|
||||
sd_init_done = true;
|
||||
insertion_event = true;
|
||||
}
|
||||
else
|
||||
sd_init_done = false;
|
||||
|
||||
return res;
|
||||
return emmc_init_retry(power_cycle);
|
||||
}
|
||||
|
||||
bool sd_initialize(bool power_cycle)
|
||||
{
|
||||
if (power_cycle)
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
|
||||
int res = !sd_init_retry(false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!res)
|
||||
return true;
|
||||
else if (!sdmmc_get_sd_inserted()) // SD Card is not inserted.
|
||||
{
|
||||
sd_mode = SD_DEFAULT_SPEED;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sd_errors[SD_ERROR_INIT_FAIL]++;
|
||||
|
||||
if (sd_mode == SD_INIT_FAIL)
|
||||
break;
|
||||
else
|
||||
res = !sd_init_retry(true);
|
||||
}
|
||||
}
|
||||
|
||||
sdmmc_storage_end(&sd_storage);
|
||||
|
||||
return false;
|
||||
return emmc_initialize(power_cycle);
|
||||
}
|
||||
|
||||
bool sd_mount()
|
||||
@ -239,7 +142,7 @@ static void _sd_deinit(bool deinit)
|
||||
}
|
||||
|
||||
void sd_unmount() { _sd_deinit(false); }
|
||||
void sd_end() { _sd_deinit(true); }
|
||||
void sd_end() { emmc_end(); }
|
||||
|
||||
bool sd_is_gpt()
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <storage/sdmmc.h>
|
||||
#include <storage/sdmmc_driver.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <storage/emmc.h>
|
||||
|
||||
#define SD_BLOCKSIZE SDMMC_DAT_BLOCKSIZE
|
||||
|
||||
@ -44,9 +45,10 @@ enum
|
||||
SD_ERROR_RW_RETRY = 2
|
||||
};
|
||||
|
||||
extern sdmmc_t sd_sdmmc;
|
||||
extern sdmmc_storage_t sd_storage;
|
||||
extern FATFS sd_fs;
|
||||
// redirect to emmc variables
|
||||
#define sd_sdmmc emmc_sdmmc
|
||||
#define sd_storage emmc_storage
|
||||
#define sd_fs emmc_fs
|
||||
|
||||
void sd_error_count_increment(u8 type);
|
||||
u16 *sd_get_error_count();
|
||||
|
Loading…
Reference in New Issue
Block a user