summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2024-11-07 17:45:24 -0500
committerSolomon Peachy <pizza@shaftnet.org>2024-11-09 16:34:06 -0500
commitc61ad40812a51abf8942e3e224a17f4b61000130 (patch)
tree2a9df6d1e800de24eb2ed15191f72ed756e74415
parentbc6c189dcb5f43ace776ca2a781fd647c14fca56 (diff)
downloadrockbox-c61ad40812.tar.gz
rockbox-c61ad40812.zip
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
-rw-r--r--firmware/common/disk.c23
-rw-r--r--firmware/drivers/ata-common.c8
-rw-r--r--firmware/drivers/fat.c21
-rw-r--r--firmware/export/config.h7
-rw-r--r--firmware/export/config/ipod6g.h3
-rw-r--r--firmware/export/config/ipodvideo.h3
-rw-r--r--firmware/export/disk.h5
-rw-r--r--firmware/export/fat.h8
-rw-r--r--firmware/include/fs_defines.h4
9 files changed, 49 insertions, 33 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 73ed22d27b..ebcfe56852 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -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);
diff --git a/firmware/drivers/ata-common.c b/firmware/drivers/ata-common.c
index cd905f2da9..c8af99b60a 100644
--- a/firmware/drivers/ata-common.c
+++ b/firmware/drivers/ata-common.c
@@ -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;
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 9963919441..a3dc69275c 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -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))
{
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 65f05b3e8e..c53f8d5c69 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -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
diff --git a/firmware/export/config/ipod6g.h b/firmware/export/config/ipod6g.h
index 2a218e4ee1..c13e35d7df 100644
--- a/firmware/export/config/ipod6g.h
+++ b/firmware/export/config/ipod6g.h
@@ -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
diff --git a/firmware/export/config/ipodvideo.h b/firmware/export/config/ipodvideo.h
index a9d7314068..15b188fbe6 100644
--- a/firmware/export/config/ipodvideo.h
+++ b/firmware/export/config/ipodvideo.h
@@ -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"
diff --git a/firmware/export/disk.h b/firmware/export/disk.h
index c2bbd8b1a2..408998f075 100644
--- a/firmware/export/disk.h
+++ b/firmware/export/disk.h
@@ -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));
diff --git a/firmware/export/fat.h b/firmware/export/fat.h
index 36e29e73d9..4ff93bcc3a 100644
--- a/firmware/export/fat.h
+++ b/firmware/export/fat.h
@@ -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);
diff --git a/firmware/include/fs_defines.h b/firmware/include/fs_defines.h
index 04e2b001a9..70e083ae2e 100644
--- a/firmware/include/fs_defines.h
+++ b/firmware/include/fs_defines.h
@@ -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