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