diff --git a/firmware/SOURCES b/firmware/SOURCES index 567fa1c579..f299d51a53 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -117,6 +117,8 @@ drivers/ata_flash.c target/arm/ata-nand-telechips.c #elif (CONFIG_STORAGE & STORAGE_ATA) drivers/ata.c +#elif (CONFIG_STORAGE & STORAGE_RAMDISK) +drivers/ramdisk.c #endif /* CONFIG_STORAGE */ drivers/fat.c #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) diff --git a/firmware/drivers/ramdisk.c b/firmware/drivers/ramdisk.c new file mode 100644 index 0000000000..da0a12f836 --- /dev/null +++ b/firmware/drivers/ramdisk.c @@ -0,0 +1,102 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ramdisk.c 18965 2008-11-01 17:33:21Z gevaerts $ + * + * Copyright (C) 2008 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 +#include + +#include "storage.h" + +#define SECTOR_SIZE 512 +#define NUM_SECTORS 16384 + +extern unsigned char ramdisk[SECTOR_SIZE * NUM_SECTORS]; + +long last_disk_activity = -1; + +int ramdisk_read_sectors(IF_MV2(int drive,) + unsigned long start, + int count, + void* buf) +{ + if(start+count>=NUM_SECTORS) + { + return -1; + } + memcpy(buf,&ramdisk[start*SECTOR_SIZE],count*SECTOR_SIZE); + return 0; +} + +int ramdisk_write_sectors(IF_MV2(int drive,) + unsigned long start, + int count, + const void* buf) +{ + if(start+count>=NUM_SECTORS) + { + return -1; + } + memcpy(&ramdisk[start*SECTOR_SIZE],buf,count*SECTOR_SIZE); + return 0; +} + +int ramdisk_init(void) +{ + return 0; +} + +long ramdisk_last_disk_activity(void) +{ + return last_disk_activity; +} + +void ramdisk_sleep(void) +{ +} + +void ramdisk_spin(void) +{ +} + +void ramdisk_sleepnow(void) +{ +} + +void ramdisk_spindown(int seconds) +{ + (void)seconds; +} +#ifdef STORAGE_GET_INFO +void ramdisk_get_info(struct storage_info *info) +{ + /* firmware version */ + info->revision="0.00"; + + /* vendor field, need better name? */ + info->vendor="Rockbox"; + /* model field, need better name? */ + info->product="Ramdisk"; + + /* blocks count */ + info->num_sectors=NUM_SECTORS; + info->sector_size=SECTOR_SIZE; +} +#endif + diff --git a/firmware/export/config.h b/firmware/export/config.h index 1574d40040..914ac1ee9d 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -29,10 +29,11 @@ /* symbolic names for multiple choice configurations: */ /* CONFIG_STORAGE (note these are combineable bit-flags) */ -#define STORAGE_ATA 0x01 -#define STORAGE_MMC 0x02 -#define STORAGE_SD 0x04 -#define STORAGE_NAND 0x08 +#define STORAGE_ATA 0x01 +#define STORAGE_MMC 0x02 +#define STORAGE_SD 0x04 +#define STORAGE_NAND 0x08 +#define STORAGE_RAMDISK 0x10 /* CONFIG_TUNER (note these are combineable bit-flags) */ #define S1A0903X01 0x01 /* Samsung */ diff --git a/firmware/export/ramdisk.h b/firmware/export/ramdisk.h new file mode 100644 index 0000000000..7fb8fb7cbc --- /dev/null +++ b/firmware/export/ramdisk.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Alan Korr + * 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. + * + ****************************************************************************/ +#ifndef __RAMDISK_H__ +#define __RAMDISK_H__ + +#include +#include "mv.h" /* for HAVE_MULTIVOLUME or not */ + +struct storage_info; + +void ramdisk_enable(bool on); +void ramdisk_spindown(int seconds); +void ramdisk_sleep(void); +bool ramdisk_disk_is_active(void); +int ramdisk_hard_reset(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); +void ramdisk_spin(void); +void ramdisk_sleepnow(void); + +#if (CONFIG_LED == LED_REAL) +void ramdisk_set_led_enabled(bool enabled); +#endif + +#ifdef STORAGE_GET_INFO +void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info); +#endif + +long ramdisk_last_disk_activity(void); + +#endif diff --git a/firmware/export/storage.h b/firmware/export/storage.h index d4e69163b7..4040fe952f 100644 --- a/firmware/export/storage.h +++ b/firmware/export/storage.h @@ -38,6 +38,9 @@ #if (CONFIG_STORAGE & STORAGE_NAND) #include "nand.h" #endif +#if (CONFIG_STORAGE & STORAGE_RAMDISK) +#include "ramdisk.h" +#endif struct storage_info { @@ -165,6 +168,34 @@ struct storage_info #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_hard_reset() (void)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() + + #if (CONFIG_LED == LED_REAL) + #define storage_set_led_enabled(enabled) ramdisk_set_led_enabled(enabled) + #endif + #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 diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index 7724049415..6003c8d197 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c @@ -300,6 +300,19 @@ static void set_serial_descriptor(void) } usb_string_iSerial.bLength=84; } +#elif (CONFIG_STORAGE & STORAGE_RAMDISK) +/* This "serial number" isn't unique, but it should never actually + appear in non-testing use */ +static void set_serial_descriptor(void) +{ + short* p = &usb_string_iSerial.wString[1]; + int i; + for (i = 0; i < 16; i++) { + *p++ = hex[(2*i)&0xF]; + *p++ = hex[(2*i+1)&0xF]; + } + usb_string_iSerial.bLength=68; +} #else #error No set_serial_descriptor() implementation for this target #endif