FreeCalypso > hg > freecalypso-sw
changeset 229:24ed817dd25d
tiffs IVA: reads image via mmap and displays block headers
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 25 Jan 2014 23:56:47 +0000 |
parents | 3275c8881cb7 |
children | ffaa033e7643 |
files | ffstools/tiffs-rd/Makefile ffstools/tiffs-rd/basics.c ffstools/tiffs-rd/main.c |
diffstat | 3 files changed, 82 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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}
--- /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 <sys/types.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <strings.h> +#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); +}
--- 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 <strings.h> #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;