FreeCalypso > hg > freecalypso-reveng
comparison miscprog/calextract.c @ 180:25b54c5ad6c2
calextract tool written, works
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 12 Jul 2014 00:05:22 +0000 |
parents | |
children | c38075b8a625 |
comparison
equal
deleted
inserted
replaced
179:d0e8cdb82117 | 180:25b54c5ad6c2 |
---|---|
1 /* | |
2 * GSM firmwares constructed per TI's canon contain several hard-coded | |
3 * T_RF_BAND structures, one per band, emitted literally in the .const | |
4 * section as they are constant initialized data, i.e., | |
5 * const T_RF_BAND rf_XXX = { blah }. This utility extracts one of these | |
6 * structures from a binary file (hex offset must be given) and parses it | |
7 * into a C form suitable for placement in l1_rf12.c in the FreeCalypso | |
8 * gsm-fw source. | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 | |
14 char *binfilename; | |
15 FILE *binf; | |
16 u_long start_offset; | |
17 | |
18 getbyte() | |
19 { | |
20 int c; | |
21 | |
22 c = getc(binf); | |
23 if (c < 0) { | |
24 fprintf(stderr, "error or EOF reading from %s\n", binfilename); | |
25 exit(1); | |
26 } | |
27 return(c); | |
28 } | |
29 | |
30 get_u16() | |
31 { | |
32 int lo, hi; | |
33 | |
34 lo = getbyte(); | |
35 hi = getbyte(); | |
36 return((hi << 8) | lo); | |
37 } | |
38 | |
39 get_s16() | |
40 { | |
41 int i; | |
42 | |
43 i = get_u16(); | |
44 if (i >= 32768) | |
45 i -= 65536; | |
46 return(i); | |
47 } | |
48 | |
49 do_rx_cal_params() | |
50 { | |
51 int i; | |
52 | |
53 puts(" { /* T_RX_CAL_PARAMS */"); | |
54 for (i = 0; i < 4; i++) | |
55 printf("%10d,\n", get_u16()); | |
56 puts(" },"); | |
57 } | |
58 | |
59 do_rx_agc_bands() | |
60 { | |
61 int i, u, s; | |
62 | |
63 puts(" { /* T_RF_AGC_BANDs */"); | |
64 for (i = 0; i < 10; i++) { | |
65 u = get_u16(); | |
66 s = get_s16(); | |
67 printf(" {%5d,%6d},\n", u, s); | |
68 } | |
69 puts(" },"); | |
70 } | |
71 | |
72 do_rx_temp_comp() | |
73 { | |
74 int i, s1, s2; | |
75 | |
76 puts(" { /* Rx temperature compensation */"); | |
77 for (i = 0; i < 11; i++) { | |
78 s1 = get_s16(); | |
79 s2 = get_s16(); | |
80 printf(" {%6d,%6d},\n", s1, s2); | |
81 } | |
82 puts(" },"); | |
83 } | |
84 | |
85 do_rx() | |
86 { | |
87 puts(" { /* Rx structure */"); | |
88 do_rx_cal_params(); | |
89 do_rx_agc_bands(); | |
90 do_rx_temp_comp(); | |
91 puts(" },"); | |
92 } | |
93 | |
94 do_tx_levels() | |
95 { | |
96 int i, u, b1, b2; | |
97 | |
98 puts(" { /* levels */"); | |
99 for (i = 0; i < 32; i++) { | |
100 u = get_u16(); | |
101 b1 = getbyte(); | |
102 b2 = getbyte(); | |
103 printf(" {%5d,%3d,%3d}, /* %d */\n", u, b1, b2, i); | |
104 } | |
105 puts(" },"); | |
106 } | |
107 | |
108 do_tx_calchan() | |
109 { | |
110 int i, j, u, s; | |
111 | |
112 puts(" { /* channel calibration tables */"); | |
113 for (i = 0; i < 4; i++) { | |
114 printf(" { /* calibration table %d */\n", i); | |
115 for (j = 0; j < 8; j++) { | |
116 u = get_u16(); | |
117 s = get_s16(); | |
118 printf("\t{%5d,%6d},\n", u, s); | |
119 } | |
120 puts(" },"); | |
121 } | |
122 puts(" },"); | |
123 } | |
124 | |
125 do_ramp_16bytes() | |
126 { | |
127 int i, b; | |
128 | |
129 putchar('\t'); | |
130 putchar('{'); | |
131 for (i = 0; i < 16; i++) { | |
132 b = getbyte(); | |
133 printf("%3d%c", b, i == 15 ? '}' : ','); | |
134 } | |
135 putchar(','); | |
136 putchar('\n'); | |
137 } | |
138 | |
139 do_tx_ramps() | |
140 { | |
141 int i; | |
142 | |
143 puts(" { /* ramps */"); | |
144 for (i = 0; i < 16; i++) { | |
145 printf(" { /* profile %d */\n", i); | |
146 puts("\t/* ramp-up */"); | |
147 do_ramp_16bytes(); | |
148 puts("\t/* ramp-down */"); | |
149 do_ramp_16bytes(); | |
150 puts(" },"); | |
151 } | |
152 puts(" },"); | |
153 } | |
154 | |
155 do_tx_temp_comp() | |
156 { | |
157 int i, j, s[4]; | |
158 | |
159 puts(" { /* Tx temperature compensation */"); | |
160 for (i = 0; i < 5; i++) { | |
161 for (j = 0; j < 4; j++) | |
162 s[j] = get_s16(); | |
163 printf(" {%6d,%6d,%6d,%6d},\n", s[0], s[1], s[2], s[3]); | |
164 } | |
165 puts(" },"); | |
166 } | |
167 | |
168 do_tx() | |
169 { | |
170 puts(" { /* Tx structure */"); | |
171 do_tx_levels(); | |
172 do_tx_calchan(); | |
173 do_tx_ramps(); | |
174 do_tx_temp_comp(); | |
175 puts(" },"); | |
176 } | |
177 | |
178 main(argc, argv) | |
179 char **argv; | |
180 { | |
181 if (argc != 3) { | |
182 fprintf(stderr, "usage: %s binfile hex-offset\n", argv[0]); | |
183 exit(1); | |
184 } | |
185 binfilename = argv[1]; | |
186 start_offset = strtoul(argv[2], 0, 16); | |
187 binf = fopen(binfilename, "r"); | |
188 if (!binf) { | |
189 perror(binfilename); | |
190 exit(1); | |
191 } | |
192 fseek(binf, start_offset, SEEK_SET); | |
193 puts("const T_RF_BAND rf_XXX = {"); | |
194 do_rx(); | |
195 do_tx(); | |
196 printf(" %d\n}\n", getbyte()); | |
197 exit(0); | |
198 } |