summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2009-07-17 22:28:49 +0000
committerFrank Gevaerts <frank@gevaerts.be>2009-07-17 22:28:49 +0000
commitc0a5a67387c4eec3db3bad4da77ba5126faf03c4 (patch)
treed7e61f6287c5fcdce903489b6b72d474225b98a7
parentbb3b57f64594ba517e06add4cfeff72b2b06e65b (diff)
downloadrockbox-c0a5a67387c4eec3db3bad4da77ba5126faf03c4.tar.gz
rockbox-c0a5a67387c4eec3db3bad4da77ba5126faf03c4.zip
Commit FS#9545, storage cleanup and multi-driver support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21933 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES23
-rw-r--r--firmware/common/disk.c34
-rw-r--r--firmware/drivers/ata.c33
-rw-r--r--firmware/drivers/ata_flash.c14
-rw-r--r--firmware/drivers/ata_mmc.c40
-rw-r--r--firmware/drivers/fat.c6
-rw-r--r--firmware/drivers/ramdisk.c46
-rw-r--r--firmware/export/ata.h14
-rw-r--r--firmware/export/config-c200.h3
-rw-r--r--firmware/export/config-e200.h3
-rw-r--r--firmware/export/config-e200v2.h3
-rw-r--r--firmware/export/config-fuze.h3
-rw-r--r--firmware/export/config-ondavx747.h6
-rw-r--r--firmware/export/config-ondavx767.h3
-rw-r--r--firmware/export/config-ondiofm.h3
-rw-r--r--firmware/export/config-ondiosp.h3
-rw-r--r--firmware/export/config.h36
-rw-r--r--firmware/export/disk.h2
-rw-r--r--firmware/export/fat.h2
-rw-r--r--firmware/export/mmc.h17
-rw-r--r--firmware/export/mv.h18
-rw-r--r--firmware/export/nand.h18
-rw-r--r--firmware/export/ramdisk.h13
-rw-r--r--firmware/export/sd.h23
-rw-r--r--firmware/export/storage.h270
-rw-r--r--firmware/storage.c545
-rw-r--r--firmware/target/arm/as3525/ata_sd_as3525.c58
-rw-r--r--firmware/target/arm/ata-nand-telechips.c51
-rw-r--r--firmware/target/arm/ata-sd-pp.c36
-rw-r--r--firmware/target/arm/s5l8700/ata-nand-s5l8700.c15
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c16
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-target.h4
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c25
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c35
-rw-r--r--firmware/test/fat/main.c4
-rw-r--r--firmware/test/i2c/main.c2
-rw-r--r--firmware/usbstack/usb_storage.c45
37 files changed, 1157 insertions, 315 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index bfb31e1b43..add88848dc 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -126,19 +126,28 @@ drivers/touchscreen.c
126#ifndef SIMULATOR 126#ifndef SIMULATOR
127#if (CONFIG_STORAGE & STORAGE_MMC) 127#if (CONFIG_STORAGE & STORAGE_MMC)
128drivers/ata_mmc.c 128drivers/ata_mmc.c
129#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_IFP7XX) 129#endif
130#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_IFP7XX)
130drivers/ata_flash.c 131drivers/ata_flash.c
131#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_TCC) 132#endif
133#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_TCC)
132target/arm/ata-nand-telechips.c 134target/arm/ata-nand-telechips.c
133#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_SAMSUNG) 135#endif
136#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_SAMSUNG)
134target/arm/s5l8700/ata-nand-s5l8700.c 137target/arm/s5l8700/ata-nand-s5l8700.c
135#elif (CONFIG_STORAGE & STORAGE_ATA) 138#endif
139#if (CONFIG_STORAGE & STORAGE_ATA)
136drivers/ata.c 140drivers/ata.c
137#elif (CONFIG_STORAGE & STORAGE_SD) 141#endif
142#if (CONFIG_STORAGE & STORAGE_SD)
138drivers/sd.c 143drivers/sd.c
139#elif (CONFIG_STORAGE & STORAGE_RAMDISK) 144#endif
145#if (CONFIG_STORAGE & STORAGE_RAMDISK)
140drivers/ramdisk.c 146drivers/ramdisk.c
141#endif /* CONFIG_STORAGE */ 147#endif
148#ifdef CONFIG_STORAGE_MULTI
149storage.c
150#endif
142drivers/fat.c 151drivers/fat.c
143#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) 152#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
144hotswap.c 153hotswap.c
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index cc0f0d657d..abeadb5c23 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -44,8 +44,8 @@
44 12-15: nr of sectors in partition 44 12-15: nr of sectors in partition
45*/ 45*/
46 46
47#define BYTES2INT32(array,pos) \ 47#define BYTES2INT32(array,pos) \
48 ((long)array[pos] | ((long)array[pos+1] << 8 ) | \ 48 ((long)array[pos] | ((long)array[pos+1] << 8 ) | \
49 ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 )) 49 ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 ))
50 50
51static const unsigned char fat_partition_types[] = { 51static const unsigned char fat_partition_types[] = {
@@ -58,18 +58,18 @@ static const unsigned char fat_partition_types[] = {
58#endif 58#endif
59}; 59};
60 60
61static struct partinfo part[8]; /* space for 4 partitions on 2 drives */ 61static struct partinfo part[NUM_DRIVES*4]; /* space for 4 partitions on 2 drives */
62static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */ 62static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */
63 63
64#ifdef MAX_LOG_SECTOR_SIZE 64#ifdef MAX_LOG_SECTOR_SIZE
65int disk_sector_multiplier = 1; 65int disk_sector_multiplier = 1;
66#endif 66#endif
67 67
68struct partinfo* disk_init(IF_MV_NONVOID(int drive)) 68struct partinfo* disk_init(IF_MD_NONVOID(int drive))
69{ 69{
70 int i; 70 int i;
71 unsigned char sector[512]; 71 unsigned char sector[512];
72#ifdef HAVE_MULTIVOLUME 72#ifdef HAVE_MULTIDRIVE
73 /* For each drive, start at a different position, in order not to destroy 73 /* For each drive, start at a different position, in order not to destroy
74 the first entry of drive 0. 74 the first entry of drive 0.
75 That one is needed to calculate config sector position. */ 75 That one is needed to calculate config sector position. */
@@ -115,7 +115,7 @@ struct partinfo* disk_partinfo(int partition)
115 115
116int disk_mount_all(void) 116int disk_mount_all(void)
117{ 117{
118 int mounted; 118 int mounted=0;
119 int i; 119 int i;
120 120
121#ifdef HAVE_HOTSWAP 121#ifdef HAVE_HOTSWAP
@@ -126,13 +126,19 @@ int disk_mount_all(void)
126 for (i=0; i<NUM_VOLUMES; i++) 126 for (i=0; i<NUM_VOLUMES; i++)
127 vol_drive[i] = -1; /* mark all as unassigned */ 127 vol_drive[i] = -1; /* mark all as unassigned */
128 128
129#ifndef HAVE_MULTIDRIVE
129 mounted = disk_mount(0); 130 mounted = disk_mount(0);
130#ifdef HAVE_HOTSWAP 131#else
131 if (card_detect()) 132 for(i=0;i<NUM_DRIVES;i++)
132 { 133 {
133 mounted += disk_mount(1); /* try 2nd "drive", too */ 134#ifdef HAVE_HOTSWAP
135 if (storage_present(i))
136#endif
137 mounted += disk_mount(i);
134 } 138 }
139#endif
135 140
141#ifdef HAVE_HOTSWAP
136 card_enable_monitoring(true); 142 card_enable_monitoring(true);
137#endif 143#endif
138 144
@@ -155,7 +161,7 @@ int disk_mount(int drive)
155{ 161{
156 int mounted = 0; /* reset partition-on-drive flag */ 162 int mounted = 0; /* reset partition-on-drive flag */
157 int volume = get_free_volume(); 163 int volume = get_free_volume();
158 struct partinfo* pinfo = disk_init(IF_MV(drive)); 164 struct partinfo* pinfo = disk_init(IF_MD(drive));
159 165
160 if (pinfo == NULL) 166 if (pinfo == NULL)
161 { 167 {
@@ -166,7 +172,7 @@ int disk_mount(int drive)
166#else 172#else
167 int i = 0; 173 int i = 0;
168#endif 174#endif
169 for (; volume != -1 && i<4; i++) 175 for (; volume != -1 && i<4 && mounted<NUM_VOLUMES_PER_DRIVE; i++)
170 { 176 {
171 if (memchr(fat_partition_types, pinfo[i].type, 177 if (memchr(fat_partition_types, pinfo[i].type,
172 sizeof(fat_partition_types)) == NULL) 178 sizeof(fat_partition_types)) == NULL)
@@ -177,7 +183,7 @@ int disk_mount(int drive)
177 183
178 for (j = 1; j <= (MAX_LOG_SECTOR_SIZE/SECTOR_SIZE); j <<= 1) 184 for (j = 1; j <= (MAX_LOG_SECTOR_SIZE/SECTOR_SIZE); j <<= 1)
179 { 185 {
180 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start * j)) 186 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start * j))
181 { 187 {
182 pinfo[i].start *= j; 188 pinfo[i].start *= j;
183 pinfo[i].size *= j; 189 pinfo[i].size *= j;
@@ -190,7 +196,7 @@ int disk_mount(int drive)
190 } 196 }
191 } 197 }
192#else 198#else
193 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start)) 199 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) pinfo[i].start))
194 { 200 {
195 mounted++; 201 mounted++;
196 vol_drive[volume] = drive; /* remember the drive for this volume */ 202 vol_drive[volume] = drive; /* remember the drive for this volume */
@@ -202,7 +208,7 @@ int disk_mount(int drive)
202 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */ 208 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */
203 { /* try "superfloppy" mode */ 209 { /* try "superfloppy" mode */
204 DEBUGF("No partition found, trying to mount sector 0.\n"); 210 DEBUGF("No partition found, trying to mount sector 0.\n");
205 if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) 0)) 211 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) 0))
206 { 212 {
207 mounted = 1; 213 mounted = 1;
208 vol_drive[volume] = drive; /* remember the drive for this volume */ 214 vol_drive[volume] = drive; /* remember the drive for this volume */
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index adc720eaf8..3c37077fd3 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -307,7 +307,7 @@ static int _read_sectors(unsigned long start,
307 int incount, 307 int incount,
308 void* inbuf) 308 void* inbuf)
309#else 309#else
310int ata_read_sectors(IF_MV2(int drive,) 310int ata_read_sectors(IF_MD2(int drive,)
311 unsigned long start, 311 unsigned long start,
312 int incount, 312 int incount,
313 void* inbuf) 313 void* inbuf)
@@ -323,7 +323,7 @@ int ata_read_sectors(IF_MV2(int drive,)
323#endif 323#endif
324 324
325#ifndef MAX_PHYS_SECTOR_SIZE 325#ifndef MAX_PHYS_SECTOR_SIZE
326#ifdef HAVE_MULTIVOLUME 326#ifdef HAVE_MULTIDRIVE
327 (void)drive; /* unused for now */ 327 (void)drive; /* unused for now */
328#endif 328#endif
329 mutex_lock(&ata_mtx); 329 mutex_lock(&ata_mtx);
@@ -555,7 +555,7 @@ static int _write_sectors(unsigned long start,
555 int count, 555 int count,
556 const void* buf) 556 const void* buf)
557#else 557#else
558int ata_write_sectors(IF_MV2(int drive,) 558int ata_write_sectors(IF_MD2(int drive,)
559 unsigned long start, 559 unsigned long start,
560 int count, 560 int count,
561 const void* buf) 561 const void* buf)
@@ -569,7 +569,7 @@ int ata_write_sectors(IF_MV2(int drive,)
569#endif 569#endif
570 570
571#ifndef MAX_PHYS_SECTOR_SIZE 571#ifndef MAX_PHYS_SECTOR_SIZE
572#ifdef HAVE_MULTIVOLUME 572#ifdef HAVE_MULTIDRIVE
573 (void)drive; /* unused for now */ 573 (void)drive; /* unused for now */
574#endif 574#endif
575 mutex_lock(&ata_mtx); 575 mutex_lock(&ata_mtx);
@@ -728,7 +728,7 @@ static inline int flush_current_sector(void)
728 sector_cache.data); 728 sector_cache.data);
729} 729}
730 730
731int ata_read_sectors(IF_MV2(int drive,) 731int ata_read_sectors(IF_MD2(int drive,)
732 unsigned long start, 732 unsigned long start,
733 int incount, 733 int incount,
734 void* inbuf) 734 void* inbuf)
@@ -736,7 +736,7 @@ int ata_read_sectors(IF_MV2(int drive,)
736 int rc = 0; 736 int rc = 0;
737 int offset; 737 int offset;
738 738
739#ifdef HAVE_MULTIVOLUME 739#ifdef HAVE_MULTIDRIVE
740 (void)drive; /* unused for now */ 740 (void)drive; /* unused for now */
741#endif 741#endif
742 mutex_lock(&ata_mtx); 742 mutex_lock(&ata_mtx);
@@ -794,7 +794,7 @@ int ata_read_sectors(IF_MV2(int drive,)
794 return rc; 794 return rc;
795} 795}
796 796
797int ata_write_sectors(IF_MV2(int drive,) 797int ata_write_sectors(IF_MD2(int drive,)
798 unsigned long start, 798 unsigned long start,
799 int count, 799 int count,
800 const void* buf) 800 const void* buf)
@@ -802,7 +802,7 @@ int ata_write_sectors(IF_MV2(int drive,)
802 int rc = 0; 802 int rc = 0;
803 int offset; 803 int offset;
804 804
805#ifdef HAVE_MULTIVOLUME 805#ifdef HAVE_MULTIDRIVE
806 (void)drive; /* unused for now */ 806 (void)drive; /* unused for now */
807#endif 807#endif
808 mutex_lock(&ata_mtx); 808 mutex_lock(&ata_mtx);
@@ -1503,7 +1503,7 @@ int ata_init(void)
1503 create_thread(ata_thread, ata_stack, 1503 create_thread(ata_thread, ata_stack,
1504 sizeof(ata_stack), 0, ata_thread_name 1504 sizeof(ata_stack), 0, ata_thread_name
1505 IF_PRIO(, PRIORITY_USER_INTERFACE) 1505 IF_PRIO(, PRIORITY_USER_INTERFACE)
1506 IF_COP(, CPU)); 1506 IF_COP(, CPU));
1507 initialized = true; 1507 initialized = true;
1508 1508
1509 } 1509 }
@@ -1552,12 +1552,15 @@ int ata_spinup_time(void)
1552} 1552}
1553 1553
1554#ifdef STORAGE_GET_INFO 1554#ifdef STORAGE_GET_INFO
1555void ata_get_info(struct storage_info *info) 1555void ata_get_info(IF_MD2(int drive,)struct storage_info *info)
1556{ 1556{
1557 unsigned short *src,*dest; 1557 unsigned short *src,*dest;
1558 static char vendor[8]; 1558 static char vendor[8];
1559 static char product[16]; 1559 static char product[16];
1560 static char revision[4]; 1560 static char revision[4];
1561#ifdef HAVE_MULTIDRIVE
1562 (void)drive; /* unused for now */
1563#endif
1561 int i; 1564 int i;
1562 info->sector_size = SECTOR_SIZE; 1565 info->sector_size = SECTOR_SIZE;
1563 info->num_sectors= total_sectors; 1566 info->num_sectors= total_sectors;
@@ -1595,3 +1598,13 @@ void ata_keep_active(void)
1595 last_disk_activity = current_tick; 1598 last_disk_activity = current_tick;
1596} 1599}
1597#endif 1600#endif
1601
1602#ifdef CONFIG_STORAGE_MULTI
1603int ata_num_drives(int first_drive)
1604{
1605 /* We don't care which logical drive number(s) we have been assigned */
1606 (void)first_drive;
1607
1608 return 1;
1609}
1610#endif
diff --git a/firmware/drivers/ata_flash.c b/firmware/drivers/ata_flash.c
index ba96ea0f7d..2d31b413ac 100644
--- a/firmware/drivers/ata_flash.c
+++ b/firmware/drivers/ata_flash.c
@@ -384,7 +384,7 @@ int flash_disk_read_sectors(unsigned long start,
384 return done; 384 return done;
385} 385}
386 386
387int nand_read_sectors(IF_MV2(int drive,) 387int nand_read_sectors(IF_MD2(int drive,)
388 unsigned long start, 388 unsigned long start,
389 int incount, 389 int incount,
390 void* inbuf) 390 void* inbuf)
@@ -401,7 +401,7 @@ int nand_read_sectors(IF_MV2(int drive,)
401 return 0; 401 return 0;
402} 402}
403 403
404int nand_write_sectors(IF_MV2(int drive,) 404int nand_write_sectors(IF_MD2(int drive,)
405 unsigned long start, 405 unsigned long start,
406 int count, 406 int count,
407 const void* buf) 407 const void* buf)
@@ -472,3 +472,13 @@ void nand_get_info(struct storage_info *info)
472} 472}
473#endif 473#endif
474 474
475#ifdef CONFIG_STORAGE_MULTI
476int nand_num_drives(int first_drive)
477{
478 /* We don't care which logical drive number(s) we have been assigned */
479 (void)first_drive;
480
481 return 1;
482}
483#endif
484
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 0fe89c5be8..239778577d 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -126,7 +126,7 @@ static int current_buffer = 0;
126static const unsigned char *send_block_addr = NULL; 126static const unsigned char *send_block_addr = NULL;
127 127
128static tCardInfo card_info[2]; 128static tCardInfo card_info[2];
129#ifndef HAVE_MULTIVOLUME 129#ifndef HAVE_MULTIDRIVE
130static int current_card = 0; 130static int current_card = 0;
131#endif 131#endif
132static bool last_mmc_status = false; 132static bool last_mmc_status = false;
@@ -602,7 +602,7 @@ static int send_block_send(unsigned char start_token, long timeout,
602 return rc; 602 return rc;
603} 603}
604 604
605int mmc_read_sectors(IF_MV2(int drive,) 605int mmc_read_sectors(IF_MD2(int drive,)
606 unsigned long start, 606 unsigned long start,
607 int incount, 607 int incount,
608 void* inbuf) 608 void* inbuf)
@@ -611,7 +611,7 @@ int mmc_read_sectors(IF_MV2(int drive,)
611 int lastblock = 0; 611 int lastblock = 0;
612 unsigned long end_block; 612 unsigned long end_block;
613 tCardInfo *card; 613 tCardInfo *card;
614#ifndef HAVE_MULTIVOLUME 614#ifndef HAVE_MULTIDRIVE
615 int drive = current_card; 615 int drive = current_card;
616#endif 616#endif
617 617
@@ -688,7 +688,7 @@ int mmc_read_sectors(IF_MV2(int drive,)
688 return rc; 688 return rc;
689} 689}
690 690
691int mmc_write_sectors(IF_MV2(int drive,) 691int mmc_write_sectors(IF_MD2(int drive,)
692 unsigned long start, 692 unsigned long start,
693 int count, 693 int count,
694 const void* buf) 694 const void* buf)
@@ -697,7 +697,7 @@ int mmc_write_sectors(IF_MV2(int drive,)
697 int write_cmd; 697 int write_cmd;
698 unsigned char start_token; 698 unsigned char start_token;
699 tCardInfo *card; 699 tCardInfo *card;
700#ifndef HAVE_MULTIVOLUME 700#ifndef HAVE_MULTIDRIVE
701 int drive = current_card; 701 int drive = current_card;
702#endif 702#endif
703 703
@@ -920,7 +920,7 @@ int mmc_init(void)
920 led(false); 920 led(false);
921 921
922 last_mmc_status = mmc_detect(); 922 last_mmc_status = mmc_detect();
923#ifndef HAVE_MULTIVOLUME 923#ifndef HAVE_MULTIDRIVE
924 /* Use MMC if inserted, internal flash otherwise */ 924 /* Use MMC if inserted, internal flash otherwise */
925 current_card = last_mmc_status ? 1 : 0; 925 current_card = last_mmc_status ? 1 : 0;
926#endif 926#endif
@@ -949,7 +949,7 @@ int mmc_init(void)
949 create_thread(mmc_thread, mmc_stack, 949 create_thread(mmc_thread, mmc_stack,
950 sizeof(mmc_stack), 0, mmc_thread_name 950 sizeof(mmc_stack), 0, mmc_thread_name
951 IF_PRIO(, PRIORITY_SYSTEM) 951 IF_PRIO(, PRIORITY_SYSTEM)
952 IF_COP(, CPU)); 952 IF_COP(, CPU));
953 tick_add_task(mmc_tick); 953 tick_add_task(mmc_tick);
954 initialized = true; 954 initialized = true;
955 } 955 }
@@ -965,9 +965,9 @@ long mmc_last_disk_activity(void)
965} 965}
966 966
967#ifdef STORAGE_GET_INFO 967#ifdef STORAGE_GET_INFO
968void mmc_get_info(IF_MV2(int drive,) struct storage_info *info) 968void mmc_get_info(IF_MD2(int drive,) struct storage_info *info)
969{ 969{
970#ifndef HAVE_MULTIVOLUME 970#ifndef HAVE_MULTIDRIVE
971 const int drive=0; 971 const int drive=0;
972#endif 972#endif
973 info->sector_size=card_info[drive].blocksize; 973 info->sector_size=card_info[drive].blocksize;
@@ -986,17 +986,17 @@ void mmc_get_info(IF_MV2(int drive,) struct storage_info *info)
986#endif 986#endif
987 987
988#ifdef HAVE_HOTSWAP 988#ifdef HAVE_HOTSWAP
989bool mmc_removable(IF_MV_NONVOID(int drive)) 989bool mmc_removable(IF_MD_NONVOID(int drive))
990{ 990{
991#ifndef HAVE_MULTIVOLUME 991#ifndef HAVE_MULTIDRIVE
992 const int drive=0; 992 const int drive=0;
993#endif 993#endif
994 return (drive==1); 994 return (drive==1);
995} 995}
996 996
997bool mmc_present(IF_MV_NONVOID(int drive)) 997bool mmc_present(IF_MD_NONVOID(int drive))
998{ 998{
999#ifndef HAVE_MULTIVOLUME 999#ifndef HAVE_MULTIDRIVE
1000 const int drive=0; 1000 const int drive=0;
1001#endif 1001#endif
1002 return (card_info[drive].initialized && card_info[drive].numblocks > 0); 1002 return (card_info[drive].initialized && card_info[drive].numblocks > 0);
@@ -1016,3 +1016,17 @@ void mmc_spindown(int seconds)
1016{ 1016{
1017 (void)seconds; 1017 (void)seconds;
1018} 1018}
1019
1020#ifdef CONFIG_STORAGE_MULTI
1021int mmc_num_drives(int first_drive)
1022{
1023 /* We don't care which logical drive number(s) we have been assigned */
1024 (void)first_drive;
1025
1026#ifdef HAVE_MULTIDRIVE
1027 return 2;
1028#else
1029 return 1;
1030#endif
1031}
1032#endif
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index a710593a69..e319669e97 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -167,7 +167,9 @@ struct bpb
167 * of first pseudo cluster */ 167 * of first pseudo cluster */
168#endif /* #ifdef HAVE_FAT16SUPPORT */ 168#endif /* #ifdef HAVE_FAT16SUPPORT */
169#ifdef HAVE_MULTIVOLUME 169#ifdef HAVE_MULTIVOLUME
170#ifdef HAVE_MULTIDRIVE
170 int drive; /* on which physical device is this located */ 171 int drive; /* on which physical device is this located */
172#endif
171 bool mounted; /* flag if this volume is mounted */ 173 bool mounted; /* flag if this volume is mounted */
172#endif 174#endif
173}; 175};
@@ -285,7 +287,7 @@ void fat_init(void)
285#endif 287#endif
286} 288}
287 289
288int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector) 290int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector)
289{ 291{
290#ifndef HAVE_MULTIVOLUME 292#ifndef HAVE_MULTIVOLUME
291 const int volume = 0; 293 const int volume = 0;
@@ -309,7 +311,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector)
309 311
310 memset(fat_bpb, 0, sizeof(struct bpb)); 312 memset(fat_bpb, 0, sizeof(struct bpb));
311 fat_bpb->startsector = startsector; 313 fat_bpb->startsector = startsector;
312#ifdef HAVE_MULTIVOLUME 314#ifdef HAVE_MULTIDRIVE
313 fat_bpb->drive = drive; 315 fat_bpb->drive = drive;
314#endif 316#endif
315 317
diff --git a/firmware/drivers/ramdisk.c b/firmware/drivers/ramdisk.c
index 0ea4012ef1..661aa39695 100644
--- a/firmware/drivers/ramdisk.c
+++ b/firmware/drivers/ramdisk.c
@@ -31,11 +31,14 @@ unsigned char ramdisk[SECTOR_SIZE * NUM_SECTORS];
31 31
32long last_disk_activity = -1; 32long last_disk_activity = -1;
33 33
34int ramdisk_read_sectors(IF_MV2(int drive,) 34int ramdisk_read_sectors(IF_MD2(int drive,)
35 unsigned long start, 35 unsigned long start,
36 int count, 36 int count,
37 void* buf) 37 void* buf)
38{ 38{
39#ifdef HAVE_MULTIDRIVE
40 (void)drive; /* unused for now */
41#endif
39 if(start+count>NUM_SECTORS) 42 if(start+count>NUM_SECTORS)
40 { 43 {
41 return -1; 44 return -1;
@@ -44,11 +47,14 @@ int ramdisk_read_sectors(IF_MV2(int drive,)
44 return 0; 47 return 0;
45} 48}
46 49
47int ramdisk_write_sectors(IF_MV2(int drive,) 50int ramdisk_write_sectors(IF_MD2(int drive,)
48 unsigned long start, 51 unsigned long start,
49 int count, 52 int count,
50 const void* buf) 53 const void* buf)
51{ 54{
55#ifdef HAVE_MULTIDRIVE
56 (void)drive; /* unused for now */
57#endif
52 if(start+count>NUM_SECTORS) 58 if(start+count>NUM_SECTORS)
53 { 59 {
54 return -1; 60 return -1;
@@ -79,13 +85,36 @@ void ramdisk_sleepnow(void)
79{ 85{
80} 86}
81 87
88void ramdisk_enable(bool on)
89{
90 (void)on;
91}
92
93bool ramdisk_disk_is_active(void)
94{
95 return true;
96}
97
98int ramdisk_soft_reset(void)
99{
100 return 0;
101}
102
103int ramdisk_spinup_time(void)
104{
105 return 0;
106}
107
82void ramdisk_spindown(int seconds) 108void ramdisk_spindown(int seconds)
83{ 109{
84 (void)seconds; 110 (void)seconds;
85} 111}
86#ifdef STORAGE_GET_INFO 112#ifdef STORAGE_GET_INFO
87void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info) 113void ramdisk_get_info(IF_MD2(int drive,) struct storage_info *info)
88{ 114{
115#ifdef HAVE_MULTIDRIVE
116 (void)drive; /* unused for now */
117#endif
89 /* firmware version */ 118 /* firmware version */
90 info->revision="0.00"; 119 info->revision="0.00";
91 120
@@ -100,3 +129,14 @@ void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info)
100} 129}
101#endif 130#endif
102 131
132#ifdef CONFIG_STORAGE_MULTI
133int ramdisk_num_drives(int first_drive)
134{
135 /* We don't care which logical drive number(s) we have been assigned */
136 (void)first_drive;
137
138 return 1;
139}
140#endif
141
142
diff --git a/firmware/export/ata.h b/firmware/export/ata.h
index b5e39de3aa..5be32da231 100644
--- a/firmware/export/ata.h
+++ b/firmware/export/ata.h
@@ -39,8 +39,8 @@ bool ata_disk_is_active(void);
39int ata_soft_reset(void); 39int ata_soft_reset(void);
40int ata_init(void); 40int ata_init(void);
41void ata_close(void); 41void ata_close(void);
42int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 42int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
43int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 43int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
44void ata_spin(void); 44void ata_spin(void);
45#if (CONFIG_LED == LED_REAL) 45#if (CONFIG_LED == LED_REAL)
46void ata_set_led_enabled(bool enabled); 46void ata_set_led_enabled(bool enabled);
@@ -48,14 +48,18 @@ void ata_set_led_enabled(bool enabled);
48unsigned short* ata_get_identify(void); 48unsigned short* ata_get_identify(void);
49 49
50#ifdef STORAGE_GET_INFO 50#ifdef STORAGE_GET_INFO
51void ata_get_info(IF_MV2(int drive,) struct storage_info *info); 51void ata_get_info(IF_MD2(int drive,) struct storage_info *info);
52#endif 52#endif
53#ifdef HAVE_HOTSWAP 53#ifdef HAVE_HOTSWAP
54bool ata_removable(IF_MV_NONVOID(int drive)); 54bool ata_removable(IF_MD_NONVOID(int drive));
55bool ata_present(IF_MV_NONVOID(int drive)); 55bool ata_present(IF_MD_NONVOID(int drive));
56#endif 56#endif
57 57
58 58
59#ifdef CONFIG_STORAGE_MULTI
60int ata_num_drives(int first_drive);
61#endif
62
59 63
60long ata_last_disk_activity(void); 64long ata_last_disk_activity(void);
61int ata_spinup_time(void); /* ticks */ 65int ata_spinup_time(void); /* ticks */
diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h
index 9bb8ead4a8..db64e5cacc 100644
--- a/firmware/export/config-c200.h
+++ b/firmware/export/config-c200.h
@@ -177,7 +177,8 @@
177#define FIRMWARE_OFFSET_FILE_DATA 0x8 177#define FIRMWARE_OFFSET_FILE_DATA 0x8
178 178
179#ifndef BOOTLOADER 179#ifndef BOOTLOADER
180#define HAVE_MULTIVOLUME 180#define HAVE_MULTIDRIVE
181#define NUM_DRIVES 2
181#define HAVE_HOTSWAP 182#define HAVE_HOTSWAP
182#endif 183#endif
183 184
diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h
index 59ac564c01..adae8a211d 100644
--- a/firmware/export/config-e200.h
+++ b/firmware/export/config-e200.h
@@ -171,7 +171,8 @@
171#define FIRMWARE_OFFSET_FILE_DATA 0x8 171#define FIRMWARE_OFFSET_FILE_DATA 0x8
172 172
173#ifndef BOOTLOADER 173#ifndef BOOTLOADER
174#define HAVE_MULTIVOLUME 174#define HAVE_MULTIDRIVE
175#define NUM_DRIVES 2
175#define HAVE_HOTSWAP 176#define HAVE_HOTSWAP
176#endif 177#endif
177 178
diff --git a/firmware/export/config-e200v2.h b/firmware/export/config-e200v2.h
index a1c41fbe7d..d66bde4943 100644
--- a/firmware/export/config-e200v2.h
+++ b/firmware/export/config-e200v2.h
@@ -180,7 +180,8 @@
180#define FIRMWARE_OFFSET_FILE_DATA 0x8 180#define FIRMWARE_OFFSET_FILE_DATA 0x8
181 181
182#ifndef BOOTLOADER 182#ifndef BOOTLOADER
183#define HAVE_MULTIVOLUME 183#define HAVE_MULTIDRIVE
184#define NUM_DRIVES 2
184#define HAVE_HOTSWAP 185#define HAVE_HOTSWAP
185#endif 186#endif
186 187
diff --git a/firmware/export/config-fuze.h b/firmware/export/config-fuze.h
index b9c5acb9b1..c8d7e2fba9 100644
--- a/firmware/export/config-fuze.h
+++ b/firmware/export/config-fuze.h
@@ -178,7 +178,8 @@
178#define FIRMWARE_OFFSET_FILE_DATA 0x8 178#define FIRMWARE_OFFSET_FILE_DATA 0x8
179 179
180#ifndef BOOTLOADER 180#ifndef BOOTLOADER
181#define HAVE_MULTIVOLUME 181#define HAVE_MULTIDRIVE
182#define NUM_DRIVES 2
182#define HAVE_HOTSWAP 183#define HAVE_HOTSWAP
183#endif 184#endif
184 185
diff --git a/firmware/export/config-ondavx747.h b/firmware/export/config-ondavx747.h
index 1d9a7a8883..dbb37c972d 100644
--- a/firmware/export/config-ondavx747.h
+++ b/firmware/export/config-ondavx747.h
@@ -42,8 +42,7 @@
42//#define HAVE_ATA_SD 42//#define HAVE_ATA_SD
43//#define HAVE_HOTSWAP 43//#define HAVE_HOTSWAP
44 44
45//#define CONFIG_STORAGE (STORAGE_NAND | STORAGE_SD) 45#define CONFIG_STORAGE (STORAGE_NAND | STORAGE_SD)
46#define CONFIG_STORAGE STORAGE_SD
47 46
48/* Support FAT16 for SD cards <= 2GB */ 47/* Support FAT16 for SD cards <= 2GB */
49#define HAVE_FAT16SUPPORT 48#define HAVE_FAT16SUPPORT
@@ -51,6 +50,9 @@
51/* ChinaChip NAND FTL */ 50/* ChinaChip NAND FTL */
52#define CONFIG_NAND NAND_CC 51#define CONFIG_NAND NAND_CC
53 52
53#define HAVE_MULTIDRIVE
54#define NUM_DRIVES 2
55
54/* define this if you have a bitmap LCD display */ 56/* define this if you have a bitmap LCD display */
55#define HAVE_LCD_BITMAP 57#define HAVE_LCD_BITMAP
56 58
diff --git a/firmware/export/config-ondavx767.h b/firmware/export/config-ondavx767.h
index a662fc0da9..d4873370dd 100644
--- a/firmware/export/config-ondavx767.h
+++ b/firmware/export/config-ondavx767.h
@@ -41,7 +41,8 @@
41 41
42#define CONFIG_NAND NAND_CC 42#define CONFIG_NAND NAND_CC
43 43
44#define HAVE_MULTIVOLUME 44#define HAVE_MULTIDRIVE
45#define NUM_DRIVES 2
45 46
46/* define this if you have a bitmap LCD display */ 47/* define this if you have a bitmap LCD display */
47#define HAVE_LCD_BITMAP 48#define HAVE_LCD_BITMAP
diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h
index a43810e3ff..a8802dcea8 100644
--- a/firmware/export/config-ondiofm.h
+++ b/firmware/export/config-ondiofm.h
@@ -125,7 +125,8 @@
125#define HAVE_MAS_SIBI_CONTROL 125#define HAVE_MAS_SIBI_CONTROL
126 126
127/* define this if more than one device/partition can be used */ 127/* define this if more than one device/partition can be used */
128#define HAVE_MULTIVOLUME 128#define HAVE_MULTIDRIVE
129#define NUM_DRIVES 2
129 130
130/* define this if media can be exchanged on the fly */ 131/* define this if media can be exchanged on the fly */
131#define HAVE_HOTSWAP 132#define HAVE_HOTSWAP
diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h
index 1fcf45b200..ba26713612 100644
--- a/firmware/export/config-ondiosp.h
+++ b/firmware/export/config-ondiosp.h
@@ -106,7 +106,8 @@
106#define HAVE_MAS_SIBI_CONTROL 106#define HAVE_MAS_SIBI_CONTROL
107 107
108/* define this if more than one device/partition can be used */ 108/* define this if more than one device/partition can be used */
109#define HAVE_MULTIVOLUME 109#define HAVE_MULTIDRIVE
110#define NUM_DRIVES 2
110 111
111/* define this if media can be exchanged on the fly */ 112/* define this if media can be exchanged on the fly */
112#define HAVE_HOTSWAP 113#define HAVE_HOTSWAP
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 406ef509c8..092e02f458 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -539,11 +539,6 @@ Lyre prototype 1*/
539#define CONFIG_TUNER_MULTI 539#define CONFIG_TUNER_MULTI
540#endif 540#endif
541 541
542#if (CONFIG_STORAGE & (CONFIG_STORAGE - 1)) != 0
543/* Multiple storage drivers */
544#define CONFIG_STORAGE_MULTI
545#endif
546
547/* deactivate fading in bootloader/sim */ 542/* deactivate fading in bootloader/sim */
548#if defined(BOOTLOADER) || defined(SIMULATOR) 543#if defined(BOOTLOADER) || defined(SIMULATOR)
549#undef CONFIG_BACKLIGHT_FADING 544#undef CONFIG_BACKLIGHT_FADING
@@ -571,6 +566,37 @@ Lyre prototype 1*/
571 566
572#endif /* CONFIG_BACKLIGHT_FADING */ 567#endif /* CONFIG_BACKLIGHT_FADING */
573 568
569/* Storage related config handling */
570
571#if (CONFIG_STORAGE & (CONFIG_STORAGE - 1)) != 0
572/* Multiple storage drivers */
573#define CONFIG_STORAGE_MULTI
574#endif
575
576/* Explicit HAVE_MULTIVOLUME in the config file. Allow the maximum number */
577#ifdef HAVE_MULTIVOLUME
578#define NUM_VOLUMES_PER_DRIVE 4
579#else
580#define NUM_VOLUMES_PER_DRIVE 1
581#endif
582#if defined(CONFIG_STORAGE_MULTI) && !defined(HAVE_MULTIDRIVE)
583#define HAVE_MULTIDRIVE
584#endif
585
586#if defined(HAVE_MULTIDRIVE) && !defined(HAVE_MULTIVOLUME)
587#define HAVE_MULTIVOLUME
588#endif
589
590#if defined(HAVE_MULTIDRIVE) && !defined(NUM_DRIVES)
591#error HAVE_MULTIDRIVE needs to have an explicit NUM_DRIVES
592#endif
593
594#ifndef NUM_DRIVES
595#define NUM_DRIVES 1
596#endif
597
598#define NUM_VOLUMES (NUM_DRIVES * NUM_VOLUMES_PER_DRIVE)
599
574#if defined(BOOTLOADER) && defined(HAVE_ADJUSTABLE_CPU_FREQ) 600#if defined(BOOTLOADER) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
575/* Bootloaders don't use CPU frequency adjustment */ 601/* Bootloaders don't use CPU frequency adjustment */
576#undef HAVE_ADJUSTABLE_CPU_FREQ 602#undef HAVE_ADJUSTABLE_CPU_FREQ
diff --git a/firmware/export/disk.h b/firmware/export/disk.h
index cec9bfa3fc..cd937fdf66 100644
--- a/firmware/export/disk.h
+++ b/firmware/export/disk.h
@@ -35,7 +35,7 @@ struct partinfo {
35#define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84 35#define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84
36 36
37/* returns a pointer to an array of 8 partinfo structs */ 37/* returns a pointer to an array of 8 partinfo structs */
38struct partinfo* disk_init(IF_MV_NONVOID(int volume)); 38struct partinfo* disk_init(IF_MD_NONVOID(int drive));
39struct partinfo* disk_partinfo(int partition); 39struct partinfo* disk_partinfo(int partition);
40int disk_mount_all(void); /* returns the # of successful mounts */ 40int disk_mount_all(void); /* returns the # of successful mounts */
41int disk_mount(int drive); 41int disk_mount(int drive);
diff --git a/firmware/export/fat.h b/firmware/export/fat.h
index c99a1a75f8..d6e753f9cb 100644
--- a/firmware/export/fat.h
+++ b/firmware/export/fat.h
@@ -90,7 +90,7 @@ extern void fat_unlock(void);
90#endif 90#endif
91 91
92extern void fat_init(void); 92extern void fat_init(void);
93extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector); 93extern int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector);
94extern int fat_unmount(int volume, bool flush); 94extern int fat_unmount(int volume, bool flush);
95extern void fat_size(IF_MV2(int volume,) /* public for info */ 95extern void fat_size(IF_MV2(int volume,) /* public for info */
96 unsigned long* size, 96 unsigned long* size,
diff --git a/firmware/export/mmc.h b/firmware/export/mmc.h
index 06d99d219e..f2b0ad3509 100644
--- a/firmware/export/mmc.h
+++ b/firmware/export/mmc.h
@@ -23,7 +23,7 @@
23#define __MMC_H__ 23#define __MMC_H__
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "mv.h" /* for HAVE_MULTIVOLUME or not */ 26#include "mv.h" /* for HAVE_MULTIDRIVE or not */
27 27
28struct storage_info; 28struct storage_info;
29 29
@@ -35,19 +35,24 @@ bool mmc_disk_is_active(void);
35int mmc_soft_reset(void); 35int mmc_soft_reset(void);
36int mmc_init(void); 36int mmc_init(void);
37void mmc_close(void); 37void mmc_close(void);
38int mmc_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 38int mmc_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
39int mmc_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 39int mmc_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
40void mmc_spin(void); 40void mmc_spin(void);
41int mmc_spinup_time(void); 41int mmc_spinup_time(void);
42 42
43#ifdef STORAGE_GET_INFO 43#ifdef STORAGE_GET_INFO
44void mmc_get_info(IF_MV2(int drive,) struct storage_info *info); 44void mmc_get_info(IF_MD2(int drive,) struct storage_info *info);
45#endif 45#endif
46#ifdef HAVE_HOTSWAP 46#ifdef HAVE_HOTSWAP
47bool mmc_removable(IF_MV_NONVOID(int drive)); 47bool mmc_removable(IF_MD_NONVOID(int drive));
48bool mmc_present(IF_MV_NONVOID(int drive)); 48bool mmc_present(IF_MD_NONVOID(int drive));
49#endif 49#endif
50 50
51long mmc_last_disk_activity(void); 51long mmc_last_disk_activity(void);
52 52
53#ifdef CONFIG_STORAGE_MULTI
54int mmc_num_drives(int first_drive);
55#endif
56
57
53#endif 58#endif
diff --git a/firmware/export/mv.h b/firmware/export/mv.h
index fda650c7e9..b1d16a7267 100644
--- a/firmware/export/mv.h
+++ b/firmware/export/mv.h
@@ -26,16 +26,28 @@
26 26
27/* FixMe: These macros are a bit nasty and perhaps misplaced here. 27/* FixMe: These macros are a bit nasty and perhaps misplaced here.
28 We'll get rid of them once decided on how to proceed with multivolume. */ 28 We'll get rid of them once decided on how to proceed with multivolume. */
29
30/* Drives are things like a disk, a card, a flash chip. They can have volumes on them */
31#ifdef HAVE_MULTIDRIVE
32#define IF_MD(x) x /* optional drive parameter */
33#define IF_MD2(x,y) x,y /* same, for a list of arguments */
34#define IF_MD_NONVOID(x) x /* for prototype with sole volume parameter */
35#else /* empty definitions if no multi-drive */
36#define IF_MD(x)
37#define IF_MD2(x,y)
38#define IF_MD_NONVOID(x) void
39#endif
40
41/* Volumes mean things that have filesystems on them, like partitions */
29#ifdef HAVE_MULTIVOLUME 42#ifdef HAVE_MULTIVOLUME
30#define IF_MV(x) x /* optional volume/drive parameter */ 43#define IF_MV(x) x /* optional volume parameter */
31#define IF_MV2(x,y) x,y /* same, for a list of arguments */ 44#define IF_MV2(x,y) x,y /* same, for a list of arguments */
32#define IF_MV_NONVOID(x) x /* for prototype with sole volume parameter */ 45#define IF_MV_NONVOID(x) x /* for prototype with sole volume parameter */
33#define NUM_VOLUMES 2
34#else /* empty definitions if no multi-volume */ 46#else /* empty definitions if no multi-volume */
35#define IF_MV(x) 47#define IF_MV(x)
36#define IF_MV2(x,y) 48#define IF_MV2(x,y)
37#define IF_MV_NONVOID(x) void 49#define IF_MV_NONVOID(x) void
38#define NUM_VOLUMES 1
39#endif 50#endif
40 51
52
41#endif 53#endif
diff --git a/firmware/export/nand.h b/firmware/export/nand.h
index a5b0a1ceee..67ebe73ddf 100644
--- a/firmware/export/nand.h
+++ b/firmware/export/nand.h
@@ -23,25 +23,31 @@
23#define __NAND_H__ 23#define __NAND_H__
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "mv.h" /* for HAVE_MULTIVOLUME or not */ 26#include "mv.h" /* for HAVE_MULTIDRIVE or not */
27 27
28struct storage_info; 28struct storage_info;
29 29
30void nand_enable(bool on); 30void nand_enable(bool on);
31void nand_spindown(int seconds); 31void nand_spindown(int seconds);
32void nand_sleep(void); 32void nand_sleep(void);
33void nand_sleepnow(void);
33bool nand_disk_is_active(void); 34bool nand_disk_is_active(void);
34int nand_soft_reset(void); 35int nand_soft_reset(void);
35int nand_init(void); 36int nand_init(void);
36void nand_close(void); 37void nand_close(void);
37int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 38int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
38int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 39int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
39void nand_spin(void); 40void nand_spin(void);
41int nand_spinup_time(void); /* ticks */
40 42
41#ifdef STORAGE_GET_INFO 43#ifdef STORAGE_GET_INFO
42void nand_get_info(IF_MV2(int drive,) struct storage_info *info); 44void nand_get_info(IF_MD2(int drive,) struct storage_info *info);
43#endif 45#endif
44 46
45long nand_last_disk_activity(void); 47long nand_last_disk_activity(void);
46 48
49#ifdef CONFIG_STORAGE_MULTI
50int nand_num_drives(int first_drive);
51#endif
52
47#endif 53#endif
diff --git a/firmware/export/ramdisk.h b/firmware/export/ramdisk.h
index a0c011fadd..79551ca287 100644
--- a/firmware/export/ramdisk.h
+++ b/firmware/export/ramdisk.h
@@ -23,7 +23,7 @@
23#define __RAMDISK_H__ 23#define __RAMDISK_H__
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "mv.h" /* for HAVE_MULTIVOLUME or not */ 26#include "mv.h" /* for HAVE_MULTIDRIVE or not */
27 27
28struct storage_info; 28struct storage_info;
29 29
@@ -34,15 +34,20 @@ bool ramdisk_disk_is_active(void);
34int ramdisk_soft_reset(void); 34int ramdisk_soft_reset(void);
35int ramdisk_init(void); 35int ramdisk_init(void);
36void ramdisk_close(void); 36void ramdisk_close(void);
37int ramdisk_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 37int ramdisk_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
38int ramdisk_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 38int ramdisk_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
39void ramdisk_spin(void); 39void ramdisk_spin(void);
40void ramdisk_sleepnow(void); 40void ramdisk_sleepnow(void);
41int ramdisk_spinup_time(void);
41 42
42#ifdef STORAGE_GET_INFO 43#ifdef STORAGE_GET_INFO
43void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info); 44void ramdisk_get_info(IF_MD2(int drive,) struct storage_info *info);
44#endif 45#endif
45 46
46long ramdisk_last_disk_activity(void); 47long ramdisk_last_disk_activity(void);
47 48
49#ifdef CONFIG_STORAGE_MULTI
50int ramdisk_num_drives(int first_drive);
51#endif
52
48#endif 53#endif
diff --git a/firmware/export/sd.h b/firmware/export/sd.h
index d313a4c2e1..0b64bd768d 100644
--- a/firmware/export/sd.h
+++ b/firmware/export/sd.h
@@ -23,7 +23,7 @@
23#define __SD_H__ 23#define __SD_H__
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "mv.h" /* for HAVE_MULTIVOLUME or not */ 26#include "mv.h" /* for HAVE_MULTIDRIVE or not */
27 27
28#define SD_BLOCK_SIZE 512 /* XXX : support other sizes ? */ 28#define SD_BLOCK_SIZE 512 /* XXX : support other sizes ? */
29 29
@@ -32,27 +32,34 @@ struct storage_info;
32void sd_enable(bool on); 32void sd_enable(bool on);
33void sd_spindown(int seconds); 33void sd_spindown(int seconds);
34void sd_sleep(void); 34void sd_sleep(void);
35void sd_sleepnow(void);
35bool sd_disk_is_active(void); 36bool sd_disk_is_active(void);
36int sd_soft_reset(void); 37int sd_soft_reset(void);
37int sd_init(void); 38int sd_init(void);
38void sd_close(void); 39void sd_close(void);
39int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 40int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
40int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 41int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
41void sd_spin(void); 42void sd_spin(void);
43int sd_spinup_time(void); /* ticks */
42 44
43#ifdef STORAGE_GET_INFO 45#ifdef STORAGE_GET_INFO
44void sd_get_info(IF_MV2(int drive,) struct storage_info *info); 46void sd_get_info(IF_MD2(int drive,) struct storage_info *info);
45#endif 47#endif
46#ifdef HAVE_HOTSWAP 48#ifdef HAVE_HOTSWAP
47bool sd_removable(IF_MV_NONVOID(int drive)); 49bool sd_removable(IF_MV_NONVOID(int drive));
48bool sd_present(IF_MV_NONVOID(int drive)); 50bool sd_present(IF_MV_NONVOID(int drive));
49void card_enable_monitoring_target(bool on); 51void card_enable_monitoring_target(bool on);
50#endif 52#endif
51 53
52bool card_detect_target(void); 54bool card_detect_target(void);
53 55
54long sd_last_disk_activity(void); 56long sd_last_disk_activity(void);
55 57
58#ifdef CONFIG_STORAGE_MULTI
59int sd_num_drives(int first_drive);
60#endif
61
62
56/* SD States */ 63/* SD States */
57#define SD_IDLE 0 64#define SD_IDLE 0
58#define SD_READY 1 65#define SD_READY 1
diff --git a/firmware/export/storage.h b/firmware/export/storage.h
index 47d8abda52..dbcc7a69ab 100644
--- a/firmware/export/storage.h
+++ b/firmware/export/storage.h
@@ -23,7 +23,7 @@
23#define __STORAGE_H__ 23#define __STORAGE_H__
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "config.h" /* for HAVE_MULTIVOLUME or not */ 26#include "config.h" /* for HAVE_MULTIDRIVE or not */
27#include "mv.h" 27#include "mv.h"
28 28
29#if (CONFIG_STORAGE & STORAGE_SD) 29#if (CONFIG_STORAGE & STORAGE_SD)
@@ -51,154 +51,147 @@ struct storage_info
51 char *revision; 51 char *revision;
52}; 52};
53 53
54#ifndef SIMULATOR 54#if !defined(SIMULATOR) && !defined(CONFIG_STORAGE_MULTI)
55 #ifndef CONFIG_STORAGE_MULTI 55/* storage_spindown, storage_sleep and storage_spin are passed as
56 /* storage_spindown, storage_sleep and storage_spin are passed as 56 * pointers, which doesn't work with argument-macros.
57 * pointers, which doesn't work with argument-macros. 57 */
58 */ 58 #define storage_num_drives() NUM_DRIVES
59 #if (CONFIG_STORAGE & STORAGE_ATA) 59 #if (CONFIG_STORAGE & STORAGE_ATA)
60 #define storage_spindown ata_spindown 60 #define storage_spindown ata_spindown
61 #define storage_sleep ata_sleep 61 #define storage_sleep ata_sleep
62 #define storage_spin ata_spin 62 #define storage_spin ata_spin
63 63
64 #define storage_enable(on) ata_enable(on) 64 #define storage_enable(on) ata_enable(on)
65 #define storage_sleepnow() ata_sleepnow() 65 #define storage_sleepnow() ata_sleepnow()
66 #define storage_disk_is_active() ata_disk_is_active() 66 #define storage_disk_is_active() ata_disk_is_active()
67 #define storage_soft_reset() ata_soft_reset() 67 #define storage_soft_reset() ata_soft_reset()
68 #define storage_init() ata_init() 68 #define storage_init() ata_init()
69 #define storage_close() ata_close() 69 #define storage_close() ata_close()
70 #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MV2(drive,) start, count, buf) 70 #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MD2(drive,) start, count, buf)
71 #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MV2(drive,) start, count, buf) 71 #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MD2(drive,) start, count, buf)
72 #define storage_last_disk_activity() ata_last_disk_activity() 72 #define storage_last_disk_activity() ata_last_disk_activity()
73 #define storage_spinup_time() ata_spinup_time() 73 #define storage_spinup_time() ata_spinup_time()
74 #define storage_get_identify() ata_get_identify() 74 #define storage_get_identify() ata_get_identify()
75 75
76 #ifdef STORAGE_GET_INFO 76 #ifdef STORAGE_GET_INFO
77 #define storage_get_info(drive, info) ata_get_info(IF_MV2(drive,) info) 77 #define storage_get_info(drive, info) ata_get_info(IF_MD2(drive,) info)
78 #endif 78 #endif
79 #ifdef HAVE_HOTSWAP 79 #ifdef HAVE_HOTSWAP
80 #define storage_removable(drive) ata_removable(IF_MV(drive)) 80 #define storage_removable(drive) ata_removable(IF_MD(drive))
81 #define storage_present(drive) ata_present(IF_MV(drive)) 81 #define storage_present(drive) ata_present(IF_MD(drive))
82 #endif 82 #endif
83 #elif (CONFIG_STORAGE & STORAGE_SD) 83 #elif (CONFIG_STORAGE & STORAGE_SD)
84 #define storage_spindown sd_spindown 84 #define storage_spindown sd_spindown
85 #define storage_sleep sd_sleep 85 #define storage_sleep sd_sleep
86 #define storage_spin sd_spin 86 #define storage_spin sd_spin
87 87
88 #define storage_enable(on) sd_enable(on) 88 #define storage_enable(on) sd_enable(on)
89 #define storage_sleepnow() sd_sleepnow() 89 #define storage_sleepnow() sd_sleepnow()
90 #define storage_disk_is_active() 0 90 #define storage_disk_is_active() 0
91 #define storage_soft_reset() (void)0 91 #define storage_soft_reset() (void)0
92 #define storage_init() sd_init() 92 #define storage_init() sd_init()
93 #define storage_close() sd_close() 93 #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MD2(drive,) start, count, buf)
94 #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MV2(drive,) start, count, buf) 94 #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MD2(drive,) start, count, buf)
95 #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MV2(drive,) start, count, buf) 95 #define storage_last_disk_activity() sd_last_disk_activity()
96 #define storage_last_disk_activity() sd_last_disk_activity() 96 #define storage_spinup_time() 0
97 #define storage_spinup_time() 0 97 #define storage_get_identify() sd_get_identify()
98 #define storage_get_identify() sd_get_identify() 98
99 99 #ifdef STORAGE_GET_INFO
100 #ifdef STORAGE_GET_INFO 100 #define storage_get_info(drive, info) sd_get_info(IF_MD2(drive,) info)
101 #define storage_get_info(drive, info) sd_get_info(IF_MV2(drive,) info) 101 #endif
102 #endif 102 #ifdef HAVE_HOTSWAP
103 #ifdef HAVE_HOTSWAP 103 #define storage_removable(drive) sd_removable(IF_MD(drive))
104 #define storage_removable(drive) sd_removable(IF_MV(drive)) 104 #define storage_present(drive) sd_present(IF_MD(drive))
105 #define storage_present(drive) sd_present(IF_MV(drive)) 105 #endif
106 #endif 106 #elif (CONFIG_STORAGE & STORAGE_MMC)
107 #elif (CONFIG_STORAGE & STORAGE_MMC) 107 #define storage_spindown mmc_spindown
108 #define storage_spindown mmc_spindown 108 #define storage_sleep mmc_sleep
109 #define storage_sleep mmc_sleep 109 #define storage_spin mmc_spin
110 #define storage_spin mmc_spin 110
111 111 #define storage_enable(on) mmc_enable(on)
112 #define storage_enable(on) mmc_enable(on) 112 #define storage_sleepnow() mmc_sleepnow()
113 #define storage_sleepnow() mmc_sleepnow() 113 #define storage_disk_is_active() mmc_disk_is_active()
114 #define storage_disk_is_active() mmc_disk_is_active() 114 #define storage_soft_reset() (void)0
115 #define storage_soft_reset() (void)0 115 #define storage_init() mmc_init()
116 #define storage_init() mmc_init() 116 #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MD2(drive,) start, count, buf)
117 #define storage_close() mmc_close() 117 #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MD2(drive,) start, count, buf)
118 #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MV2(drive,) start, count, buf) 118 #define storage_last_disk_activity() mmc_last_disk_activity()
119 #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MV2(drive,) start, count, buf) 119 #define storage_spinup_time() 0
120 #define storage_last_disk_activity() mmc_last_disk_activity() 120 #define storage_get_identify() mmc_get_identify()
121 #define storage_spinup_time() 0 121
122 #define storage_get_identify() mmc_get_identify() 122 #ifdef STORAGE_GET_INFO
123 123 #define storage_get_info(drive, info) mmc_get_info(IF_MD2(drive,) info)
124 #ifdef STORAGE_GET_INFO 124 #endif
125 #define storage_get_info(drive, info) mmc_get_info(IF_MV2(drive,) info) 125 #ifdef HAVE_HOTSWAP
126 #endif 126 #define storage_removable(drive) mmc_removable(IF_MD(drive))
127 #ifdef HAVE_HOTSWAP 127 #define storage_present(drive) mmc_present(IF_MD(drive))
128 #define storage_removable(drive) mmc_removable(IF_MV(drive)) 128 #endif
129 #define storage_present(drive) mmc_present(IF_MV(drive)) 129 #elif (CONFIG_STORAGE & STORAGE_NAND)
130 #endif 130 #define storage_spindown nand_spindown
131 #elif (CONFIG_STORAGE & STORAGE_NAND) 131 #define storage_sleep nand_sleep
132 #define storage_spindown nand_spindown 132 #define storage_spin nand_spin
133 #define storage_sleep nand_sleep 133
134 #define storage_spin nand_spin 134 #define storage_enable(on) (void)0
135 135 #define storage_sleepnow() nand_sleepnow()
136 #define storage_enable(on) (void)0 136 #define storage_disk_is_active() 0
137 #define storage_sleepnow() nand_sleepnow() 137 #define storage_soft_reset() (void)0
138 #define storage_disk_is_active() 0 138 #define storage_init() nand_init()
139 #define storage_soft_reset() (void)0 139 #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MD2(drive,) start, count, buf)
140 #define storage_init() nand_init() 140 #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MD2(drive,) start, count, buf)
141 #define storage_close() nand_close() 141 #define storage_last_disk_activity() nand_last_disk_activity()
142 #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MV2(drive,) start, count, buf) 142 #define storage_spinup_time() 0
143 #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MV2(drive,) start, count, buf) 143 #define storage_get_identify() nand_get_identify()
144 #define storage_last_disk_activity() nand_last_disk_activity() 144
145 #define storage_spinup_time() 0 145 #ifdef STORAGE_GET_INFO
146 #define storage_get_identify() nand_get_identify() 146 #define storage_get_info(drive, info) nand_get_info(IF_MD2(drive,) info)
147 147 #endif
148 #ifdef STORAGE_GET_INFO 148 #ifdef HAVE_HOTSWAP
149 #define storage_get_info(drive, info) nand_get_info(IF_MV2(drive,) info) 149 #define storage_removable(drive) nand_removable(IF_MD(drive))
150 #endif 150 #define storage_present(drive) nand_present(IF_MD(drive))
151 #ifdef HAVE_HOTSWAP 151 #endif
152 #define storage_removable(drive) nand_removable(IF_MV(drive)) 152 #elif (CONFIG_STORAGE & STORAGE_RAMDISK)
153 #define storage_present(drive) nand_present(IF_MV(drive)) 153 #define storage_spindown ramdisk_spindown
154 #endif 154 #define storage_sleep ramdisk_sleep
155 #elif (CONFIG_STORAGE & STORAGE_RAMDISK) 155 #define storage_spin ramdisk_spin
156 #define storage_spindown ramdisk_spindown 156
157 #define storage_sleep ramdisk_sleep 157 #define storage_enable(on) (void)0
158 #define storage_spin ramdisk_spin 158 #define storage_sleepnow() ramdisk_sleepnow()
159 159 #define storage_disk_is_active() 0
160 #define storage_enable(on) (void)0 160 #define storage_soft_reset() (void)0
161 #define storage_sleepnow() ramdisk_sleepnow() 161 #define storage_init() ramdisk_init()
162 #define storage_disk_is_active() 0 162 #define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MD2(drive,) start, count, buf)
163 #define storage_soft_reset() (void)0 163 #define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MD2(drive,) start, count, buf)
164 #define storage_init() ramdisk_init() 164 #define storage_last_disk_activity() ramdisk_last_disk_activity()
165 #define storage_close() ramdisk_close() 165 #define storage_spinup_time() 0
166 #define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MV2(drive,) start, count, buf) 166 #define storage_get_identify() ramdisk_get_identify()
167 #define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MV2(drive,) start, count, buf) 167
168 #define storage_last_disk_activity() ramdisk_last_disk_activity() 168 #ifdef STORAGE_GET_INFO
169 #define storage_spinup_time() 0 169 #define storage_get_info(drive, info) ramdisk_get_info(IF_MD2(drive,) info)
170 #define storage_get_identify() ramdisk_get_identify() 170 #endif
171 171 #ifdef HAVE_HOTSWAP
172 #ifdef STORAGE_GET_INFO 172 #define storage_removable(drive) ramdisk_removable(IF_MD(drive))
173 #define storage_get_info(drive, info) ramdisk_get_info(IF_MV2(drive,) info) 173 #define storage_present(drive) ramdisk_present(IF_MD(drive))
174 #endif 174 #endif
175 #ifdef HAVE_HOTSWAP 175 #else
176 #define storage_removable(drive) ramdisk_removable(IF_MV(drive)) 176 //#error No storage driver!
177 #define storage_present(drive) ramdisk_present(IF_MV(drive)) 177 #endif
178 #endif 178#else /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/
179 #else 179
180 //#error No storage driver! 180/* Simulator and multi-driver use normal functions */
181 #endif 181
182 #else /* NOT CONFIG_STORAGE_MULTI */
183
184 /* TODO : implement multi-driver here */
185 #error Multi-driver storage not implemented yet
186
187 #endif /* NOT CONFIG_STORAGE_MULTI */
188#else /*NOT SIMULATOR */
189void storage_enable(bool on); 182void storage_enable(bool on);
190void storage_sleep(void); 183void storage_sleep(void);
191void storage_sleepnow(void); 184void storage_sleepnow(void);
192bool storage_disk_is_active(void); 185bool storage_disk_is_active(void);
193int storage_soft_reset(void); 186int storage_soft_reset(void);
194int storage_init(void); 187int storage_init(void);
195void storage_close(void);
196int storage_read_sectors(int drive, unsigned long start, int count, void* buf); 188int storage_read_sectors(int drive, unsigned long start, int count, void* buf);
197int storage_write_sectors(int drive, unsigned long start, int count, const void* buf); 189int storage_write_sectors(int drive, unsigned long start, int count, const void* buf);
198void storage_spin(void); 190void storage_spin(void);
199void storage_spindown(int seconds); 191void storage_spindown(int seconds);
200long storage_last_disk_activity(void); 192long storage_last_disk_activity(void);
201int storage_spinup_time(void); 193int storage_spinup_time(void);
194int storage_num_drives(void);
202#ifdef STORAGE_GET_INFO 195#ifdef STORAGE_GET_INFO
203void storage_get_info(int drive, struct storage_info *info); 196void storage_get_info(int drive, struct storage_info *info);
204#endif 197#endif
@@ -206,5 +199,6 @@ void storage_get_info(int drive, struct storage_info *info);
206bool storage_removable(int drive); 199bool storage_removable(int drive);
207bool storage_present(int drive); 200bool storage_present(int drive);
208#endif 201#endif
209#endif/*NOT SIMULATOR */ 202
203#endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/
210#endif 204#endif
diff --git a/firmware/storage.c b/firmware/storage.c
new file mode 100644
index 0000000000..1528d03919
--- /dev/null
+++ b/firmware/storage.c
@@ -0,0 +1,545 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: buffer.c 17847 2008-06-28 18:10:04Z bagder $
9 *
10 * Copyright (C) 2008 by Frank Gevaerts
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "storage.h"
22
23#define DRIVER_MASK 0xff000000
24#define DRIVER_OFFSET 24
25#define DRIVE_MASK 0x00ff0000
26#define DRIVE_OFFSET 16
27#define PARTITION_MASK 0x0000ff00
28
29static unsigned int storage_drivers[NUM_DRIVES];
30static unsigned int num_drives;
31
32int storage_num_drives(void)
33{
34 return num_drives;
35}
36
37int storage_init(void)
38{
39 int rc=0;
40 int i;
41 num_drives=0;
42
43#if (CONFIG_STORAGE & STORAGE_ATA)
44 if ((rc=ata_init())) return rc;
45
46 int ata_drives = ata_num_drives(num_drives);
47 for (i=0; i<ata_drives; i++)
48 {
49 storage_drivers[num_drives++] =
50 (STORAGE_ATA<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
51 }
52#endif
53
54#if (CONFIG_STORAGE & STORAGE_MMC)
55 if ((rc=mmc_init())) return rc;
56
57 int mmc_drives = mmc_num_drives(num_drives);
58 for (i=0; i<mmc_drives ;i++)
59 {
60 storage_drivers[num_drives++] =
61 (STORAGE_MMC<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
62 }
63#endif
64
65#if (CONFIG_STORAGE & STORAGE_SD)
66 if ((rc=sd_init())) return rc;
67
68 int sd_drives = sd_num_drives(num_drives);
69 for (i=0; i<sd_drives; i++)
70 {
71 storage_drivers[num_drives++] =
72 (STORAGE_SD<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
73 }
74#endif
75
76#if (CONFIG_STORAGE & STORAGE_NAND)
77 if ((rc=nand_init())) return rc;
78
79 int nand_drives = nand_num_drives(num_drives);
80 for (i=0; i<nand_drives; i++)
81 {
82 storage_drivers[num_drives++] =
83 (STORAGE_NAND<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
84 }
85#endif
86
87#if (CONFIG_STORAGE & STORAGE_RAMDISK)
88 if ((rc=ramdisk_init())) return rc;
89
90 int ramdisk_drives = ramdisk_num_drives(num_drives);
91 for (i=0; i<ramdisk_drives; i++)
92 {
93 storage_drivers[num_drives++] =
94 (STORAGE_RAMDISK<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
95 }
96#endif
97
98 return 0;
99}
100
101int storage_read_sectors(int drive, unsigned long start, int count,
102 void* buf)
103{
104 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
105 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
106
107 switch (driver)
108 {
109#if (CONFIG_STORAGE & STORAGE_ATA)
110 case STORAGE_ATA:
111 return ata_read_sectors(ldrive,start,count,buf);
112#endif
113
114#if (CONFIG_STORAGE & STORAGE_MMC)
115 case STORAGE_MMC:
116 return mmc_read_sectors(ldrive,start,count,buf);
117#endif
118
119#if (CONFIG_STORAGE & STORAGE_SD)
120 case STORAGE_SD:
121 return sd_read_sectors(ldrive,start,count,buf);
122#endif
123
124#if (CONFIG_STORAGE & STORAGE_NAND)
125 case STORAGE_NAND:
126 return nand_read_sectors(ldrive,start,count,buf);
127#endif
128
129#if (CONFIG_STORAGE & STORAGE_RAMDISK)
130 case STORAGE_RAMDISK:
131 return ramdisk_read_sectors(ldrive,start,count,buf);
132#endif
133 }
134
135 return -1;
136}
137
138int storage_write_sectors(int drive, unsigned long start, int count,
139 const void* buf)
140{
141 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
142 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
143
144 switch (driver)
145 {
146#if (CONFIG_STORAGE & STORAGE_ATA)
147 case STORAGE_ATA:
148 return ata_write_sectors(ldrive,start,count,buf);
149#endif
150
151#if (CONFIG_STORAGE & STORAGE_MMC)
152 case STORAGE_MMC:
153 return mmc_write_sectors(ldrive,start,count,buf);
154#endif
155
156#if (CONFIG_STORAGE & STORAGE_SD)
157 case STORAGE_SD:
158 return sd_write_sectors(ldrive,start,count,buf);
159#endif
160
161#if (CONFIG_STORAGE & STORAGE_NAND)
162 case STORAGE_NAND:
163 return nand_write_sectors(ldrive,start,count,buf);
164#endif
165
166#if (CONFIG_STORAGE & STORAGE_RAMDISK)
167 case STORAGE_RAMDISK:
168 return ramdisk_write_sectors(ldrive,start,count,buf);
169#endif
170 }
171
172 return -1;
173}
174
175void storage_enable(bool on)
176{
177#if (CONFIG_STORAGE & STORAGE_ATA)
178 ata_enable(on);
179#endif
180
181#if (CONFIG_STORAGE & STORAGE_MMC)
182 mmc_enable(on);
183#endif
184
185#if (CONFIG_STORAGE & STORAGE_SD)
186 sd_enable(on);
187#endif
188
189#if (CONFIG_STORAGE & STORAGE_NAND)
190 nand_enable(on);
191#endif
192
193#if (CONFIG_STORAGE & STORAGE_RAMDISK)
194 ramdisk_enable(on);
195#endif
196}
197
198void storage_sleep(void)
199{
200#if (CONFIG_STORAGE & STORAGE_ATA)
201 ata_sleep();
202#endif
203
204#if (CONFIG_STORAGE & STORAGE_MMC)
205 mmc_sleep();
206#endif
207
208#if (CONFIG_STORAGE & STORAGE_SD)
209 sd_sleep();
210#endif
211
212#if (CONFIG_STORAGE & STORAGE_NAND)
213 nand_sleep();
214#endif
215
216#if (CONFIG_STORAGE & STORAGE_RAMDISK)
217 ramdisk_sleep();
218#endif
219}
220
221void storage_sleepnow(void)
222{
223#if (CONFIG_STORAGE & STORAGE_ATA)
224 ata_sleepnow();
225#endif
226
227#if (CONFIG_STORAGE & STORAGE_MMC)
228 mmc_sleepnow();
229#endif
230
231#if (CONFIG_STORAGE & STORAGE_SD)
232 //sd_sleepnow();
233#endif
234
235#if (CONFIG_STORAGE & STORAGE_NAND)
236 nand_sleepnow();
237#endif
238
239#if (CONFIG_STORAGE & STORAGE_RAMDISK)
240 ramdisk_sleepnow();
241#endif
242}
243
244bool storage_disk_is_active(void)
245{
246#if (CONFIG_STORAGE & STORAGE_ATA)
247 if (ata_disk_is_active()) return true;
248#endif
249
250#if (CONFIG_STORAGE & STORAGE_MMC)
251 if (mmc_disk_is_active()) return true;
252#endif
253
254#if (CONFIG_STORAGE & STORAGE_SD)
255 //if (sd_disk_is_active()) return true;
256#endif
257
258#if (CONFIG_STORAGE & STORAGE_NAND)
259 if (nand_disk_is_active()) return true;
260#endif
261
262#if (CONFIG_STORAGE & STORAGE_RAMDISK)
263 if (ramdisk_disk_is_active()) return true;
264#endif
265
266 return false;
267}
268
269int storage_soft_reset(void)
270{
271 int rc=0;
272
273#if (CONFIG_STORAGE & STORAGE_ATA)
274 if ((rc=ata_soft_reset())) return rc;
275#endif
276
277#if (CONFIG_STORAGE & STORAGE_MMC)
278 if ((rc=mmc_soft_reset())) return rc;
279#endif
280
281#if (CONFIG_STORAGE & STORAGE_SD)
282 //if ((rc=sd_soft_reset())) return rc;
283#endif
284
285#if (CONFIG_STORAGE & STORAGE_NAND)
286 if ((rc=nand_soft_reset())) return rc;
287#endif
288
289#if (CONFIG_STORAGE & STORAGE_RAMDISK)
290 if ((rc=ramdisk_soft_reset())) return rc;
291#endif
292
293 return 0;
294}
295
296void storage_spin(void)
297{
298#if (CONFIG_STORAGE & STORAGE_ATA)
299 ata_spin();
300#endif
301
302#if (CONFIG_STORAGE & STORAGE_MMC)
303 mmc_spin();
304#endif
305
306#if (CONFIG_STORAGE & STORAGE_SD)
307 sd_spin();
308#endif
309
310#if (CONFIG_STORAGE & STORAGE_NAND)
311 nand_spin();
312#endif
313
314#if (CONFIG_STORAGE & STORAGE_RAMDISK)
315 ramdisk_spin();
316#endif
317}
318
319void storage_spindown(int seconds)
320{
321#if (CONFIG_STORAGE & STORAGE_ATA)
322 ata_spindown(seconds);
323#endif
324
325#if (CONFIG_STORAGE & STORAGE_MMC)
326 mmc_spindown(seconds);
327#endif
328
329#if (CONFIG_STORAGE & STORAGE_SD)
330 sd_spindown(seconds);
331#endif
332
333#if (CONFIG_STORAGE & STORAGE_NAND)
334 nand_spindown(seconds);
335#endif
336
337#if (CONFIG_STORAGE & STORAGE_RAMDISK)
338 ramdisk_spindown(seconds);
339#endif
340}
341
342#if (CONFIG_LED == LED_REAL)
343void storage_set_led_enabled(bool enabled)
344{
345#if (CONFIG_STORAGE & STORAGE_ATA)
346 ata_set_led_enabled(enabled);
347#endif
348
349#if (CONFIG_STORAGE & STORAGE_MMC)
350 mmc_set_led_enabled(enabled);
351#endif
352
353#if (CONFIG_STORAGE & STORAGE_SD)
354 sd_set_led_enabled(enabled);
355#endif
356
357#if (CONFIG_STORAGE & STORAGE_NAND)
358 nand_set_led_enabled(enabled);
359#endif
360
361#if (CONFIG_STORAGE & STORAGE_RAMDISK)
362 ramdisk_set_led_enabled(enabled);
363#endif
364}
365#endif /* CONFIG_LED == LED_REAL */
366
367long storage_last_disk_activity(void)
368{
369 long max=0;
370 long t;
371
372#if (CONFIG_STORAGE & STORAGE_ATA)
373 t=ata_last_disk_activity();
374 if (t>max) max=t;
375#endif
376
377#if (CONFIG_STORAGE & STORAGE_MMC)
378 t=mmc_last_disk_activity();
379 if (t>max) max=t;
380#endif
381
382#if (CONFIG_STORAGE & STORAGE_SD)
383 t=sd_last_disk_activity();
384 if (t>max) max=t;
385#endif
386
387#if (CONFIG_STORAGE & STORAGE_NAND)
388 t=nand_last_disk_activity();
389 if (t>max) max=t;
390#endif
391
392#if (CONFIG_STORAGE & STORAGE_RAMDISK)
393 t=ramdisk_last_disk_activity();
394 if (t>max) max=t;
395#endif
396
397 return max;
398}
399
400int storage_spinup_time(void)
401{
402 int max=0;
403 int t;
404
405#if (CONFIG_STORAGE & STORAGE_ATA)
406 t=ata_spinup_time();
407 if (t>max) max=t;
408#endif
409
410#if (CONFIG_STORAGE & STORAGE_MMC)
411 t=mmc_spinup_time();
412 if (t>max) max=t;
413#endif
414
415#if (CONFIG_STORAGE & STORAGE_SD)
416 //t=sd_spinup_time();
417 //if (t>max) max=t;
418#endif
419
420#if (CONFIG_STORAGE & STORAGE_NAND)
421 t=nand_spinup_time();
422 if (t>max) max=t;
423#endif
424
425#if (CONFIG_STORAGE & STORAGE_RAMDISK)
426 t=ramdisk_spinup_time();
427 if (t>max) max=t;
428#endif
429
430 return max;
431}
432
433#ifdef STORAGE_GET_INFO
434void storage_get_info(int drive, struct storage_info *info)
435{
436 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
437 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
438
439 switch(driver)
440 {
441#if (CONFIG_STORAGE & STORAGE_ATA)
442 case STORAGE_ATA:
443 return ata_get_info(ldrive,info);
444#endif
445
446#if (CONFIG_STORAGE & STORAGE_MMC)
447 case STORAGE_MMC:
448 return mmc_get_info(ldrive,info);
449#endif
450
451#if (CONFIG_STORAGE & STORAGE_SD)
452 case STORAGE_SD:
453 return sd_get_info(ldrive,info);
454#endif
455
456#if (CONFIG_STORAGE & STORAGE_NAND)
457 case STORAGE_NAND:
458 return nand_get_info(ldrive,info);
459#endif
460
461#if (CONFIG_STORAGE & STORAGE_RAMDISK)
462 case STORAGE_RAMDISK:
463 return ramdisk_get_info(ldrive,info);
464#endif
465 }
466}
467#endif /* STORAGE_GET_INFO */
468
469#ifdef HAVE_HOTSWAP
470bool storage_removable(int drive)
471{
472 bool ret = false;
473
474 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
475 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
476
477 switch(driver)
478 {
479#if (CONFIG_STORAGE & STORAGE_ATA)
480 case STORAGE_ATA:
481 ret = ata_removable(ldrive);
482#endif
483
484#if (CONFIG_STORAGE & STORAGE_MMC)
485 case STORAGE_MMC:
486 ret = mmc_removable(ldrive);
487#endif
488
489#if (CONFIG_STORAGE & STORAGE_SD)
490 case STORAGE_SD:
491 ret = sd_removable(ldrive);
492#endif
493
494#if (CONFIG_STORAGE & STORAGE_NAND)
495 case STORAGE_NAND:
496 ret = false;
497#endif
498
499#if (CONFIG_STORAGE & STORAGE_RAMDISK)
500 case STORAGE_RAMDISK:
501 ret = false;
502#endif
503 }
504
505 return ret;
506}
507
508bool storage_present(int drive)
509{
510 bool ret = false;
511
512 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
513 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
514
515 switch(driver)
516 {
517#if (CONFIG_STORAGE & STORAGE_ATA)
518 case STORAGE_ATA:
519 ret = ata_present(ldrive);
520#endif
521
522#if (CONFIG_STORAGE & STORAGE_MMC)
523 case STORAGE_MMC:
524 ret = mmc_present(ldrive);
525#endif
526
527#if (CONFIG_STORAGE & STORAGE_SD)
528 case STORAGE_SD:
529 ret = sd_present(ldrive);
530#endif
531
532#if (CONFIG_STORAGE & STORAGE_NAND)
533 case STORAGE_NAND:
534 ret = true;
535#endif
536
537#if (CONFIG_STORAGE & STORAGE_RAMDISK)
538 case STORAGE_RAMDISK:
539 ret = true;
540#endif
541 }
542
543 return ret;
544}
545#endif
diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c
index 8a18a70826..bca52a09f1 100644
--- a/firmware/target/arm/as3525/ata_sd_as3525.c
+++ b/firmware/target/arm/as3525/ata_sd_as3525.c
@@ -24,7 +24,7 @@
24 24
25/* TODO: Find the real capacity of >2GB models (will be useful for USB) */ 25/* TODO: Find the real capacity of >2GB models (will be useful for USB) */
26 26
27#include "config.h" /* for HAVE_MULTIVOLUME & AMS_OF_SIZE */ 27#include "config.h" /* for HAVE_MULTIDRIVE & AMS_OF_SIZE */
28#include "fat.h" 28#include "fat.h"
29#include "thread.h" 29#include "thread.h"
30#include "led.h" 30#include "led.h"
@@ -88,9 +88,9 @@
88#define INTERNAL_AS3525 0 /* embedded SD card */ 88#define INTERNAL_AS3525 0 /* embedded SD card */
89#define SD_SLOT_AS3525 1 /* SD slot if present */ 89#define SD_SLOT_AS3525 1 /* SD slot if present */
90 90
91static const int pl180_base[NUM_VOLUMES] = { 91static const int pl180_base[NUM_DRIVES] = {
92 NAND_FLASH_BASE 92 NAND_FLASH_BASE
93#ifdef HAVE_MULTIVOLUME 93#ifdef HAVE_MULTIDRIVE
94 , SD_MCI_BASE 94 , SD_MCI_BASE
95#endif 95#endif
96}; 96};
@@ -101,7 +101,7 @@ static void init_pl180_controller(const int drive);
101#define SECTOR_SIZE 512 /* XXX: different sector sizes ? */ 101#define SECTOR_SIZE 512 /* XXX: different sector sizes ? */
102#define BLOCKS_PER_BANK 0x7a7800 102#define BLOCKS_PER_BANK 0x7a7800
103 103
104static tCardInfo card_info[NUM_VOLUMES]; 104static tCardInfo card_info[NUM_DRIVES];
105 105
106/* maximum timeouts recommanded in the SD Specification v2.00 */ 106/* maximum timeouts recommanded in the SD Specification v2.00 */
107#define SD_MAX_READ_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 100) /* 100 ms */ 107#define SD_MAX_READ_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 100) /* 100 ms */
@@ -169,7 +169,7 @@ void INT_NAND(void)
169 MCI_CLEAR(INTERNAL_AS3525) = status; 169 MCI_CLEAR(INTERNAL_AS3525) = status;
170} 170}
171 171
172#ifdef HAVE_MULTIVOLUME 172#ifdef HAVE_MULTIDRIVE
173void INT_MCI0(void) 173void INT_MCI0(void)
174{ 174{
175 const int status = MCI_STATUS(SD_SLOT_AS3525); 175 const int status = MCI_STATUS(SD_SLOT_AS3525);
@@ -436,7 +436,7 @@ static void init_pl180_controller(const int drive)
436 436
437 MCI_MASK0(drive) = MCI_MASK1(drive) = MCI_ERROR | MCI_DATA_END; 437 MCI_MASK0(drive) = MCI_MASK1(drive) = MCI_ERROR | MCI_DATA_END;
438 438
439#ifdef HAVE_MULTIVOLUME 439#ifdef HAVE_MULTIDRIVE
440 VIC_INT_ENABLE |= 440 VIC_INT_ENABLE |=
441 (drive == INTERNAL_AS3525) ? INTERRUPT_NAND : INTERRUPT_MCI0; 441 (drive == INTERNAL_AS3525) ? INTERRUPT_NAND : INTERRUPT_MCI0;
442 442
@@ -478,7 +478,7 @@ int sd_init(void)
478 478
479 479
480 CGU_PERI |= CGU_NAF_CLOCK_ENABLE; 480 CGU_PERI |= CGU_NAF_CLOCK_ENABLE;
481#ifdef HAVE_MULTIVOLUME 481#ifdef HAVE_MULTIDRIVE
482 CGU_PERI |= CGU_MCI_CLOCK_ENABLE; 482 CGU_PERI |= CGU_MCI_CLOCK_ENABLE;
483 CCU_IO &= ~(1<<3); /* bits 3:2 = 01, xpd is SD interface */ 483 CCU_IO &= ~(1<<3); /* bits 3:2 = 01, xpd is SD interface */
484 CCU_IO |= (1<<2); 484 CCU_IO |= (1<<2);
@@ -490,7 +490,7 @@ int sd_init(void)
490 ret = sd_init_card(INTERNAL_AS3525); 490 ret = sd_init_card(INTERNAL_AS3525);
491 if(ret < 0) 491 if(ret < 0)
492 return ret; 492 return ret;
493#ifdef HAVE_MULTIVOLUME 493#ifdef HAVE_MULTIDRIVE
494 init_pl180_controller(SD_SLOT_AS3525); 494 init_pl180_controller(SD_SLOT_AS3525);
495#endif 495#endif
496 496
@@ -509,17 +509,17 @@ int sd_init(void)
509} 509}
510 510
511#ifdef HAVE_HOTSWAP 511#ifdef HAVE_HOTSWAP
512bool sd_removable(IF_MV_NONVOID(int drive)) 512bool sd_removable(IF_MD_NONVOID(int drive))
513{ 513{
514#ifndef HAVE_MULTIVOLUME 514#ifndef HAVE_MULTIDRIVE
515 const int drive=0; 515 const int drive=0;
516#endif 516#endif
517 return (drive==1); 517 return (drive==1);
518} 518}
519 519
520bool sd_present(IF_MV_NONVOID(int drive)) 520bool sd_present(IF_MD_NONVOID(int drive))
521{ 521{
522#ifndef HAVE_MULTIVOLUME 522#ifndef HAVE_MULTIDRIVE
523 const int drive=0; 523 const int drive=0;
524#endif 524#endif
525 return (card_info[drive].initialized && card_info[drive].numblocks > 0); 525 return (card_info[drive].initialized && card_info[drive].numblocks > 0);
@@ -619,10 +619,10 @@ static int sd_select_bank(signed char bank)
619 return 0; 619 return 0;
620} 620}
621 621
622static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, 622static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
623 int count, void* buf, const bool write) 623 int count, void* buf, const bool write)
624{ 624{
625#ifndef HAVE_MULTIVOLUME 625#ifndef HAVE_MULTIDRIVE
626 const int drive = 0; 626 const int drive = 0;
627#endif 627#endif
628 int ret = 0; 628 int ret = 0;
@@ -774,18 +774,18 @@ sd_transfer_error:
774 return ret; 774 return ret;
775} 775}
776 776
777int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count, 777int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
778 void* buf) 778 void* buf)
779{ 779{
780 return sd_transfer_sectors(IF_MV2(drive,) start, count, buf, false); 780 return sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false);
781} 781}
782 782
783int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, 783int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
784 const void* buf) 784 const void* buf)
785{ 785{
786 786
787#ifdef BOOTLOADER /* we don't need write support in bootloader */ 787#ifdef BOOTLOADER /* we don't need write support in bootloader */
788#ifdef HAVE_MULTIVOLUME 788#ifdef HAVE_MULTIDRIVE
789 (void) drive; 789 (void) drive;
790#endif 790#endif
791 (void) start; 791 (void) start;
@@ -793,7 +793,7 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
793 (void) buf; 793 (void) buf;
794 return -1; 794 return -1;
795#else 795#else
796 return sd_transfer_sectors(IF_MV2(drive,) start, count, (void*)buf, true); 796 return sd_transfer_sectors(IF_MD2(drive,) start, count, (void*)buf, true);
797#endif 797#endif
798} 798}
799 799
@@ -807,7 +807,7 @@ void sd_enable(bool on)
807{ 807{
808 /* buttonlight AMSes need a bit of special handling for the buttonlight here, 808 /* buttonlight AMSes need a bit of special handling for the buttonlight here,
809 * due to the dual mapping of GPIOD and XPD */ 809 * due to the dual mapping of GPIOD and XPD */
810#if defined(HAVE_BUTTON_LIGHT) && defined(HAVE_MULTIVOLUME) 810#if defined(HAVE_BUTTON_LIGHT) && defined(HAVE_MULTIDRIVE)
811 extern int buttonlight_is_on; 811 extern int buttonlight_is_on;
812#endif 812#endif
813 if (sd_enabled == on) 813 if (sd_enabled == on)
@@ -815,7 +815,7 @@ void sd_enable(bool on)
815 if(on) 815 if(on)
816 { 816 {
817 CGU_PERI |= CGU_NAF_CLOCK_ENABLE; 817 CGU_PERI |= CGU_NAF_CLOCK_ENABLE;
818#ifdef HAVE_MULTIVOLUME 818#ifdef HAVE_MULTIDRIVE
819 CGU_PERI |= CGU_MCI_CLOCK_ENABLE; 819 CGU_PERI |= CGU_MCI_CLOCK_ENABLE;
820#ifdef HAVE_BUTTON_LIGHT 820#ifdef HAVE_BUTTON_LIGHT
821 CCU_IO |= (1<<2); 821 CCU_IO |= (1<<2);
@@ -832,7 +832,7 @@ void sd_enable(bool on)
832 else 832 else
833 { 833 {
834 CGU_PERI &= ~CGU_NAF_CLOCK_ENABLE; 834 CGU_PERI &= ~CGU_NAF_CLOCK_ENABLE;
835#ifdef HAVE_MULTIVOLUME 835#ifdef HAVE_MULTIDRIVE
836#ifdef HAVE_BUTTON_LIGHT 836#ifdef HAVE_BUTTON_LIGHT
837 CCU_IO &= ~(1<<2); 837 CCU_IO &= ~(1<<2);
838 if (buttonlight_is_on) 838 if (buttonlight_is_on)
@@ -882,3 +882,17 @@ void card_enable_monitoring_target(bool on)
882#endif 882#endif
883 883
884#endif /* BOOTLOADER */ 884#endif /* BOOTLOADER */
885
886#ifdef CONFIG_STORAGE_MULTI
887int sd_num_drives(int first_drive)
888{
889 /* We don't care which logical drive number(s) we have been assigned */
890 (void)first_drive;
891
892#ifdef HAVE_MULTIDRIVE
893 return 2;
894#else
895 return 1;
896#endif
897}
898#endif
diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c
index 8bef57ee21..ffe6de897e 100644
--- a/firmware/target/arm/ata-nand-telechips.c
+++ b/firmware/target/arm/ata-nand-telechips.c
@@ -696,10 +696,10 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
696} 696}
697 697
698 698
699int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, 699int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
700 void* inbuf) 700 void* inbuf)
701{ 701{
702#ifdef HAVE_MULTIVOLUME 702#ifdef HAVE_MULTIDRIVE
703 (void)drive; /* unused for now */ 703 (void)drive; /* unused for now */
704#endif 704#endif
705 705
@@ -753,11 +753,10 @@ nand_read_error:
753 return ret; 753 return ret;
754} 754}
755 755
756 756int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
757int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
758 const void* outbuf) 757 const void* outbuf)
759{ 758{
760#ifdef HAVE_MULTIVOLUME 759#ifdef HAVE_MULTIDRIVE
761 (void)drive; /* unused for now */ 760 (void)drive; /* unused for now */
762#endif 761#endif
763 762
@@ -770,8 +769,12 @@ int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
770 769
771 770
772#ifdef STORAGE_GET_INFO 771#ifdef STORAGE_GET_INFO
773void nand_get_info(struct storage_info *info) 772void nand_get_info(IF_MD2(int drive,) struct storage_info *info)
774{ 773{
774#ifdef HAVE_MULTIDRIVE
775 (void)drive; /* unused for now */
776#endif
777
775 /* firmware version */ 778 /* firmware version */
776 info->revision="0.00"; 779 info->revision="0.00";
777 780
@@ -913,3 +916,39 @@ void nand_spindown(int seconds)
913{ 916{
914 (void)seconds; 917 (void)seconds;
915} 918}
919
920#ifdef CONFIG_STORAGE_MULTI
921
922int nand_num_drives(int first_drive)
923{
924 /* We don't care which logical drive number we have been assigned */
925 (void)first_drive;
926
927 return 1;
928}
929
930void nand_sleepnow(void)
931{
932}
933
934bool nand_disk_is_active(void)
935{
936 return false;
937}
938
939int nand_soft_reset(void)
940{
941 return 0;
942}
943
944int nand_spinup_time(void)
945{
946 return 0;
947}
948
949void nand_enable(bool onoff)
950{
951 (void)onoff;
952}
953
954#endif /* CONFIG_STORAGE_MULTI */
diff --git a/firmware/target/arm/ata-sd-pp.c b/firmware/target/arm/ata-sd-pp.c
index 1a76eeeba2..77d3c3dc31 100644
--- a/firmware/target/arm/ata-sd-pp.c
+++ b/firmware/target/arm/ata-sd-pp.c
@@ -18,7 +18,7 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "config.h" /* for HAVE_MULTIVOLUME */ 21#include "config.h" /* for HAVE_MULTIDRIVE */
22#include "fat.h" 22#include "fat.h"
23#include "hotswap.h" 23#include "hotswap.h"
24#ifdef HAVE_HOTSWAP 24#ifdef HAVE_HOTSWAP
@@ -166,10 +166,10 @@ struct sd_card_status
166 int retry_max; 166 int retry_max;
167}; 167};
168 168
169static struct sd_card_status sd_status[NUM_VOLUMES] = 169static struct sd_card_status sd_status[NUM_DRIVES] =
170{ 170{
171 { 0, 1 }, 171 { 0, 1 },
172#ifdef HAVE_MULTIVOLUME 172#ifdef HAVE_MULTIDRIVE
173 { 0, 10 } 173 { 0, 10 }
174#endif 174#endif
175}; 175};
@@ -839,10 +839,10 @@ static void sd_select_device(int card_no)
839 839
840/* API Functions */ 840/* API Functions */
841 841
842int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, 842int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
843 void* inbuf) 843 void* inbuf)
844{ 844{
845#ifndef HAVE_MULTIVOLUME 845#ifndef HAVE_MULTIDRIVE
846 const int drive = 0; 846 const int drive = 0;
847#endif 847#endif
848 int ret; 848 int ret;
@@ -956,13 +956,13 @@ sd_read_error:
956 } 956 }
957} 957}
958 958
959int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, 959int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
960 const void* outbuf) 960 const void* outbuf)
961{ 961{
962/* Write support is not finished yet */ 962/* Write support is not finished yet */
963/* TODO: The standard suggests using ACMD23 prior to writing multiple blocks 963/* TODO: The standard suggests using ACMD23 prior to writing multiple blocks
964 to improve performance */ 964 to improve performance */
965#ifndef HAVE_MULTIVOLUME 965#ifndef HAVE_MULTIDRIVE
966 const int drive = 0; 966 const int drive = 0;
967#endif 967#endif
968 int ret; 968 int ret;
@@ -1330,19 +1330,33 @@ long sd_last_disk_activity(void)
1330} 1330}
1331 1331
1332#ifdef HAVE_HOTSWAP 1332#ifdef HAVE_HOTSWAP
1333bool sd_removable(IF_MV_NONVOID(int drive)) 1333bool sd_removable(IF_MD_NONVOID(int drive))
1334{ 1334{
1335#ifndef HAVE_MULTIVOLUME 1335#ifndef HAVE_MULTIDRIVE
1336 const int drive=0; 1336 const int drive=0;
1337#endif 1337#endif
1338 return (drive==1); 1338 return (drive==1);
1339} 1339}
1340 1340
1341bool sd_present(IF_MV_NONVOID(int drive)) 1341bool sd_present(IF_MD_NONVOID(int drive))
1342{ 1342{
1343#ifndef HAVE_MULTIVOLUME 1343#ifndef HAVE_MULTIDRIVE
1344 const int drive=0; 1344 const int drive=0;
1345#endif 1345#endif
1346 return (card_info[drive].initialized && card_info[drive].numblocks > 0); 1346 return (card_info[drive].initialized && card_info[drive].numblocks > 0);
1347} 1347}
1348#endif 1348#endif
1349
1350#ifdef CONFIG_STORAGE_MULTI
1351int sd_num_drives(int first_drive)
1352{
1353 /* We don't care which logical drive number(s) we have been assigned */
1354 (void)first_drive;
1355
1356#ifdef HAVE_MULTIDRIVE
1357 return 2;
1358#else
1359 return 1;
1360#endif
1361}
1362#endif
diff --git a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
index 3fc3c0efea..f268558128 100644
--- a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
+++ b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
@@ -46,7 +46,7 @@ void nand_led(bool onoff)
46 led(onoff); 46 led(onoff);
47} 47}
48 48
49int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, 49int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
50 void* inbuf) 50 void* inbuf)
51{ 51{
52 (void)start; 52 (void)start;
@@ -55,7 +55,7 @@ int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount,
55 return 0; 55 return 0;
56} 56}
57 57
58int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, 58int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
59 const void* outbuf) 59 const void* outbuf)
60{ 60{
61 (void)start; 61 (void)start;
@@ -82,7 +82,7 @@ void nand_enable(bool on)
82 (void)on; 82 (void)on;
83} 83}
84 84
85void nand_get_info(IF_MV2(int drive,) struct storage_info *info) 85void nand_get_info(IF_MD2(int drive,) struct storage_info *info)
86{ 86{
87 (void)info; 87 (void)info;
88} 88}
@@ -98,3 +98,12 @@ int nand_init(void)
98 return 0; 98 return 0;
99} 99}
100 100
101#ifdef CONFIG_STORAGE_MULTI
102int nand_num_drives(int first_drive)
103{
104 /* We don't care which logical drive number(s) we have been assigned */
105 (void)first_drive;
106
107 return 1;
108}
109#endif
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
index f9acdf5eb2..f84d904205 100644
--- a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
@@ -125,8 +125,8 @@ void GIO2(void)
125 125
126#define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */ 126#define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */
127 127
128extern int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 128extern int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
129extern int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 129extern int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
130 130
131struct main_header 131struct main_header
132{ 132{
@@ -378,14 +378,14 @@ static inline unsigned long map_sector(unsigned long sector)
378 return cfs_start+sectors[sector/64]*64+sector%64; 378 return cfs_start+sectors[sector/64]*64+sector%64;
379} 379}
380 380
381int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf) 381int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf)
382{ 382{
383 if(!cfs_inited) 383 if(!cfs_inited)
384 cfs_init(); 384 cfs_init();
385 385
386 /* Check if count is lesser than or equal to 1 native CFS sector */ 386 /* Check if count is lesser than or equal to 1 native CFS sector */
387 if(count <= 64) 387 if(count <= 64)
388 return _ata_read_sectors(IF_MV2(drive,) map_sector(start), count, buf); 388 return _ata_read_sectors(IF_MD2(drive,) map_sector(start), count, buf);
389 else 389 else
390 { 390 {
391 int i, ret; 391 int i, ret;
@@ -394,7 +394,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* bu
394 /* Read sectors in parts of 0x8000 */ 394 /* Read sectors in parts of 0x8000 */
395 for(i=0; i<count; i+=64) 395 for(i=0; i<count; i+=64)
396 { 396 {
397 ret = _ata_read_sectors(IF_MV2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (void*)dest); 397 ret = _ata_read_sectors(IF_MD2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (void*)dest);
398 if(ret != 0) 398 if(ret != 0)
399 return ret; 399 return ret;
400 400
@@ -405,7 +405,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* bu
405 } 405 }
406} 406}
407 407
408int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf) 408int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf)
409{ 409{
410 if(!cfs_inited) 410 if(!cfs_inited)
411 cfs_init(); 411 cfs_init();
@@ -413,7 +413,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
413#if 0 /* Disabled for now */ 413#if 0 /* Disabled for now */
414 /* Check if count is lesser than or equal to 1 native CFS sector */ 414 /* Check if count is lesser than or equal to 1 native CFS sector */
415 if(count <= 64) 415 if(count <= 64)
416 return _ata_write_sectors(IF_MV2(drive,) map_sector(start), count, buf); 416 return _ata_write_sectors(IF_MD2(drive,) map_sector(start), count, buf);
417 else 417 else
418 { 418 {
419 int i, ret; 419 int i, ret;
@@ -422,7 +422,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
422 /* Read sectors in parts of 0x8000 */ 422 /* Read sectors in parts of 0x8000 */
423 for(i=0; i<count; i+=64) 423 for(i=0; i<count; i+=64)
424 { 424 {
425 ret = _ata_write_sectors(IF_MV2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (const void*)dest); 425 ret = _ata_write_sectors(IF_MD2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (const void*)dest);
426 if(ret != 0) 426 if(ret != 0)
427 return ret; 427 return ret;
428 428
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
index 64c49fe68e..a1d4a90cb8 100644
--- a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
@@ -38,8 +38,8 @@ void copy_write_sectors(const unsigned char* buf, int wordcount);
38/* Nasty hack, but Creative is nasty... */ 38/* Nasty hack, but Creative is nasty... */
39#define ata_read_sectors _ata_read_sectors 39#define ata_read_sectors _ata_read_sectors
40#define ata_write_sectors _ata_write_sectors 40#define ata_write_sectors _ata_write_sectors
41extern int _ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); 41extern int _ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
42extern int _ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); 42extern int _ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
43 43
44/* General purpose memory region #1 */ 44/* General purpose memory region #1 */
45#define ATA_IOBASE 0x50FEE000 45#define ATA_IOBASE 0x50FEE000
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
index 8bd7d42e1f..a51dc5e882 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
@@ -707,6 +707,21 @@ void nand_enable(bool on)
707 (void)on; 707 (void)on;
708} 708}
709 709
710/* TODO */
711long nand_last_disk_activity(void)
712{
713 return 0;
714}
715
716int nand_spinup_time(void)
717{
718 return 0;
719}
720
721void nand_sleepnow(void)
722{
723}
724
710#ifdef STORAGE_GET_INFO 725#ifdef STORAGE_GET_INFO
711void nand_get_info(IF_MV2(int drive,) struct storage_info *info) 726void nand_get_info(IF_MV2(int drive,) struct storage_info *info)
712{ 727{
@@ -725,3 +740,13 @@ void nand_get_info(IF_MV2(int drive,) struct storage_info *info)
725 info->sector_size = 512; 740 info->sector_size = 512;
726} 741}
727#endif 742#endif
743
744#ifdef CONFIG_STORAGE_MULTI
745int nand_num_drives(int first_drive)
746{
747 /* We don't care which logical drive number(s) we have been assigned */
748 (void)first_drive;
749
750 return 1;
751}
752#endif
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
index 5de40c99dc..b1a9d599d9 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c
@@ -1328,6 +1328,31 @@ long sd_last_disk_activity(void)
1328 return last_disk_activity; 1328 return last_disk_activity;
1329} 1329}
1330 1330
1331int sd_spinup_time(void)
1332{
1333 return 0;
1334}
1335
1336void sd_enable(bool on)
1337{
1338 (void)on;
1339}
1340
1341void sd_sleepnow(void)
1342{
1343}
1344
1345/* TODO */
1346bool sd_disk_is_active(void)
1347{
1348 return false;
1349}
1350
1351int sd_soft_reset(void)
1352{
1353 return 0;
1354}
1355
1331#ifdef HAVE_HOTSWAP 1356#ifdef HAVE_HOTSWAP
1332bool sd_removable(IF_MV_NONVOID(int drive)) 1357bool sd_removable(IF_MV_NONVOID(int drive))
1333{ 1358{
@@ -1346,3 +1371,13 @@ bool sd_present(IF_MV_NONVOID(int drive))
1346#endif 1371#endif
1347 return (card.numblocks > 0 && card_detect_target()); 1372 return (card.numblocks > 0 && card_detect_target());
1348} 1373}
1374
1375#ifdef CONFIG_STORAGE_MULTI
1376int sd_num_drives(int first_drive)
1377{
1378 /* We don't care which logical drive number(s) we have been assigned */
1379 (void)first_drive;
1380
1381 return 1;
1382}
1383#endif
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 9fd150429f..e190d81045 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -696,7 +696,7 @@ int main(int argc, char *argv[])
696#endif 696#endif
697 ) { 697 ) {
698 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start); 698 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start);
699 rc = fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start); 699 rc = fat_mount(IF_MV2(0,) IF_MD2(0,) pinfo[i].start);
700 if(rc) { 700 if(rc) {
701 DEBUGF("mount: %d",rc); 701 DEBUGF("mount: %d",rc);
702 return -1; 702 return -1;
@@ -705,7 +705,7 @@ int main(int argc, char *argv[])
705 } 705 }
706 } 706 }
707 if ( i==4 ) { 707 if ( i==4 ) {
708 if(fat_mount(IF_MV2(0,) IF_MV2(0,) 0)) { 708 if(fat_mount(IF_MV2(0,) IF_MD2(0,) 0)) {
709 DEBUGF("No FAT32 partition!"); 709 DEBUGF("No FAT32 partition!");
710 return -1; 710 return -1;
711 } 711 }
diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c
index f4540e4959..ad0f8efcbd 100644
--- a/firmware/test/i2c/main.c
+++ b/firmware/test/i2c/main.c
@@ -642,7 +642,7 @@ int main(void)
642 642
643 643
644 644
645 i = fat_mount(IF_MV2(0,) IF_MV2(0,) part[0].start); 645 i = fat_mount(IF_MV2(0,) IF_MD2(0,) part[0].start);
646 646
647 debugf("fat_mount() returned %d\n", i); 647 debugf("fat_mount() returned %d\n", i);
648 648
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 28510089f1..d29e731d5a 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -153,8 +153,7 @@ struct inquiry_data {
153struct report_lun_data { 153struct report_lun_data {
154 unsigned int lun_list_length; 154 unsigned int lun_list_length;
155 unsigned int reserved1; 155 unsigned int reserved1;
156 // TODO this should be cleaned up with the VOLUMES vs DRIVES mess 156 unsigned char luns[NUM_DRIVES][8];
157 unsigned char luns[NUM_VOLUMES][8];
158} __attribute__ ((packed)); 157} __attribute__ ((packed));
159 158
160struct sense_data { 159struct sense_data {
@@ -271,10 +270,10 @@ static void send_command_result(void *data,int size);
271static void send_command_failed_result(void); 270static void send_command_failed_result(void);
272static void send_block_data(void *data,int size); 271static void send_block_data(void *data,int size);
273static void receive_block_data(void *data,int size); 272static void receive_block_data(void *data,int size);
274static void fill_inquiry(IF_MV_NONVOID(int lun)); 273static void fill_inquiry(IF_MD_NONVOID(int lun));
275static void send_and_read_next(void); 274static void send_and_read_next(void);
276static bool ejected[NUM_VOLUMES]; 275static bool ejected[NUM_DRIVES];
277static bool locked[NUM_VOLUMES]; 276static bool locked[NUM_DRIVES];
278 277
279static int usb_interface; 278static int usb_interface;
280static int ep_in, ep_out; 279static int ep_in, ep_out;
@@ -309,7 +308,7 @@ static void fix_mbr(unsigned char* mbr)
309} 308}
310#endif 309#endif
311 310
312static bool check_disk_present(IF_MV_NONVOID(int volume)) 311static bool check_disk_present(IF_MD_NONVOID(int volume))
313{ 312{
314#ifdef USB_USE_RAMDISK 313#ifdef USB_USE_RAMDISK
315 return true; 314 return true;
@@ -325,7 +324,7 @@ void usb_storage_try_release_storage(void)
325 release excusive access */ 324 release excusive access */
326 bool canrelease=true; 325 bool canrelease=true;
327 int i; 326 int i;
328 for(i=0;i<NUM_VOLUMES;i++) { 327 for(i=0;i<storage_num_drives();i++) {
329 if(ejected[i]==false && locked[i]==true) { 328 if(ejected[i]==false && locked[i]==true) {
330 canrelease=false; 329 canrelease=false;
331 break; 330 break;
@@ -341,7 +340,7 @@ void usb_storage_try_release_storage(void)
341void usb_storage_notify_hotswap(int volume,bool inserted) 340void usb_storage_notify_hotswap(int volume,bool inserted)
342{ 341{
343 logf("notify %d",inserted); 342 logf("notify %d",inserted);
344 if(inserted && check_disk_present(IF_MV(volume))) { 343 if(inserted && check_disk_present(IF_MD(volume))) {
345 ejected[volume] = false; 344 ejected[volume] = false;
346 } 345 }
347 else { 346 else {
@@ -436,7 +435,7 @@ void usb_storage_init_connection(void)
436 usb_drv_recv(ep_out, cbw_buffer, 1024); 435 usb_drv_recv(ep_out, cbw_buffer, 1024);
437 436
438 int i; 437 int i;
439 for(i=0;i<NUM_VOLUMES;i++) { 438 for(i=0;i<storage_num_drives();i++) {
440#ifdef TOSHIBA_GIGABEAT_S 439#ifdef TOSHIBA_GIGABEAT_S
441 /* As long as the Gigabeat S is a non-removable device, we need 440 /* As long as the Gigabeat S is a non-removable device, we need
442 to mark the device as locked to avoid usb_storage_try_release_ata() 441 to mark the device as locked to avoid usb_storage_try_release_ata()
@@ -445,7 +444,7 @@ void usb_storage_init_connection(void)
445#else 444#else
446 locked[i] = false; 445 locked[i] = false;
447#endif 446#endif
448 ejected[i] = !check_disk_present(IF_MV(i)); 447 ejected[i] = !check_disk_present(IF_MD(i));
449 queue_broadcast(SYS_USB_LUN_LOCKED, (i<<16)+0); 448 queue_broadcast(SYS_USB_LUN_LOCKED, (i<<16)+0);
450 } 449 }
451} 450}
@@ -614,10 +613,9 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des
614 (void)dest; 613 (void)dest;
615 switch (req->bRequest) { 614 switch (req->bRequest) {
616 case USB_BULK_GET_MAX_LUN: { 615 case USB_BULK_GET_MAX_LUN: {
617#ifdef ONLY_EXPOSE_CARD_SLOT 616 *tb.max_lun = storage_num_drives() - 1;
618 *tb.max_lun = 0; 617#ifdef HIDE_FIRST_DRIVE
619#else 618 *tb.max_lun --;
620 *tb.max_lun = NUM_VOLUMES - 1;
621#endif 619#endif
622 logf("ums: getmaxlun"); 620 logf("ums: getmaxlun");
623 usb_drv_send(EP_CONTROL, tb.max_lun, 1); 621 usb_drv_send(EP_CONTROL, tb.max_lun, 1);
@@ -690,12 +688,12 @@ static void handle_scsi(struct command_block_wrapper* cbw)
690 unsigned int block_size = 0; 688 unsigned int block_size = 0;
691 unsigned int block_count = 0; 689 unsigned int block_count = 0;
692 bool lun_present=true; 690 bool lun_present=true;
693#ifdef ONLY_EXPOSE_CARD_SLOT
694 unsigned char lun = cbw->lun+1;
695#else
696 unsigned char lun = cbw->lun; 691 unsigned char lun = cbw->lun;
697#endif
698 unsigned int block_size_mult = 1; 692 unsigned int block_size_mult = 1;
693#ifdef HIDE_FIRST_DRIVE
694 lun++;
695#endif
696
699 storage_get_info(lun,&info); 697 storage_get_info(lun,&info);
700#ifdef USB_USE_RAMDISK 698#ifdef USB_USE_RAMDISK
701 block_size = SECTOR_SIZE; 699 block_size = SECTOR_SIZE;
@@ -747,13 +745,14 @@ static void handle_scsi(struct command_block_wrapper* cbw)
747 logf("scsi report luns %d",lun); 745 logf("scsi report luns %d",lun);
748 int allocation_length=0; 746 int allocation_length=0;
749 int i; 747 int i;
748 unsigned int response_length = 8+8*storage_num_drives();
750 allocation_length|=(cbw->command_block[6]<<24); 749 allocation_length|=(cbw->command_block[6]<<24);
751 allocation_length|=(cbw->command_block[7]<<16); 750 allocation_length|=(cbw->command_block[7]<<16);
752 allocation_length|=(cbw->command_block[8]<<8); 751 allocation_length|=(cbw->command_block[8]<<8);
753 allocation_length|=(cbw->command_block[9]); 752 allocation_length|=(cbw->command_block[9]);
754 memset(tb.lun_data,0,sizeof(struct report_lun_data)); 753 memset(tb.lun_data,0,sizeof(struct report_lun_data));
755 tb.lun_data->lun_list_length=htobe32(8*NUM_VOLUMES); 754 tb.lun_data->lun_list_length=htobe32(8*storage_num_drives());
756 for(i=0;i<NUM_VOLUMES;i++) 755 for(i=0;i<storage_num_drives();i++)
757 { 756 {
758#ifdef HAVE_HOTSWAP 757#ifdef HAVE_HOTSWAP
759 if(storage_removable(i)) 758 if(storage_removable(i))
@@ -763,13 +762,13 @@ static void handle_scsi(struct command_block_wrapper* cbw)
763 tb.lun_data->luns[i][1]=0; 762 tb.lun_data->luns[i][1]=0;
764 } 763 }
765 send_command_result(tb.lun_data, 764 send_command_result(tb.lun_data,
766 MIN(sizeof(struct report_lun_data), length)); 765 MIN(response_length, length));
767 break; 766 break;
768 } 767 }
769 768
770 case SCSI_INQUIRY: 769 case SCSI_INQUIRY:
771 logf("scsi inquiry %d",lun); 770 logf("scsi inquiry %d",lun);
772 fill_inquiry(IF_MV(lun)); 771 fill_inquiry(IF_MD(lun));
773 length = MIN(length, cbw->command_block[4]); 772 length = MIN(length, cbw->command_block[4]);
774 send_command_result(tb.inquiry, 773 send_command_result(tb.inquiry,
775 MIN(sizeof(struct inquiry_data), length)); 774 MIN(sizeof(struct inquiry_data), length));
@@ -1136,7 +1135,7 @@ static void copy_padded(char *dest, char *src, int len)
1136} 1135}
1137 1136
1138/* build SCSI INQUIRY */ 1137/* build SCSI INQUIRY */
1139static void fill_inquiry(IF_MV_NONVOID(int lun)) 1138static void fill_inquiry(IF_MD_NONVOID(int lun))
1140{ 1139{
1141 struct storage_info info; 1140 struct storage_info info;
1142 memset(tb.inquiry, 0, sizeof(struct inquiry_data)); 1141 memset(tb.inquiry, 0, sizeof(struct inquiry_data));