annotate loadtools/romdump.c @ 587:5b88ba62b9ae

doc/Rvinterf-tools: rvinterf -P option documented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 03 Feb 2020 07:56:57 +0000
parents cef70d53fc5e
children ecea01f65146
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern struct baudrate *find_baudrate_by_name();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static struct baudrate *romdump_baudrate;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static char *output_filename;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static FILE *outfile;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 dump_receiver(line)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *line;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 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
33 puts(line);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(outfile, "%s\n", line);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
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 main(argc, argv)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 char **argv;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 extern char *optarg;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 extern int optind;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 int c;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 struct baudrate *br;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char *targv[2];
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
47 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:")) != EOF)
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 switch (c) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 case 'a':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 iramimage.filename = optarg;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 case 'b':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 set_romload_baudrate(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case 'B':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 br = find_baudrate_by_name(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!br)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1); /* error msg already printed */
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 romdump_baudrate = br;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 case 'c':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 set_compalstage_short(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 case 'C':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 set_compalstage_fullpath(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 case 'h':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 read_hwparam_file_shortname(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 case 'H':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 read_hwparam_file_fullpath(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 continue;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 case 'i':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 set_beacon_interval(optarg);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 continue;
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
76 case 'P':
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
77 if (find_bootctrl_entry(optarg) < 0)
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
78 exit(1); /* error msg already printed */
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
79 continue;
548
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);
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
94 pwon_if_needed();
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 perform_compal_stage();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 perform_romload();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /* dspdump target program should be running now */
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (tpinterf_pass_output(1) < 0)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (romdump_baudrate && romdump_baudrate != current_baud_rate) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 c = loadagent_switch_baud(romdump_baudrate);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (c)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 outfile = fopen(output_filename, "w");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (!outfile) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 perror(output_filename);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 printf("Requesting DSP ROM dump\n");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 targv[0] = "fulldump";
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 targv[1] = 0;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 tpinterf_make_cmd(targv);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (tpinterf_send_cmd() < 0)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 c = tpinterf_capture_output(2, dump_receiver);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 fclose(outfile);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (c < 0)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 default_exit(0);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }