comparison loadtools/simmain.c @ 790:0bbe0213812d

fc-simint put together, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Mar 2021 04:40:05 +0000
parents loadtools/romdump.c@464a531122ab
children 02490e26f53d
comparison
equal deleted inserted replaced
789:464a531122ab 790:0bbe0213812d
1 /*
2 * This module contains the main() function for fc-simint.
3 */
4
5 #include <sys/types.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <unistd.h>
12 #include "../libserial/baudrate.h"
13 #include "srecreader.h"
14
15 char *target_ttydev;
16
17 extern struct srecreader iramimage;
18 extern struct baudrate *current_baud_rate;
19 extern void (*default_exit)();
20
21 extern struct baudrate *find_baudrate_by_name();
22
23 static char simagent_pathname[] = "/opt/freecalypso/target-bin/simagent.srec";
24 static char simtool_pathname[] = "/opt/freecalypso/bin/fc-simtool";
25 static char uicc_tool_pathname[] = "/opt/freecalypso/bin/fc-uicc-tool";
26
27 static char *selected_simtool = simtool_pathname;
28 static struct baudrate *session_baudrate;
29
30 int sim_voltage_mode_1v8;
31 int sim_allow_spenh = 1;
32
33 static void
34 tool_select_arg(arg)
35 char *arg;
36 {
37 if (!strcmp(arg, "sim"))
38 selected_simtool = simtool_pathname;
39 else if (!strcmp(arg, "uicc"))
40 selected_simtool = uicc_tool_pathname;
41 else {
42 fprintf(stderr, "error: invalid -T argument\n");
43 exit(1);
44 }
45 }
46
47 static void
48 voltage_select_arg(arg)
49 char *arg;
50 {
51 if (!strcmp(arg, "1.8"))
52 sim_voltage_mode_1v8 = 1;
53 else if (!strcmp(arg, "3") || !strcmp(arg, "3.0"))
54 sim_voltage_mode_1v8 = 0;
55 else {
56 fprintf(stderr, "error: invalid -v argument\n");
57 exit(1);
58 }
59 }
60
61 static void
62 exec_simtool(passon_argc, passon_argv)
63 char **passon_argv;
64 {
65 char **exec_argv, *prog_base_name;
66 char **sp, **dp;
67 extern int target_fd;
68 char desc_arg[16];
69
70 prog_base_name = rindex(selected_simtool, '/') + 1;
71 sprintf(desc_arg, "-C%d", target_fd);
72 exec_argv = (char **) malloc(sizeof(char *) * (passon_argc + 3));
73 if (!exec_argv) {
74 perror("malloc argv for execv");
75 exit(1);
76 }
77 sp = passon_argv;
78 dp = exec_argv;
79 *dp++ = prog_base_name;
80 *dp++ = desc_arg;
81 while (*sp)
82 *dp++ = *sp++;
83 *dp = NULL;
84 execv(selected_simtool, exec_argv);
85 fprintf(stderr, "Unable to exec %s\n", selected_simtool);
86 exit(1);
87 }
88
89 main(argc, argv)
90 char **argv;
91 {
92 extern char *optarg;
93 extern int optind;
94 int c;
95
96 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:nP:t:T:v:")) != EOF)
97 switch (c) {
98 case 'a':
99 iramimage.filename = optarg;
100 continue;
101 case 'b':
102 set_romload_baudrate(optarg);
103 continue;
104 case 'B':
105 session_baudrate = find_baudrate_by_name(optarg);
106 if (!session_baudrate)
107 exit(1); /* error msg already printed */
108 continue;
109 case 'c':
110 set_compalstage_short(optarg);
111 continue;
112 case 'C':
113 set_compalstage_fullpath(optarg);
114 continue;
115 case 'h':
116 read_hwparam_file_shortname(optarg);
117 continue;
118 case 'H':
119 read_hwparam_file_fullpath(optarg);
120 continue;
121 case 'i':
122 set_beacon_interval(optarg);
123 continue;
124 case 'n':
125 sim_allow_spenh = 0;
126 continue;
127 case 'P':
128 if (find_bootctrl_entry(optarg) < 0)
129 exit(1); /* error msg already printed */
130 continue;
131 case 't':
132 set_romload_timeout(optarg);
133 continue;
134 case 'T':
135 tool_select_arg(optarg);
136 continue;
137 case 'v':
138 voltage_select_arg(optarg);
139 continue;
140 case '?':
141 default:
142 usage: fprintf(stderr,
143 "usage: fc-simint [options] ttyport [batch command]\n");
144 exit(1);
145 }
146 if (argc - optind < 1)
147 goto usage;
148 target_ttydev = argv[optind];
149 if (!iramimage.filename)
150 iramimage.filename = simagent_pathname;
151
152 open_serial_port(target_ttydev);
153 pwon_if_needed();
154 perform_compal_stage();
155 perform_romload();
156 /* simagent target program should be running now */
157 if (tpinterf_pass_output(1) < 0)
158 exit(1);
159 if (session_baudrate && session_baudrate != current_baud_rate) {
160 c = loadagent_switch_baud(session_baudrate);
161 if (c)
162 exit(1);
163 }
164 do_sim_up();
165 sim_atr_validate();
166 sim_spenh_logic();
167 exec_simtool(argc - optind - 1, argv + optind + 1);
168 }