FreeCalypso > hg > freecalypso-sw
annotate loadtools/ltmain.c @ 83:ebe258a85813
toolchain: binutils patch to emit the "short" form of Thumb->ARM call veneers
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 19 Aug 2013 05:16:34 +0000 |
parents | aa62352647f7 |
children | ccc5161848c7 |
rev | line source |
---|---|
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the main() function for fc-loadtool |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdint.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <unistd.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "srecreader.h" |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 extern char *target_ttydev; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 extern struct srecreader iramimage; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern char default_loadagent_image[]; |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
15 extern char hw_init_script[]; |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
23
diff
changeset
|
16 extern void (*default_exit)(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
23
diff
changeset
|
17 |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 main(argc, argv) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 char **argv; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 extern char *optarg; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 extern int optind; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 int c; |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
24 char command[512]; |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
51
aa62352647f7
loadtools: -b option works in fc-loadtool
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
26 while ((c = getopt(argc, argv, "a:b:h:H:i:")) != EOF) |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 switch (c) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 case 'a': |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 iramimage.filename = optarg; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 continue; |
51
aa62352647f7
loadtools: -b option works in fc-loadtool
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
31 case 'b': |
aa62352647f7
loadtools: -b option works in fc-loadtool
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
32 set_romload_baudrate(optarg); |
aa62352647f7
loadtools: -b option works in fc-loadtool
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
45
diff
changeset
|
33 continue; |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 case 'h': |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 read_hwparam_file_shortname(optarg); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 continue; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 case 'H': |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 read_hwparam_file_fullpath(optarg); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 continue; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 case 'i': |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 set_beacon_interval(optarg); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 continue; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 case '?': |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 default: |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 usage: fprintf(stderr, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 "usage: fc-loadtool [options] ttyport\n"); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 exit(1); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (argc - optind != 1) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 goto usage; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 target_ttydev = argv[optind]; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 if (!iramimage.filename) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 iramimage.filename = default_loadagent_image; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 open_target_serial(); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 perform_romload(); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 putchar('\n'); |
23
aca1948e9713
loadtool: initial version compiles and links
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
22
diff
changeset
|
58 if (tpinterf_pass_output(1) < 0) |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 exit(1); |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
60 putchar('\n'); |
45
16315ed6401a
init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
61 if (hw_init_script[0]) { |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
62 printf("Executing init script %s\n", hw_init_script); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
63 loadtool_exec_script(hw_init_script); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
64 } |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 for (;;) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 if (isatty(0)) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 fputs("loadtool> ", stdout); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 fflush(stdout); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 } |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
70 if (!fgets(command, sizeof command, stdin)) |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
23
diff
changeset
|
71 default_exit(); |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
72 loadtool_dispatch_cmd(command, 0); |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 } |