diff --git a/firmware/SOURCES b/firmware/SOURCES index 1ee2979..0f16589 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -126,17 +126,25 @@ drivers/touchscreen.c #ifndef SIMULATOR #if (CONFIG_STORAGE & STORAGE_MMC) drivers/ata_mmc.c -#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_IFP7XX) +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_IFP7XX) drivers/ata_flash.c -#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_TCC) +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_TCC) target/arm/ata-nand-telechips.c -#elif (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_SAMSUNG) +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_SAMSUNG) target/arm/s5l8700/ata-nand-s5l8700.c -#elif (CONFIG_STORAGE & STORAGE_ATA) +#endif +#if (CONFIG_STORAGE & STORAGE_ATA) drivers/ata.c -#elif (CONFIG_STORAGE & STORAGE_RAMDISK) +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) drivers/ramdisk.c -#endif /* CONFIG_STORAGE */ +#endif +#ifdef CONFIG_STORAGE_MULTI +storage.c +#endif drivers/fat.c #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) hotswap.c diff --git a/firmware/common/disk.c b/firmware/common/disk.c index cc0f0d6..8a445a6 100644 --- a/firmware/common/disk.c +++ b/firmware/common/disk.c @@ -65,11 +65,11 @@ static int vol_drive[NUM_VOLUMES]; /* mounted to which drive (-1 if none) */ int disk_sector_multiplier = 1; #endif -struct partinfo* disk_init(IF_MV_NONVOID(int drive)) +struct partinfo* disk_init(IF_MD_NONVOID(int drive)) { int i; unsigned char sector[512]; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE /* For each drive, start at a different position, in order not to destroy the first entry of drive 0. That one is needed to calculate config sector position. */ @@ -115,7 +115,7 @@ struct partinfo* disk_partinfo(int partition) int disk_mount_all(void) { - int mounted; + int mounted=0; int i; #ifdef HAVE_HOTSWAP @@ -126,13 +126,20 @@ int disk_mount_all(void) for (i=0; isector_size = SECTOR_SIZE; info->num_sectors= total_sectors; @@ -1450,3 +1453,10 @@ void ata_get_info(struct storage_info *info) info->revision=revision; } #endif + +#ifdef CONFIG_STORAGE_MULTI +int ata_num_drives(void) +{ + return 1; +} +#endif diff --git a/firmware/drivers/ata_flash.c b/firmware/drivers/ata_flash.c index ba96ea0..c2f3d16 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, return done; } -int nand_read_sectors(IF_MV2(int drive,) +int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, void* inbuf) @@ -401,7 +401,7 @@ int nand_read_sectors(IF_MV2(int drive,) return 0; } -int nand_write_sectors(IF_MV2(int drive,) +int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) @@ -472,3 +472,10 @@ void nand_get_info(struct storage_info *info) } #endif +#ifdef CONFIG_STORAGE_MULTI +int nand_num_drives(void) +{ + return 1; +} +#endif + diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 5104f8c..c6adcdc 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c @@ -125,7 +125,7 @@ static int current_buffer = 0; static const unsigned char *send_block_addr = NULL; static tCardInfo card_info[2]; -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE static int current_card = 0; #endif static bool last_mmc_status = false; @@ -601,7 +601,7 @@ static int send_block_send(unsigned char start_token, long timeout, return rc; } -int mmc_read_sectors(IF_MV2(int drive,) +int mmc_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, void* inbuf) @@ -610,7 +610,7 @@ int mmc_read_sectors(IF_MV2(int drive,) int lastblock = 0; unsigned long end_block; tCardInfo *card; -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE int drive = current_card; #endif @@ -687,7 +687,7 @@ int mmc_read_sectors(IF_MV2(int drive,) return rc; } -int mmc_write_sectors(IF_MV2(int drive,) +int mmc_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) @@ -696,7 +696,7 @@ int mmc_write_sectors(IF_MV2(int drive,) int write_cmd; unsigned char start_token; tCardInfo *card; -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE int drive = current_card; #endif @@ -919,7 +919,7 @@ int mmc_init(void) led(false); last_mmc_status = mmc_detect(); -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE /* Use MMC if inserted, internal flash otherwise */ current_card = last_mmc_status ? 1 : 0; #endif @@ -964,9 +964,9 @@ long mmc_last_disk_activity(void) } #ifdef STORAGE_GET_INFO -void mmc_get_info(IF_MV2(int drive,) struct storage_info *info) +void mmc_get_info(IF_MD2(int drive,) struct storage_info *info) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif info->sector_size=card_info[drive].blocksize; @@ -985,17 +985,17 @@ void mmc_get_info(IF_MV2(int drive,) struct storage_info *info) #endif #ifdef HAVE_HOTSWAP -bool mmc_removable(IF_MV_NONVOID(int drive)) +bool mmc_removable(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (drive==1); } -bool mmc_present(IF_MV_NONVOID(int drive)) +bool mmc_present(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (card_info[drive].initialized && card_info[drive].numblocks > 0); @@ -1015,3 +1015,14 @@ void mmc_spindown(int seconds) { (void)seconds; } + +#ifdef CONFIG_STORAGE_MULTI +int mmc_num_drives(void) +{ +#ifdef HAVE_MULTIDRIVE + return 2; +#else + return 1; +#endif +} +#endif diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 2ff4c61..866b6fe 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -167,7 +167,9 @@ struct bpb * of first pseudo cluster */ #endif /* #ifdef HAVE_FAT16SUPPORT */ #ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE int drive; /* on which physical device is this located */ +#endif bool mounted; /* flag if this volume is mounted */ #endif }; @@ -285,7 +287,7 @@ void fat_init(void) #endif } -int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector) +int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector) { #ifndef HAVE_MULTIVOLUME const int volume = 0; @@ -309,7 +311,7 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector) memset(fat_bpb, 0, sizeof(struct bpb)); fat_bpb->startsector = startsector; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE fat_bpb->drive = drive; #endif diff --git a/firmware/drivers/ramdisk.c b/firmware/drivers/ramdisk.c index 266d3ea..53a8a8e 100644 --- a/firmware/drivers/ramdisk.c +++ b/firmware/drivers/ramdisk.c @@ -31,11 +31,14 @@ unsigned char ramdisk[SECTOR_SIZE * NUM_SECTORS]; long last_disk_activity = -1; -int ramdisk_read_sectors(IF_MV2(int drive,) +int ramdisk_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf) { +#ifdef HAVE_MULTIDRIVE + (void)drive; /* unused for now */ +#endif if(start+count>=NUM_SECTORS) { return -1; @@ -44,11 +47,14 @@ int ramdisk_read_sectors(IF_MV2(int drive,) return 0; } -int ramdisk_write_sectors(IF_MV2(int drive,) +int ramdisk_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) { +#ifdef HAVE_MULTIDRIVE + (void)drive; /* unused for now */ +#endif if(start+count>=NUM_SECTORS) { return -1; @@ -79,13 +85,36 @@ void ramdisk_sleepnow(void) { } +void ramdisk_enable(bool on) +{ + (void)on; +} + +bool ramdisk_disk_is_active(void) +{ + return true; +} + +int ramdisk_soft_reset(void) +{ + return 0; +} + +int ramdisk_spinup_time(void) +{ + return 0; +} + void ramdisk_spindown(int seconds) { (void)seconds; } #ifdef STORAGE_GET_INFO -void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info) +void ramdisk_get_info(IF_MD2(int drive,) struct storage_info *info) { +#ifdef HAVE_MULTIDRIVE + (void)drive; /* unused for now */ +#endif /* firmware version */ info->revision="0.00"; @@ -100,3 +129,11 @@ void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info) } #endif +#ifdef CONFIG_STORAGE_MULTI +int ramdisk_num_drives(void) +{ + return 1; +} +#endif + + diff --git a/firmware/export/ata.h b/firmware/export/ata.h index f491e52..790ab0e 100644 --- a/firmware/export/ata.h +++ b/firmware/export/ata.h @@ -39,8 +39,8 @@ bool ata_disk_is_active(void); int ata_soft_reset(void); int ata_init(void); void ata_close(void); -int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); void ata_spin(void); #if (CONFIG_LED == LED_REAL) void ata_set_led_enabled(bool enabled); @@ -48,11 +48,11 @@ void ata_set_led_enabled(bool enabled); unsigned short* ata_get_identify(void); #ifdef STORAGE_GET_INFO -void ata_get_info(IF_MV2(int drive,) struct storage_info *info); +void ata_get_info(IF_MD2(int drive,) struct storage_info *info); #endif #ifdef HAVE_HOTSWAP -bool ata_removable(IF_MV_NONVOID(int drive)); -bool ata_present(IF_MV_NONVOID(int drive)); +bool ata_removable(IF_MD_NONVOID(int drive)); +bool ata_present(IF_MD_NONVOID(int drive)); #endif @@ -60,5 +60,9 @@ bool ata_present(IF_MV_NONVOID(int drive)); long ata_last_disk_activity(void); int ata_spinup_time(void); /* ticks */ +#ifdef CONFIG_STORAGE_MULTI +int ata_num_drives(void); +#endif + #endif diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h index ed16fb0..e387133 100644 --- a/firmware/export/config-c200.h +++ b/firmware/export/config-c200.h @@ -171,7 +171,8 @@ #define FIRMWARE_OFFSET_FILE_DATA 0x8 #ifndef BOOTLOADER -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 #define HAVE_HOTSWAP #endif diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h index e4d4b73..3c20c75 100644 --- a/firmware/export/config-e200.h +++ b/firmware/export/config-e200.h @@ -165,7 +165,8 @@ #define FIRMWARE_OFFSET_FILE_DATA 0x8 #ifndef BOOTLOADER -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 #define HAVE_HOTSWAP #endif diff --git a/firmware/export/config-e200v2.h b/firmware/export/config-e200v2.h index 5d2fa81..9d08a87 100644 --- a/firmware/export/config-e200v2.h +++ b/firmware/export/config-e200v2.h @@ -169,7 +169,8 @@ #define FIRMWARE_OFFSET_FILE_DATA 0x8 #ifndef BOOTLOADER -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 #define HAVE_HOTSWAP #endif diff --git a/firmware/export/config-fuze.h b/firmware/export/config-fuze.h index c52298f..b40c11b 100644 --- a/firmware/export/config-fuze.h +++ b/firmware/export/config-fuze.h @@ -169,7 +169,8 @@ #define FIRMWARE_OFFSET_FILE_DATA 0x8 #ifndef BOOTLOADER -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 #define HAVE_HOTSWAP #endif diff --git a/firmware/export/config-ondavx747.h b/firmware/export/config-ondavx747.h old mode 100644 new mode 100755 index 491dab4..c982058 --- a/firmware/export/config-ondavx747.h +++ b/firmware/export/config-ondavx747.h @@ -38,12 +38,12 @@ //#define HAVE_ATA_SD //#define HAVE_HOTSWAP -//#define CONFIG_STORAGE (STORAGE_NAND | STORAGE_SD) -#define CONFIG_STORAGE STORAGE_SD /* Multivolume currently handled at firmware/target/ level */ +#define CONFIG_STORAGE (STORAGE_NAND | STORAGE_SD) #define CONFIG_NAND NAND_CC -//#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 /* define this if you have a bitmap LCD display */ #define HAVE_LCD_BITMAP diff --git a/firmware/export/config-ondavx767.h b/firmware/export/config-ondavx767.h index 1f48143..398e56f 100644 --- a/firmware/export/config-ondavx767.h +++ b/firmware/export/config-ondavx767.h @@ -41,7 +41,8 @@ #define CONFIG_NAND NAND_CC -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 /* define this if you have a bitmap LCD display */ #define HAVE_LCD_BITMAP diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h index e5198f8..8abc0f0 100644 --- a/firmware/export/config-ondiofm.h +++ b/firmware/export/config-ondiofm.h @@ -126,7 +126,8 @@ #define HAVE_MAS_SIBI_CONTROL /* define this if more than one device/partition can be used */ -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 /* define this if media can be exchanged on the fly */ #define HAVE_HOTSWAP diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h index cf69bae..429694a 100644 --- a/firmware/export/config-ondiosp.h +++ b/firmware/export/config-ondiosp.h @@ -109,7 +109,8 @@ #define HAVE_MAS_SIBI_CONTROL /* define this if more than one device/partition can be used */ -#define HAVE_MULTIVOLUME +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 /* define this if media can be exchanged on the fly */ #define HAVE_HOTSWAP diff --git a/firmware/export/config.h b/firmware/export/config.h index 7680a9f..1af0b6c 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -482,6 +482,11 @@ #endif /* CONFIG_BACKLIGHT_FADING */ +#if defined(HAVE_MULTIDRIVE) && !defined(HAVE_MULTIVOLUME) +#define HAVE_MULTIVOLUME +#define NUM_VOLUMES NUM_DRIVES +#endif + #if defined(BOOTLOADER) && defined(HAVE_ADJUSTABLE_CPU_FREQ) /* Bootloaders don't use CPU frequency adjustment */ #undef HAVE_ADJUSTABLE_CPU_FREQ diff --git a/firmware/export/disk.h b/firmware/export/disk.h index cec9bfa..cd937fd 100644 --- a/firmware/export/disk.h +++ b/firmware/export/disk.h @@ -35,7 +35,7 @@ struct partinfo { #define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84 /* returns a pointer to an array of 8 partinfo structs */ -struct partinfo* disk_init(IF_MV_NONVOID(int volume)); +struct partinfo* disk_init(IF_MD_NONVOID(int drive)); struct partinfo* disk_partinfo(int partition); int disk_mount_all(void); /* returns the # of successful mounts */ int disk_mount(int drive); diff --git a/firmware/export/fat.h b/firmware/export/fat.h index c99a1a7..d6e753f 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h @@ -90,7 +90,7 @@ extern void fat_unlock(void); #endif extern void fat_init(void); -extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector); +extern int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector); extern int fat_unmount(int volume, bool flush); extern void fat_size(IF_MV2(int volume,) /* public for info */ unsigned long* size, diff --git a/firmware/export/mmc.h b/firmware/export/mmc.h index 06d99d2..00d087f 100644 --- a/firmware/export/mmc.h +++ b/firmware/export/mmc.h @@ -23,7 +23,7 @@ #define __MMC_H__ #include -#include "mv.h" /* for HAVE_MULTIVOLUME or not */ +#include "mv.h" /* for HAVE_MULTIDRIVE or not */ struct storage_info; @@ -35,19 +35,24 @@ bool mmc_disk_is_active(void); int mmc_soft_reset(void); int mmc_init(void); void mmc_close(void); -int mmc_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -int mmc_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +int mmc_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int mmc_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); void mmc_spin(void); int mmc_spinup_time(void); #ifdef STORAGE_GET_INFO -void mmc_get_info(IF_MV2(int drive,) struct storage_info *info); +void mmc_get_info(IF_MD2(int drive,) struct storage_info *info); #endif #ifdef HAVE_HOTSWAP -bool mmc_removable(IF_MV_NONVOID(int drive)); -bool mmc_present(IF_MV_NONVOID(int drive)); +bool mmc_removable(IF_MD_NONVOID(int drive)); +bool mmc_present(IF_MD_NONVOID(int drive)); #endif long mmc_last_disk_activity(void); +#ifdef CONFIG_STORAGE_MULTI +int mmc_num_drives(void); +#endif + + #endif diff --git a/firmware/export/mv.h b/firmware/export/mv.h index fda650c..a8bb84a 100644 --- a/firmware/export/mv.h +++ b/firmware/export/mv.h @@ -26,11 +26,30 @@ /* FixMe: These macros are a bit nasty and perhaps misplaced here. We'll get rid of them once decided on how to proceed with multivolume. */ + +/* Drives are things like a disk, a card, a flash chip. They can have volumes on them */ +#ifdef HAVE_MULTIDRIVE +#define IF_MD(x) x /* optional drive parameter */ +#define IF_MD2(x,y) x,y /* same, for a list of arguments */ +#define IF_MD_NONVOID(x) x /* for prototype with sole volume parameter */ +#ifndef NUM_DRIVES +#error The target configuration doesn't define NUM_DRIVES +#endif +#else /* empty definitions if no multi-drive */ +#define IF_MD(x) +#define IF_MD2(x,y) +#define IF_MD_NONVOID(x) void +#define NUM_DRIVES 1 +#endif + +/* Volumes mean things that have filesystems on them, like partitions */ #ifdef HAVE_MULTIVOLUME -#define IF_MV(x) x /* optional volume/drive parameter */ +#define IF_MV(x) x /* optional volume parameter */ #define IF_MV2(x,y) x,y /* same, for a list of arguments */ #define IF_MV_NONVOID(x) x /* for prototype with sole volume parameter */ -#define NUM_VOLUMES 2 +#ifndef NUM_VOLUMES +#error The target configuration doesn't define NUM_VOLUMES +#endif #else /* empty definitions if no multi-volume */ #define IF_MV(x) #define IF_MV2(x,y) @@ -38,4 +57,5 @@ #define NUM_VOLUMES 1 #endif + #endif diff --git a/firmware/export/nand.h b/firmware/export/nand.h old mode 100644 new mode 100755 index a5b0a1c..f89c4a1 --- a/firmware/export/nand.h +++ b/firmware/export/nand.h @@ -23,25 +23,31 @@ #define __NAND_H__ #include -#include "mv.h" /* for HAVE_MULTIVOLUME or not */ +#include "mv.h" /* for HAVE_MULTIDRIVE or not */ struct storage_info; void nand_enable(bool on); void nand_spindown(int seconds); void nand_sleep(void); +void nand_sleepnow(void); bool nand_disk_is_active(void); -int nand_soft_reset(void); -int nand_init(void); +int nand_soft_reset(void); +int nand_init(void); void nand_close(void); -int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); void nand_spin(void); +int nand_spinup_time(void); /* ticks */ #ifdef STORAGE_GET_INFO -void nand_get_info(IF_MV2(int drive,) struct storage_info *info); +void nand_get_info(IF_MD2(int drive,) struct storage_info *info); #endif long nand_last_disk_activity(void); +#ifdef CONFIG_STORAGE_MULTI +int nand_num_drives(void); +#endif + #endif diff --git a/firmware/export/ramdisk.h b/firmware/export/ramdisk.h index a0c011f..52a17fe 100644 --- a/firmware/export/ramdisk.h +++ b/firmware/export/ramdisk.h @@ -23,7 +23,7 @@ #define __RAMDISK_H__ #include -#include "mv.h" /* for HAVE_MULTIVOLUME or not */ +#include "mv.h" /* for HAVE_MULTIDRIVE or not */ struct storage_info; @@ -34,15 +34,20 @@ bool ramdisk_disk_is_active(void); int ramdisk_soft_reset(void); int ramdisk_init(void); void ramdisk_close(void); -int ramdisk_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -int ramdisk_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +int ramdisk_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int ramdisk_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); void ramdisk_spin(void); void ramdisk_sleepnow(void); +int ramdisk_spinup_time(void); #ifdef STORAGE_GET_INFO -void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info); +void ramdisk_get_info(IF_MD2(int drive,) struct storage_info *info); #endif long ramdisk_last_disk_activity(void); +#ifdef CONFIG_STORAGE_MULTI +int ramdisk_num_drives(void); +#endif + #endif diff --git a/firmware/export/sd.h b/firmware/export/sd.h old mode 100644 new mode 100755 index eb0f065..7902987 --- a/firmware/export/sd.h +++ b/firmware/export/sd.h @@ -23,31 +23,38 @@ #define __SD_H__ #include -#include "mv.h" /* for HAVE_MULTIVOLUME or not */ +#include "mv.h" /* for HAVE_MULTIDRIVE or not */ struct storage_info; void sd_enable(bool on); void sd_spindown(int seconds); void sd_sleep(void); +void sd_sleepnow(void); bool sd_disk_is_active(void); -int sd_soft_reset(void); -int sd_init(void); +int sd_soft_reset(void); +int sd_init(void); void sd_close(void); -int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); void sd_spin(void); +int sd_spinup_time(void); /* ticks */ #ifdef STORAGE_GET_INFO -void sd_get_info(IF_MV2(int drive,) struct storage_info *info); +void sd_get_info(IF_MD2(int drive,) struct storage_info *info); #endif #ifdef HAVE_HOTSWAP -bool sd_removable(IF_MV_NONVOID(int drive)); -bool sd_present(IF_MV_NONVOID(int drive)); +bool sd_removable(IF_MD_NONVOID(int drive)); +bool sd_present(IF_MD_NONVOID(int drive)); #endif long sd_last_disk_activity(void); +#ifdef CONFIG_STORAGE_MULTI +int sd_num_drives(void); +#endif + + /* SD States */ #define SD_IDLE 0 #define SD_READY 1 diff --git a/firmware/export/storage.h b/firmware/export/storage.h index 47d8abd..8793134 100644 --- a/firmware/export/storage.h +++ b/firmware/export/storage.h @@ -23,7 +23,7 @@ #define __STORAGE_H__ #include -#include "config.h" /* for HAVE_MULTIVOLUME or not */ +#include "config.h" /* for HAVE_MULTIDRIVE or not */ #include "mv.h" #if (CONFIG_STORAGE & STORAGE_SD) @@ -51,154 +51,149 @@ struct storage_info char *revision; }; -#ifndef SIMULATOR - #ifndef CONFIG_STORAGE_MULTI - /* storage_spindown, storage_sleep and storage_spin are passed as - * pointers, which doesn't work with argument-macros. - */ - #if (CONFIG_STORAGE & STORAGE_ATA) - #define storage_spindown ata_spindown - #define storage_sleep ata_sleep - #define storage_spin ata_spin - - #define storage_enable(on) ata_enable(on) - #define storage_sleepnow() ata_sleepnow() - #define storage_disk_is_active() ata_disk_is_active() - #define storage_soft_reset() ata_soft_reset() - #define storage_init() ata_init() - #define storage_close() ata_close() - #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MV2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MV2(drive,) start, count, buf) - #define storage_last_disk_activity() ata_last_disk_activity() - #define storage_spinup_time() ata_spinup_time() - #define storage_get_identify() ata_get_identify() - - #ifdef STORAGE_GET_INFO - #define storage_get_info(drive, info) ata_get_info(IF_MV2(drive,) info) - #endif - #ifdef HAVE_HOTSWAP - #define storage_removable(drive) ata_removable(IF_MV(drive)) - #define storage_present(drive) ata_present(IF_MV(drive)) - #endif - #elif (CONFIG_STORAGE & STORAGE_SD) - #define storage_spindown sd_spindown - #define storage_sleep sd_sleep - #define storage_spin sd_spin - - #define storage_enable(on) sd_enable(on) - #define storage_sleepnow() sd_sleepnow() - #define storage_disk_is_active() 0 - #define storage_soft_reset() (void)0 - #define storage_init() sd_init() - #define storage_close() sd_close() - #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MV2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MV2(drive,) start, count, buf) - #define storage_last_disk_activity() sd_last_disk_activity() - #define storage_spinup_time() 0 - #define storage_get_identify() sd_get_identify() - - #ifdef STORAGE_GET_INFO - #define storage_get_info(drive, info) sd_get_info(IF_MV2(drive,) info) - #endif - #ifdef HAVE_HOTSWAP - #define storage_removable(drive) sd_removable(IF_MV(drive)) - #define storage_present(drive) sd_present(IF_MV(drive)) - #endif - #elif (CONFIG_STORAGE & STORAGE_MMC) - #define storage_spindown mmc_spindown - #define storage_sleep mmc_sleep - #define storage_spin mmc_spin - - #define storage_enable(on) mmc_enable(on) - #define storage_sleepnow() mmc_sleepnow() - #define storage_disk_is_active() mmc_disk_is_active() - #define storage_soft_reset() (void)0 - #define storage_init() mmc_init() - #define storage_close() mmc_close() - #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MV2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MV2(drive,) start, count, buf) - #define storage_last_disk_activity() mmc_last_disk_activity() - #define storage_spinup_time() 0 - #define storage_get_identify() mmc_get_identify() - - #ifdef STORAGE_GET_INFO - #define storage_get_info(drive, info) mmc_get_info(IF_MV2(drive,) info) - #endif - #ifdef HAVE_HOTSWAP - #define storage_removable(drive) mmc_removable(IF_MV(drive)) - #define storage_present(drive) mmc_present(IF_MV(drive)) - #endif - #elif (CONFIG_STORAGE & STORAGE_NAND) - #define storage_spindown nand_spindown - #define storage_sleep nand_sleep - #define storage_spin nand_spin - - #define storage_enable(on) (void)0 - #define storage_sleepnow() nand_sleepnow() - #define storage_disk_is_active() 0 - #define storage_soft_reset() (void)0 - #define storage_init() nand_init() - #define storage_close() nand_close() - #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MV2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MV2(drive,) start, count, buf) - #define storage_last_disk_activity() nand_last_disk_activity() - #define storage_spinup_time() 0 - #define storage_get_identify() nand_get_identify() - - #ifdef STORAGE_GET_INFO - #define storage_get_info(drive, info) nand_get_info(IF_MV2(drive,) info) - #endif - #ifdef HAVE_HOTSWAP - #define storage_removable(drive) nand_removable(IF_MV(drive)) - #define storage_present(drive) nand_present(IF_MV(drive)) - #endif - #elif (CONFIG_STORAGE & STORAGE_RAMDISK) - #define storage_spindown ramdisk_spindown - #define storage_sleep ramdisk_sleep - #define storage_spin ramdisk_spin - - #define storage_enable(on) (void)0 - #define storage_sleepnow() ramdisk_sleepnow() - #define storage_disk_is_active() 0 - #define storage_soft_reset() (void)0 - #define storage_init() ramdisk_init() - #define storage_close() ramdisk_close() - #define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MV2(drive,) start, count, buf) - #define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MV2(drive,) start, count, buf) - #define storage_last_disk_activity() ramdisk_last_disk_activity() - #define storage_spinup_time() 0 - #define storage_get_identify() ramdisk_get_identify() - - #ifdef STORAGE_GET_INFO - #define storage_get_info(drive, info) ramdisk_get_info(IF_MV2(drive,) info) - #endif - #ifdef HAVE_HOTSWAP - #define storage_removable(drive) ramdisk_removable(IF_MV(drive)) - #define storage_present(drive) ramdisk_present(IF_MV(drive)) - #endif - #else - //#error No storage driver! - #endif - #else /* NOT CONFIG_STORAGE_MULTI */ - - /* TODO : implement multi-driver here */ - #error Multi-driver storage not implemented yet - - #endif /* NOT CONFIG_STORAGE_MULTI */ -#else /*NOT SIMULATOR */ +#if !defined(SIMULATOR) && !defined(CONFIG_STORAGE_MULTI) +/* storage_spindown, storage_sleep and storage_spin are passed as + * pointers, which doesn't work with argument-macros. + */ + #define storage_num_drives() NUM_DRIVES + #if (CONFIG_STORAGE & STORAGE_ATA) + #define storage_spindown ata_spindown + #define storage_sleep ata_sleep + #define storage_spin ata_spin + + #define storage_enable(on) ata_enable(on) + #define storage_sleepnow() ata_sleepnow() + #define storage_disk_is_active() ata_disk_is_active() + #define storage_soft_reset() ata_soft_reset() + #define storage_init() ata_init() + #define storage_close() ata_close() + #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MD2(drive,) start, count, buf) + #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MD2(drive,) start, count, buf) + #define storage_last_disk_activity() ata_last_disk_activity() + #define storage_spinup_time() ata_spinup_time() + #define storage_get_identify() ata_get_identify() + + #ifdef STORAGE_GET_INFO + #define storage_get_info(drive, info) ata_get_info(IF_MD2(drive,) info) + #endif + #ifdef HAVE_HOTSWAP + #define storage_removable(drive) ata_removable(IF_MD(drive)) + #define storage_present(drive) ata_present(IF_MD(drive)) + #endif + #elif (CONFIG_STORAGE & STORAGE_SD) + #define storage_spindown sd_spindown + #define storage_sleep sd_sleep + #define storage_spin sd_spin + + #define storage_enable(on) sd_enable(on) + #define storage_sleepnow() sd_sleepnow() + #define storage_disk_is_active() 0 + #define storage_soft_reset() (void)0 + #define storage_init() sd_init() + #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MD2(drive,) start, count, buf) + #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MD2(drive,) start, count, buf) + #define storage_last_disk_activity() sd_last_disk_activity() + #define storage_spinup_time() 0 + #define storage_get_identify() sd_get_identify() + + #ifdef STORAGE_GET_INFO + #define storage_get_info(drive, info) sd_get_info(IF_MD2(drive,) info) + #endif + #ifdef HAVE_HOTSWAP + #define storage_removable(drive) sd_removable(IF_MD(drive)) + #define storage_present(drive) sd_present(IF_MD(drive)) + #endif + #elif (CONFIG_STORAGE & STORAGE_MMC) + #define storage_spindown mmc_spindown + #define storage_sleep mmc_sleep + #define storage_spin mmc_spin + + #define storage_enable(on) mmc_enable(on) + #define storage_sleepnow() mmc_sleepnow() + #define storage_disk_is_active() mmc_disk_is_active() + #define storage_soft_reset() (void)0 + #define storage_init() mmc_init() + #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MD2(drive,) start, count, buf) + #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MD2(drive,) start, count, buf) + #define storage_last_disk_activity() mmc_last_disk_activity() + #define storage_spinup_time() 0 + #define storage_get_identify() mmc_get_identify() + + #ifdef STORAGE_GET_INFO + #define storage_get_info(drive, info) mmc_get_info(IF_MD2(drive,) info) + #endif + #ifdef HAVE_HOTSWAP + #define storage_removable(drive) mmc_removable(IF_MD(drive)) + #define storage_present(drive) mmc_present(IF_MD(drive)) + #endif + #elif (CONFIG_STORAGE & STORAGE_NAND) + #define storage_spindown nand_spindown + #define storage_sleep nand_sleep + #define storage_spin nand_spin + + #define storage_enable(on) (void)0 + #define storage_sleepnow() nand_sleepnow() + #define storage_disk_is_active() 0 + #define storage_soft_reset() (void)0 + #define storage_init() nand_init() + #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MD2(drive,) start, count, buf) + #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MD2(drive,) start, count, buf) + #define storage_last_disk_activity() nand_last_disk_activity() + #define storage_spinup_time() 0 + #define storage_get_identify() nand_get_identify() + + #ifdef STORAGE_GET_INFO + #define storage_get_info(drive, info) nand_get_info(IF_MD2(drive,) info) + #endif + #ifdef HAVE_HOTSWAP + #define storage_removable(drive) nand_removable(IF_MD(drive)) + #define storage_present(drive) nand_present(IF_MD(drive)) + #endif + #elif (CONFIG_STORAGE & STORAGE_RAMDISK) + #define storage_spindown ramdisk_spindown + #define storage_sleep ramdisk_sleep + #define storage_spin ramdisk_spin + + #define storage_enable(on) (void)0 + #define storage_sleepnow() ramdisk_sleepnow() + #define storage_disk_is_active() 0 + #define storage_soft_reset() (void)0 + #define storage_init() ramdisk_init() + #define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MD2(drive,) start, count, buf) + #define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MD2(drive,) start, count, buf) + #define storage_last_disk_activity() ramdisk_last_disk_activity() + #define storage_spinup_time() 0 + #define storage_get_identify() ramdisk_get_identify() + + #ifdef STORAGE_GET_INFO + #define storage_get_info(drive, info) ramdisk_get_info(IF_MD2(drive,) info) + #endif + #ifdef HAVE_HOTSWAP + #define storage_removable(drive) ramdisk_removable(IF_MD(drive)) + #define storage_present(drive) ramdisk_present(IF_MD(drive)) + #endif + #else + //#error No storage driver! + #endif +#else /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ + +/* Simulator and multi-driver use normal functions */ + +#define MAX_NUM_DRIVES 10 + void storage_enable(bool on); void storage_sleep(void); void storage_sleepnow(void); bool storage_disk_is_active(void); int storage_soft_reset(void); int storage_init(void); -void storage_close(void); int storage_read_sectors(int drive, unsigned long start, int count, void* buf); int storage_write_sectors(int drive, unsigned long start, int count, const void* buf); void storage_spin(void); void storage_spindown(int seconds); long storage_last_disk_activity(void); int storage_spinup_time(void); +int storage_num_drives(void); #ifdef STORAGE_GET_INFO void storage_get_info(int drive, struct storage_info *info); #endif @@ -206,5 +201,6 @@ void storage_get_info(int drive, struct storage_info *info); bool storage_removable(int drive); bool storage_present(int drive); #endif -#endif/*NOT SIMULATOR */ + +#endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ #endif diff --git a/firmware/storage.c b/firmware/storage.c new file mode 100755 index 0000000..a4caeb9 --- /dev/null +++ b/firmware/storage.c @@ -0,0 +1,432 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: buffer.c 17847 2008-06-28 18:10:04Z bagder $ + * + * Copyright (C) 2008 by Frank Gevaerts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "storage.h" + + +#define DRIVER_MASK 0xff000000 +#define DRIVER_OFFSET 24 +#define DRIVE_MASK 0x00ff0000 +#define DRIVE_OFFSET 16 +#define PARTITION_MASK 0x0000ff00 +static unsigned int storage_drivers[MAX_NUM_DRIVES]; +static unsigned int num_drives; + +int storage_num_drives(void) +{ + return num_drives; +} + +int storage_init(void) +{ + int rc=0; + int i; + num_drives=0; +#if (CONFIG_STORAGE & STORAGE_ATA) + if((rc=ata_init())) return rc; + for(i=0;i>DRIVER_OFFSET; + int ldrive=(storage_drivers[drive]&DRIVE_MASK)>>DRIVE_OFFSET; + switch(driver) + { +#if (CONFIG_STORAGE & STORAGE_ATA) + case STORAGE_ATA: + return ata_read_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_read_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_read_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_read_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_read_sectors(ldrive,start,count,buf); +#endif + } + return -1; +} +int storage_write_sectors(int drive, unsigned long start, int count, const void* buf) +{ + int driver=(storage_drivers[drive]&DRIVER_MASK)>>DRIVER_OFFSET; + int ldrive=(storage_drivers[drive]&DRIVE_MASK)>>DRIVE_OFFSET; + switch(driver) + { +#if (CONFIG_STORAGE & STORAGE_ATA) + case STORAGE_ATA: + return ata_write_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_write_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_write_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_write_sectors(ldrive,start,count,buf); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_write_sectors(ldrive,start,count,buf); +#endif + } + return -1; +} + +void storage_enable(bool on) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_enable(on); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_enable(on); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_enable(on); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_enable(on); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_enable(on); +#endif +} + +void storage_sleep(void) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_sleep(); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_sleep(); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_sleep(); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_sleep(); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_sleep(); +#endif +} + +void storage_sleepnow(void) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_sleepnow(); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_sleepnow(); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_sleepnow(); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_sleepnow(); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_sleepnow(); +#endif +} + +bool storage_disk_is_active(void) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + if(ata_disk_is_active()) return true; +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + if(mmc_disk_is_active()) return true; +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + if(sd_disk_is_active()) return true; +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + if(nand_disk_is_active()) return true; +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + if(ramdisk_disk_is_active()) return true; +#endif + return false; +} +int storage_soft_reset(void) +{ + int rc=0; +#if (CONFIG_STORAGE & STORAGE_ATA) + if((rc=ata_soft_reset())) return rc; +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + if((rc=mmc_soft_reset())) return rc; +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + if((rc=sd_soft_reset())) return rc; +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + if((rc=nand_soft_reset())) return rc; +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + if((rc=ramdisk_soft_reset())) return rc; +#endif + return 0; +} + +void storage_spin(void) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_spin(); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_spin(); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_spin(); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_spin(); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_spin(); +#endif +} +void storage_spindown(int seconds) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_spindown(seconds); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_spindown(seconds); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_spindown(seconds); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_spindown(seconds); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_spindown(seconds); +#endif +} +#if (CONFIG_LED == LED_REAL) +void storage_set_led_enabled(bool enabled) +{ +#if (CONFIG_STORAGE & STORAGE_ATA) + ata_set_led_enabled(enabled); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + mmc_set_led_enabled(enabled); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + sd_set_led_enabled(enabled); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + nand_set_led_enabled(enabled); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + ramdisk_set_led_enabled(enabled); +#endif +} +#endif +long storage_last_disk_activity(void) +{ + long max=0; + long t; +#if (CONFIG_STORAGE & STORAGE_ATA) + t=ata_last_disk_activity(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + t=mmc_last_disk_activity(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + t=sd_last_disk_activity(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + t=nand_last_disk_activity(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + t=ramdisk_last_disk_activity(); + if(t>max) max=t; +#endif + return max; +} +int storage_spinup_time(void) +{ + int max=0; + int t; +#if (CONFIG_STORAGE & STORAGE_ATA) + t=ata_spinup_time(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + t=mmc_spinup_time(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + t=sd_spinup_time(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + t=nand_spinup_time(); + if(t>max) max=t; +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + t=ramdisk_spinup_time(); + if(t>max) max=t; +#endif + return max; +} +#ifdef STORAGE_GET_INFO +void storage_get_info(int drive, struct storage_info *info) +{ + int driver=(storage_drivers[drive]&DRIVER_MASK)>>DRIVER_OFFSET; + int ldrive=(storage_drivers[drive]&DRIVE_MASK)>>DRIVE_OFFSET; + switch(driver) + { +#if (CONFIG_STORAGE & STORAGE_ATA) + case STORAGE_ATA: + return ata_get_info(ldrive,info); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_get_info(ldrive,info); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_get_info(ldrive,info); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_get_info(ldrive,info); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_get_info(ldrive,info); +#endif + } +} +#endif +#ifdef HOTSWAP +bool storage_removable(int drive) +{ + int driver=(storage_drivers[drive]&DRIVER_MASK)>>DRIVER_OFFSET; + int ldrive=(storage_drivers[drive]&DRIVE_MASK)>>DRIVE_OFFSET; + switch(driver) + { +#if (CONFIG_STORAGE & STORAGE_ATA) + case STORAGE_ATA: + return ata_removable(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_removable(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_removable(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_removable(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_removable(ldrive); +#endif + } +} +bool storage_present(int drive) +{ + int driver=(storage_drivers[drive]&DRIVER_MASK)>>DRIVER_OFFSET; + int ldrive=(storage_drivers[drive]&DRIVE_MASK)>>DRIVE_OFFSET; + switch(driver) + { +#if (CONFIG_STORAGE & STORAGE_ATA) + case STORAGE_ATA: + return ata_present(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_MMC) + case STORAGE_MMC: + return mmc_present(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_SD) + case STORAGE_SD: + return sd_present(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_NAND) + case STORAGE_NAND: + return nand_present(ldrive); +#endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) + case STORAGE_RAMDISK: + return ramdisk_present(ldrive); +#endif + } +} +#endif + diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c old mode 100644 new mode 100755 index da455ce..00273e0 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c @@ -22,7 +22,7 @@ /* Driver for the ARM PL180 SD/MMC controller inside AS3525 SoC */ -#include "config.h" /* for HAVE_MULTIVOLUME */ +#include "config.h" /* for HAVE_MULTIDRIVE */ #include "fat.h" #include "thread.h" #include "hotswap.h" @@ -80,9 +80,9 @@ #define INTERNAL_AS3525 0 /* embedded SD card */ #define SD_SLOT_AS3525 1 /* SD slot if present */ -static const int pl180_base[NUM_VOLUMES] = { +static const int pl180_base[NUM_DRIVES] = { NAND_FLASH_BASE -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE , SD_MCI_BASE #endif }; @@ -93,7 +93,7 @@ static void init_pl180_controller(const int drive); #define BLOCK_SIZE 512 #define SECTOR_SIZE 512 -static tSDCardInfo card_info[NUM_VOLUMES]; +static tSDCardInfo card_info[NUM_DRIVES]; /* for compatibility */ static long last_disk_activity = -1; @@ -179,7 +179,7 @@ void INT_NAND(void) MCI_CLEAR(INTERNAL_AS3525) = status; } -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE void INT_MCI0(void) { const int status = MCI_STATUS(SD_SLOT_AS3525); @@ -318,7 +318,7 @@ static int sd_init_card(const int drive) card_info[drive].numblocks = c_size * c_mult * (card_info[drive].max_read_bl_len/512); card_info[drive].capacity = card_info[drive].numblocks * card_info[drive].block_size; } -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE else if( (card_info[drive].csd[3]>>30) == 1) { /* CSD version 2.0 */ @@ -437,7 +437,7 @@ static void init_pl180_controller(const int drive) MCI_MASK0(drive) = MCI_MASK1(drive) = MCI_ERROR | MCI_DATA_END; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE VIC_INT_ENABLE |= (drive == INTERNAL_AS3525) ? INTERRUPT_NAND : INTERRUPT_MCI0; @@ -483,7 +483,7 @@ int sd_init(void) CGU_PERI |= CGU_NAF_CLOCK_ENABLE; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE CGU_PERI |= CGU_MCI_CLOCK_ENABLE; CCU_IO &= ~(1<<3); /* bits 3:2 = 01, xpd is SD interface */ CCU_IO |= (1<<2); @@ -495,7 +495,7 @@ int sd_init(void) ret = sd_init_card(INTERNAL_AS3525); if(ret < 0) return ret; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE init_pl180_controller(SD_SLOT_AS3525); #endif @@ -514,9 +514,9 @@ int sd_init(void) } #ifdef STORAGE_GET_INFO -void sd_get_info(IF_MV2(int drive,) struct storage_info *info) +void sd_get_info(IF_MD2(int drive,) struct storage_info *info) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif info->sector_size=card_info[drive].block_size; @@ -528,17 +528,17 @@ void sd_get_info(IF_MV2(int drive,) struct storage_info *info) #endif #ifdef HAVE_HOTSWAP -bool sd_removable(IF_MV_NONVOID(int drive)) +bool sd_removable(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (drive==1); } -bool sd_present(IF_MV_NONVOID(int drive)) +bool sd_present(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (card_info[drive].initialized && card_info[drive].numblocks > 0); @@ -574,10 +574,10 @@ static int sd_wait_for_state(const int drive, unsigned int state) } } -static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, +static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf, bool write) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive = 0; #endif int ret = 0; @@ -690,18 +690,18 @@ sd_transfer_error: return ret; } -int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count, +int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf) { - return sd_transfer_sectors(IF_MV2(drive,) start, count, buf, false); + return sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false); } -int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, +int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) { #ifdef BOOTLOADER /* we don't need write support in bootloader */ -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE (void) drive; #endif (void) start; @@ -709,7 +709,7 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, (void) buf; return -1; #else - return sd_transfer_sectors(IF_MV2(drive,) start, count, (void*)buf, true); + return sd_transfer_sectors(IF_MD2(drive,) start, count, (void*)buf, true); #endif } @@ -739,7 +739,7 @@ void sd_enable(bool on) if(on) { CGU_PERI |= CGU_NAF_CLOCK_ENABLE; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE CGU_PERI |= CGU_MCI_CLOCK_ENABLE; /* Needed for buttonlight and MicroSD to work at the same time */ /* Turn ROD control on, as the OF does */ @@ -753,7 +753,7 @@ void sd_enable(bool on) else { CGU_PERI &= ~CGU_NAF_CLOCK_ENABLE; -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE CGU_PERI &= ~CGU_MCI_CLOCK_ENABLE; /* Needed for buttonlight and MicroSD to work at the same time */ /* Turn ROD control off, as the OF does */ @@ -829,3 +829,14 @@ void card_enable_monitoring_target(bool on) #endif #endif /* BOOTLOADER */ + +#ifdef CONFIG_STORAGE_MULTI +int sd_num_drives(void) +{ +#ifdef HAVE_MULTIDRIVE + return 2; +#else + return 1; +#endif +} +#endif diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c index 6d1d536..4d014ee 100644 --- a/firmware/target/arm/ata-nand-telechips.c +++ b/firmware/target/arm/ata-nand-telechips.c @@ -692,10 +692,10 @@ static void read_inplace_writes_cache(int bank, int phys_segment) } -int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, +int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, void* inbuf) { -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE (void)drive; /* unused for now */ #endif mutex_lock(&ata_mtx); @@ -732,11 +732,10 @@ int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, return 0; } - -int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, +int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* outbuf) { -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE (void)drive; /* unused for now */ #endif @@ -888,3 +887,10 @@ void nand_spindown(int seconds) { (void)seconds; } + +#ifdef CONFIG_STORAGE_MULTI +int nand_num_drives(void) +{ + return 1; +} +#endif diff --git a/firmware/target/arm/ata-sd-pp.c b/firmware/target/arm/ata-sd-pp.c index cde474c..894ac21 100644 --- a/firmware/target/arm/ata-sd-pp.c +++ b/firmware/target/arm/ata-sd-pp.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include "config.h" /* for HAVE_MULTIVOLUME */ +#include "config.h" /* for HAVE_MULTIDRIVE */ #include "fat.h" #include "hotswap.h" #include "ata-sd-target.h" @@ -165,10 +165,10 @@ struct sd_card_status int retry_max; }; -static struct sd_card_status sd_status[NUM_VOLUMES] = +static struct sd_card_status sd_status[NUM_DRIVES] = { { 0, 1 }, -#ifdef HAVE_MULTIVOLUME +#ifdef HAVE_MULTIDRIVE { 0, 10 } #endif }; @@ -842,10 +842,10 @@ static void sd_led(bool onoff) led(onoff); } -int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, +int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, void* inbuf) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive = 0; #endif int ret; @@ -959,13 +959,13 @@ sd_read_error: } } -int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, +int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* outbuf) { /* Write support is not finished yet */ /* TODO: The standard suggests using ACMD23 prior to writing multiple blocks to improve performance */ -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive = 0; #endif int ret; @@ -1354,9 +1354,9 @@ long sd_last_disk_activity(void) } #ifdef STORAGE_GET_INFO -void sd_get_info(IF_MV2(int drive,) struct storage_info *info) +void sd_get_info(IF_MD2(int drive,) struct storage_info *info) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif info->sector_size=card_info[drive].block_size; @@ -1375,17 +1375,17 @@ void sd_get_info(IF_MV2(int drive,) struct storage_info *info) #endif #ifdef HAVE_HOTSWAP -bool sd_removable(IF_MV_NONVOID(int drive)) +bool sd_removable(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (drive==1); } -bool sd_present(IF_MV_NONVOID(int drive)) +bool sd_present(IF_MD_NONVOID(int drive)) { -#ifndef HAVE_MULTIVOLUME +#ifndef HAVE_MULTIDRIVE const int drive=0; #endif return (card_info[drive].initialized && card_info[drive].numblocks > 0); @@ -1404,3 +1404,14 @@ void sd_spindown(int seconds) { (void)seconds; } + +#ifdef CONFIG_STORAGE_MULTI +int sd_num_drives(void) +{ +#ifdef HAVE_MULTIDRIVE + return 2; +#else + return 1; +#endif +} +#endif diff --git a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c index 8c66c14..ee46028 100644 --- a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c +++ b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c @@ -46,13 +46,13 @@ void nand_led(bool onoff) led(onoff); } -int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, +int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount, void* inbuf) { } -int nand_write_sectors(IF_MV2(int drive,) unsigned long start, int count, +int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* outbuf) { } @@ -87,3 +87,10 @@ void nand_enable(bool on) int nand_init(void) { } + +#ifdef CONFIG_STORAGE_MULTI +int nand_num_drives(void) +{ + return 1; +} +#endif diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c old mode 100644 new mode 100755 index f9acdf5..f84d904 --- 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) #define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */ -extern int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -extern int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +extern int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +extern int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); struct main_header { @@ -378,14 +378,14 @@ static inline unsigned long map_sector(unsigned long sector) return cfs_start+sectors[sector/64]*64+sector%64; } -int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf) +int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf) { if(!cfs_inited) cfs_init(); /* Check if count is lesser than or equal to 1 native CFS sector */ if(count <= 64) - return _ata_read_sectors(IF_MV2(drive,) map_sector(start), count, buf); + return _ata_read_sectors(IF_MD2(drive,) map_sector(start), count, buf); else { int i, ret; @@ -394,7 +394,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* bu /* Read sectors in parts of 0x8000 */ for(i=0; i= 64 ? 64 : count-i), (void*)dest); + ret = _ata_read_sectors(IF_MD2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (void*)dest); if(ret != 0) return ret; @@ -405,7 +405,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* bu } } -int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf) +int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) { if(!cfs_inited) cfs_init(); @@ -413,7 +413,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v #if 0 /* Disabled for now */ /* Check if count is lesser than or equal to 1 native CFS sector */ if(count <= 64) - return _ata_write_sectors(IF_MV2(drive,) map_sector(start), count, buf); + return _ata_write_sectors(IF_MD2(drive,) map_sector(start), count, buf); else { int i, ret; @@ -422,7 +422,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v /* Read sectors in parts of 0x8000 */ for(i=0; i= 64 ? 64 : count-i), (const void*)dest); + ret = _ata_write_sectors(IF_MD2(drive,) map_sector(start+i), (count-i >= 64 ? 64 : count-i), (const void*)dest); if(ret != 0) return ret; diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h index 64c49fe..a1d4a90 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); /* Nasty hack, but Creative is nasty... */ #define ata_read_sectors _ata_read_sectors #define ata_write_sectors _ata_write_sectors -extern int _ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf); -extern int _ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf); +extern int _ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf); +extern int _ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf); /* General purpose memory region #1 */ #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 old mode 100644 new mode 100755 index d918928..e3daaeb --- a/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c @@ -737,3 +737,10 @@ void nand_get_info(IF_MV2(int drive,) struct storage_info *info) info->sector_size = 512; } #endif + +#ifdef CONFIG_STORAGE_MULTI +int nand_num_drives(void) +{ + return 1; +} +#endif diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c old mode 100644 new mode 100755 index 6ee18a4..b267ffa --- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c @@ -1839,3 +1839,10 @@ void sd_get_info(IF_MV2(int drive,) struct storage_info *info) info->sector_size = mmcinfo.block_len; } #endif + +#ifdef CONFIG_STORAGE_MULTI +int sd_num_drives(void) +{ + return 1; +} +#endif diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index 9fd1504..e190d81 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c @@ -696,7 +696,7 @@ int main(int argc, char *argv[]) #endif ) { DEBUGF("*** Mounting at block %ld\n",pinfo[i].start); - rc = fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start); + rc = fat_mount(IF_MV2(0,) IF_MD2(0,) pinfo[i].start); if(rc) { DEBUGF("mount: %d",rc); return -1; @@ -705,7 +705,7 @@ int main(int argc, char *argv[]) } } if ( i==4 ) { - if(fat_mount(IF_MV2(0,) IF_MV2(0,) 0)) { + if(fat_mount(IF_MV2(0,) IF_MD2(0,) 0)) { DEBUGF("No FAT32 partition!"); return -1; } diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c index f4540e4..ad0f8ef 100644 --- a/firmware/test/i2c/main.c +++ b/firmware/test/i2c/main.c @@ -642,7 +642,7 @@ int main(void) - i = fat_mount(IF_MV2(0,) IF_MV2(0,) part[0].start); + i = fat_mount(IF_MV2(0,) IF_MD2(0,) part[0].start); debugf("fat_mount() returned %d\n", i); diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c old mode 100644 new mode 100755 diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c old mode 100644 new mode 100755 index aa8cb29..22f6e6c --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -22,7 +22,7 @@ #include "system.h" #include "usb_core.h" #include "usb_drv.h" -//#define LOGF_ENABLE +#define LOGF_ENABLE #include "logf.h" #include "storage.h" #include "hotswap.h" @@ -141,8 +141,7 @@ struct inquiry_data { struct report_lun_data { unsigned int lun_list_length; unsigned int reserved1; - // TODO this should be cleaned up with the VOLUMES vs DRIVES mess - unsigned char luns[NUM_VOLUMES][8]; + unsigned char luns[NUM_DRIVES][8]; } __attribute__ ((packed)); struct sense_data { @@ -257,10 +256,10 @@ static void send_command_result(void *data,int size); static void send_command_failed_result(void); static void send_block_data(void *data,int size); static void receive_block_data(void *data,int size); -static void fill_inquiry(IF_MV_NONVOID(int lun)); +static void fill_inquiry(IF_MD_NONVOID(int lun)); static void send_and_read_next(void); -static bool ejected[NUM_VOLUMES]; -static bool locked[NUM_VOLUMES]; +static bool ejected[NUM_DRIVES]; +static bool locked[NUM_DRIVES]; static int usb_interface; static int ep_in, ep_out; @@ -295,7 +294,7 @@ static void fix_mbr(unsigned char* mbr) } #endif -static bool check_disk_present(IF_MV_NONVOID(int volume)) +static bool check_disk_present(IF_MD_NONVOID(int volume)) { #ifdef USB_USE_RAMDISK return true; @@ -311,7 +310,7 @@ void usb_storage_try_release_storage(void) release excusive access */ bool canrelease=true; int i; - for(i=0;ibRequest) { case USB_BULK_GET_MAX_LUN: { -#ifdef ONLY_EXPOSE_CARD_SLOT - *tb.max_lun = 0; -#else - *tb.max_lun = NUM_VOLUMES - 1; + *tb.max_lun = storage_num_drives() - 1; +#ifdef HIDE_FIRST_DRIVE + *tb.max_lun --; #endif logf("ums: getmaxlun"); usb_drv_send(EP_CONTROL, tb.max_lun, 1); @@ -678,12 +676,12 @@ static void handle_scsi(struct command_block_wrapper* cbw) unsigned int block_size = 0; unsigned int block_count = 0; bool lun_present=true; -#ifdef ONLY_EXPOSE_CARD_SLOT - unsigned char lun = cbw->lun+1; -#else unsigned char lun = cbw->lun; -#endif unsigned int block_size_mult = 1; +#ifdef HIDE_FIRST_DRIVE + lun++; +#endif + storage_get_info(lun,&info); #ifdef USB_USE_RAMDISK block_size = SECTOR_SIZE; @@ -735,13 +733,14 @@ static void handle_scsi(struct command_block_wrapper* cbw) logf("scsi report luns %d",lun); int allocation_length=0; int i; + unsigned int response_length = 8+8*storage_num_drives(); allocation_length|=(cbw->command_block[6]<<24); allocation_length|=(cbw->command_block[7]<<16); allocation_length|=(cbw->command_block[8]<<8); allocation_length|=(cbw->command_block[9]); memset(tb.lun_data,0,sizeof(struct report_lun_data)); - tb.lun_data->lun_list_length=htobe32(8*NUM_VOLUMES); - for(i=0;ilun_list_length=htobe32(8*storage_num_drives()); + for(i=0;iluns[i][1]=0; } send_command_result(tb.lun_data, - MIN(sizeof(struct report_lun_data), length)); + MIN(response_length, length)); break; } case SCSI_INQUIRY: logf("scsi inquiry %d",lun); - fill_inquiry(IF_MV(lun)); + fill_inquiry(IF_MD(lun)); length = MIN(length, cbw->command_block[4]); send_command_result(tb.inquiry, MIN(sizeof(struct inquiry_data), length)); @@ -1125,7 +1124,7 @@ static void copy_padded(char *dest, char *src, int len) } /* build SCSI INQUIRY */ -static void fill_inquiry(IF_MV_NONVOID(int lun)) +static void fill_inquiry(IF_MD_NONVOID(int lun)) { memset(tb.inquiry, 0, sizeof(struct inquiry_data)); struct storage_info info;