annotate loadtools/ltmain.c @ 23:aca1948e9713

loadtool: initial version compiles and links
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 04 May 2013 04:52:05 +0000
parents e658a84b37df
children ae6294b8a015
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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[];
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char loadtool_command[512];
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
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;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 while ((c = getopt(argc, argv, "a:h:H:i:")) != EOF)
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 switch (c) {
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 case 'a':
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 iramimage.filename = optarg;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 continue;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 case 'h':
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 read_hwparam_file_shortname(optarg);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 continue;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 case 'H':
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 read_hwparam_file_fullpath(optarg);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 continue;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 case 'i':
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 set_beacon_interval(optarg);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 continue;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case '?':
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 default:
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 usage: fprintf(stderr,
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 "usage: fc-loadtool [options] ttyport\n");
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 exit(1);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 }
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (argc - optind != 1)
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 goto usage;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 target_ttydev = argv[optind];
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (!iramimage.filename)
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 iramimage.filename = default_loadagent_image;
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 open_target_serial();
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 perform_romload();
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 putchar('\n');
23
aca1948e9713 loadtool: initial version compiles and links
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 22
diff changeset
54 if (tpinterf_pass_output(1) < 0)
22
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 exit(1);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 for (;;) {
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 if (isatty(0)) {
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 fputs("loadtool> ", stdout);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 fflush(stdout);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 }
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 if (!fgets(loadtool_command, sizeof loadtool_command, stdin))
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 exit(0);
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 loadtool_dispatch_cmd();
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 }
e658a84b37df loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }