init_cmd_reboot.c 2.7 KB
Newer Older
H
handyohos 已提交
1
/*
X
xionglei6 已提交
2
 * Copyright (c) 2022 Huawei Device Co., Ltd.
H
handyohos 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "init_reboot.h"
#include "begetctl.h"

#define REBOOT_CMD_NUMBER 2
X
xionglei6 已提交
23
static int main_cmd(BShellHandle shell, int argc, char* argv[])
H
handyohos 已提交
24 25
{
    if (argc > REBOOT_CMD_NUMBER) {
X
xionglei6 已提交
26
        BShellCmdHelp(shell, argc, argv);
H
handyohos 已提交
27 28 29 30 31
        return 0;
    }

    if (argc == REBOOT_CMD_NUMBER && strcmp(argv[1], "shutdown") != 0 &&
        strcmp(argv[1], "updater") != 0 &&
X
xionglei6 已提交
32
        strcmp(argv[1], "suspend") != 0 &&
H
handyohos 已提交
33
        strcmp(argv[1], "flashd") != 0 &&
X
xionglei6 已提交
34
#ifdef INIT_TEST
M
Mupceet 已提交
35
        strcmp(argv[1], "charge") != 0 &&
X
xionglei6 已提交
36
#endif
Y
yanghongliang 已提交
37 38 39
#ifdef PRODUCT_RK
        strcmp(argv[1], "loader") != 0 &&
#endif
H
handyohos 已提交
40 41
        strncmp(argv[1], "updater:", strlen("updater:")) != 0 &&
        strncmp(argv[1], "flashd:", strlen("flashd:")) != 0) {
X
xionglei6 已提交
42
        BShellCmdHelp(shell, argc, argv);
H
handyohos 已提交
43 44
        return 0;
    }
X
xionglei6 已提交
45
    int ret;
H
handyohos 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    if (argc == REBOOT_CMD_NUMBER) {
        ret = DoReboot(argv[1]);
    } else {
        ret = DoReboot(NULL);
    }
    if (ret != 0) {
        printf("[reboot command] DoReboot Api return error\n");
    } else {
        printf("[reboot command] DoReboot Api return ok\n");
    }
    while (1) {
        pause();
    }
    return 0;
}

X
xionglei6 已提交
62
MODULE_CONSTRUCTOR(void)
H
handyohos 已提交
63
{
X
xionglei6 已提交
64 65 66
    CmdInfo infos[] = {
        {"reboot", main_cmd, "reboot system", "reboot", ""},
        {"reboot", main_cmd, "shutdown system", "reboot shutdown", ""},
X
xionglei6 已提交
67
        {"reboot", main_cmd, "suspend system", "reboot suspend", ""},
X
xionglei6 已提交
68 69 70 71
        {"reboot", main_cmd, "reboot and boot into updater", "reboot updater", ""},
        {"reboot", main_cmd, "reboot and boot into updater", "reboot updater[:options]", ""},
        {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
        {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd[:options]", ""},
X
xionglei6 已提交
72
#ifdef INIT_TEST
M
Mupceet 已提交
73
        {"reboot", main_cmd, "reboot and boot into charge", "reboot charge", ""},
X
xionglei6 已提交
74
#endif
X
xionglei6 已提交
75 76 77 78 79
#ifdef PRODUCT_RK
        {"reboot", main_cmd, "reboot loader", "reboot loader", ""}
#endif
    };
    for (size_t i = sizeof(infos) / sizeof(infos[0]); i > 0; i--) {
C
cheng_jinsong 已提交
80
        BShellEnvRegisterCmd(GetShellHandle(), &infos[i - 1]);
X
xionglei6 已提交
81
    }
H
handyohos 已提交
82
}