annotate ffstools/caltools/fc-bin2rftab.c @ 717:178ed445021d

tiffs-mkfs: journal creation implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Aug 2020 03:40:10 +0000
parents 68c7e4edc4da
children a58a38cae51c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility reads a binary RF table or extracts it out of some larger
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * binary file such as an alien fw image (the user must specify the offset
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * in the binary file and the expected RF table type), and emits it in our
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * FreeCalypso ASCII format.
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/file.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <ctype.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern void write_afcparams_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern void write_agcwords_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern void write_agcglobals_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern void write_il2agc_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void write_tx_ramps_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void write_tx_levels_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern void write_tx_calchan_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern void write_tx_caltemp_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern void write_rx_calchan_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern void write_rx_caltemp_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern void write_rx_agcparams_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static struct table_map {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *type;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int size;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 void (*func)();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 } table_map[] = {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"afcparams", 24, write_afcparams_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"agc-table", 40, write_agcwords_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"agc-global-params", 8, write_agcglobals_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"il2agc", 121, write_il2agc_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"tx-ramps", 512, write_tx_ramps_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {"tx-levels", 128, write_tx_levels_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {"tx-calchan", 128, write_tx_calchan_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {"tx-caltemp", 40, write_tx_caltemp_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"rx-calchan", 40, write_rx_calchan_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"rx-caltemp", 44, write_rx_caltemp_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {"rx-agc-params", 8, write_rx_agcparams_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {0, 0, 0}
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 };
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 main(argc, argv)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 char **argv;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 struct table_map *tp;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 u_char buf[512];
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 int ifd, cc;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 u_long offset;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 char *endp;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 FILE *outf;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (argc < 4 || argc > 5) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fprintf(stderr, "usage: %s binfile offset type [outfile]\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 argv[0]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 ifd = open(argv[1], O_RDONLY);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (ifd < 0) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 perror(argv[1]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!isdigit(argv[2][0])) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 inv_offset: fprintf(stderr, "error: specified offset \"%s\" is invalid\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 argv[2]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 offset = strtoul(argv[2], &endp, 0);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (*endp)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 goto inv_offset;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 lseek(ifd, offset, SEEK_SET);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 for (tp = table_map; tp->type; tp++)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!strcmp(tp->type, argv[3]))
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 break;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!tp->type) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fprintf(stderr, "error: RF table type \"%s\" not known\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 argv[3]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 cc = read(ifd, buf, tp->size);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (cc < 0) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 perror("error reading from file");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (cc != tp->size) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fprintf(stderr, "error: short read\n");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 close(ifd);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (argc >= 5) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 outf = fopen(argv[4], "w");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (!outf) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 perror(argv[4]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 tp->func(buf, outf);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 fclose(outf);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 } else
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 tp->func(buf, stdout);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 exit(0);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }