FreeCalypso > hg > freecalypso-sw
annotate loadtools/ltexit.c @ 275:cedf09b6b5ac
started laying the foundation for fc-fsio host utility
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Feb 2014 20:27:15 +0000 |
parents | 6f8d3771aa6c |
children | 134c047c1269 |
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 |
85
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
18 exit_gta02_cutpwr() |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
19 { |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
20 #ifdef GTA0x_AP_BUILD |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
21 set_gta_modem_power_ctrl(0); |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
22 #endif |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
23 exit(0); |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
24 } |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
25 |
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
26 static void |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 exit_jump0() |
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 char *jump0_argv[3] = {"jump", "0", 0}; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 tpinterf_make_cmd(jump0_argv); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 tpinterf_send_cmd(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 exit(0); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 } |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 void (*default_exit)() = exit_bare; |
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 static struct kwtab { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 char *kw; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 void (*func)(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 } exit_modes[] = { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 {"bare", exit_bare}, |
85
6f8d3771aa6c
loadtools for GTA0x AP: GTA02 modem power-off implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
28
diff
changeset
|
43 {"gta02-cutpwr", exit_gta02_cutpwr}, |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 {"jump0", exit_jump0}, |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 {0, 0} |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 }; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 cmd_exit(argc, argv) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 char **argv; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 struct kwtab *tp; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 if (argc < 2) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 default_exit(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 for (tp = exit_modes; tp->kw; tp++) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 if (!strcmp(tp->kw, argv[1])) |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 break; |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 if (!tp->func) { |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 fprintf(stderr, |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 "error: \"%s\" is not an understood exit mode\n", |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 argv[1]); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 return(-1); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 } |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 tp->func(); |
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |
28
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 /* called from hwparam.c config file parser */ |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
68 void |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
69 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
|
70 char *arg; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
71 char *filename_for_errs; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
72 int lineno_for_errs; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
73 { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
74 char *cp; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
75 struct kwtab *tp; |
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 while (isspace(*arg)) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
78 arg++; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
79 if (!*arg) { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
80 fprintf(stderr, |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
81 "%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
|
82 filename_for_errs, lineno_for_errs); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
83 exit(1); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
84 } |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
85 for (cp = arg; *cp && !isspace(*cp); cp++) |
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 *cp = '\0'; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
88 for (tp = exit_modes; tp->kw; tp++) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
89 if (!strcmp(tp->kw, arg)) |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
90 break; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
91 if (!tp->func) { |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
92 fprintf(stderr, |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
93 "%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
|
94 filename_for_errs, lineno_for_errs, arg); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
95 exit(1); |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
96 } |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
97 default_exit = tp->func; |
768a3d012931
loadtool: default exit mode setting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
98 } |