annotate loadtools/romdump.c @ 927:4e243402f453

rvinterf/lowlevel: use libprint for backslash-escape output
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 03:59:42 +0000
parents 464a531122ab
children
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
789
464a531122ab loadtools: some paths moved out of defpath.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 683
diff changeset
17 char default_dspdump_image[] = "/opt/freecalypso/target-bin/dspdump.srec";
464a531122ab loadtools: some paths moved out of defpath.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 683
diff changeset
18
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct srecreader iramimage;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct baudrate *current_baud_rate;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void (*default_exit)();
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
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
48 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
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;
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
77 case 'P':
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
78 if (find_bootctrl_entry(optarg) < 0)
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
79 exit(1); /* error msg already printed */
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
80 continue;
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
81 case 't':
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
82 set_romload_timeout(optarg);
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 575
diff changeset
83 continue;
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 case '?':
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 default:
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 usage: fprintf(stderr,
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 "usage: fc-dspromdump [options] ttyport output-file\n");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (argc - optind != 2)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 goto usage;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 target_ttydev = argv[optind];
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 output_filename = argv[optind+1];
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (!iramimage.filename)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 iramimage.filename = default_dspdump_image;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 open_serial_port(target_ttydev);
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
98 pwon_if_needed();
548
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 perform_compal_stage();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 perform_romload();
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 /* dspdump target program should be running now */
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (tpinterf_pass_output(1) < 0)
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 if (romdump_baudrate && romdump_baudrate != current_baud_rate) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 c = loadagent_switch_baud(romdump_baudrate);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (c)
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 outfile = fopen(output_filename, "w");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (!outfile) {
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 perror(output_filename);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 printf("Requesting DSP ROM dump\n");
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 targv[0] = "fulldump";
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 targv[1] = 0;
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 tpinterf_make_cmd(targv);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (tpinterf_send_cmd() < 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 c = tpinterf_capture_output(2, dump_receiver);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 fclose(outfile);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (c < 0)
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 exit(1);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 default_exit(0);
2e4ab60919b9 fc-dspromdump front end program implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }