comparison loadtools/romdump.c @ 548:2e4ab60919b9

fc-dspromdump front end program implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2019 22:08:38 +0000
parents
children aba969153d20
comparison
equal deleted inserted replaced
547:a28e4ddd09a6 548:2e4ab60919b9
1 /*
2 * This module contains the main() function for fc-dspromdump.
3 */
4
5 #include <sys/types.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <unistd.h>
12 #include "../libserial/baudrate.h"
13 #include "srecreader.h"
14
15 char *target_ttydev;
16
17 extern struct srecreader iramimage;
18 extern char default_dspdump_image[];
19 extern struct baudrate *current_baud_rate;
20 extern void (*default_exit)();
21 extern int gta_modem_poweron;
22
23 extern struct baudrate *find_baudrate_by_name();
24
25 static struct baudrate *romdump_baudrate;
26 static char *output_filename;
27 static FILE *outfile;
28
29 static
30 dump_receiver(line)
31 char *line;
32 {
33 if (!strncmp(line, "DSP dump:", 9) || !strncmp(line, "ERROR:", 6))
34 puts(line);
35 fprintf(outfile, "%s\n", line);
36 return(1);
37 }
38
39 main(argc, argv)
40 char **argv;
41 {
42 extern char *optarg;
43 extern int optind;
44 int c;
45 struct baudrate *br;
46 char *targv[2];
47
48 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:n")) != EOF)
49 switch (c) {
50 case 'a':
51 iramimage.filename = optarg;
52 continue;
53 case 'b':
54 set_romload_baudrate(optarg);
55 continue;
56 case 'B':
57 br = find_baudrate_by_name(optarg);
58 if (!br)
59 exit(1); /* error msg already printed */
60 romdump_baudrate = br;
61 continue;
62 case 'c':
63 set_compalstage_short(optarg);
64 continue;
65 case 'C':
66 set_compalstage_fullpath(optarg);
67 continue;
68 case 'h':
69 read_hwparam_file_shortname(optarg);
70 continue;
71 case 'H':
72 read_hwparam_file_fullpath(optarg);
73 continue;
74 case 'i':
75 set_beacon_interval(optarg);
76 continue;
77 case 'n':
78 gta_modem_poweron = 0;
79 continue;
80 case '?':
81 default:
82 usage: fprintf(stderr,
83 "usage: fc-dspromdump [options] ttyport output-file\n");
84 exit(1);
85 }
86 if (argc - optind != 2)
87 goto usage;
88 target_ttydev = argv[optind];
89 output_filename = argv[optind+1];
90 if (!iramimage.filename)
91 iramimage.filename = default_dspdump_image;
92
93 open_serial_port(target_ttydev);
94 perform_compal_stage();
95 perform_romload();
96 /* dspdump target program should be running now */
97 if (tpinterf_pass_output(1) < 0)
98 exit(1);
99 if (romdump_baudrate && romdump_baudrate != current_baud_rate) {
100 c = loadagent_switch_baud(romdump_baudrate);
101 if (c)
102 exit(1);
103 }
104 outfile = fopen(output_filename, "w");
105 if (!outfile) {
106 perror(output_filename);
107 exit(1);
108 }
109 printf("Requesting DSP ROM dump\n");
110 targv[0] = "fulldump";
111 targv[1] = 0;
112 tpinterf_make_cmd(targv);
113 if (tpinterf_send_cmd() < 0)
114 exit(1);
115 c = tpinterf_capture_output(2, dump_receiver);
116 fclose(outfile);
117 if (c < 0)
118 exit(1);
119 default_exit(0);
120 }