diff options
| author | Björn Stenberg <bjorn@haxx.se> | 2002-04-26 16:44:58 +0000 |
|---|---|---|
| committer | Björn Stenberg <bjorn@haxx.se> | 2002-04-26 16:44:58 +0000 |
| commit | 1dff4b65f725c2174c65698e498b1d58d61e3968 (patch) | |
| tree | 14403dd8415cc0fd6389bb873ae166ded43dd6ee /firmware/test | |
| parent | cfc2bbeef28cfd0159d59ef813ac2a7b956f13a8 (diff) | |
| download | rockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.zip rockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.tar.gz rockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.tar.bz2 rockbox-1dff4b65f725c2174c65698e498b1d58d61e3968.tar.xz | |
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/Makefile | 25 | ||||
| -rw-r--r-- | firmware/test/fat/ata-sim.c | 52 | ||||
| -rw-r--r-- | firmware/test/fat/debug.c | 175 | ||||
| -rw-r--r-- | firmware/test/fat/debug.h | 9 |
4 files changed, 261 insertions, 0 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile new file mode 100644 index 0000000..8b60aba --- /dev/null +++ b/firmware/test/fat/Makefile @@ -0,0 +1,25 @@ +DRIVERS = ../../drivers + +CFLAGS = -g -Wall -DTEST_FAT -I$(DRIVERS) -I. + +TARGET = fat + +$(TARGET): fat.o ata-sim.o debug.o + gcc -g -o fat $+ -lfl + +fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h + $(CC) $(CFLAGS) -c $< -o $@ + +ata-sim.o: ata-sim.c $(DRIVERS)/ata.h + +debug.o: debug.c debug.h $(DRIVERS)/ata.h + +clean: + rm -f *.o $(TARGET) + rm -f *~ + rm -f cmd.tab.h lex.yy.c cmd.tab.c + rm -f core + +tar: + rm -f $(TARGET).tar + 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 0000000..d8c28d9 --- /dev/null +++ b/firmware/test/fat/ata-sim.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "ata.h" + +#define BLOCK_SIZE 512 + +static FILE* file; + +int ata_read_sectors(unsigned long start, unsigned char count, void* buf) +{ + if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { + perror("fseek"); + return -1; + } + if(!fread(buf,BLOCK_SIZE,count,file)) { + printf("Failed reading %d blocks starting at block %ld\n",count,start); + perror("fread"); + return -1; + } + return 0; +} + +int ata_write_sectors(unsigned long start, unsigned char count, void* buf) +{ + if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { + perror("fseek"); + return -1; + } + if(!fwrite(buf,BLOCK_SIZE,count,file)) { + perror("fwrite"); + return -1; + } + return 0; +} + +int ata_init(void) +{ + /* check disk size */ + file=fopen("disk.img","r+"); + if(!file) { + fprintf(stderr, "read_disk() - Could not find \"disk.img\"\n"); + return -1; + } + return 0; +} + +void ata_exit(void) +{ + fclose(file); +} diff --git a/firmware/test/fat/debug.c b/firmware/test/fat/debug.c new file mode 100644 index 0000000..046a67e --- /dev/null +++ b/firmware/test/fat/debug.c @@ -0,0 +1,175 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "fat.h" +#include "ata.h" +#include "debug.h" + +void dbg_dump_sector(int sec) +{ + unsigned char buf[512]; + + ata_read_sectors(sec,1,buf); + printf("---< Sector %d >-----------------------------------------\n", sec); + dbg_dump_buffer(buf); +} + +void dbg_dump_buffer(unsigned char *buf) +{ + int i, j; + unsigned char c; + unsigned char ascii[33]; + + for(i = 0;i < 512/32;i++) + { + for(j = 0;j < 32;j++) + { + c = buf[i*32+j]; + + printf("%02x ", c); + if(c < 32 || c > 127) + { + ascii[j] = '.'; + } + else + { + ascii[j] = c; + } + } + + ascii[j] = 0; + printf("%s\n", ascii); + } +} + +void dbg_print_bpb(struct bpb *bpb) +{ + printf("bpb_oemname = \"%s\"\n", bpb->bs_oemname); + printf("bpb_bytspersec = %d\n", bpb->bpb_bytspersec); + printf("bpb_secperclus = %d\n", bpb->bpb_secperclus); + printf("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt); + printf("bpb_numfats = %d\n", bpb->bpb_numfats); + printf("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt); + printf("bpb_totsec16 = %d\n", bpb->bpb_totsec16); + printf("bpb_media = %02x\n", bpb->bpb_media); + printf("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16); + printf("bpb_secpertrk = %d\n", bpb->bpb_secpertrk); + printf("bpb_numheads = %d\n", bpb->bpb_numheads); + printf("bpb_hiddsec = %u\n", bpb->bpb_hiddsec); + printf("bpb_totsec32 = %u\n", bpb->bpb_totsec32); + + printf("bs_drvnum = %d\n", bpb->bs_drvnum); + printf("bs_bootsig = %02x\n", bpb->bs_bootsig); + if(bpb->bs_bootsig == 0x29) + { + printf("bs_volid = %xl\n", bpb->bs_volid); + printf("bs_vollab = \"%s\"\n", bpb->bs_vollab); + printf("bs_filsystype = \"%s\"\n", bpb->bs_filsystype); + } + + printf("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32); + printf("last_word = %04x\n", bpb->last_word); + + switch(bpb->fat_type) + { + case FATTYPE_FAT12: + printf("fat_type = FAT12\n"); + break; + case FATTYPE_FAT16: + printf("fat_type = FAT16\n"); + break; + case FATTYPE_FAT32: + printf("fat_type = FAT32\n"); + break; + default: + printf("fat_type = UNKNOWN (%d)\n", bpb->fat_type); + break; + } +} + +void dbg_dir(struct bpb *bpb, int currdir) +{ + struct fat_dirent dent; + struct fat_direntry de; + + if(fat_opendir(bpb, &dent, currdir) >= 0) + { + while(fat_getnext(bpb, &dent, &de) >= 0) + { + printf("%s\n", de.name); + } + } + else + { + fprintf(stderr, "Could not read dir on cluster %d\n", currdir); + } +} + +extern char current_directory[]; +int last_secnum = 0; + +void dbg_prompt(void) +{ + printf("C:%s> ", current_directory); +} + +void dbg_console(struct bpb* bpb) +{ + char cmd[32] = ""; + char last_cmd[32] = ""; + int quit = 0; + char *s; + int secnum; + + while(!quit) + { + dbg_prompt(); + if(fgets(cmd, sizeof(cmd) - 1, stdin)) + { + if(strlen(cmd) == 1) /* empty command? */ + { + strcpy(cmd, last_cmd); + } + + /* Get the first token */ + s = strtok(cmd, " \n"); + if(s) + { + if(!strcasecmp(s, "dir")) + { + secnum = 0; + if((s = strtok(NULL, " \n"))) + { + secnum = atoi(s); + } + dbg_dir(bpb, secnum); + continue; + } + + if(!strcasecmp(s, "ds")) + { + /* Remember the command */ + strcpy(last_cmd, s); + + if((s = strtok(NULL, " \n"))) + { + last_secnum = atoi(s); + } + else + { + last_secnum++; + } + printf("secnum: %d\n", last_secnum); + dbg_dump_sector(last_secnum); + continue; + } + + if(!strcasecmp(s, "exit") || + !strcasecmp(s, "x")) + { + quit = 1; + } + } + } + } +} diff --git a/firmware/test/fat/debug.h b/firmware/test/fat/debug.h new file mode 100644 index 0000000..ff786ab --- /dev/null +++ b/firmware/test/fat/debug.h @@ -0,0 +1,9 @@ +#ifndef DEBUG_H +#define DEBUG_H + +void dbg_dump_sector(int sec); +void dbg_dump_buffer(unsigned char *buf); +void dbg_print_bpb(struct bpb *bpb); +void dbg_console(struct bpb *bpb); + +#endif |