summaryrefslogtreecommitdiff
path: root/firmware/test
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test')
-rw-r--r--firmware/test/fat/README25
-rw-r--r--firmware/test/fat/ata-sim.c7
-rw-r--r--firmware/test/fat/main.c52
3 files changed, 79 insertions, 5 deletions
diff --git a/firmware/test/fat/README b/firmware/test/fat/README
new file mode 100644
index 0000000000..76141c0044
--- /dev/null
+++ b/firmware/test/fat/README
@@ -0,0 +1,25 @@
1This code is for testing the Rockbox fat code on a dummy drive image file.
2
3Dummy image
4-----------
5Here's how to create a 1 gig dummy drive image in linux:
6
7# dd if=/dev/hda of=disk.img bs=1M count=1024
8
9You can then format disk.img as a FAT32 partition:
10
11# mkdosfs -F 32 disk.img
12
13To mount the image, your linux kernel must include the loopback device:
14
15# mount -o loop disk.img /mnt/image
16
17Now copy some test data to the disk, umount it and start testing.
18
19
20Test code
21---------
22The files in this dir build the 'fat' program. It will read 'disk.img' and
23treat is as a real disk, thanks to the ata-sim.c module.
24
25Modify the main.c source code to make it perform the tests you want.
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c
index ab7266d6a0..a37fabcfc0 100644
--- a/firmware/test/fat/ata-sim.c
+++ b/firmware/test/fat/ata-sim.c
@@ -24,6 +24,13 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
24 24
25int ata_write_sectors(unsigned long start, unsigned char count, void* buf) 25int ata_write_sectors(unsigned long start, unsigned char count, void* buf)
26{ 26{
27 DEBUGF("Writing block 0x%lx\n",start);
28
29 if (start == 0) {
30 DEBUGF("Holy crap! You're writing on sector 0!\n");
31 exit(0);
32 }
33
27 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { 34 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
28 perror("fseek"); 35 perror("fseek");
29 return -1; 36 return -1;
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 4a11e0a08a..1b9fd22183 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -1,6 +1,7 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <stdarg.h>
4#include "fat.h" 5#include "fat.h"
5#include "debug.h" 6#include "debug.h"
6#include "disk.h" 7#include "disk.h"
@@ -14,6 +15,15 @@ void dbg_dump_sector(int sec);
14void dbg_dump_buffer(unsigned char *buf); 15void dbg_dump_buffer(unsigned char *buf);
15void dbg_console(void); 16void dbg_console(void);
16 17
18void panicf( char *fmt, ...)
19{
20 va_list ap;
21 va_start( ap, fmt );
22 vprintf( fmt, ap );
23 va_end( ap );
24 exit(0);
25}
26
17void dbg_dump_sector(int sec) 27void dbg_dump_sector(int sec)
18{ 28{
19 unsigned char buf[512]; 29 unsigned char buf[512];
@@ -75,14 +85,16 @@ void dbg_dir(char* currdir)
75void dbg_mkfile(char* name) 85void dbg_mkfile(char* name)
76{ 86{
77 char* text = "Detta är en dummy-text\n"; 87 char* text = "Detta är en dummy-text\n";
88 int i;
78 int fd = open(name,O_WRONLY); 89 int fd = open(name,O_WRONLY);
79 if (fd<0) { 90 if (fd<0) {
80 DEBUGF("Failed creating file\n"); 91 DEBUGF("Failed creating file\n");
81 return; 92 return;
82 } 93 }
83 if (write(fd, text, strlen(text)) < 0) 94 for (i=0;i<200;i++)
84 DEBUGF("Failed writing data\n"); 95 if (write(fd, text, strlen(text)) < 0)
85 96 DEBUGF("Failed writing data\n");
97
86 close(fd); 98 close(fd);
87} 99}
88 100
@@ -168,6 +180,33 @@ void dbg_tail(char* name)
168 close(fd); 180 close(fd);
169} 181}
170 182
183void dbg_head(char* name)
184{
185 unsigned char buf[SECTOR_SIZE*5];
186 int fd,rc;
187
188 fd = open(name,O_RDONLY);
189 if (fd<0)
190 return;
191 DEBUGF("Got file descriptor %d\n",fd);
192
193 rc = read(fd, buf, SECTOR_SIZE);
194 if( rc > 0 )
195 {
196 buf[rc]=0;
197 printf("%d: %s\n", strlen(buf), buf);
198 }
199 else if ( rc == 0 ) {
200 DEBUGF("EOF\n");
201 }
202 else
203 {
204 DEBUGF("Failed reading file: %d\n",rc);
205 }
206
207 close(fd);
208}
209
171char current_directory[256] = "\\"; 210char current_directory[256] = "\\";
172int last_secnum = 0; 211int last_secnum = 0;
173 212
@@ -284,9 +323,12 @@ int main(int argc, char *argv[])
284 } 323 }
285 324
286 //dbg_console(); 325 //dbg_console();
287 //dbg_tail("/fat.h");
288 //dbg_dir("/"); 326 //dbg_dir("/");
289 dbg_mkfile("/apa.txt"); 327#if 1
328 dbg_head("/bepa.txt");
329#else
330 dbg_mkfile("/bepa.txt");
331#endif
290 dbg_dir("/"); 332 dbg_dir("/");
291 333
292 return 0; 334 return 0;