move boot_storage.h/.c to bdk/storage, check result of ensure_partition
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
#include "../frontend/fe_tools.h"
|
||||
#include "../config.h"
|
||||
#include "../storage/emummc.h"
|
||||
#include "../storage/boot_storage.h"
|
||||
#include <storage/boot_storage.h>
|
||||
|
||||
extern hekate_config h_cfg;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "../hos/pkg1.h"
|
||||
#include "l4t.h"
|
||||
#include "l4t_config.inl"
|
||||
#include "../storage/boot_storage.h"
|
||||
#include <storage/boot_storage.h>
|
||||
|
||||
/*
|
||||
* API Revision info
|
||||
|
||||
@@ -69,6 +69,10 @@ DRESULT disk_read (
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
if(!ensure_partition(pdrv)){
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
sdmmc_storage_t *storage = &sd_storage;
|
||||
u32 actual_sector = sector;
|
||||
switch(pdrv){
|
||||
@@ -87,7 +91,6 @@ DRESULT disk_read (
|
||||
|
||||
}
|
||||
|
||||
ensure_partition(pdrv);
|
||||
|
||||
return sdmmc_storage_read(storage, actual_sector, count, buff) ? RES_OK : RES_ERROR;
|
||||
}
|
||||
@@ -102,6 +105,10 @@ DRESULT disk_write (
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
if(!ensure_partition(pdrv)){
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
sdmmc_storage_t *storage = &sd_storage;
|
||||
u32 actual_sector = sector;
|
||||
switch(pdrv){
|
||||
@@ -120,7 +127,6 @@ DRESULT disk_write (
|
||||
|
||||
}
|
||||
|
||||
ensure_partition(pdrv);
|
||||
|
||||
return sdmmc_storage_write(storage, actual_sector, count, (void*)buff) ? RES_OK : RES_ERROR;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <libs/compr/blz.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "storage/emummc.h"
|
||||
#include "storage/boot_storage.h"
|
||||
#include <storage/boot_storage.h>
|
||||
|
||||
#include "frontend/fe_tools.h"
|
||||
#include "frontend/fe_info.h"
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
#include "boot_storage.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <fatfs_cfg.h>
|
||||
#include <storage/sd.h>
|
||||
#include <storage/emmc.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
#define DEV_INVALID 0xff
|
||||
|
||||
static FATFS boot_storage_fs;
|
||||
static BYTE drive = -1;
|
||||
|
||||
static const char* drive_base_paths[] = {
|
||||
[DRIVE_SD] = XSTR(DRIVE_SD) ":",
|
||||
[DRIVE_BOOT1] = XSTR(DRIVE_BOOT1) ":",
|
||||
[DRIVE_BOOT1_1MB] = XSTR(DRIVE_BOOT1_1MB) ":",
|
||||
[DRIVE_EMMC] = XSTR(DRIVE_EMMC) ":",
|
||||
};
|
||||
|
||||
static bool _is_eligible(){
|
||||
if(f_stat(".no_boot_storage", NULL) == FR_OK){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boot_storage_get_mounted(){
|
||||
return drive != DEV_INVALID;
|
||||
}
|
||||
|
||||
bool boot_storage_get_initialized(){
|
||||
switch(drive){
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
return emmc_get_initialized();
|
||||
case DRIVE_SD:
|
||||
return sd_get_card_initialized();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool _boot_storage_initialize(){
|
||||
switch(drive){
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
return emmc_initialize(false);
|
||||
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){
|
||||
sd_unmount();
|
||||
}else{
|
||||
f_mount(NULL, drive_base_paths[drive], false);
|
||||
}
|
||||
drive = DEV_INVALID;
|
||||
}
|
||||
if(deinit){
|
||||
if(drive == DRIVE_SD){
|
||||
sd_end();
|
||||
}else{
|
||||
emmc_end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void boot_storage_unmount(){
|
||||
_boot_storage_end(false);
|
||||
}
|
||||
|
||||
void boot_storage_end(){
|
||||
_boot_storage_end(true);
|
||||
}
|
||||
|
||||
static bool _boot_storage_mount(){
|
||||
// may want to check sd card first and prioritize it
|
||||
|
||||
FRESULT res;
|
||||
|
||||
if(!emmc_get_initialized() && !emmc_initialize(false)){
|
||||
goto emmc_init_fail;
|
||||
}
|
||||
|
||||
static const BYTE emmc_drives[] = {DRIVE_BOOT1_1MB, DRIVE_BOOT1, DRIVE_EMMC};
|
||||
|
||||
for(BYTE i = 0; i < ARRAY_SIZE(emmc_drives); i++){
|
||||
res = f_mount(&boot_storage_fs, drive_base_paths[i], true);
|
||||
if(res == FR_OK){
|
||||
res = f_chdrive(drive_base_paths[i]);
|
||||
if(res == FR_OK && _is_eligible()){
|
||||
drive = i;
|
||||
break;
|
||||
}else{
|
||||
f_mount(NULL, drive_base_paths[i],false);
|
||||
res = FR_INVALID_DRIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(res != FR_OK){
|
||||
emmc_end();
|
||||
}
|
||||
|
||||
if(res == FR_OK){
|
||||
return true;
|
||||
}
|
||||
|
||||
emmc_init_fail:
|
||||
if(!sd_initialize(false)){
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(!sd_mount()){
|
||||
sd_end();
|
||||
goto out;
|
||||
}
|
||||
|
||||
res = f_chdrive(drive_base_paths[DRIVE_SD]);
|
||||
|
||||
if(res == FR_OK && _is_eligible()){
|
||||
drive = DRIVE_SD;
|
||||
return true;
|
||||
}
|
||||
|
||||
sd_end();
|
||||
|
||||
out:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool boot_storage_mount(){
|
||||
bool mounted = boot_storage_get_mounted();
|
||||
bool initialized = boot_storage_get_initialized();
|
||||
if(mounted && initialized){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!mounted){
|
||||
// not mounted. mounting will also initialize.
|
||||
return _boot_storage_mount();
|
||||
}
|
||||
|
||||
if(!initialized){
|
||||
return _boot_storage_initialize();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef _BOOT_STORAGE_H
|
||||
#define _BOOT_STORAGE_H
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
// check if boot1 (1mb), boot1, gpp, sd (in that order) have fat32 partition,
|
||||
// mount the partition and set the current drive to it
|
||||
bool boot_storage_mount();
|
||||
|
||||
void boot_storage_unmount();
|
||||
void boot_storage_end();
|
||||
|
||||
bool boot_storage_get_mounted();
|
||||
bool boot_storage_get_initialized();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user