comparison loadtools/ltmain.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 6616f4e35579
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module contains the main() function for fc-loadtool
3 */
4
5 #include <sys/types.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include "srecreader.h"
11
12 extern char *target_ttydev;
13 extern struct srecreader iramimage;
14 extern char default_loadagent_image[];
15 extern char hw_init_script[];
16 extern void (*default_exit)();
17 extern int gta_modem_poweron;
18
19 extern struct baudrate *find_baudrate_by_name();
20
21 static struct baudrate *reattach;
22
23 main(argc, argv)
24 char **argv;
25 {
26 extern char *optarg;
27 extern int optind;
28 int c;
29 char command[512];
30
31 while ((c = getopt(argc, argv, "a:b:c:C:h:H:i:nr:")) != EOF)
32 switch (c) {
33 case 'a':
34 iramimage.filename = optarg;
35 continue;
36 case 'b':
37 set_romload_baudrate(optarg);
38 continue;
39 case 'c':
40 set_compalstage_short(optarg);
41 continue;
42 case 'C':
43 set_compalstage_fullpath(optarg);
44 continue;
45 case 'h':
46 read_hwparam_file_shortname(optarg);
47 continue;
48 case 'H':
49 read_hwparam_file_fullpath(optarg);
50 continue;
51 case 'i':
52 set_beacon_interval(optarg);
53 continue;
54 case 'n':
55 gta_modem_poweron = 0;
56 continue;
57 case 'r':
58 reattach = find_baudrate_by_name(optarg);
59 if (!reattach)
60 exit(1); /* error msg already printed */
61 continue;
62 case '?':
63 default:
64 usage: fprintf(stderr,
65 "usage: fc-loadtool [options] ttyport\n");
66 exit(1);
67 }
68 if (argc - optind != 1)
69 goto usage;
70 target_ttydev = argv[optind];
71 if (!iramimage.filename)
72 iramimage.filename = default_loadagent_image;
73
74 open_target_serial();
75 if (reattach)
76 switch_baud_rate(reattach);
77 else {
78 perform_compal_stage(1);
79 perform_romload();
80 putchar('\n');
81 if (tpinterf_pass_output(1) < 0)
82 exit(1);
83 putchar('\n');
84 if (hw_init_script[0]) {
85 printf("Executing init script %s\n", hw_init_script);
86 loadtool_exec_script(hw_init_script);
87 }
88 }
89 for (;;) {
90 if (isatty(0)) {
91 fputs("loadtool> ", stdout);
92 fflush(stdout);
93 }
94 if (!fgets(command, sizeof command, stdin))
95 default_exit();
96 loadtool_dispatch_cmd(command, 0);
97 }
98 }