annotate ffstools/caltools/fc-bin2rftab.c @ 996:162d2cf394e2

fc-loadtool help: document new commands for sector lock/unlock
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 23:00:04 +0000
parents a58a38cae51c
children
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
722
a58a38cae51c fc-bin2rftab: added support for adc-cal table type
Mychaela Falconia <falcon@freecalypso.org>
parents: 484
diff changeset
17 extern void write_adccal_table();
484
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern void write_afcparams_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern void write_agcwords_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern void write_agcglobals_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void write_il2agc_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void write_tx_ramps_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern void write_tx_levels_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern void write_tx_calchan_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern void write_tx_caltemp_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern void write_rx_calchan_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern void write_rx_caltemp_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 extern void write_rx_agcparams_table();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static struct table_map {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char *type;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int size;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 void (*func)();
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 } table_map[] = {
722
a58a38cae51c fc-bin2rftab: added support for adc-cal table type
Mychaela Falconia <falcon@freecalypso.org>
parents: 484
diff changeset
35 {"adc-cal", 36, write_adccal_table},
484
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"afcparams", 24, write_afcparams_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"agc-table", 40, write_agcwords_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"agc-global-params", 8, write_agcglobals_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {"il2agc", 121, write_il2agc_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {"tx-ramps", 512, write_tx_ramps_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {"tx-levels", 128, write_tx_levels_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"tx-calchan", 128, write_tx_calchan_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"tx-caltemp", 40, write_tx_caltemp_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {"rx-calchan", 40, write_rx_calchan_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {"rx-caltemp", 44, write_rx_caltemp_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {"rx-agc-params", 8, write_rx_agcparams_table},
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {0, 0, 0}
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 };
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 main(argc, argv)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 char **argv;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 struct table_map *tp;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 u_char buf[512];
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 int ifd, cc;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 u_long offset;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char *endp;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 FILE *outf;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (argc < 4 || argc > 5) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "usage: %s binfile offset type [outfile]\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 argv[0]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 ifd = open(argv[1], O_RDONLY);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (ifd < 0) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 perror(argv[1]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!isdigit(argv[2][0])) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 inv_offset: fprintf(stderr, "error: specified offset \"%s\" is invalid\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 argv[2]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 offset = strtoul(argv[2], &endp, 0);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (*endp)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 goto inv_offset;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 lseek(ifd, offset, SEEK_SET);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 for (tp = table_map; tp->type; tp++)
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!strcmp(tp->type, argv[3]))
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 break;
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (!tp->type) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr, "error: RF table type \"%s\" not known\n",
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 argv[3]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 cc = read(ifd, buf, tp->size);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (cc < 0) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 perror("error reading from file");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (cc != tp->size) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 fprintf(stderr, "error: short read\n");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 close(ifd);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (argc >= 5) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 outf = fopen(argv[4], "w");
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (!outf) {
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 perror(argv[4]);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 exit(1);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 tp->func(buf, outf);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 fclose(outf);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 } else
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 tp->func(buf, stdout);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 exit(0);
68c7e4edc4da fc-bin2rftab utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }