comparison loadtools/ltexit.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 96332d875fc9
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module implements the loadtool exit command, along with its
3 * options for jump-reboot and Iota power-off.
4 */
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdlib.h>
10
11 static void
12 exit_bare()
13 {
14 exit(0);
15 }
16
17 static void
18 exit_gta02_cutpwr()
19 {
20 #ifdef GTA0x_AP_BUILD
21 set_gta_modem_power_ctrl(0);
22 #endif
23 exit(0);
24 }
25
26 static void
27 exit_iotaoff()
28 {
29 static char *poweroff_argv[2] = {"poweroff", 0};
30
31 tpinterf_make_cmd(poweroff_argv);
32 tpinterf_send_cmd();
33 exit(0);
34 }
35
36 static void
37 exit_jump0()
38 {
39 static char *jump0_argv[3] = {"jump", "0", 0};
40
41 tpinterf_make_cmd(jump0_argv);
42 tpinterf_send_cmd();
43 exit(0);
44 }
45
46 void (*default_exit)() = exit_bare;
47
48 static struct kwtab {
49 char *kw;
50 void (*func)();
51 } exit_modes[] = {
52 {"bare", exit_bare},
53 {"gta02-cutpwr", exit_gta02_cutpwr},
54 {"iota-off", exit_iotaoff},
55 {"jump0", exit_jump0},
56 {0, 0}
57 };
58
59 cmd_exit(argc, argv)
60 char **argv;
61 {
62 struct kwtab *tp;
63
64 if (argc < 2)
65 default_exit();
66 for (tp = exit_modes; tp->kw; tp++)
67 if (!strcmp(tp->kw, argv[1]))
68 break;
69 if (!tp->func) {
70 fprintf(stderr,
71 "error: \"%s\" is not an understood exit mode\n",
72 argv[1]);
73 return(-1);
74 }
75 tp->func();
76 }
77
78 /* called from hwparam.c config file parser */
79 void
80 set_default_exit_mode(arg, filename_for_errs, lineno_for_errs)
81 char *arg;
82 char *filename_for_errs;
83 int lineno_for_errs;
84 {
85 char *cp;
86 struct kwtab *tp;
87
88 while (isspace(*arg))
89 arg++;
90 if (!*arg) {
91 fprintf(stderr,
92 "%s line %d: exit-mode setting requires an argument\n",
93 filename_for_errs, lineno_for_errs);
94 exit(1);
95 }
96 for (cp = arg; *cp && !isspace(*cp); cp++)
97 ;
98 *cp = '\0';
99 for (tp = exit_modes; tp->kw; tp++)
100 if (!strcmp(tp->kw, arg))
101 break;
102 if (!tp->func) {
103 fprintf(stderr,
104 "%s line %d: \"%s\" is not an understood exit mode\n",
105 filename_for_errs, lineno_for_errs, arg);
106 exit(1);
107 }
108 default_exit = tp->func;
109 }