annotate loadtools/clmain.c @ 121:15e972110527

RVM compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 31 Oct 2013 00:55:14 +0000
parents ccc5161848c7
children e4257294102b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the main() function for the XRAM chain-loading
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * utility fc-xram.
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdint.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
10 #include <termios.h>
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
12 #include "baudrate.h"
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "srecreader.h"
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern char *target_ttydev;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct srecreader iramimage;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern char default_loadagent_image[];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern struct srecreader xramimage;
45
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
19 extern char hw_init_script[];
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
20 extern struct baudrate baud_rate_table[];
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
21 extern struct baudrate *current_baud_rate;
84
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
22 extern int gta_modem_poweron;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
23
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
24 extern struct baudrate *find_baudrate_by_name();
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
25
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
26 struct baudrate *xram_load_baudrate;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
27 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 main(argc, argv)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 char **argv;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 {
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 extern char *optarg;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 extern int optind;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 int c;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
35 struct baudrate *br;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36
84
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
37 while ((c = getopt(argc, argv, "a:b:B:h:H:i:n")) != EOF)
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 switch (c) {
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case 'a':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 iramimage.filename = optarg;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 continue;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
42 case 'b':
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
43 set_romload_baudrate(optarg);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
44 continue;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
45 case 'B':
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
46 br = find_baudrate_by_name(optarg);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
47 if (!br)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
48 exit(1); /* error msg already printed */
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
49 xram_load_baudrate = br;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
50 continue;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 case 'h':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 read_hwparam_file_shortname(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 continue;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 case 'H':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 read_hwparam_file_fullpath(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 continue;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 case 'i':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 set_beacon_interval(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 continue;
84
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
60 case 'n':
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
61 gta_modem_poweron = 0;
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
62 continue;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 case '?':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 default:
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 usage: fprintf(stderr,
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
66 "usage: fc-xram [options] ttyport xramimage.srec [runbaud]\n");
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 exit(1);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
69 if (argc - optind < 2)
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 goto usage;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 target_ttydev = argv[optind];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 xramimage.filename = argv[optind+1];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (!iramimage.filename)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 iramimage.filename = default_loadagent_image;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
75 if (argc - optind >= 3) {
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
76 if (argc - optind > 3)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
77 goto usage;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
78 br = find_baudrate_by_name(argv[optind+2]);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
79 if (!br)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
80 exit(1); /* error msg already printed */
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
81 xram_run_baudrate = br;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
82 }
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 open_target_serial();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 perform_romload();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 /* loadagent should be running now */
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 if (tpinterf_pass_output(1) < 0)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 exit(1);
45
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
89 if (hw_init_script[0]) {
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
90 printf("Executing init script %s\n", hw_init_script);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
91 c = exec_init_script(hw_init_script);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
92 if (c)
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
93 exit(1);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
94 }
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
95 if (xram_load_baudrate && xram_load_baudrate != current_baud_rate) {
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
96 c = loadagent_switch_baud(xram_load_baudrate);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
97 if (c)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
98 exit(1);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
99 }
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 printf("Sending XRAM image to loadagent\n");
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 perform_chain_load();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 tty_passthru();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 exit(0);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 }