FreeCalypso > hg > freecalypso-sw
annotate loadtools/clmain.c @ 56:d98137625c0d
fc-loadtool flash: total_size logic implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 20:50:41 +0000 |
parents | 278052b6afda |
children | ccc5161848c7 |
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; |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
22 |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
23 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
|
24 |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
25 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
|
26 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
|
27 |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 main(argc, argv) |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 char **argv; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 { |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 extern char *optarg; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 extern int optind; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 int c; |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
34 struct baudrate *br; |
42
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
36 while ((c = getopt(argc, argv, "a:b:B:h:H:i:")) != EOF) |
42
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 switch (c) { |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 case 'a': |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 iramimage.filename = optarg; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 continue; |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
41 case 'b': |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
42 set_romload_baudrate(optarg); |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
43 continue; |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
44 case 'B': |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
45 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
|
46 if (!br) |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
47 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
|
48 xram_load_baudrate = br; |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
49 continue; |
42
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 case 'h': |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 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
|
52 continue; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 case 'H': |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 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
|
55 continue; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 case 'i': |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 set_beacon_interval(optarg); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 continue; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 case '?': |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 default: |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 usage: fprintf(stderr, |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
62 "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
|
63 exit(1); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
65 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
|
66 goto usage; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 target_ttydev = argv[optind]; |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 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
|
69 if (!iramimage.filename) |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 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
|
71 if (argc - optind >= 3) { |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
72 if (argc - optind > 3) |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
73 goto usage; |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
74 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
|
75 if (!br) |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
76 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
|
77 xram_run_baudrate = br; |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
78 } |
42
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 open_target_serial(); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 perform_romload(); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 /* 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
|
83 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
|
84 exit(1); |
45
16315ed6401a
init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
85 if (hw_init_script[0]) { |
16315ed6401a
init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
86 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
|
87 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
|
88 if (c) |
16315ed6401a
init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
89 exit(1); |
16315ed6401a
init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
90 } |
53
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
91 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
|
92 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
|
93 if (c) |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
94 exit(1); |
604648026e9c
fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
95 } |
42
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 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
|
97 perform_chain_load(); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 tty_passthru(); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 exit(0); |
5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 } |