FreeCalypso > hg > freecalypso-sw
diff ffstools/tiffs-rd/basics.c @ 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 | |
children | ffaa033e7643 |
line wrap: on
line diff
--- /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); +}