annotate loadtools/romdump.c @ 741:72feb9763de4

lunadrv documentation updates for upcoming release
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Oct 2020 03:38:14 +0000
parents ecea01f65146
children 464a531122ab
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
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
47 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:t:")) != 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;
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
80 case 't':
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
81 set_romload_timeout(optarg);
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
82 continue;
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 case '?':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 default:
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 usage: fprintf(stderr,
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 "usage: fc-dspromdump [options] ttyport output-file\n");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (argc - optind != 2)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 goto usage;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 target_ttydev = argv[optind];
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 output_filename = argv[optind+1];
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!iramimage.filename)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 iramimage.filename = default_dspdump_image;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 open_serial_port(target_ttydev);
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
97 pwon_if_needed();
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 perform_compal_stage();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 perform_romload();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 /* dspdump target program should be running now */
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (tpinterf_pass_output(1) < 0)
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 if (romdump_baudrate && romdump_baudrate != current_baud_rate) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 c = loadagent_switch_baud(romdump_baudrate);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (c)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 outfile = fopen(output_filename, "w");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (!outfile) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 perror(output_filename);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 printf("Requesting DSP ROM dump\n");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 targv[0] = "fulldump";
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 targv[1] = 0;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 tpinterf_make_cmd(targv);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (tpinterf_send_cmd() < 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 c = tpinterf_capture_output(2, dump_receiver);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 fclose(outfile);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (c < 0)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 default_exit(0);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }