FreeCalypso > hg > freecalypso-tools
comparison loadtools/clmain.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 064d4eedb3a6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This module contains the main() function for the XRAM chain-loading | |
3 * utility fc-xram. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdint.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <termios.h> | |
11 #include <unistd.h> | |
12 #include "baudrate.h" | |
13 #include "srecreader.h" | |
14 | |
15 extern char *target_ttydev; | |
16 extern struct srecreader iramimage; | |
17 extern char default_loadagent_image[]; | |
18 extern struct srecreader xramimage; | |
19 extern char hw_init_script[]; | |
20 extern struct baudrate baud_rate_table[]; | |
21 extern struct baudrate *current_baud_rate; | |
22 extern int gta_modem_poweron; | |
23 | |
24 extern struct baudrate *find_baudrate_by_name(); | |
25 | |
26 struct baudrate *xram_load_baudrate; | |
27 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */ | |
28 | |
29 char **passon_argv; | |
30 int passon_argc; | |
31 | |
32 main(argc, argv) | |
33 char **argv; | |
34 { | |
35 extern char *optarg; | |
36 extern int optind; | |
37 int c; | |
38 struct baudrate *br; | |
39 | |
40 while ((c = getopt(argc, argv, "+a:b:B:c:C:h:H:i:nr:")) != EOF) | |
41 switch (c) { | |
42 case 'a': | |
43 iramimage.filename = optarg; | |
44 continue; | |
45 case 'b': | |
46 set_romload_baudrate(optarg); | |
47 continue; | |
48 case 'B': | |
49 br = find_baudrate_by_name(optarg); | |
50 if (!br) | |
51 exit(1); /* error msg already printed */ | |
52 xram_load_baudrate = br; | |
53 continue; | |
54 case 'c': | |
55 set_compalstage_short(optarg); | |
56 continue; | |
57 case 'C': | |
58 set_compalstage_fullpath(optarg); | |
59 continue; | |
60 case 'h': | |
61 read_hwparam_file_shortname(optarg); | |
62 continue; | |
63 case 'H': | |
64 read_hwparam_file_fullpath(optarg); | |
65 continue; | |
66 case 'i': | |
67 set_beacon_interval(optarg); | |
68 continue; | |
69 case 'n': | |
70 gta_modem_poweron = 0; | |
71 continue; | |
72 case 'r': | |
73 br = find_baudrate_by_name(optarg); | |
74 if (!br) | |
75 exit(1); /* error msg already printed */ | |
76 xram_run_baudrate = br; | |
77 continue; | |
78 case '?': | |
79 default: | |
80 usage: fprintf(stderr, | |
81 "usage: fc-xram [options] ttyport xramimage.srec [2ndprog]\n"); | |
82 exit(1); | |
83 } | |
84 if (argc - optind < 2) | |
85 goto usage; | |
86 target_ttydev = argv[optind]; | |
87 xramimage.filename = argv[optind+1]; | |
88 if (!iramimage.filename) | |
89 iramimage.filename = default_loadagent_image; | |
90 if (argc - optind >= 3) { | |
91 passon_argv = argv + optind + 2; | |
92 passon_argc = argc - optind - 2; | |
93 } | |
94 | |
95 open_target_serial(); | |
96 perform_compal_stage(1); | |
97 perform_romload(); | |
98 /* loadagent should be running now */ | |
99 if (tpinterf_pass_output(1) < 0) | |
100 exit(1); | |
101 if (hw_init_script[0]) { | |
102 printf("Executing init script %s\n", hw_init_script); | |
103 c = exec_init_script(hw_init_script); | |
104 if (c) | |
105 exit(1); | |
106 } | |
107 if (xram_load_baudrate && xram_load_baudrate != current_baud_rate) { | |
108 c = loadagent_switch_baud(xram_load_baudrate); | |
109 if (c) | |
110 exit(1); | |
111 } | |
112 printf("Sending XRAM image to loadagent\n"); | |
113 perform_chain_load(); | |
114 if (passon_argv) | |
115 exec_2nd_prog(); | |
116 tty_passthru(); | |
117 exit(0); | |
118 } | |
119 | |
120 exec_2nd_prog() | |
121 { | |
122 char **execp_argv; | |
123 char **sp, **dp; | |
124 extern int target_fd; | |
125 char desc_arg[16]; | |
126 | |
127 sprintf(desc_arg, "-d%d", target_fd); | |
128 execp_argv = (char **) malloc(sizeof(char *) * (passon_argc + 2)); | |
129 if (!execp_argv) { | |
130 perror("malloc argv for execvp"); | |
131 exit(1); | |
132 } | |
133 sp = passon_argv; | |
134 dp = execp_argv; | |
135 *dp++ = *sp++; | |
136 *dp++ = desc_arg; | |
137 while (*sp) | |
138 *dp++ = *sp++; | |
139 *dp = NULL; | |
140 execvp(execp_argv[0], execp_argv); | |
141 fprintf(stderr, "Unable to execvp %s\n", passon_argv[0]); | |
142 exit(1); | |
143 } |