FreeCalypso > hg > freecalypso-sw
annotate loadtools/ltexit.c @ 55:278052b6afda
loadtools: started laying the foundation for flash support
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 20:13:59 +0000 |
parents | 768a3d012931 |
children | 6f8d3771aa6c |
rev | line source |
---|---|
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the loadtool exit command, along with its |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * options for jump-reboot or eventual Iota power-off. |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 static void |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 exit_bare() |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 exit(0); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 } |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 static void |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 exit_jump0() |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 static char *jump0_argv[3] = {"jump", "0", 0}; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 tpinterf_make_cmd(jump0_argv); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 tpinterf_send_cmd(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 exit(0); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 } |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 void (*default_exit)() = exit_bare; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 static struct kwtab { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 char *kw; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 void (*func)(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } exit_modes[] = { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 {"bare", exit_bare}, |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 {"jump0", exit_jump0}, |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 {0, 0} |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 }; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 cmd_exit(argc, argv) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 char **argv; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 struct kwtab *tp; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 if (argc < 2) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 default_exit(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 for (tp = exit_modes; tp->kw; tp++) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 if (!strcmp(tp->kw, argv[1])) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 break; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (!tp->func) { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 fprintf(stderr, |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 "error: \"%s\" is not an understood exit mode\n", |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 argv[1]); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(-1); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 tp->func(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } |
28
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
56 |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
57 /* called from hwparam.c config file parser */ |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
58 void |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
59 set_default_exit_mode(arg, filename_for_errs, lineno_for_errs) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
60 char *arg; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
61 char *filename_for_errs; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
62 int lineno_for_errs; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
63 { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
64 char *cp; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
65 struct kwtab *tp; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
66 |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
67 while (isspace(*arg)) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
68 arg++; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
69 if (!*arg) { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
70 fprintf(stderr, |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
71 "%s line %d: exit-mode setting requires an argument\n", |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
72 filename_for_errs, lineno_for_errs); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
73 exit(1); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
74 } |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
75 for (cp = arg; *cp && !isspace(*cp); cp++) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
76 ; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
77 *cp = '\0'; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
78 for (tp = exit_modes; tp->kw; tp++) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
79 if (!strcmp(tp->kw, arg)) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
80 break; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
81 if (!tp->func) { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
82 fprintf(stderr, |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
83 "%s line %d: \"%s\" is not an understood exit mode\n", |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
84 filename_for_errs, lineno_for_errs, arg); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
85 exit(1); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
86 } |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
87 default_exit = tp->func; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
88 } |