summaryrefslogtreecommitdiff
path: root/firmware/test
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-04-26 16:44:58 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-04-26 16:44:58 +0000
commit1dff4b65f725c2174c65698e498b1d58d61e3968 (patch)
tree14403dd8415cc0fd6389bb873ae166ded43dd6ee /firmware/test
parentcfc2bbeef28cfd0159d59ef813ac2a7b956f13a8 (diff)
downloadrockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.tar.gz
rockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.zip
FAT update
Added fat test code git-svn-id: svn://svn.rockbox.org/rockbox/trunk@254 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test')
-rw-r--r--firmware/test/fat/Makefile25
-rw-r--r--firmware/test/fat/ata-sim.c52
-rw-r--r--firmware/test/fat/debug.c175
-rw-r--r--firmware/test/fat/debug.h9
4 files changed, 261 insertions, 0 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile
new file mode 100644
index 0000000000..8b60aba99c
--- /dev/null
+++ b/firmware/test/fat/Makefile
@@ -0,0 +1,25 @@
1DRIVERS = ../../drivers
2
3CFLAGS = -g -Wall -DTEST_FAT -I$(DRIVERS) -I.
4
5TARGET = fat
6
7$(TARGET): fat.o ata-sim.o debug.o
8 gcc -g -o fat $+ -lfl
9
10fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h
11 $(CC) $(CFLAGS) -c $< -o $@
12
13ata-sim.o: ata-sim.c $(DRIVERS)/ata.h
14
15debug.o: debug.c debug.h $(DRIVERS)/ata.h
16
17clean:
18 rm -f *.o $(TARGET)
19 rm -f *~
20 rm -f cmd.tab.h lex.yy.c cmd.tab.c
21 rm -f core
22
23tar:
24 rm -f $(TARGET).tar
25 tar cvf $(TARGET).tar -C .. fat
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c
new file mode 100644
index 0000000000..d8c28d9467
--- /dev/null
+++ b/firmware/test/fat/ata-sim.c
@@ -0,0 +1,52 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "ata.h"
6
7#define BLOCK_SIZE 512
8
9static FILE* file;
10
11int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
12{
13 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
14 perror("fseek");
15 return -1;
16 }
17 if(!fread(buf,BLOCK_SIZE,count,file)) {
18 printf("Failed reading %d blocks starting at block %ld\n",count,start);
19 perror("fread");
20 return -1;
21 }
22 return 0;
23}
24
25int ata_write_sectors(unsigned long start, unsigned char count, void* buf)
26{
27 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
28 perror("fseek");
29 return -1;
30 }
31 if(!fwrite(buf,BLOCK_SIZE,count,file)) {
32 perror("fwrite");
33 return -1;
34 }
35 return 0;
36}
37
38int ata_init(void)
39{
40 /* check disk size */
41 file=fopen("disk.img","r+");
42 if(!file) {
43 fprintf(stderr, "read_disk() - Could not find \"disk.img\"\n");
44 return -1;
45 }
46 return 0;
47}
48
49void ata_exit(void)
50{
51 fclose(file);
52}
diff --git a/firmware/test/fat/debug.c b/firmware/test/fat/debug.c
new file mode 100644
index 0000000000..046a67e06c
--- /dev/null
+++ b/firmware/test/fat/debug.c
@@ -0,0 +1,175 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "fat.h"
5#include "ata.h"
6#include "debug.h"
7
8void dbg_dump_sector(int sec)
9{
10 unsigned char buf[512];
11
12 ata_read_sectors(sec,1,buf);
13 printf("---< Sector %d >-----------------------------------------\n", sec);
14 dbg_dump_buffer(buf);
15}
16
17void dbg_dump_buffer(unsigned char *buf)
18{
19 int i, j;
20 unsigned char c;
21 unsigned char ascii[33];
22
23 for(i = 0;i < 512/32;i++)
24 {
25 for(j = 0;j < 32;j++)
26 {
27 c = buf[i*32+j];
28
29 printf("%02x ", c);
30 if(c < 32 || c > 127)
31 {
32 ascii[j] = '.';
33 }
34 else
35 {
36 ascii[j] = c;
37 }
38 }
39
40 ascii[j] = 0;
41 printf("%s\n", ascii);
42 }
43}
44
45void dbg_print_bpb(struct bpb *bpb)
46{
47 printf("bpb_oemname = \"%s\"\n", bpb->bs_oemname);
48 printf("bpb_bytspersec = %d\n", bpb->bpb_bytspersec);
49 printf("bpb_secperclus = %d\n", bpb->bpb_secperclus);
50 printf("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt);
51 printf("bpb_numfats = %d\n", bpb->bpb_numfats);
52 printf("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt);
53 printf("bpb_totsec16 = %d\n", bpb->bpb_totsec16);
54 printf("bpb_media = %02x\n", bpb->bpb_media);
55 printf("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16);
56 printf("bpb_secpertrk = %d\n", bpb->bpb_secpertrk);
57 printf("bpb_numheads = %d\n", bpb->bpb_numheads);
58 printf("bpb_hiddsec = %u\n", bpb->bpb_hiddsec);
59 printf("bpb_totsec32 = %u\n", bpb->bpb_totsec32);
60
61 printf("bs_drvnum = %d\n", bpb->bs_drvnum);
62 printf("bs_bootsig = %02x\n", bpb->bs_bootsig);
63 if(bpb->bs_bootsig == 0x29)
64 {
65 printf("bs_volid = %xl\n", bpb->bs_volid);
66 printf("bs_vollab = \"%s\"\n", bpb->bs_vollab);
67 printf("bs_filsystype = \"%s\"\n", bpb->bs_filsystype);
68 }
69
70 printf("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32);
71 printf("last_word = %04x\n", bpb->last_word);
72
73 switch(bpb->fat_type)
74 {
75 case FATTYPE_FAT12:
76 printf("fat_type = FAT12\n");
77 break;
78 case FATTYPE_FAT16:
79 printf("fat_type = FAT16\n");
80 break;
81 case FATTYPE_FAT32:
82 printf("fat_type = FAT32\n");
83 break;
84 default:
85 printf("fat_type = UNKNOWN (%d)\n", bpb->fat_type);
86 break;
87 }
88}
89
90void dbg_dir(struct bpb *bpb, int currdir)
91{
92 struct fat_dirent dent;
93 struct fat_direntry de;
94
95 if(fat_opendir(bpb, &dent, currdir) >= 0)
96 {
97 while(fat_getnext(bpb, &dent, &de) >= 0)
98 {
99 printf("%s\n", de.name);
100 }
101 }
102 else
103 {
104 fprintf(stderr, "Could not read dir on cluster %d\n", currdir);
105 }
106}
107
108extern char current_directory[];
109int last_secnum = 0;
110
111void dbg_prompt(void)
112{
113 printf("C:%s> ", current_directory);
114}
115
116void dbg_console(struct bpb* bpb)
117{
118 char cmd[32] = "";
119 char last_cmd[32] = "";
120 int quit = 0;
121 char *s;
122 int secnum;
123
124 while(!quit)
125 {
126 dbg_prompt();
127 if(fgets(cmd, sizeof(cmd) - 1, stdin))
128 {
129 if(strlen(cmd) == 1) /* empty command? */
130 {
131 strcpy(cmd, last_cmd);
132 }
133
134 /* Get the first token */
135 s = strtok(cmd, " \n");
136 if(s)
137 {
138 if(!strcasecmp(s, "dir"))
139 {
140 secnum = 0;
141 if((s = strtok(NULL, " \n")))
142 {
143 secnum = atoi(s);
144 }
145 dbg_dir(bpb, secnum);
146 continue;
147 }
148
149 if(!strcasecmp(s, "ds"))
150 {
151 /* Remember the command */
152 strcpy(last_cmd, s);
153
154 if((s = strtok(NULL, " \n")))
155 {
156 last_secnum = atoi(s);
157 }
158 else
159 {
160 last_secnum++;
161 }
162 printf("secnum: %d\n", last_secnum);
163 dbg_dump_sector(last_secnum);
164 continue;
165 }
166
167 if(!strcasecmp(s, "exit") ||
168 !strcasecmp(s, "x"))
169 {
170 quit = 1;
171 }
172 }
173 }
174 }
175}
diff --git a/firmware/test/fat/debug.h b/firmware/test/fat/debug.h
new file mode 100644
index 0000000000..ff786ab2b1
--- /dev/null
+++ b/firmware/test/fat/debug.h
@@ -0,0 +1,9 @@
1#ifndef DEBUG_H
2#define DEBUG_H
3
4void dbg_dump_sector(int sec);
5void dbg_dump_buffer(unsigned char *buf);
6void dbg_print_bpb(struct bpb *bpb);
7void dbg_console(struct bpb *bpb);
8
9#endif