annotate loadtools/ltmain.c @ 624:7485e75d9477

srec-regions: removed unnecessary prohibition against address going backward
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 27 Feb 2020 08:12:11 +0000
parents cef70d53fc5e
children ecea01f65146
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the main() function for fc-loadtool
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <unistd.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "srecreader.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 232
diff changeset
12 char *target_ttydev;
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 232
diff changeset
13
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern struct srecreader iramimage;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern char default_loadagent_image[];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern char hw_init_script[];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern void (*default_exit)();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct baudrate *find_baudrate_by_name();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
232
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
21 static struct baudrate *reattach, *batch_baud;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 main(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern char *optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern int optind;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 int c;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char command[512];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
31 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:")) != EOF)
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 switch (c) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 case 'a':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 iramimage.filename = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case 'b':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 set_romload_baudrate(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 continue;
232
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
39 case 'B':
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
40 batch_baud = find_baudrate_by_name(optarg);
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
41 if (!batch_baud)
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
42 exit(1); /* error msg already printed */
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
43 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case 'c':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 set_compalstage_short(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case 'C':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 set_compalstage_fullpath(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 case 'h':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 read_hwparam_file_shortname(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case 'H':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 read_hwparam_file_fullpath(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 case 'i':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 set_beacon_interval(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 continue;
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
59 case 'P':
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
60 if (find_bootctrl_entry(optarg) < 0)
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
61 exit(1); /* error msg already printed */
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
62 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 case 'r':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 reattach = find_baudrate_by_name(optarg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (!reattach)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1); /* error msg already printed */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 case '?':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 default:
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 usage: fprintf(stderr,
230
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
71 "usage: fc-loadtool [options] ttyport [command-script]\n");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
230
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
74 if (argc - optind < 1 || argc - optind > 2)
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 goto usage;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 target_ttydev = argv[optind];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (!iramimage.filename)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 iramimage.filename = default_loadagent_image;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 232
diff changeset
80 open_serial_port(target_ttydev);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (reattach)
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 232
diff changeset
82 set_serial_baudrate(reattach);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 else {
575
cef70d53fc5e loadtools: new -P boot control mechanism implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
84 pwon_if_needed();
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 232
diff changeset
85 perform_compal_stage();
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 perform_romload();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 putchar('\n');
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (tpinterf_pass_output(1) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 putchar('\n');
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (hw_init_script[0]) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 printf("Executing init script %s\n", hw_init_script);
230
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
93 c = loadtool_exec_script(hw_init_script, 1);
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
94 } else
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
95 c = 0;
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
96 if (argc - optind > 1) {
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
97 if (c)
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
98 exit(1);
232
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
99 if (batch_baud) {
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
100 c = loadagent_switch_baud(batch_baud);
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
101 if (c)
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
102 exit(1);
353218c38996 fc-loadtool batch mode: added -B option
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
103 }
230
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
104 printf("Executing command script %s\n", argv[optind+1]);
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
105 c = loadtool_exec_script(argv[optind+1], 0);
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
106 if (c)
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
107 exit(1);
a91dc7157544 fc-loadtool: automated command script mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 229
diff changeset
108 default_exit(0);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 for (;;) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (isatty(0)) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 fputs("loadtool> ", stdout);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 fflush(stdout);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (!fgets(command, sizeof command, stdin))
229
96332d875fc9 loadtools: preparations for loadtool exit code possibly being nonzero
Mychaela Falconia <falcon@freecalypso.org>
parents: 227
diff changeset
117 default_exit(0);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 loadtool_dispatch_cmd(command, 0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }