FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/memdump.c @ 153:9925fba699be
fc-olddump replaced with fc-memdump
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 Mar 2017 01:19:51 +0000 |
parents | |
children | e40bb5a6c6b9 |
comparison
equal
deleted
inserted
replaced
152:9a08c09a07c0 | 153:9925fba699be |
---|---|
1 /* | |
2 * This utility uses one of TI's Test Mode memory read commands (either TM3 or | |
3 * ETM) in a synchronous manner (using our etmsync infrastructure) to read the | |
4 * memory of a GSM device running a compatible fw version. It supplants | |
5 * the former fc-olddump tool. | |
6 */ | |
7 | |
8 #include <sys/types.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <strings.h> | |
13 #include <unistd.h> | |
14 #include "etm.h" | |
15 #include "tm3.h" | |
16 #include "localtypes.h" | |
17 #include "exitcodes.h" | |
18 | |
19 int use_etm; | |
20 | |
21 extern char *socket_pathname; | |
22 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; | |
23 | |
24 single_op_main(argc, argv) | |
25 char **argv; | |
26 { | |
27 u32 addr, len, chunk, maxchunk; | |
28 char buf[MAX_MEMREAD_BYTES]; | |
29 FILE *outf; | |
30 int rc; | |
31 | |
32 if (argc != 3) { | |
33 fprintf(stderr, | |
34 "usage: fc-memdump [options] start-addr dump-length binfile\n"); | |
35 exit(ERROR_USAGE); | |
36 } | |
37 addr = strtoul(argv[0], 0, 16); | |
38 len = strtoul(argv[1], 0, 16); | |
39 outf = fopen(argv[2], "w"); | |
40 if (!outf) { | |
41 perror(argv[2]); | |
42 exit(ERROR_UNIX); | |
43 } | |
44 if (use_etm) | |
45 maxchunk = MAX_MEMREAD_BYTES; | |
46 else | |
47 maxchunk = TM3_MEMREAD_MAX; | |
48 while (len) { | |
49 chunk = len; | |
50 if (chunk > maxchunk) | |
51 chunk = maxchunk; | |
52 if (use_etm) | |
53 rc = do_memory_read(addr, buf, chunk); | |
54 else | |
55 rc = do_memory_read_tm3(addr, buf, chunk); | |
56 if (rc) | |
57 exit(rc); | |
58 fwrite(buf, 1, chunk, outf); | |
59 putchar('.'); | |
60 fflush(stdout); | |
61 addr += chunk; | |
62 len -= chunk; | |
63 } | |
64 putchar('\n'); | |
65 fclose(outf); | |
66 exit(0); | |
67 } | |
68 | |
69 main(argc, argv) | |
70 char **argv; | |
71 { | |
72 extern int optind; | |
73 extern char *optarg; | |
74 int c, sopt = 0; | |
75 | |
76 while ((c = getopt(argc, argv, "B:el:p:s:w:")) != EOF) | |
77 switch (c) { | |
78 case 'B': | |
79 rvinterf_Bopt = optarg; | |
80 continue; | |
81 case 'e': | |
82 use_etm++; | |
83 continue; | |
84 case 'l': | |
85 rvinterf_lopt = optarg; | |
86 continue; | |
87 case 'p': | |
88 rvinterf_ttyport = optarg; | |
89 continue; | |
90 case 's': | |
91 socket_pathname = optarg; | |
92 sopt++; | |
93 continue; | |
94 case 'w': | |
95 rvinterf_wopt = optarg; | |
96 continue; | |
97 case '?': | |
98 default: | |
99 /* error msg already printed */ | |
100 exit(ERROR_USAGE); | |
101 } | |
102 if (rvinterf_ttyport) { | |
103 if (sopt) { | |
104 fprintf(stderr, | |
105 "%s error: -p and -s options are mutually exclusive\n", | |
106 argv[0]); | |
107 exit(ERROR_USAGE); | |
108 } | |
109 launch_rvinterf(); | |
110 } else { | |
111 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { | |
112 fprintf(stderr, | |
113 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", | |
114 argv[0]); | |
115 exit(ERROR_USAGE); | |
116 } | |
117 connect_local_socket(); | |
118 } | |
119 | |
120 return single_op_main(argc - optind, argv + optind); | |
121 } |