comparison rvinterf/etmsync/pirmagnetite.c @ 15:5cc0791a6eb6

Pirelli etmsync hacks absorbed into fc-fsio
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 03 Oct 2016 07:18:09 +0000
parents rvinterf/etmsync/pirhackinit.c@e7502631a0f9
children a3763707317f
comparison
equal deleted inserted replaced
14:3d148edb87c2 15:5cc0791a6eb6
1 /*
2 * This pirelli-magnetite-init special command should ONLY be run
3 * against FreeCalypso Magnetite firmware running on the Pirelli target.
4 * It initializes the FFS for FC Magnetite (essentially TCS211)
5 * appropriately for the Pirelli target, copying the IMEI and the
6 * RF calibration values from Pirelli's factory data block.
7 */
8
9 #include <sys/types.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include "etm.h"
15 #include "ffs.h"
16 #include "tmffs2.h"
17 #include "localtypes.h"
18 #include "exitcodes.h"
19
20 extern u_char pirelli_imeisv[8];
21
22 static
23 write_pcm_imei()
24 {
25 static char destfile[] = "/pcm/IMEI";
26 u_char swapped[8];
27 int i, d1, d2;
28
29 printf("Writing %s\n", destfile);
30 for (i = 0; i < 8; i++) {
31 d1 = pirelli_imeisv[i] >> 4;
32 d2 = pirelli_imeisv[i] & 0xF;
33 swapped[i] = (d2 << 4) | d1;
34 }
35 return do_short_fwrite(destfile, swapped, 8);
36 }
37
38 static
39 read_mem_region(memaddr, databuf, total_bytes)
40 u32 memaddr;
41 u_char *databuf;
42 {
43 int chunk, remain, rc;
44
45 for (remain = total_bytes; remain; remain -= chunk) {
46 chunk = remain;
47 if (chunk > MAX_MEMREAD_BYTES)
48 chunk = MAX_MEMREAD_BYTES;
49 rc = do_memory_read(memaddr, databuf, chunk);
50 if (rc)
51 return(rc);
52 memaddr += chunk;
53 databuf += chunk;
54 }
55 return(0);
56 }
57
58 static
59 write_buf_to_file(pathname, data, datalen)
60 char *pathname;
61 u_char *data;
62 {
63 int tfd, rc, chunk, remain;
64
65 if (datalen <= max_short_file_write(pathname))
66 return do_short_fwrite(pathname, data, datalen);
67 /* do it the long way */
68 rc = fd_open(pathname, FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, &tfd);
69 if (rc)
70 return(rc);
71 for (remain = datalen; remain; remain -= chunk) {
72 chunk = remain;
73 if (chunk > 240)
74 chunk = 240;
75 rc = fd_write(tfd, data, chunk);
76 if (rc) {
77 fd_close(tfd);
78 return(rc);
79 }
80 data += chunk;
81 }
82 return fd_close(tfd);
83 }
84
85 static
86 copy_calib_record(memaddr, pathname, size)
87 u32 memaddr;
88 char *pathname;
89 int size;
90 {
91 u_char *buf;
92 int rc;
93
94 buf = malloc(size);
95 if (!buf) {
96 perror("malloc");
97 exit(ERROR_UNIX);
98 }
99 rc = read_mem_region(memaddr, buf, size);
100 if (rc) {
101 free(buf);
102 return(rc);
103 }
104 rc = write_buf_to_file(pathname, buf, size);
105 free(buf);
106 return(rc);
107 }
108
109 static struct calmap {
110 u32 offset;
111 int size;
112 char *ti_equiv;
113 } pirelli_cal_map[] = {
114 {0x06E5, 36, "/sys/adccal"},
115 {0x072B, 512, "/gsm/rf/tx/ramps.900"},
116 {0x092C, 128, "/gsm/rf/tx/levels.900"},
117 {0x09AD, 128, "/gsm/rf/tx/calchan.900"},
118 {0x0A2E, 512, "/gsm/rf/tx/ramps.1800"},
119 {0x0C2F, 128, "/gsm/rf/tx/levels.1800"},
120 {0x0CB0, 128, "/gsm/rf/tx/calchan.1800"},
121 {0x0D31, 512, "/gsm/rf/tx/ramps.1900"},
122 {0x0F32, 128, "/gsm/rf/tx/levels.1900"},
123 {0x0FB3, 128, "/gsm/rf/tx/calchan.1900"},
124 {0x10AF, 40, "/gsm/rf/rx/calchan.900"},
125 {0x10D8, 8, "/gsm/rf/rx/agcparams.900"},
126 {0x10E1, 40, "/gsm/rf/rx/calchan.1800"},
127 {0x110A, 8, "/gsm/rf/rx/agcparams.1800"},
128 {0x1113, 40, "/gsm/rf/rx/calchan.1900"},
129 {0x113C, 8, "/gsm/rf/rx/agcparams.1900"},
130 {0, 0, 0}
131 };
132
133 static
134 copy_calib_data()
135 {
136 struct calmap *tp;
137 int rc;
138
139 printf("Copying calibration records to FFS\n");
140 for (tp = pirelli_cal_map; tp->size; tp++) {
141 rc = copy_calib_record(0x027F0000 + tp->offset, tp->ti_equiv,
142 tp->size);
143 if (rc)
144 return(rc);
145 }
146 return(0);
147 }
148
149 pirelli_magnetite_init()
150 {
151 int rc;
152
153 rc = get_pirelli_imei();
154 if (rc)
155 return(rc);
156 printf("Creating TCS211 file system directories\n");
157 rc = create_std_dirs();
158 if (rc)
159 return(rc);
160 rc = write_pcm_imei();
161 if (rc)
162 return(rc);
163 rc = copy_calib_data();
164 if (rc)
165 return(rc);
166 return set_rfcap("tri900");
167 }