1 /*
2 * Copyright (c) 2012 Google, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <debug.h>
24 #include <err.h>
25 #include <compiler.h>
26 #include <platform.h>
27 #include <platform/debug.h>
28 #include <kernel/thread.h>
29 #include <stdio.h>
30 #include <lib/console.h>
31 #include <version.h>
32
33 /*
34 * default implementations of these routines, if the platform code
35 * chooses not to implement.
36 */
platform_halt(platform_halt_action suggested_action,platform_halt_reason reason)37 __WEAK void platform_halt(platform_halt_action suggested_action,
38 platform_halt_reason reason)
39 {
40 #if ENABLE_PANIC_SHELL
41
42 if (reason == HALT_REASON_SW_PANIC) {
43 dprintf(ALWAYS, "CRASH: starting debug shell... (reason = %d)\n", reason);
44 arch_disable_ints();
45 panic_shell_start();
46 }
47
48 #endif // ENABLE_PANIC_SHELL
49
50 dprintf(ALWAYS, "%s\n", lk_version);
51 dprintf(ALWAYS, "HALT: spinning forever... (reason = %d)\n", reason);
52 arch_disable_ints();
53 for (;;);
54 }
55
56 #if WITH_LIB_CONSOLE
57
58 #include <lib/console.h>
59
cmd_reboot(int argc,const cmd_args * argv)60 static int cmd_reboot(int argc, const cmd_args *argv)
61 {
62 platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_RESET);
63 return 0;
64 }
65
cmd_poweroff(int argc,const cmd_args * argv)66 static int cmd_poweroff(int argc, const cmd_args *argv)
67 {
68 platform_halt(HALT_ACTION_SHUTDOWN, HALT_REASON_SW_RESET);
69 return 0;
70 }
71
72 STATIC_COMMAND_START
73 #if LK_DEBUGLEVEL > 1
74 STATIC_COMMAND("reboot", "soft reset", &cmd_reboot)
75 STATIC_COMMAND("poweroff", "powerdown", &cmd_poweroff)
76 #endif
77 STATIC_COMMAND_END(platform_power);
78
79 #endif
80