comparison ffstools/tiffs-rd/main.c @ 225:c04aa85559ed

TIFFS in vitro reader started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 13 Jan 2014 09:05:01 +0000
parents
children 24ed817dd25d
comparison
equal deleted inserted replaced
224:2900fe603f8a 225:c04aa85559ed
1 /*
2 * This C module contains the main() function for the tiffs utility,
3 * dispatching control to different operation commands.
4 */
5
6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include "types.h"
13
14 u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02};
15 u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
17
18 char *imgfile;
19 u32 eraseblk_size;
20 int total_blocks;
21 u32 total_ffs_size;
22 int index_blk_num = -1, root_node_no;
23 int offset_blocks;
24 int verbose;
25
26 parse_org_arg(arg)
27 char *arg;
28 {
29 char *cp;
30
31 cp = index(arg, 'x');
32 if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) {
33 fprintf(stderr,
34 "error: TIFFS organization argument \"%s\" is invalid\n", arg);
35 exit(1);
36 }
37 *cp++ = '\0';
38 if (!strcmp(arg, "16"))
39 eraseblk_size = 0x4000;
40 else if (!strcmp(arg, "32"))
41 eraseblk_size = 0x8000;
42 else if (!strcmp(arg, "64"))
43 eraseblk_size = 0x10000;
44 else if (!strcmp(arg, "128"))
45 eraseblk_size = 0x20000;
46 else if (!strcmp(arg, "256"))
47 eraseblk_size = 0x40000;
48 else {
49 fprintf(stderr,
50 "error: \"%s\" is not a recognized flash sector size\n",
51 arg);
52 exit(1);
53 }
54 total_blocks = atoi(cp);
55 if (total_blocks < 1 || total_blocks > 128) {
56 fprintf(stderr,
57 "error: \"%s\" is not a reasonable number of FFS sectors\n",
58 cp);
59 exit(1);
60 }
61 total_ffs_size = eraseblk_size * total_blocks;
62 }
63
64 static struct cmdtab {
65 char *cmd;
66 int (*func)();
67 } cmdtab[] = {
68 {"cat", NULL},
69 {"fsck", NULL},
70 {"ls", NULL},
71 {"xtr", NULL},
72 {NULL, NULL}
73 };
74
75 main(argc, argv)
76 char **argv;
77 {
78 extern int optind;
79 extern char *optarg;
80 int c;
81 char *cmd;
82 struct cmdtab *tp;
83
84 while ((c = getopt(argc, argv, "+a:o:r:v")) != EOF)
85 switch (c) {
86 case 'a':
87 index_blk_num = atoi(optarg);
88 continue;
89 case 'o':
90 offset_blocks = atoi(optarg);
91 continue;
92 case 'r':
93 root_node_no = atoi(optarg);
94 continue;
95 case 'v':
96 verbose++;
97 continue;
98 default:
99 usage: fprintf(stderr,
100 "usage: %s [global-options] <imgfile> <org> <op> ...\n",
101 argv[0]);
102 exit(1);
103 }
104 if (argc - optind < 3)
105 goto usage;
106 imgfile = argv[optind];
107 parse_org_arg(argv[optind+1]);
108 cmd = argv[optind+2];
109
110 for (tp = cmdtab; tp->cmd; tp++)
111 if (!strcmp(tp->cmd, cmd))
112 break;
113 if (!tp->func) {
114 fprintf(stderr,
115 "%s: operation \"%s\" is unknown or unimplemented\n",
116 argv[0], cmd);
117 exit(1);
118 }
119 optind += 2;
120 return tp->func(argc - optind, argv + optind);
121 }