FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/olddump.c @ 1034:405b5469abc4 default tip
top README: repository change notice
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 12 Jun 2016 19:06:34 +0000 |
parents | 461f7ee5f254 |
children |
rev | line source |
---|---|
981
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This utility uses the old TM3 memory read command (in a synchronous manner |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * using our etmsync infrastructure) to read the memory of a GSM device running |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * a compatible fw version; it was written as an aid for reverse-engineering |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * bootloader-locked Mot C139 fw versions. |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 */ |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <sys/types.h> |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdio.h> |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <string.h> |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <strings.h> |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "tm3.h" |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "localtypes.h" |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "exitcodes.h" |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #define CHUNK_SIZE TM3_MEMREAD_MAX |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 single_op_main(argc, argv) |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 char **argv; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 { |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 u32 addr, len, chunk; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char buf[CHUNK_SIZE]; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 FILE *outf; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int rc; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 if (argc != 3) { |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 fprintf(stderr, |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 "usage: fc-olddump [options] start-addr dump-length binfile\n"); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 exit(ERROR_USAGE); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 addr = strtoul(argv[0], 0, 16); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 len = strtoul(argv[1], 0, 16); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 outf = fopen(argv[2], "w"); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 if (!outf) { |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 perror(argv[2]); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 exit(ERROR_UNIX); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 } |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 while (len) { |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 chunk = len; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (chunk > CHUNK_SIZE) |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 chunk = CHUNK_SIZE; |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 rc = do_memory_read_tm3(addr, buf, chunk); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (rc) |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 exit(rc); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 fwrite(buf, 1, chunk, outf); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 putchar('.'); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 fflush(stdout); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 addr += chunk; |
982
461f7ee5f254
fc-olddump: brown paper bag
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
981
diff
changeset
|
50 len -= chunk; |
981
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 } |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 putchar('\n'); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 fclose(outf); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 exit(0); |
0feb3db6f097
fc-olddump written, compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } |