summaryrefslogtreecommitdiff
path: root/firmware/test/fat
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/fat')
-rw-r--r--firmware/test/fat/Makefile2
-rw-r--r--firmware/test/fat/ata-sim.c9
-rw-r--r--firmware/test/fat/main.c73
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 @@
1FIRMWARE = ../.. 1FIRMWARE = ../..
2DRIVERS = ../../drivers 2DRIVERS = ../../drivers
3 3
4CFLAGS = -g -Wall -DTEST_FAT -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -I. -DDEBUG -DCRT_DISPLAY 4CFLAGS = -g -Wall -DTEST_FAT -I. -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -DDEBUG -DCRT_DISPLAY
5 5
6TARGET = fat 6TARGET = 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
9static FILE* file; 7static FILE* file;
10 8
11int ata_read_sectors(unsigned long start, unsigned char count, void* buf) 9int 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
38int ata_init(void) 37int 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
10extern int ata_init(char*);
11extern void ata_read_sectors(int, int, char*);
12
11void dbg_dump_sector(int sec); 13void dbg_dump_sector(int sec);
12void dbg_dump_buffer(unsigned char *buf); 14void dbg_dump_buffer(unsigned char *buf);
13void dbg_print_bpb(struct bpb *bpb);
14void dbg_console(void); 15void dbg_console(void);
15 16
16void dbg_dump_sector(int sec) 17void 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
53void 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
84void dbg_dir(char* currdir) 55void 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
103void dbg_type(char* name) 74void dbg_type(char* name)
@@ -261,21 +232,45 @@ void dbg_console(void)
261 232
262int main(int argc, char *argv[]) 233int 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}