# HG changeset patch # User Michael Spacefalcon # Date 1390694207 0 # Node ID 24ed817dd25da554f70a3941c32a1d4638196546 # Parent 3275c8881cb701966d39b1b90d847f84ef59884b tiffs IVA: reads image via mmap and displays block headers diff -r 3275c8881cb7 -r 24ed817dd25d ffstools/tiffs-rd/Makefile --- a/ffstools/tiffs-rd/Makefile Sat Jan 25 18:16:52 2014 +0000 +++ b/ffstools/tiffs-rd/Makefile Sat Jan 25 23:56:47 2014 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 PROG= tiffs -OBJS= main.o +OBJS= basics.o main.o all: ${PROG} diff -r 3275c8881cb7 -r 24ed817dd25d ffstools/tiffs-rd/basics.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/tiffs-rd/basics.c Sat Jan 25 23:56:47 2014 +0000 @@ -0,0 +1,74 @@ +/* + * This C module implements the "basics" of TIFFS image analysis. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "types.h" + +u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02}; +u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +extern char *imgfile; +extern u32 eraseblk_size; +extern int total_blocks; +extern u32 total_ffs_size; +extern int index_blk_num, root_node_no; +extern int verbose; + +u_char *image; + +read_ffs_image() +{ + int fd; + struct stat st; + + fd = open(imgfile, O_RDONLY); + if (fd < 0) { + perror(imgfile); + exit(1); + } + fstat(fd, &st); + if (!S_ISREG(st.st_mode)) { + fprintf(stderr, "error: %s is not a regular file\n", imgfile); + exit(1); + } + if (st.st_size < total_ffs_size) { + fprintf(stderr, + "error: %s is shorter than FFS size of 0x%lx bytes\n", + imgfile, (u_long)total_ffs_size); + exit(1); + } + image = mmap(NULL, total_ffs_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (image == MAP_FAILED) { + perror("mmap"); + exit(1); + } +} + +cmd_blkhdr() +{ + int blk; + u8 *blkhdr; + + read_ffs_image(); + for (blk = 0; blk < total_blocks; blk++) { + printf("Block %3d: ", blk); + blkhdr = image + blk * eraseblk_size; + if (bcmp(blkhdr, tiffs_header, sizeof tiffs_header)) { + printf("No TIFFS header\n"); + continue; + } + printf("age %02X%02X, type/status %02X\n", + blkhdr[7], blkhdr[6], blkhdr[8]); + } + exit(0); +} diff -r 3275c8881cb7 -r 24ed817dd25d ffstools/tiffs-rd/main.c --- a/ffstools/tiffs-rd/main.c Sat Jan 25 18:16:52 2014 +0000 +++ b/ffstools/tiffs-rd/main.c Sat Jan 25 23:56:47 2014 +0000 @@ -11,16 +11,11 @@ #include #include "types.h" -u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02}; -u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - char *imgfile; u32 eraseblk_size; int total_blocks; u32 total_ffs_size; int index_blk_num = -1, root_node_no; -int offset_blocks; int verbose; parse_org_arg(arg) @@ -35,7 +30,9 @@ exit(1); } *cp++ = '\0'; - if (!strcmp(arg, "16")) + if (!strcmp(arg, "8")) + eraseblk_size = 0x2000; + else if (!strcmp(arg, "16")) eraseblk_size = 0x4000; else if (!strcmp(arg, "32")) eraseblk_size = 0x8000; @@ -61,10 +58,13 @@ total_ffs_size = eraseblk_size * total_blocks; } +extern int cmd_blkhdr(); + static struct cmdtab { char *cmd; int (*func)(); } cmdtab[] = { + {"blkhdr", cmd_blkhdr}, {"cat", NULL}, {"fsck", NULL}, {"ls", NULL}, @@ -81,14 +81,11 @@ char *cmd; struct cmdtab *tp; - while ((c = getopt(argc, argv, "+a:o:r:v")) != EOF) + while ((c = getopt(argc, argv, "+a:r:v")) != EOF) switch (c) { case 'a': index_blk_num = atoi(optarg); continue; - case 'o': - offset_blocks = atoi(optarg); - continue; case 'r': root_node_no = atoi(optarg); continue;