comparison 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
comparison
equal deleted inserted replaced
228:3275c8881cb7 229:24ed817dd25d
1 /*
2 * This C module implements the "basics" of TIFFS image analysis.
3 */
4
5 #include <sys/types.h>
6 #include <sys/file.h>
7 #include <sys/stat.h>
8 #include <sys/mman.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <strings.h>
14 #include "types.h"
15
16 u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02};
17 u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
18 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
19
20 extern char *imgfile;
21 extern u32 eraseblk_size;
22 extern int total_blocks;
23 extern u32 total_ffs_size;
24 extern int index_blk_num, root_node_no;
25 extern int verbose;
26
27 u_char *image;
28
29 read_ffs_image()
30 {
31 int fd;
32 struct stat st;
33
34 fd = open(imgfile, O_RDONLY);
35 if (fd < 0) {
36 perror(imgfile);
37 exit(1);
38 }
39 fstat(fd, &st);
40 if (!S_ISREG(st.st_mode)) {
41 fprintf(stderr, "error: %s is not a regular file\n", imgfile);
42 exit(1);
43 }
44 if (st.st_size < total_ffs_size) {
45 fprintf(stderr,
46 "error: %s is shorter than FFS size of 0x%lx bytes\n",
47 imgfile, (u_long)total_ffs_size);
48 exit(1);
49 }
50 image = mmap(NULL, total_ffs_size, PROT_READ, MAP_PRIVATE, fd, 0);
51 if (image == MAP_FAILED) {
52 perror("mmap");
53 exit(1);
54 }
55 }
56
57 cmd_blkhdr()
58 {
59 int blk;
60 u8 *blkhdr;
61
62 read_ffs_image();
63 for (blk = 0; blk < total_blocks; blk++) {
64 printf("Block %3d: ", blk);
65 blkhdr = image + blk * eraseblk_size;
66 if (bcmp(blkhdr, tiffs_header, sizeof tiffs_header)) {
67 printf("No TIFFS header\n");
68 continue;
69 }
70 printf("age %02X%02X, type/status %02X\n",
71 blkhdr[7], blkhdr[6], blkhdr[8]);
72 }
73 exit(0);
74 }