• 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 #ifndef SUPPORT_REBOOT_CHARGE
32         if (strncmp(argv[1], "charge", strlen("charge")) == 0) {
33             ret = DoReboot(NULL);
34         } else {
35             ret = DoReboot(argv[1]);
36         }
37 #else
38         ret = DoReboot(argv[1]);
39 #endif
40     } else {
41         ret = DoReboot(NULL);
42     }
43     if (ret != 0) {
44         printf("[reboot command] DoReboot Api return error\n");
45     } else {
46         printf("[reboot command] DoReboot Api return ok\n");
47     }
48 #ifndef STARTUP_INIT_TEST
49     while (1) {
50         pause();
51     }
52 #endif
53     return 0;
54 }
55 
MODULE_CONSTRUCTOR(void)56 MODULE_CONSTRUCTOR(void)
57 {
58     CmdInfo infos[] = {
59         {"reboot", main_cmd, "reboot system", "reboot", ""},
60         {"reboot", main_cmd, "shutdown system", "reboot shutdown[:options]", ""},
61         {"reboot", main_cmd, "suspend system", "reboot suspend", ""},
62         {"reboot", main_cmd, "reboot and boot into updater", "reboot updater", ""},
63         {"reboot", main_cmd, "reboot and boot into updater", "reboot updater[:options]", ""},
64         {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
65         {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd[:options]", ""},
66 #ifdef SUPPORT_REBOOT_CHARGE
67         {"reboot", main_cmd, "reboot and boot into charge", "reboot charge", ""},
68 #endif
69     };
70     for (size_t i = sizeof(infos) / sizeof(infos[0]); i > 0; i--) {
71         BShellEnvRegisterCmd(GetShellHandle(), &infos[i - 1]);
72     }
73 }
74