diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 6a126f3..70d75f9 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -238,3 +238,5 @@ test_touchscreen.c #endif test_viewports.c #endif + +test_disk.c diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c index c83fb7e..fbd9baf 100644 --- a/apps/plugins/test_disk.c +++ b/apps/plugins/test_disk.c @@ -41,7 +41,7 @@ static ssize_t audiobuflen; static unsigned short frnd_buffer; static int line = 0; static int max_line = 0; -static int log_fd; +//static int log_fd; static char logfilename[MAX_PATH]; static const char testbasedir[] = TESTBASEDIR; @@ -85,8 +85,8 @@ static bool log_init(void) rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt", 2 IF_CNFN_NUM_(, NULL)); - log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); - return log_fd >= 0; + //log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); + return true;//log_fd >= 0; } static void log_text(char *text, bool advance) @@ -97,19 +97,22 @@ static void log_text(char *text, bool advance) { if (++line >= max_line) line = 0; - rb->fdprintf(log_fd, "%s\n", text); + //rb->fdprintf(log_fd, "%s\n", text); } } static void log_close(void) { - rb->close(log_fd); + //rb->close(log_fd); } +static const int align = 32; +#define ALIGN(x) ((typeof(x)) (((uintptr_t)(x) + 31) & ~31)) + static bool test_fs(void) { unsigned char text_buf[32]; - int total, current, align; + int total, current; int fd; log_init(); @@ -134,15 +137,14 @@ static bool test_fs(void) total = TEST_SIZE; while (total > 0) { - align = rb->rand() & 0xf; current = rb->rand() % (audiobuflen - align); current = MIN(current, total); rb->snprintf(text_buf, sizeof text_buf, "Wrt %dKB, %dKB left", current >> 10, total >> 10); log_text(text_buf, false); - mem_fill_frnd(audiobuf + align, current); - if (current != rb->write(fd, audiobuf + align, current)) + mem_fill_frnd(ALIGN(audiobuf), current); + if (current != rb->write(fd, ALIGN(audiobuf), current)) { rb->splash(0, "write() failed."); rb->close(fd); @@ -163,20 +165,19 @@ static bool test_fs(void) total = TEST_SIZE; while (total > 0) { - align = rb->rand() & 0xf; current = rb->rand() % (audiobuflen - align); current = MIN(current, total); rb->snprintf(text_buf, sizeof text_buf, "Cmp %dKB, %dKB left", current >> 10, total >> 10); log_text(text_buf, false); - if (current != rb->read(fd, audiobuf + align, current)) + if (current != rb->read(fd, ALIGN(audiobuf), current)) { rb->splash(0, "read() failed."); rb->close(fd); goto error; } - if (!mem_cmp_frnd(audiobuf + align, current)) + if (!mem_cmp_frnd(ALIGN(audiobuf), current)) { log_text(text_buf, true); log_text("Compare error.", true); @@ -198,7 +199,7 @@ error: return false; } -static bool file_speed(int chunksize, bool align) +static bool file_speed(int chunksize) { unsigned char text_buf[64]; int fd; @@ -220,7 +221,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick; while (TIME_BEFORE(*rb->current_tick, time + TEST_TIME*HZ)) { - if (chunksize != rb->write(fd, audiobuf + (align ? 0 : 1), chunksize)) + if (chunksize != rb->write(fd, ALIGN(audiobuf), chunksize)) { rb->splash(HZ, "write() failed."); rb->close(fd); @@ -231,7 +232,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick - time; rb->close(fd); rb->snprintf(text_buf, sizeof text_buf, "Create (%d,%c): %ld KB/s", - chunksize, align ? 'A' : 'U', (25 * (filesize>>8) / time) ); + chunksize, 'A', (25 * (filesize>>8) / time) ); log_text(text_buf, true); /* Existing file write speed */ @@ -244,7 +245,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick; for (size = filesize; size > 0; size -= chunksize) { - if (chunksize != rb->write(fd, audiobuf + (align ? 0 : 1), chunksize)) + if (chunksize != rb->write(fd, ALIGN(audiobuf), chunksize)) { rb->splash(0, "write() failed."); rb->close(fd); @@ -254,7 +255,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick - time; rb->close(fd); rb->snprintf(text_buf, sizeof text_buf, "Write (%d,%c): %ld KB/s", - chunksize, align ? 'A' : 'U', (25 * (filesize>>8) / time) ); + chunksize, 'A', (25 * (filesize>>8) / time) ); log_text(text_buf, true); /* File read speed */ @@ -267,7 +268,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick; for (size = filesize; size > 0; size -= chunksize) { - if (chunksize != rb->read(fd, audiobuf + (align ? 0 : 1), chunksize)) + if (chunksize != rb->read(fd, ALIGN(audiobuf), chunksize)) { rb->splash(0, "read() failed."); rb->close(fd); @@ -277,7 +278,7 @@ static bool file_speed(int chunksize, bool align) time = *rb->current_tick - time; rb->close(fd); rb->snprintf(text_buf, sizeof text_buf, "Read (%d,%c): %ld KB/s", - chunksize, align ? 'A' : 'U', (25 * (filesize>>8) / time) ); + chunksize, 'A', (25 * (filesize>>8) / time) ); log_text(text_buf, true); rb->remove(TEST_FILE); return true; @@ -375,12 +376,9 @@ static bool test_speed(void) last_file * HZ / (*rb->current_tick - time)); log_text(text_buf, true); - if (file_speed(512, true) - && file_speed(512, false) - && file_speed(4096, true) - && file_speed(4096, false) - && file_speed(1048576, true)) - file_speed(1048576, false); + if (file_speed(512) && file_speed(4096) && file_speed(1048576)) + { + } log_text("DONE", false); log_close(); @@ -409,7 +407,6 @@ enum plugin_status plugin_start(const void* parameter) "Disk speed", "Write & verify"); int selected=0; bool quit = false; - int align; DIR *dir; (void)parameter; @@ -428,10 +425,8 @@ enum plugin_status plugin_start(const void* parameter) } audiobuf = rb->plugin_get_audio_buffer((size_t *)&audiobuflen); - /* align start and length to 32 bit */ - align = (-(int)audiobuf) & 3; - audiobuf += align; - audiobuflen = (audiobuflen - align) & ~3; + audiobuf = ALIGN(audiobuf); + audiobuflen &= ~31; rb->srand(*rb->current_tick); diff --git a/firmware/common/disk.c b/firmware/common/disk.c index f8efe1c..4e52cdf 100644 --- a/firmware/common/disk.c +++ b/firmware/common/disk.c @@ -20,6 +20,7 @@ ****************************************************************************/ #include #include "storage.h" +#include "system.h" #include "debug.h" #include "fat.h" #ifdef HAVE_HOTSWAP @@ -68,7 +69,9 @@ int disk_sector_multiplier = 1; struct partinfo* disk_init(IF_MD_NONVOID(int drive)) { int i; - unsigned char sector[SECTOR_SIZE]; + unsigned char _sector[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *sector = STORAGE_ALIGN_UP(&_sector[0]); + #ifdef HAVE_MULTIDRIVE /* For each drive, start at a different position, in order not to destroy the first entry of drive 0. @@ -82,7 +85,7 @@ struct partinfo* disk_init(IF_MD_NONVOID(int drive)) (void)drive; #endif - storage_read_sectors(IF_MD2(drive,) 0,1, §or); + storage_read_sectors(IF_MD2(drive,) 0,1, sector); /* check that the boot sector is initialized */ if ( (sector[510] != 0x55) || (sector[511] != 0xaa)) { diff --git a/firmware/common/file.c b/firmware/common/file.c index 438a710..7b6b3c0 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -39,7 +39,7 @@ */ struct filedesc { - unsigned char cache[SECTOR_SIZE]; + unsigned char cache[STORAGE_PAD(SECTOR_SIZE)]; /* first member is aligned on struct size */ int cacheoffset; /* invariant: 0 <= cacheoffset <= SECTOR_SIZE */ long fileoffset; long size; @@ -49,9 +49,9 @@ struct filedesc { bool write; bool dirty; bool trunc; -}; +} STORAGE_ALIGN_ATTR; -static struct filedesc openfiles[MAX_OPEN_FILES]; +static struct filedesc openfiles[MAX_OPEN_FILES] STORAGE_ALIGN_ATTR; static int flush_cache(int fd); @@ -647,7 +647,7 @@ static int readwrite(int fd, void* buf, long count, bool write) file->dirty = true; } else { - rc = fat_readwrite(&(file->fatfile), 1, &(file->cache),false); + rc = fat_readwrite(&(file->fatfile), 1, file->cache,false); if (rc < 1 ) { DEBUGF("Failed caching sector\n"); errno = EIO; @@ -756,8 +756,7 @@ off_t lseek(int fd, off_t offset, int whence) } } if ( sectoroffset ) { - rc = fat_readwrite(&(file->fatfile), 1, - &(file->cache),false); + rc = fat_readwrite(&(file->fatfile), 1, file->cache, false); if ( rc < 0 ) { errno = EIO; return rc * 10 - 6; diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index f93b32f..593eab7 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -211,7 +211,7 @@ struct fat_cache_entry #endif }; -static char fat_cache_sectors[FAT_CACHE_SIZE][SECTOR_SIZE]; +static char fat_cache_sectors[FAT_CACHE_SIZE][SECTOR_SIZE] STORAGE_ALIGN_ATTR; static struct fat_cache_entry fat_cache[FAT_CACHE_SIZE]; static struct mutex cache_mutex SHAREDBSS_ATTR; @@ -302,7 +302,9 @@ int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector) const int volume = 0; #endif struct bpb* fat_bpb = &fat_bpbs[volume]; - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); + int rc; int secmult; long datasec; @@ -934,7 +936,9 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb)) #ifndef HAVE_MULTIVOLUME struct bpb* fat_bpb = &fat_bpbs[0]; #endif - unsigned char fsinfo[SECTOR_SIZE]; + unsigned char _fsinfo[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *fsinfo = STORAGE_ALIGN_UP(&_fsinfo[0]); + unsigned long* intptr; int rc; @@ -1103,7 +1107,9 @@ static int write_long_name(struct fat_file* file, const unsigned char* shortname, bool is_directory) { - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); + unsigned char* entry; unsigned int idx = firstentry % DIR_ENTRIES_PER_SECTOR; unsigned int sector = firstentry / DIR_ENTRIES_PER_SECTOR; @@ -1274,7 +1280,8 @@ static int add_dir_entry(struct fat_dir* dir, #else struct bpb* fat_bpb = &fat_bpbs[0]; #endif - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); unsigned char shortname[12]; int rc; unsigned int sector; @@ -1531,7 +1538,9 @@ static void randomize_dos_name(unsigned char *name) static int update_short_entry( struct fat_file* file, long size, int attr ) { - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); + int sector = file->direntry / DIR_ENTRIES_PER_SECTOR; unsigned char* entry = buf + DIR_ENTRY_SIZE * (file->direntry % DIR_ENTRIES_PER_SECTOR); @@ -1699,7 +1708,9 @@ int fat_create_dir(const char* name, #else struct bpb* fat_bpb = &fat_bpbs[0]; #endif - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); + int i; long sector; int rc; @@ -1837,7 +1848,9 @@ int fat_closewrite(struct fat_file *file, long size, int attr) static int free_direntries(struct fat_file* file) { - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); + struct fat_file dir; int numentries = file->direntries; unsigned int entry = file->direntry - numentries + 1; @@ -1939,7 +1952,8 @@ int fat_rename(struct fat_file* file, int rc; struct fat_dir olddir; struct fat_file newfile = *file; - unsigned char buf[SECTOR_SIZE]; + unsigned char _buf[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); unsigned char* entry = NULL; unsigned short* clusptr = NULL; unsigned int parentcluster; @@ -2353,6 +2367,7 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) { if ( !(dir->entry % DIR_ENTRIES_PER_SECTOR) || !dir->sector ) { + dir->sectorcache = STORAGE_ALIGN_UP(&dir->_sectorcache[0]); rc = fat_readwrite(&dir->file, 1, dir->sectorcache, false); if (rc == 0) { /* eof */ diff --git a/firmware/export/as3525.h b/firmware/export/as3525.h index a58a0ae..949eefb 100644 --- a/firmware/export/as3525.h +++ b/firmware/export/as3525.h @@ -21,6 +21,7 @@ #define __AS3525_H__ #define CACHEALIGN_BITS (5) +#define STORAGE_WANTS_ALIGN #define UART_CHANNELS 1 diff --git a/firmware/export/fat.h b/firmware/export/fat.h index 5df5dc4..cca6354 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h @@ -25,6 +25,7 @@ #include #include "mv.h" /* for volume definitions */ #include "config.h" +#include "system.h" /* for storage alignement */ /* This value can be overwritten by a target in config-[target].h, but that behaviour is still experimental */ @@ -85,7 +86,8 @@ struct fat_dir unsigned int entrycount; long sector; struct fat_file file; - unsigned char sectorcache[SECTOR_SIZE]; + unsigned char _sectorcache[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *sectorcache; /* aligned pointer */ /* There are 2-bytes per characters. We don't want to bother too much, as LFN entries are * at much 255 characters longs, that's at most 20 LFN entries. Each entry hold at most * 13 characters, that a total of 260 characters. So we keep a buffer of that size. diff --git a/firmware/export/system.h b/firmware/export/system.h index db4b365..bde621f 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -336,14 +336,21 @@ static inline void cpucache_flush(void) #endif /* PROC_NEEDS_CACHEALIGN */ #ifdef STORAGE_WANTS_ALIGN +#define STORAGE_ALIGN_ATTR __attribute__((aligned(CACHEALIGN_SIZE))) +#define STORAGE_ALIGN_SIZE(x) ((x + CACHEALIGN_SIZE - 1) & ~(CACHEALIGN_SIZE - 1)) #define STORAGE_ALIGN_DOWN(x) \ ((typeof (x))ALIGN_DOWN_P2((uintptr_t)(x), CACHEALIGN_BITS)) +#define STORAGE_ALIGN_UP(x) \ + ((typeof (x))ALIGN_UP_P2((uintptr_t)(x), CACHEALIGN_BITS)) /* Pad a size so the buffer can be aligned later */ #define STORAGE_PAD(x) ((x) + CACHEALIGN_SIZE - 1) /* Number of bytes in the last cacheline assuming buffer of size x is aligned */ #define STORAGE_OVERLAP(x) ((x) & (CACHEALIGN_SIZE - 1)) #else +#define STORAGE_ALIGN_ATTR +#define STORAGE_ALIGN_SIZE(x) (x) #define STORAGE_ALIGN_DOWN(x) (x) +#define STORAGE_ALIGN_UP(x) (x) #define STORAGE_PAD(x) (x) #define STORAGE_OVERLAP(x) 0 #endif diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index 81dc637..7166d22 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c @@ -136,14 +136,8 @@ static struct wakeup transfer_completion_signal; static volatile unsigned int transfer_error[NUM_VOLUMES]; #define PL180_MAX_TRANSFER_ERRORS 10 -#define UNALIGNED_NUM_SECTORS 10 -static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS* SD_BLOCK_SIZE] __attribute__((aligned(32))); /* align on cache line size */ -static unsigned char *uncached_buffer = AS3525_UNCACHED_ADDR(&aligned_buffer[0]); - - static inline void mci_delay(void) { udelay(1000) ; } - static inline bool card_detect_target(void) { #if defined(HAVE_MULTIDRIVE) @@ -599,6 +593,8 @@ static int sd_select_bank(signed char bank) { int ret; unsigned loops = 0; + unsigned char _buf[STORAGE_PAD(512)]; + unsigned char *buf = STORAGE_ALIGN_UP(&_buf[0]); do { if(loops++ > PL180_MAX_TRANSFER_ERRORS) @@ -619,20 +615,22 @@ static int sd_select_bank(signed char bank) mci_delay(); - memset(uncached_buffer, 0, 512); + memset(buf, 0, 512); if(bank == -1) { /* enable bank switching */ - uncached_buffer[0] = 16; - uncached_buffer[1] = 1; - uncached_buffer[2] = 10; + buf[0] = 16; + buf[1] = 1; + buf[2] = 10; } else - uncached_buffer[0] = bank; + buf[0] = bank; + + clean_dcache_range(buf, 512); dma_retain(); /* we don't use the uncached buffer here, because we need the * physical memory address for DMA transfers */ - dma_enable_channel(0, aligned_buffer, MCI_FIFO(INTERNAL_AS3525), + dma_enable_channel(0, buf, MCI_FIFO(INTERNAL_AS3525), DMA_PERI_SD, DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL); @@ -658,9 +656,16 @@ static int sd_select_bank(signed char bank) return 0; } +#define UNALIGNED_NUM_SECTORS 10 +static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS* SD_BLOCK_SIZE] STORAGE_ALIGN_ATTR; +static unsigned char *uncached_buffer = AS3525_UNCACHED_ADDR(&aligned_buffer[0]); + + static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf, const bool write) { + bool aligned = !((uintptr_t)buf & 31); + //panicf("UNALIGNED"); #ifndef HAVE_MULTIDRIVE const int drive = 0; #endif @@ -701,14 +706,8 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, while(count) { - /* 128 * 512 = 2^16, and doesn't fit in the 16 bits of DATA_LENGTH - * register, so we have to transfer maximum 127 sectors at a time. */ - unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */ - void *dma_buf; - const int cmd = - write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK; + unsigned int transfer = count; unsigned long bank_start = start; - /* Only switch banks for internal storage */ if(drive == INTERNAL_AS3525) { @@ -735,17 +734,13 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, transfer = BLOCKS_PER_BANK - bank_start; } + if(!aligned && transfer > UNALIGNED_NUM_SECTORS) + transfer = UNALIGNED_NUM_SECTORS; + /* Set bank_start to the correct unit (blocks or bytes) */ if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ bank_start *= SD_BLOCK_SIZE; - dma_buf = aligned_buffer; - if(transfer > UNALIGNED_NUM_SECTORS) - transfer = UNALIGNED_NUM_SECTORS; - - if(write) - memcpy(uncached_buffer, buf, transfer * SD_BLOCK_SIZE); - ret = sd_wait_for_state(drive, SD_TRAN); if (ret < 0) { @@ -753,6 +748,8 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, goto sd_transfer_error; } + const int cmd = write? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK; + if(!send_cmd(drive, cmd, bank_start, MCI_ARG, NULL)) { ret -= 3*20; @@ -761,6 +758,17 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, if(write) { + void *dma_buf; + if(aligned) + { + clean_dcache_range(buf, transfer * SD_BLOCK_SIZE); + dma_buf = buf; + } + else + { + memcpy(uncached_buffer, buf, transfer * SD_BLOCK_SIZE); + dma_buf = aligned_buffer; + } dma_enable_channel(0, dma_buf, MCI_FIFO(drive), (drive == INTERNAL_AS3525) ? DMA_PERI_SD : DMA_PERI_SD_SLOT, DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL); @@ -775,9 +783,21 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, #endif } else + { + void *dma_buf; + if(aligned) + { + dump_dcache_range(buf, transfer * SD_BLOCK_SIZE); + dma_buf = buf; + } + else + { + dma_buf = aligned_buffer; + } dma_enable_channel(0, MCI_FIFO(drive), dma_buf, (drive == INTERNAL_AS3525) ? DMA_PERI_SD : DMA_PERI_SD_SLOT, DMAC_FLOWCTRL_PERI_PERI_TO_MEM, false, true, 0, DMA_S8, NULL); + } MCI_DATA_TIMER(drive) = write ? SD_MAX_WRITE_TIMEOUT : SD_MAX_READ_TIMEOUT; @@ -788,7 +808,10 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, (9<<4) /* 2^9 = 512 */ ; /* Wakeup signal from NAND/MCIO isr on MCI_DATA_ERROR | MCI_DATA_END */ - wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK); + while(wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK) == + OBJ_WAIT_TIMEDOUT + ) + ; /* Wait for FIFO to empty, card may still be in PRG state for writes */ while(MCI_STATUS(drive) & MCI_TX_ACTIVE); @@ -803,7 +826,7 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, if(!transfer_error[drive]) { - if(!write) + if(!aligned && !write) memcpy(buf, uncached_buffer, transfer * SD_BLOCK_SIZE); buf += transfer * SD_BLOCK_SIZE; start += transfer; @@ -842,7 +865,7 @@ int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf) { - + //return -1; /* don't corrupt the FS */ #ifdef BOOTLOADER /* we don't need write support in bootloader */ #ifdef HAVE_MULTIDRIVE (void) drive; diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index 3373bf4..7db52b9 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -355,7 +355,9 @@ static bool check_disk_present(IF_MD_NONVOID(int volume)) #ifdef USB_USE_RAMDISK return true; #else - unsigned char sector[SECTOR_SIZE]; + unsigned char _sector[STORAGE_PAD(SECTOR_SIZE)]; + unsigned char *sector = STORAGE_ALIGN_DOWN(&_sector[0]); + return storage_read_sectors(IF_MD2(volume,)0,1,sector) == 0; #endif }