2019-06-20 20:03:38 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
/*
|
|
|
|
* Reboot the device to a specific mode
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Daniele Debernardi <drebrez@gmail.com>
|
|
|
|
*/
|
2019-08-07 19:00:12 +00:00
|
|
|
#include <errno.h>
|
2019-06-25 06:29:37 +00:00
|
|
|
#include <linux/reboot.h>
|
2019-06-20 20:03:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/syscall.h>
|
2019-06-25 06:29:37 +00:00
|
|
|
#include <unistd.h>
|
2019-06-20 20:03:38 +00:00
|
|
|
|
2019-06-25 06:29:37 +00:00
|
|
|
void usage(char *appname)
|
2019-06-20 20:03:38 +00:00
|
|
|
{
|
|
|
|
printf("Usage: %s [-h] MODE\n\n", appname);
|
|
|
|
printf("Reboot the device to the MODE specified (e.g. recovery, bootloader)\n\n");
|
|
|
|
printf("WARNING: the reboot is instantaneous\n\n");
|
|
|
|
printf("optional arguments:\n");
|
|
|
|
printf(" -h Show this help message and exit\n");
|
|
|
|
}
|
|
|
|
|
2019-06-25 06:29:37 +00:00
|
|
|
int main(int argc, char **argv)
|
2019-06-20 20:03:38 +00:00
|
|
|
{
|
2019-06-25 06:29:37 +00:00
|
|
|
if (argc != 2) {
|
2019-06-20 20:03:38 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int opt;
|
2019-06-25 06:29:37 +00:00
|
|
|
while ((opt = getopt(argc, argv, "h")) != -1) {
|
|
|
|
switch (opt) {
|
2019-06-20 20:03:38 +00:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sync();
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, argv[1]);
|
|
|
|
|
2019-08-07 19:00:12 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
printf("Error: %s\n", strerror(errno));
|
2019-06-20 20:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|