storage: Wrap runtime variable sector size with MAX_VARIABLE_LOG_SECTOR

When enabled this allows 512n and 4Kn drives to be used with a single build.
(So far all ATA SSDs use 512 byte logical sectors)

Change-Id: I902d2318ca8abb581699c0bca68d6e3ec227d064
This commit is contained in:
Solomon Peachy 2024-11-07 17:45:24 -05:00
parent bc6c189dcb
commit c61ad40812
9 changed files with 49 additions and 33 deletions

View file

@ -126,7 +126,7 @@ int disk_get_sector_multiplier(IF_MD_NONVOID(int drive))
}
#endif /* MAX_VIRT_SECTOR_SIZE */
#if (CONFIG_STORAGE & STORAGE_ATA) // XXX make this more generic?
#ifdef MAX_VARIABLE_LOG_SECTOR
static uint16_t disk_log_sector_size[NUM_DRIVES] =
{ [0 ... NUM_DRIVES-1] = SECTOR_SIZE }; /* Updated from STORAGE_INFO */
int disk_get_log_sector_size(IF_MD_NONVOID(int drive))
@ -140,14 +140,9 @@ int disk_get_log_sector_size(IF_MD_NONVOID(int drive))
return size;
}
#define LOG_SECTOR_SIZE(__drive) disk_log_sector_size[IF_MD_DRV(__drive)]
#else /* !STORAGE_ATA */
#else /* !MAX_VARIABLE_LOG_SECTOR */
#define LOG_SECTOR_SIZE(__drive) SECTOR_SIZE
int disk_get_log_sector_size(IF_MD_NONVOID(int drive))
{
IF_MD((void)drive);
return SECTOR_SIZE;
}
#endif /* !CONFIG_STORAGE & STORAGE_ATA */
#endif /* !MAX_VARIABLE_LOG_SECTOR */
bool disk_init(IF_MD_NONVOID(int drive))
{
@ -163,23 +158,23 @@ bool disk_init(IF_MD_NONVOID(int drive))
struct storage_info *info = (struct storage_info*) sector;
storage_get_info(IF_MD_DRV(drive), info);
disk_writer_lock();
#ifdef MAX_VIRT_SECTOR_SIZE
#ifdef MAX_VARIABLE_LOG_SECTOR
disk_log_sector_size[IF_MD_DRV(drive)] = info->sector_size;
#endif
disk_writer_unlock();
#ifdef MAX_VIRT_SECTOR_SIZE
if (info->sector_size > MAX_VIRT_SECTOR_SIZE || info->sector_size > DC_CACHE_BUFSIZE) {
#ifdef MAX_VARIABLE_LOG_SECTOR
if (info->sector_size > MAX_VARIABLE_LOG_SECTOR || info->sector_size > DC_CACHE_BUFSIZE) {
panicf("Unsupported logical sector size: %d",
info->sector_size);
}
#else
#else /* !MAX_VARIABLE_LOG_SECTOR */
if (info->sector_size != SECTOR_SIZE) {
panicf("Unsupported logical sector size: %d",
info->sector_size);
}
#endif
#endif /* CONFIG_STORAGE & STORAGE_ATA */
#endif /* !MAX_VARIABLE_LOG_SECTOR */
#endif /* STORAGE_ATA */
memset(sector, 0, DC_CACHE_BUFSIZE);
storage_read_sectors(IF_MD(drive,) 0, 1, sector);

View file

@ -22,10 +22,10 @@
#ifdef MAX_PHYS_SECTOR_SIZE
#ifdef MAX_VIRT_SECTOR_SIZE
#define __MAX_VIRT_SECTOR_SIZE MAX_VIRT_SECTOR_SIZE
#ifdef MAX_VARIABLE_LOG_SECTOR
#define __MAX_VARIABLE_LOG_SECTOR MAX_VARIABLE_LOG_SECTOR
#else
#define __MAX_VIRT_SECTOR_SIZE SECTOR_SIZE
#define __MAX_VARIABLE_LOG_SECTOR SECTOR_SIZE
#endif
struct sector_cache_entry {
@ -226,7 +226,7 @@ static int ata_get_phys_sector_mult(void)
sector 1 then assume the drive supports "512e" and will handle
it better than us, so ignore the large physical sectors.
*/
char throwaway[__MAX_VIRT_SECTOR_SIZE];
char throwaway[__MAX_VARIABLE_LOG_SECTOR];
rc = ata_transfer_sectors(1, 1, &throwaway, false);
if (rc == 0)
phys_sector_mult = 1;

View file

@ -163,7 +163,7 @@ union raw_dirent
#define FAT_NTRES_LC_NAME 0x08
#define FAT_NTRES_LC_EXT 0x10
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
#define LOG_SECTOR_SIZE(bpb) fat_bpb->sector_size
#else
#define LOG_SECTOR_SIZE(bpb) SECTOR_SIZE
@ -272,14 +272,14 @@ static struct bpb
int BPB_FN_DECL(update_fat_entry, unsigned long, unsigned long);
void BPB_FN_DECL(fat_recalc_free_internal);
#endif /* HAVE_FAT16SUPPORT */
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
uint16_t sector_size;
#endif
} fat_bpbs[NUM_VOLUMES]; /* mounted partition info */
#ifdef STORAGE_NEEDS_BOUNCE_BUFFER
#ifdef MAX_VIRT_SECTOR_SIZE
#define BOUNCE_SECTOR_SIZE MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VARIABLE_LOG_SECTOR)
#define BOUNCE_SECTOR_SIZE MAX_VARIABLE_LOG_SECTOR
#else
#define BOUNCE_SECTOR_SIZE SECTOR_SIZE
#endif
@ -1997,14 +1997,14 @@ static int free_cluster_chain(struct bpb *fat_bpb, long startcluster)
/** File entity functions **/
#if defined(MAX_VARIABLE_LOG_SECTOR)
int fat_file_sector_size(const struct fat_file *file)
{
#ifdef MAX_VIRT_SECTOR_SIZE
const struct bpb *fat_bpb = FAT_BPB(file->volume);
#endif
return LOG_SECTOR_SIZE(fat_bpb);
}
#endif
int fat_create_file(struct fat_file *parent, const char *name,
uint8_t attr, struct fat_file *file,
@ -2769,7 +2769,7 @@ int fat_readdir(struct fat_filestr *dirstr, struct fat_dirscan_info *scan,
scan->entries = 0;
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
struct fat_file *file = dirstr->fatfilep;
const struct bpb *fat_bpb = FAT_BPB(file->volume);
#endif
@ -2916,8 +2916,7 @@ int fat_mount(IF_MV(int volume,) IF_MD(int drive,) unsigned long startsector)
#ifdef HAVE_MULTIDRIVE
fat_bpb->drive = drive;
#endif
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
fat_bpb->sector_size = disk_get_log_sector_size(IF_MD(drive));
#endif
@ -2959,7 +2958,7 @@ int fat_unmount(IF_MV_NONVOID(int volume))
/** Debug screen stuff **/
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
/* This isn't necessarily the same as storage's logical sector size;
we can have situations where the filesystem (and partition table)
uses a larger "virtual sector" than the underlying storage device */
@ -2973,7 +2972,7 @@ int fat_get_bytes_per_sector(IF_MV_NONVOID(int volume))
return bytes;
}
#endif /* MAX_VIRT_SECTOR_SIZE */
#endif /* MAX_VIRT_SECTOR_SIZE || MAX_VARIAGLE_LOG_SECTOR */
unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume))
{

View file

@ -924,6 +924,13 @@ Lyre prototype 1 */
#define NUM_VOLUMES (NUM_DRIVES * NUM_VOLUMES_PER_DRIVE)
/* Sanity check sector size options */
#if defined(MAX_VARIABLE_LOG_SECTOR) && defined(MAX_VIRT_SECTOR_SIZE)
#if (MAX_VIRT_SECTOR_SIZE < MAX_VARIABLE_LOG_SECTOR)
#error "optional MAX_VIRT_SECTOR_SIZE must be at least as large as MAX_VARIABLE_LOG_SECTOR"
#endif
#endif
#if defined(BOOTLOADER) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
/* Bootloaders don't use CPU frequency adjustment */
#undef HAVE_ADJUSTABLE_CPU_FREQ

View file

@ -197,6 +197,9 @@
/* This is the minimum access size for the device, even if it's larger than the logical sector size */
#define MAX_PHYS_SECTOR_SIZE 4096
/* define this if we want to support 512n and 4Kn drives */
//#define MAX_VARIABLE_LOG_SECTOR 4096
//#define STORAGE_NEEDS_BOUNCE_BUFFER
#define STORAGE_WANTS_ALIGN

View file

@ -221,6 +221,9 @@
/* and doesn't handle them in the drive firmware */
#define MAX_PHYS_SECTOR_SIZE 1024
/* define this if we want to support 512n and 4Kn drives */
//#define MAX_VARIABLE_LOG_SECTOR 4096
#define BOOTFILE_EXT "ipod"
#define BOOTFILE "rockbox." BOOTFILE_EXT
#define BOOTDIR "/.rockbox"

View file

@ -51,8 +51,13 @@ int disk_unmount(int drive);
#ifdef MAX_VIRT_SECTOR_SIZE
int disk_get_sector_multiplier(IF_MD_NONVOID(int drive));
#endif
#ifdef MAX_VARIABLE_LOG_SECTOR
/* The size of the drive's smallest addressible unit */
int disk_get_log_sector_size(IF_MD_NONVOID(int drive));
#else
#define disk_get_log_sector_size(...) SECTOR_SIZE
#endif
bool disk_present(IF_MD_NONVOID(int drive));

View file

@ -143,7 +143,11 @@ int fat_rename(struct fat_file *parent, struct fat_file *file,
int fat_modtime(struct fat_file *parent, struct fat_file *file,
time_t modtime);
#if defined(MAX_VARIABLE_LOG_SECTOR)
int fat_file_sector_size(const struct fat_file *file);
#else
#define fat_file_sector_size(__file) SECTOR_SIZE
#endif
/** File stream functions **/
int fat_closewrite(struct fat_filestr *filestr, uint32_t size,
@ -170,9 +174,9 @@ int fat_mount(IF_MV(int volume,) IF_MD(int drive,) unsigned long startsector);
int fat_unmount(IF_MV_NONVOID(int volume));
/** Debug screen stuff **/
#ifdef MAX_VIRT_SECTOR_SIZE
#if defined(MAX_VIRT_SECTOR_SIZE) || defined(MAX_VARIABLE_LOG_SECTOR)
int fat_get_bytes_per_sector(IF_MV_NONVOID(int volume));
#endif /* MAX_VIRT_SECTOR_SIZE */
#endif /* MAX_VIRT_SECTOR_SIZE || MAX_VARIABLE_LOG_SECTOR */
unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume));
void fat_recalc_free(IF_MV_NONVOID(int volume));
bool fat_size(IF_MV(int volume,) sector_t *size, sector_t *free);

View file

@ -108,8 +108,8 @@
#endif
/* this _could_ be larger than a sector if that would ever be useful */
#ifdef MAX_VIRT_SECTOR_SIZE
#define DC_CACHE_BUFSIZE MAX_VIRT_SECTOR_SIZE
#ifdef MAX_VARIABLE_LOG_SECTOR
#define DC_CACHE_BUFSIZE MAX_VARIABLE_LOG_SECTOR
#else
#define DC_CACHE_BUFSIZE SECTOR_SIZE
#endif