diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-10-15 14:36:52 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-10-15 14:36:52 +0000 |
commit | eebd237d465352508192a2c8419c224f8c7bc7a9 (patch) | |
tree | 6795d0fc550be76eba416f5bf00dcfdc7e83f5c6 /firmware/test/fat | |
parent | 016bea8e451664934edb14b79ee586a650724d8d (diff) | |
download | rockbox-eebd237d465352508192a2c8419c224f8c7bc7a9.tar.gz rockbox-eebd237d465352508192a2c8419c224f8c7bc7a9.zip |
Fat32 test code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2669 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/fat')
-rw-r--r-- | firmware/test/fat/Makefile | 16 | ||||
-rw-r--r-- | firmware/test/fat/ata-sim.c | 7 | ||||
-rw-r--r-- | firmware/test/fat/main.c | 19 |
3 files changed, 36 insertions, 6 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile index b47a724f01..fa9ac33fb7 100644 --- a/firmware/test/fat/Makefile +++ b/firmware/test/fat/Makefile | |||
@@ -1,14 +1,22 @@ | |||
1 | FIRMWARE = ../.. | 1 | FIRMWARE = ../.. |
2 | DRIVERS = ../../drivers | 2 | DRIVERS = ../../drivers |
3 | 3 | ||
4 | CFLAGS = -g -Wall -DTEST_FAT -I. -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -DDEBUG -DCRT_DISPLAY | 4 | INCLUDE = -I$(DRIVERS) -I$(FIRMWARE) -I$(FIRMWARE)/common |
5 | RINCLUDE = -I$(FIRMWARE)/include | ||
6 | DEFINES = -DTEST_FAT -DDEBUG -DCRT_DISPLAY -DDISK_WRITE | ||
7 | |||
8 | CFLAGS = -g -Wall $(DEFINES) -I. $(INCLUDE) $(RINCLUDE) -DLITTLE_ENDIAN | ||
9 | SIMFLAGS = -g -Wall $(DEFINES) -I. $(INCLUDE) | ||
5 | 10 | ||
6 | TARGET = fat | 11 | TARGET = fat |
7 | 12 | ||
8 | $(TARGET): fat.o ata-sim.o main.o disk.o debug.o dir.o file.o | 13 | $(TARGET): fat.o ata-sim.o main.o disk.o debug.o dir.o file.o ctype.o |
9 | gcc -g -o fat $+ -lfl | 14 | gcc -g -o fat $+ -lfl |
10 | 15 | ||
11 | fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h | 16 | fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h |
17 | $(CC) $(CFLAGS) -DSIMULATOR -c $< -o $@ | ||
18 | |||
19 | ctype.o: $(FIRMWARE)/common/ctype.c | ||
12 | $(CC) $(CFLAGS) -c $< -o $@ | 20 | $(CC) $(CFLAGS) -c $< -o $@ |
13 | 21 | ||
14 | disk.o: $(FIRMWARE)/common/disk.c | 22 | disk.o: $(FIRMWARE)/common/disk.c |
@@ -21,11 +29,13 @@ file.o: $(FIRMWARE)/common/file.c | |||
21 | $(CC) $(CFLAGS) -c $< -o $@ | 29 | $(CC) $(CFLAGS) -c $< -o $@ |
22 | 30 | ||
23 | debug.o: $(FIRMWARE)/debug.c | 31 | debug.o: $(FIRMWARE)/debug.c |
24 | $(CC) $(CFLAGS) -DSIMULATOR -c $< -o $@ | 32 | $(CC) $(SIMFLAGS) -DSIMULATOR -c $< -o $@ |
25 | 33 | ||
26 | ata-sim.o: ata-sim.c $(DRIVERS)/ata.h | 34 | ata-sim.o: ata-sim.c $(DRIVERS)/ata.h |
35 | $(CC) $(SIMFLAGS) -DSIMULATOR -c $< -o $@ | ||
27 | 36 | ||
28 | main.o: main.c $(DRIVERS)/ata.h | 37 | main.o: main.c $(DRIVERS)/ata.h |
38 | $(CC) $(SIMFLAGS) -c $< -o $@ | ||
29 | 39 | ||
30 | clean: | 40 | clean: |
31 | rm -f *.o $(TARGET) | 41 | rm -f *.o $(TARGET) |
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c index 97abb33f56..ab7266d6a0 100644 --- a/firmware/test/fat/ata-sim.c +++ b/firmware/test/fat/ata-sim.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 "debug.h" | ||
4 | 5 | ||
5 | #define BLOCK_SIZE 512 | 6 | #define BLOCK_SIZE 512 |
6 | 7 | ||
@@ -8,7 +9,7 @@ static FILE* file; | |||
8 | 9 | ||
9 | int ata_read_sectors(unsigned long start, unsigned char count, void* buf) | 10 | int ata_read_sectors(unsigned long start, unsigned char count, void* buf) |
10 | { | 11 | { |
11 | printf("Reading block 0x%lx\n",start); | 12 | DEBUGF("Reading block 0x%lx\n",start); |
12 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { | 13 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { |
13 | perror("fseek"); | 14 | perror("fseek"); |
14 | return -1; | 15 | return -1; |
@@ -36,10 +37,12 @@ int ata_write_sectors(unsigned long start, unsigned char count, void* buf) | |||
36 | 37 | ||
37 | int ata_init(char* filename) | 38 | int ata_init(char* filename) |
38 | { | 39 | { |
40 | if (!filename) | ||
41 | filename = "disk.img"; | ||
39 | /* check disk size */ | 42 | /* check disk size */ |
40 | file=fopen(filename,"r+"); | 43 | file=fopen(filename,"r+"); |
41 | if(!file) { | 44 | if(!file) { |
42 | fprintf(stderr, "read_disk() - Could not find \"disk.img\"\n"); | 45 | fprintf(stderr, "read_disk() - Could not find \"%s\"\n",filename); |
43 | return -1; | 46 | return -1; |
44 | } | 47 | } |
45 | return 0; | 48 | return 0; |
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index fcd2dcc5eb..4a11e0a08a 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c | |||
@@ -61,7 +61,8 @@ void dbg_dir(char* currdir) | |||
61 | if (dir) | 61 | if (dir) |
62 | { | 62 | { |
63 | while ( (entry = readdir(dir)) ) { | 63 | while ( (entry = readdir(dir)) ) { |
64 | DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size); | 64 | DEBUGF("%15s (%d bytes) %x\n", |
65 | entry->d_name, entry->size, entry->startcluster); | ||
65 | } | 66 | } |
66 | closedir(dir); | 67 | closedir(dir); |
67 | } | 68 | } |
@@ -71,6 +72,20 @@ void dbg_dir(char* currdir) | |||
71 | } | 72 | } |
72 | } | 73 | } |
73 | 74 | ||
75 | void dbg_mkfile(char* name) | ||
76 | { | ||
77 | char* text = "Detta är en dummy-text\n"; | ||
78 | int fd = open(name,O_WRONLY); | ||
79 | if (fd<0) { | ||
80 | DEBUGF("Failed creating file\n"); | ||
81 | return; | ||
82 | } | ||
83 | if (write(fd, text, strlen(text)) < 0) | ||
84 | DEBUGF("Failed writing data\n"); | ||
85 | |||
86 | close(fd); | ||
87 | } | ||
88 | |||
74 | void dbg_type(char* name) | 89 | void dbg_type(char* name) |
75 | { | 90 | { |
76 | unsigned char buf[SECTOR_SIZE*5]; | 91 | unsigned char buf[SECTOR_SIZE*5]; |
@@ -270,6 +285,8 @@ int main(int argc, char *argv[]) | |||
270 | 285 | ||
271 | //dbg_console(); | 286 | //dbg_console(); |
272 | //dbg_tail("/fat.h"); | 287 | //dbg_tail("/fat.h"); |
288 | //dbg_dir("/"); | ||
289 | dbg_mkfile("/apa.txt"); | ||
273 | dbg_dir("/"); | 290 | dbg_dir("/"); |
274 | 291 | ||
275 | return 0; | 292 | return 0; |