Add support for reading boot files from FAT partition on BOOT1/GPP/SD in that order

Emummc config is read from boot partition, file based files still read from SD
This commit is contained in:
Christoph Baumann
2025-04-22 13:42:20 +02:00
parent 9d2ec42a9f
commit 5798dcde0d
14 changed files with 310 additions and 38 deletions

View File

@@ -7,11 +7,37 @@
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include <storage/sd.h>
#include <storage/sdmmc.h>
#include <string.h>
#include <bdk.h>
#include <libs/fatfs/diskio.h> /* FatFs lower layer API */
#include "ffconf.h"
static bool ensure_partition(BYTE pdrv){
u8 part;
switch(pdrv){
case FF_DEV_SD:
return true;
case FF_DEV_BOOT1:
case FF_DEV_BOOT1_1MB:
part = EMMC_BOOT1;
break;
case FF_DEV_GPP:
part = EMMC_GPP;
break;
default:
return false;
}
if(emmc_storage.partition != part){
return emmc_set_partition(part);
}
return true;
}
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
@@ -43,7 +69,27 @@ DRESULT disk_read (
UINT count /* Number of sectors to read */
)
{
return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR;
sdmmc_storage_t *storage = &sd_storage;
u32 actual_sector = sector;
switch(pdrv){
case FF_DEV_SD:
break;
case FF_DEV_BOOT1:
case FF_DEV_GPP:
storage = &emmc_storage;
break;
case FF_DEV_BOOT1_1MB:
storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512);
break;
default:
return RES_ERROR;
}
ensure_partition(pdrv);
return sdmmc_storage_read(storage, actual_sector, count, buff) ? RES_OK : RES_ERROR;
}
/*-----------------------------------------------------------------------*/
@@ -56,7 +102,27 @@ DRESULT disk_write (
UINT count /* Number of sectors to write */
)
{
return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
sdmmc_storage_t *storage = &sd_storage;
u32 actual_sector = sector;
switch(pdrv){
case FF_DEV_SD:
break;
case FF_DEV_BOOT1:
case FF_DEV_GPP:
storage = &emmc_storage;
break;
case FF_DEV_BOOT1_1MB:
storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512);
break;
default:
return RES_ERROR;
}
ensure_partition(pdrv);
return sdmmc_storage_write(storage, actual_sector, count, (void*)buff) ? RES_OK : RES_ERROR;
}
/*-----------------------------------------------------------------------*/

View File

@@ -166,7 +166,7 @@
*/
#define FF_FS_RPATH 0
#define FF_FS_RPATH 1
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.
@@ -179,12 +179,12 @@
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
#define FF_VOLUMES 1
#define FF_VOLUMES 4
/* Number of volumes (logical drives) to be used. (1-10) */
#define FF_STR_VOLUME_ID 0
#define FF_VOLUME_STRS "sd"
#define FF_VOLUME_STRS "sd", "boot1", "boot1_1mb", "gpp"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
@@ -300,6 +300,9 @@
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */
#define FF_DEV_BOOT1 1
#define FF_DEV_BOOT1_1MB 2
#define FF_DEV_SD 0
#define FF_DEV_GPP 3
/*--- End of configuration options ---*/