FreeCalypso > hg > freecalypso-tools
annotate ffstools/tiffs-wrappers/tiffs-8m.c @ 733:bed7981ac8ca
doc/Compal-FFS: update for IMEI found in OTP cells
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 28 Aug 2020 15:58:46 +0000 |
parents | 8e7f6cca385b |
children |
rev | line source |
---|---|
728
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * tiffs-8m is a wrapper around tiffs similar to mokoffs: we pass the user's |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * command along, together with any options, but insert the 64x15 FFS |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * organization argument automatically, and translate -f into -o0x700000. |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <unistd.h> |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char tiffs_prog_pathname[]; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char *imgfile; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *aopt, *ropt; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int fflag, Oflag; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char **passon_argv; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int passon_argc; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int output_argc; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 char **output_argv; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 main(argc, argv) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char **argv; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 { |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern int optind; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 extern char *optarg; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int c; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 char **sp, **dp; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 while ((c = getopt(argc, argv, "+a:fOr:")) != EOF) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 switch (c) { |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 case 'a': |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 aopt = optarg; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 continue; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 case 'f': |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fflag++; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 continue; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case 'O': |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 Oflag++; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 continue; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 case 'r': |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 ropt = optarg; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 continue; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 default: |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 usage: fprintf(stderr, |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 "usage: %s [global-options] <imgfile> <op> ...\n", |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 argv[0]); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (argc - optind < 2) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 goto usage; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 imgfile = argv[optind++]; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 passon_argv = argv + optind; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 passon_argc = argc - optind; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 output_argc = passon_argc + 3; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (fflag) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 output_argc++; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (Oflag) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 output_argc++; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (aopt) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 output_argc += 2; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (ropt) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 output_argc += 2; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 output_argv = malloc(sizeof(char *) * (output_argc + 1)); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (!output_argv) { |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 perror("malloc for tiffs argument list"); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 exit(1); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 dp = output_argv; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 *dp++ = "tiffs"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (fflag) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *dp++ = "-o0x700000"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (Oflag) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 *dp++ = "-O"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (aopt) { |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 *dp++ = "-a"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 *dp++ = aopt; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (ropt) { |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 *dp++ = "-r"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 *dp++ = ropt; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 *dp++ = imgfile; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 *dp++ = "64x15"; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 for (sp = passon_argv; *sp; sp++) |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 *dp++ = *sp; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 *dp = 0; |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 execvp(tiffs_prog_pathname, output_argv); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 perror(tiffs_prog_pathname); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 exit(1); |
8e7f6cca385b
tiffs-8m wrapper utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |