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