comparison rvinterf/etmsync/pirhackinit.c @ 918:c298d579788e

fc-pirhackinit implemented, compiles
author Space Falcon <falcon@ivan.Harhan.ORG>
date Tue, 08 Sep 2015 19:46:40 +0000
parents
children 7cb0b32f1997
comparison
equal deleted inserted replaced
917:9b4b0fcddc77 918:c298d579788e
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 "ffserr.h"
15 #include "tmffs2.h"
16 #include "localtypes.h"
17 #include "exitcodes.h"
18
19 extern u_char pirelli_imeisv[8];
20
21 write_pcm_imei()
22 {
23 static char destfile[] = "/pcm/IMEI";
24 u_char swapped[8];
25 int i, d1, d2;
26
27 printf("Writing %s\n", destfile);
28 for (i = 0; i < 8; i++) {
29 d1 = pirelli_imeisv[i] >> 4;
30 d2 = pirelli_imeisv[i] & 0xF;
31 swapped[i] = (d2 << 4) | d1;
32 }
33 return do_short_fwrite(destfile, swapped, 8);
34 }
35
36 read_mem_region(memaddr, databuf, total_bytes)
37 u32 memaddr;
38 u_char *databuf;
39 {
40 int chunk, remain, rc;
41
42 for (remain = total_bytes; remain; remain -= chunk) {
43 chunk = remain;
44 if (chunk > 240)
45 chunk = 240;
46 rc = do_memory_read(memaddr, databuf, chunk);
47 if (rc)
48 return(rc);
49 memaddr += chunk;
50 databuf += chunk;
51 }
52 return(0);
53 }
54
55 write_buf_to_file(pathname, data, datalen)
56 char *pathname;
57 u_char *data;
58 {
59 int tfd, rc, chunk, remain;
60
61 if (datalen <= max_short_file_write(pathname))
62 return do_short_fwrite(pathname, data, datalen);
63 /* do it the long way */
64 rc = fd_open(pathname, FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, &tfd);
65 if (rc)
66 return(rc);
67 for (remain = datalen; remain; remain -= chunk) {
68 chunk = remain;
69 if (chunk > 240)
70 chunk = 240;
71 rc = fd_write(tfd, data, chunk);
72 if (rc) {
73 fd_close(tfd);
74 return(rc);
75 }
76 data += chunk;
77 }
78 return fd_close(tfd);
79 }
80
81 copy_calib_record(memaddr, pathname, size)
82 u32 memaddr;
83 char *pathname;
84 int size;
85 {
86 u_char *buf;
87 int rc;
88
89 buf = malloc(size);
90 if (!buf) {
91 perror("malloc");
92 exit(ERROR_UNIX);
93 }
94 rc = read_mem_region(memaddr, buf, size);
95 if (rc) {
96 free(buf);
97 return(rc);
98 }
99 rc = write_buf_to_file(pathname, buf, size);
100 free(buf);
101 return(rc);
102 }
103
104 static struct calmap {
105 u32 offset;
106 int size;
107 char *ti_equiv;
108 } pirelli_cal_map[] = {
109 {0x06E5, 36, "/sys/adccal"},
110 {0x072B, 512, "/gsm/rf/tx/ramps.900"},
111 {0x092C, 128, "/gsm/rf/tx/levels.900"},
112 {0x09AD, 128, "/gsm/rf/tx/calchan.900"},
113 {0x0A2E, 512, "/gsm/rf/tx/ramps.1800"},
114 {0x0C2F, 128, "/gsm/rf/tx/levels.1800"},
115 {0x0CB0, 128, "/gsm/rf/tx/calchan.1800"},
116 {0x0D31, 512, "/gsm/rf/tx/ramps.1900"},
117 {0x0F32, 128, "/gsm/rf/tx/levels.1900"},
118 {0x0FB3, 128, "/gsm/rf/tx/calchan.1900"},
119 {0x10AF, 40, "/gsm/rf/rx/calchan.900"},
120 {0x10D8, 8, "/gsm/rf/rx/agcparams.900"},
121 {0x10E1, 40, "/gsm/rf/rx/calchan.1800"},
122 {0x110A, 8, "/gsm/rf/rx/agcparams.1800"},
123 {0x1113, 40, "/gsm/rf/rx/calchan.1900"},
124 {0x113C, 8, "/gsm/rf/rx/agcparams.1900"},
125 {0, 0, 0}
126 };
127
128 copy_calib_data()
129 {
130 struct calmap *tp;
131 int rc;
132
133 printf("Copying calibration records to FFS\n");
134 for (tp = pirelli_cal_map; tp->size; tp++) {
135 rc = copy_calib_record(0x027F0000 + tp->offset, tp->ti_equiv,
136 tp->size);
137 if (rc)
138 return(rc);
139 }
140 return(0);
141 }
142
143 single_op_main()
144 {
145 int rc;
146
147 rc = get_pirelli_imei();
148 if (rc)
149 return(rc);
150 printf("Creating TCS211 file system directories\n");
151 rc = create_std_dirs();
152 if (rc)
153 return(rc);
154 rc = write_pcm_imei();
155 if (rc)
156 return(rc);
157 rc = copy_calib_data();
158 if (rc)
159 return(rc);
160 return set_rfcap("tri900");
161 }