summaryrefslogtreecommitdiff
path: root/firmware/test
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test')
-rw-r--r--firmware/test/fat/Makefile16
-rw-r--r--firmware/test/fat/ata-sim.c7
-rw-r--r--firmware/test/fat/main.c19
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 @@
1FIRMWARE = ../.. 1FIRMWARE = ../..
2DRIVERS = ../../drivers 2DRIVERS = ../../drivers
3 3
4CFLAGS = -g -Wall -DTEST_FAT -I. -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -DDEBUG -DCRT_DISPLAY 4INCLUDE = -I$(DRIVERS) -I$(FIRMWARE) -I$(FIRMWARE)/common
5RINCLUDE = -I$(FIRMWARE)/include
6DEFINES = -DTEST_FAT -DDEBUG -DCRT_DISPLAY -DDISK_WRITE
7
8CFLAGS = -g -Wall $(DEFINES) -I. $(INCLUDE) $(RINCLUDE) -DLITTLE_ENDIAN
9SIMFLAGS = -g -Wall $(DEFINES) -I. $(INCLUDE)
5 10
6TARGET = fat 11TARGET = 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
11fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h 16fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h
17 $(CC) $(CFLAGS) -DSIMULATOR -c $< -o $@
18
19ctype.o: $(FIRMWARE)/common/ctype.c
12 $(CC) $(CFLAGS) -c $< -o $@ 20 $(CC) $(CFLAGS) -c $< -o $@
13 21
14disk.o: $(FIRMWARE)/common/disk.c 22disk.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
23debug.o: $(FIRMWARE)/debug.c 31debug.o: $(FIRMWARE)/debug.c
24 $(CC) $(CFLAGS) -DSIMULATOR -c $< -o $@ 32 $(CC) $(SIMFLAGS) -DSIMULATOR -c $< -o $@
25 33
26ata-sim.o: ata-sim.c $(DRIVERS)/ata.h 34ata-sim.o: ata-sim.c $(DRIVERS)/ata.h
35 $(CC) $(SIMFLAGS) -DSIMULATOR -c $< -o $@
27 36
28main.o: main.c $(DRIVERS)/ata.h 37main.o: main.c $(DRIVERS)/ata.h
38 $(CC) $(SIMFLAGS) -c $< -o $@
29 39
30clean: 40clean:
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
9int ata_read_sectors(unsigned long start, unsigned char count, void* buf) 10int 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
37int ata_init(char* filename) 38int 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
75void 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
74void dbg_type(char* name) 89void 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;