FreeCalypso > hg > freecalypso-sw
comparison loadtools/clmain.c @ 53:604648026e9c
fc-xram: baud rate switching implemented per original intent
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 05:16:47 +0000 |
parents | 16315ed6401a |
children | 278052b6afda |
comparison
equal
deleted
inserted
replaced
52:b015036286f3 | 53:604648026e9c |
---|---|
5 | 5 |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <termios.h> | |
10 #include <unistd.h> | 11 #include <unistd.h> |
12 #include "baudrate.h" | |
11 #include "srecreader.h" | 13 #include "srecreader.h" |
12 | 14 |
13 extern char *target_ttydev; | 15 extern char *target_ttydev; |
14 extern struct srecreader iramimage; | 16 extern struct srecreader iramimage; |
15 extern char default_loadagent_image[]; | 17 extern char default_loadagent_image[]; |
16 extern struct srecreader xramimage; | 18 extern struct srecreader xramimage; |
17 extern char hw_init_script[]; | 19 extern char hw_init_script[]; |
20 extern struct baudrate baud_rate_table[]; | |
21 extern struct baudrate *current_baud_rate; | |
22 | |
23 extern struct baudrate *find_baudrate_by_name(); | |
24 | |
25 struct baudrate *xram_load_baudrate; | |
26 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */ | |
18 | 27 |
19 main(argc, argv) | 28 main(argc, argv) |
20 char **argv; | 29 char **argv; |
21 { | 30 { |
22 extern char *optarg; | 31 extern char *optarg; |
23 extern int optind; | 32 extern int optind; |
24 int c; | 33 int c; |
34 struct baudrate *br; | |
25 | 35 |
26 while ((c = getopt(argc, argv, "a:h:H:i:")) != EOF) | 36 while ((c = getopt(argc, argv, "a:b:B:h:H:i:")) != EOF) |
27 switch (c) { | 37 switch (c) { |
28 case 'a': | 38 case 'a': |
29 iramimage.filename = optarg; | 39 iramimage.filename = optarg; |
40 continue; | |
41 case 'b': | |
42 set_romload_baudrate(optarg); | |
43 continue; | |
44 case 'B': | |
45 br = find_baudrate_by_name(optarg); | |
46 if (!br) | |
47 exit(1); /* error msg already printed */ | |
48 xram_load_baudrate = br; | |
30 continue; | 49 continue; |
31 case 'h': | 50 case 'h': |
32 read_hwparam_file_shortname(optarg); | 51 read_hwparam_file_shortname(optarg); |
33 continue; | 52 continue; |
34 case 'H': | 53 case 'H': |
38 set_beacon_interval(optarg); | 57 set_beacon_interval(optarg); |
39 continue; | 58 continue; |
40 case '?': | 59 case '?': |
41 default: | 60 default: |
42 usage: fprintf(stderr, | 61 usage: fprintf(stderr, |
43 "usage: fc-xram [options] ttyport xramimage.srec\n"); | 62 "usage: fc-xram [options] ttyport xramimage.srec [runbaud]\n"); |
44 exit(1); | 63 exit(1); |
45 } | 64 } |
46 if (argc - optind != 2) | 65 if (argc - optind < 2) |
47 goto usage; | 66 goto usage; |
48 target_ttydev = argv[optind]; | 67 target_ttydev = argv[optind]; |
49 xramimage.filename = argv[optind+1]; | 68 xramimage.filename = argv[optind+1]; |
50 if (!iramimage.filename) | 69 if (!iramimage.filename) |
51 iramimage.filename = default_loadagent_image; | 70 iramimage.filename = default_loadagent_image; |
71 if (argc - optind >= 3) { | |
72 if (argc - optind > 3) | |
73 goto usage; | |
74 br = find_baudrate_by_name(argv[optind+2]); | |
75 if (!br) | |
76 exit(1); /* error msg already printed */ | |
77 xram_run_baudrate = br; | |
78 } | |
52 | 79 |
53 open_target_serial(); | 80 open_target_serial(); |
54 perform_romload(); | 81 perform_romload(); |
55 /* loadagent should be running now */ | 82 /* loadagent should be running now */ |
56 if (tpinterf_pass_output(1) < 0) | 83 if (tpinterf_pass_output(1) < 0) |
57 exit(1); | 84 exit(1); |
58 if (hw_init_script[0]) { | 85 if (hw_init_script[0]) { |
59 printf("Executing init script %s\n", hw_init_script); | 86 printf("Executing init script %s\n", hw_init_script); |
60 c = exec_init_script(hw_init_script); | 87 c = exec_init_script(hw_init_script); |
88 if (c) | |
89 exit(1); | |
90 } | |
91 if (xram_load_baudrate && xram_load_baudrate != current_baud_rate) { | |
92 c = loadagent_switch_baud(xram_load_baudrate); | |
61 if (c) | 93 if (c) |
62 exit(1); | 94 exit(1); |
63 } | 95 } |
64 printf("Sending XRAM image to loadagent\n"); | 96 printf("Sending XRAM image to loadagent\n"); |
65 perform_chain_load(); | 97 perform_chain_load(); |