annotate rvinterf/etmsync/memdump.c @ 956:b0b6966fa62e

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