• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Unionman Technology 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 <errno.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/syscall.h>
21 
22 #define REBOOT_MAGIC1 0xfee1dead
23 #define REBOOT_MAGIC2 672274793
24 #define REBOOT_CMD_RESTART2 0xA1B2C3D4
25 
26 #define REBOOT_FASTBOOT_MODE "fastboot"
27 #define REBOOT_UPDATE_MODE "update"
28 
DoRebootCmd(const char * cmd)29 static int DoRebootCmd(const char *cmd)
30 {
31     return syscall(__NR_reboot, REBOOT_MAGIC1, REBOOT_MAGIC2, REBOOT_CMD_RESTART2, cmd);
32 }
33 
main(int argc,const char * argv[])34 int main(int argc, const char *argv[])
35 {
36     int ret = 0;
37 
38     if (argc <= 1L) {
39         printf("DoRebootCmd : update (usb burn) mode.\n");
40         ret = DoRebootCmd(REBOOT_UPDATE_MODE);
41     } else {
42         const char *cmd = argv[1];
43         if (strncmp(cmd, REBOOT_FASTBOOT_MODE, strlen(REBOOT_FASTBOOT_MODE)) == 0) {
44             printf("DoRebootCmd : fastboot mode.\n");
45             ret = DoRebootCmd(REBOOT_FASTBOOT_MODE);
46         } else {
47             ret = DoRebootCmd(cmd);
48         }
49     }
50 
51     if (ret != 0) {
52         printf("DoRebootCmd failed! (%d) %s\n", errno, strerror(errno));
53     } else {
54         printf("DoRebootCmd : OK\n");
55     }
56 
57     return ret;
58 }
59