diff options
-rw-r--r-- | firmware/test/fat/Makefile | 2 | ||||
-rw-r--r-- | firmware/test/fat/ata-sim.c | 9 | ||||
-rw-r--r-- | firmware/test/fat/main.c | 73 |
3 files changed, 39 insertions, 45 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile index 1d69467892..b47a724f01 100644 --- a/firmware/test/fat/Makefile +++ b/firmware/test/fat/Makefile | |||
@@ -1,7 +1,7 @@ | |||
1 | FIRMWARE = ../.. | 1 | FIRMWARE = ../.. |
2 | DRIVERS = ../../drivers | 2 | DRIVERS = ../../drivers |
3 | 3 | ||
4 | CFLAGS = -g -Wall -DTEST_FAT -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -I. -DDEBUG -DCRT_DISPLAY | 4 | CFLAGS = -g -Wall -DTEST_FAT -I. -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -DDEBUG -DCRT_DISPLAY |
5 | 5 | ||
6 | TARGET = fat | 6 | TARGET = fat |
7 | 7 | ||
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c index d8c28d9467..97abb33f56 100644 --- a/firmware/test/fat/ata-sim.c +++ b/firmware/test/fat/ata-sim.c | |||
@@ -2,20 +2,19 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | 4 | ||
5 | #include "ata.h" | ||
6 | |||
7 | #define BLOCK_SIZE 512 | 5 | #define BLOCK_SIZE 512 |
8 | 6 | ||
9 | static FILE* file; | 7 | static FILE* file; |
10 | 8 | ||
11 | int ata_read_sectors(unsigned long start, unsigned char count, void* buf) | 9 | int ata_read_sectors(unsigned long start, unsigned char count, void* buf) |
12 | { | 10 | { |
11 | printf("Reading block 0x%lx\n",start); | ||
13 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { | 12 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { |
14 | perror("fseek"); | 13 | perror("fseek"); |
15 | return -1; | 14 | return -1; |
16 | } | 15 | } |
17 | if(!fread(buf,BLOCK_SIZE,count,file)) { | 16 | if(!fread(buf,BLOCK_SIZE,count,file)) { |
18 | printf("Failed reading %d blocks starting at block %ld\n",count,start); | 17 | printf("Failed reading %d blocks starting at block 0x%lx\n",count,start); |
19 | perror("fread"); | 18 | perror("fread"); |
20 | return -1; | 19 | return -1; |
21 | } | 20 | } |
@@ -35,10 +34,10 @@ int ata_write_sectors(unsigned long start, unsigned char count, void* buf) | |||
35 | return 0; | 34 | return 0; |
36 | } | 35 | } |
37 | 36 | ||
38 | int ata_init(void) | 37 | int ata_init(char* filename) |
39 | { | 38 | { |
40 | /* check disk size */ | 39 | /* check disk size */ |
41 | file=fopen("disk.img","r+"); | 40 | file=fopen(filename,"r+"); |
42 | if(!file) { | 41 | if(!file) { |
43 | fprintf(stderr, "read_disk() - Could not find \"disk.img\"\n"); | 42 | fprintf(stderr, "read_disk() - Could not find \"disk.img\"\n"); |
44 | return -1; | 43 | return -1; |
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index 6d05dbe600..fcd2dcc5eb 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c | |||
@@ -2,15 +2,16 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include "fat.h" | 4 | #include "fat.h" |
5 | #include "ata.h" | ||
6 | #include "debug.h" | 5 | #include "debug.h" |
7 | #include "disk.h" | 6 | #include "disk.h" |
8 | #include "dir.h" | 7 | #include "dir.h" |
9 | #include "file.h" | 8 | #include "file.h" |
10 | 9 | ||
10 | extern int ata_init(char*); | ||
11 | extern void ata_read_sectors(int, int, char*); | ||
12 | |||
11 | void dbg_dump_sector(int sec); | 13 | void dbg_dump_sector(int sec); |
12 | void dbg_dump_buffer(unsigned char *buf); | 14 | void dbg_dump_buffer(unsigned char *buf); |
13 | void dbg_print_bpb(struct bpb *bpb); | ||
14 | void dbg_console(void); | 15 | void dbg_console(void); |
15 | 16 | ||
16 | void dbg_dump_sector(int sec) | 17 | void dbg_dump_sector(int sec) |
@@ -30,6 +31,7 @@ void dbg_dump_buffer(unsigned char *buf) | |||
30 | 31 | ||
31 | for(i = 0;i < 512/16;i++) | 32 | for(i = 0;i < 512/16;i++) |
32 | { | 33 | { |
34 | DEBUGF("%03x: ", i*16); | ||
33 | for(j = 0;j < 16;j++) | 35 | for(j = 0;j < 16;j++) |
34 | { | 36 | { |
35 | c = buf[i*16+j]; | 37 | c = buf[i*16+j]; |
@@ -50,37 +52,6 @@ void dbg_dump_buffer(unsigned char *buf) | |||
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
53 | void dbg_print_bpb(struct bpb *bpb) | ||
54 | { | ||
55 | DEBUGF("bpb_oemname = \"%s\"\n", bpb->bs_oemname); | ||
56 | DEBUGF("bpb_bytspersec = %d\n", bpb->bpb_bytspersec); | ||
57 | DEBUGF("bpb_secperclus = %d\n", bpb->bpb_secperclus); | ||
58 | DEBUGF("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt); | ||
59 | DEBUGF("bpb_numfats = %d\n", bpb->bpb_numfats); | ||
60 | DEBUGF("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt); | ||
61 | DEBUGF("bpb_totsec16 = %d\n", bpb->bpb_totsec16); | ||
62 | DEBUGF("bpb_media = %02x\n", bpb->bpb_media); | ||
63 | DEBUGF("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16); | ||
64 | DEBUGF("bpb_secpertrk = %d\n", bpb->bpb_secpertrk); | ||
65 | DEBUGF("bpb_numheads = %d\n", bpb->bpb_numheads); | ||
66 | DEBUGF("bpb_hiddsec = %u\n", bpb->bpb_hiddsec); | ||
67 | DEBUGF("bpb_totsec32 = %u\n", bpb->bpb_totsec32); | ||
68 | |||
69 | DEBUGF("bs_drvnum = %d\n", bpb->bs_drvnum); | ||
70 | DEBUGF("bs_bootsig = %02x\n", bpb->bs_bootsig); | ||
71 | if(bpb->bs_bootsig == 0x29) | ||
72 | { | ||
73 | DEBUGF("bs_volid = %xl\n", bpb->bs_volid); | ||
74 | DEBUGF("bs_vollab = \"%s\"\n", bpb->bs_vollab); | ||
75 | DEBUGF("bs_filsystype = \"%s\"\n", bpb->bs_filsystype); | ||
76 | } | ||
77 | |||
78 | DEBUGF("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32); | ||
79 | DEBUGF("last_word = %04x\n", bpb->last_word); | ||
80 | |||
81 | DEBUGF("fat_type = FAT32\n"); | ||
82 | } | ||
83 | |||
84 | void dbg_dir(char* currdir) | 55 | void dbg_dir(char* currdir) |
85 | { | 56 | { |
86 | DIR* dir; | 57 | DIR* dir; |
@@ -92,12 +63,12 @@ void dbg_dir(char* currdir) | |||
92 | while ( (entry = readdir(dir)) ) { | 63 | while ( (entry = readdir(dir)) ) { |
93 | DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size); | 64 | DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size); |
94 | } | 65 | } |
66 | closedir(dir); | ||
95 | } | 67 | } |
96 | else | 68 | else |
97 | { | 69 | { |
98 | DEBUGF( "Could not open dir %s\n", currdir); | 70 | DEBUGF( "Could not open dir %s\n", currdir); |
99 | } | 71 | } |
100 | closedir(dir); | ||
101 | } | 72 | } |
102 | 73 | ||
103 | void dbg_type(char* name) | 74 | void dbg_type(char* name) |
@@ -261,21 +232,45 @@ void dbg_console(void) | |||
261 | 232 | ||
262 | int main(int argc, char *argv[]) | 233 | int main(int argc, char *argv[]) |
263 | { | 234 | { |
264 | if(ata_init()) { | 235 | int rc,i; |
236 | struct partinfo* pinfo; | ||
237 | |||
238 | if(ata_init(argv[1])) { | ||
265 | DEBUGF("*** Warning! The disk is uninitialized\n"); | 239 | DEBUGF("*** Warning! The disk is uninitialized\n"); |
266 | return -1; | 240 | return -1; |
267 | } | 241 | } |
268 | if (disk_init()) { | 242 | pinfo = disk_init(); |
243 | if (!pinfo) { | ||
269 | DEBUGF("*** Failed reading partitions\n"); | 244 | DEBUGF("*** Failed reading partitions\n"); |
270 | return -1; | 245 | return -1; |
271 | } | 246 | } |
272 | 247 | ||
273 | if(fat_mount(part[0].start)) { | 248 | if ( argc > 2 ) { |
274 | DEBUGF("*** Failed mounting fat\n"); | 249 | dbg_dump_sector(atoi(argv[2])); |
250 | return 0; | ||
251 | } | ||
252 | |||
253 | for ( i=0; i<4; i++ ) { | ||
254 | if ( pinfo[i].type == PARTITION_TYPE_FAT32 ) { | ||
255 | DEBUGF("*** Mounting at block %ld\n",pinfo[i].start); | ||
256 | rc = fat_mount(pinfo[i].start); | ||
257 | if(rc) { | ||
258 | DEBUGF("mount: %d",rc); | ||
259 | return 0; | ||
260 | } | ||
261 | break; | ||
262 | } | ||
263 | } | ||
264 | if ( i==4 ) { | ||
265 | if(fat_mount(0)) { | ||
266 | DEBUGF("No FAT32 partition!"); | ||
267 | return 0; | ||
268 | } | ||
275 | } | 269 | } |
276 | 270 | ||
277 | //dbg_console(); | 271 | //dbg_console(); |
278 | dbg_tail("/fat.h"); | 272 | //dbg_tail("/fat.h"); |
273 | dbg_dir("/"); | ||
279 | 274 | ||
280 | return 0; | 275 | return 0; |
281 | } | 276 | } |