• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include "init_reboot.h"
20 #include "begetctl.h"
21 
22 #define REBOOT_CMD_NUMBER 2
main_cmd(BShellHandle shell,int argc,char * argv[])23 static int main_cmd(BShellHandle shell, int argc, char* argv[])
24 {
25     if (argc > REBOOT_CMD_NUMBER) {
26         BShellCmdHelp(shell, argc, argv);
27         return 0;
28     }
29     int ret;
30     if (argc == REBOOT_CMD_NUMBER) {
31         ret = DoReboot(argv[1]);
32     } else {
33         ret = DoReboot(NULL);
34     }
35     if (ret != 0) {
36         printf("[reboot command] DoReboot Api return error\n");
37     } else {
38         printf("[reboot command] DoReboot Api return ok\n");
39     }
40 #ifndef STARTUP_INIT_TEST
41     while (1) {
42         pause();
43     }
44 #endif
45     return 0;
46 }
47 
MODULE_CONSTRUCTOR(void)48 MODULE_CONSTRUCTOR(void)
49 {
50     CmdInfo infos[] = {
51         {"reboot", main_cmd, "reboot system", "reboot", ""},
52         {"reboot", main_cmd, "shutdown system", "reboot shutdown[:options]", ""},
53         {"reboot", main_cmd, "suspend system", "reboot suspend", ""},
54         {"reboot", main_cmd, "reboot and boot into updater", "reboot updater", ""},
55         {"reboot", main_cmd, "reboot and boot into updater", "reboot updater[:options]", ""},
56         {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
57         {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd[:options]", ""},
58         {"reboot", main_cmd, "reboot and boot into charge", "reboot charge", ""},
59     };
60     for (size_t i = sizeof(infos) / sizeof(infos[0]); i > 0; i--) {
61         BShellEnvRegisterCmd(GetShellHandle(), &infos[i - 1]);
62     }
63 }
64