summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/usbstack/usb_storage.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 6d9a5b9775..8c1b02b183 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -48,6 +48,10 @@
48 */ 48 */
49//#define ONLY_EXPOSE_CARD_SLOT 49//#define ONLY_EXPOSE_CARD_SLOT
50 50
51#ifdef USB_USE_RAMDISK
52#define RAMDISK_SIZE 2048
53#endif
54
51#define SECTOR_SIZE 512 55#define SECTOR_SIZE 512
52 56
53/* We can currently use up to 20k buffer size. More than that requires 57/* We can currently use up to 20k buffer size. More than that requires
@@ -266,6 +270,10 @@ static bool ejected[NUM_VOLUMES];
266static int usb_interface; 270static int usb_interface;
267static int ep_in, ep_out; 271static int ep_in, ep_out;
268 272
273#ifdef USB_USE_RAMDISK
274static unsigned char* ramdisk_buffer;
275#endif
276
269static enum { 277static enum {
270 WAITING_FOR_COMMAND, 278 WAITING_FOR_COMMAND,
271 SENDING_BLOCKS, 279 SENDING_BLOCKS,
@@ -277,8 +285,12 @@ static enum {
277 285
278static bool check_disk_present(IF_MV_NONVOID(int volume)) 286static bool check_disk_present(IF_MV_NONVOID(int volume))
279{ 287{
288#ifdef USB_USE_RAMDISK
289 return true;
290#else
280 unsigned char sector[512]; 291 unsigned char sector[512];
281 return ata_read_sectors(IF_MV2(volume,)0,1,sector) == 0; 292 return ata_read_sectors(IF_MV2(volume,)0,1,sector) == 0;
293#endif
282} 294}
283 295
284static void try_release_ata(void) 296static void try_release_ata(void)
@@ -401,6 +413,9 @@ void usb_storage_init_connection(void)
401 tb.transfer_buffer = 413 tb.transfer_buffer =
402 (void *)UNCACHED_ADDR((unsigned int)(audio_buffer + 31) & 0xffffffe0); 414 (void *)UNCACHED_ADDR((unsigned int)(audio_buffer + 31) & 0xffffffe0);
403 invalidate_icache(); 415 invalidate_icache();
416#ifdef USB_USE_RAMDISK
417 ramdisk_buffer = tb.transfer_buffer + BUFFER_SIZE*2;
418#endif
404#endif 419#endif
405 usb_drv_recv(ep_out, tb.transfer_buffer, 1024); 420 usb_drv_recv(ep_out, tb.transfer_buffer, 1024);
406} 421}
@@ -440,6 +455,11 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
440 455
441 /* Now write the data that just came in, while the host is 456 /* Now write the data that just came in, while the host is
442 sending the next bit */ 457 sending the next bit */
458#ifdef USB_USE_RAMDISK
459 memcpy(ramdisk_buffer + cur_cmd.sector*SECTOR_SIZE,
460 cur_cmd.data[cur_cmd.data_select],
461 MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count)*SECTOR_SIZE);
462#else
443 int result = ata_write_sectors(IF_MV2(cur_cmd.lun,) 463 int result = ata_write_sectors(IF_MV2(cur_cmd.lun,)
444 cur_cmd.sector, 464 cur_cmd.sector,
445 MIN(BUFFER_SIZE/SECTOR_SIZE, 465 MIN(BUFFER_SIZE/SECTOR_SIZE,
@@ -452,6 +472,7 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
452 cur_sense_data.ascq=0; 472 cur_sense_data.ascq=0;
453 break; 473 break;
454 } 474 }
475#endif
455#ifdef SERIALIZE_WRITES 476#ifdef SERIALIZE_WRITES
456 if(next_count!=0) { 477 if(next_count!=0) {
457 /* Ask the host to send more, to the other buffer */ 478 /* Ask the host to send more, to the other buffer */
@@ -613,11 +634,17 @@ static void send_and_read_next(void)
613 if(cur_cmd.count!=0){ 634 if(cur_cmd.count!=0){
614 /* already read the next bit, so we can send it out immediately when the 635 /* already read the next bit, so we can send it out immediately when the
615 * current transfer completes. */ 636 * current transfer completes. */
637#ifdef USB_USE_RAMDISK
638 memcpy(cur_cmd.data[cur_cmd.data_select],
639 ramdisk_buffer + cur_cmd.sector*SECTOR_SIZE,
640 MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count)*SECTOR_SIZE);
641#else
616 cur_cmd.last_result = ata_read_sectors(IF_MV2(cur_cmd.lun,) 642 cur_cmd.last_result = ata_read_sectors(IF_MV2(cur_cmd.lun,)
617 cur_cmd.sector, 643 cur_cmd.sector,
618 MIN(BUFFER_SIZE/SECTOR_SIZE, 644 MIN(BUFFER_SIZE/SECTOR_SIZE,
619 cur_cmd.count), 645 cur_cmd.count),
620 cur_cmd.data[cur_cmd.data_select]); 646 cur_cmd.data[cur_cmd.data_select]);
647#endif
621 } 648 }
622} 649}
623/****************************************************************************/ 650/****************************************************************************/
@@ -637,6 +664,10 @@ static void handle_scsi(struct command_block_wrapper* cbw)
637 unsigned char lun = cbw->lun; 664 unsigned char lun = cbw->lun;
638#endif 665#endif
639 unsigned int block_size_mult = 1; 666 unsigned int block_size_mult = 1;
667#ifdef USB_USE_RAMDISK
668 block_size = SECTOR_SIZE;
669 block_count = RAMDISK_SIZE;
670#else
640#if defined(HAVE_ATA_SD) || defined(HAVE_HOTSWAP) 671#if defined(HAVE_ATA_SD) || defined(HAVE_HOTSWAP)
641 tCardInfo* cinfo = card_get_info(lun); 672 tCardInfo* cinfo = card_get_info(lun);
642 if(cinfo->initialized && cinfo->numblocks > 0) { 673 if(cinfo->initialized && cinfo->numblocks > 0) {
@@ -652,6 +683,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
652 block_size = SECTOR_SIZE; 683 block_size = SECTOR_SIZE;
653 block_count = (identify[61] << 16 | identify[60]); 684 block_count = (identify[61] << 16 | identify[60]);
654#endif 685#endif
686#endif
655 687
656 if(ejected[lun]) 688 if(ejected[lun])
657 lun_present = false; 689 lun_present = false;
@@ -938,11 +970,17 @@ static void handle_scsi(struct command_block_wrapper* cbw)
938 cur_sense_data.ascq=0; 970 cur_sense_data.ascq=0;
939 } 971 }
940 else { 972 else {
973#ifdef USB_USE_RAMDISK
974 memcpy(cur_cmd.data[cur_cmd.data_select],
975 ramdisk_buffer + cur_cmd.sector*SECTOR_SIZE,
976 MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count)*SECTOR_SIZE);
977#else
941 cur_cmd.last_result = ata_read_sectors(IF_MV2(cur_cmd.lun,) 978 cur_cmd.last_result = ata_read_sectors(IF_MV2(cur_cmd.lun,)
942 cur_cmd.sector, 979 cur_cmd.sector,
943 MIN(BUFFER_SIZE/SECTOR_SIZE, 980 MIN(BUFFER_SIZE/SECTOR_SIZE,
944 cur_cmd.count), 981 cur_cmd.count),
945 cur_cmd.data[cur_cmd.data_select]); 982 cur_cmd.data[cur_cmd.data_select]);
983#endif
946 send_and_read_next(); 984 send_and_read_next();
947 } 985 }
948 break; 986 break;