From 4a5a3b2d643eac1e05d280e0cc6c9631fa775d39 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Wed, 6 Sep 2023 18:32:04 +0200 Subject: [PATCH] cmdline: add reboot_timeout option In case communication with KTF is not possible (no PS/2 keyboard nor UART port) add an option to automatically reboot after specified amount of time. The reboot_timeout by default is off. Value 0 means reboot immediately. Values unit is seconds. Please note a timer needs to be enabled for this functionality to work. Signed-off-by: Pawel Wieczorkiewicz --- common/cmdline.c | 3 +++ common/kernel.c | 12 ++++++++++++ include/cmdline.h | 1 + 3 files changed, 16 insertions(+) diff --git a/common/cmdline.c b/common/cmdline.c index dc7da9c5..2c9c369e 100644 --- a/common/cmdline.c +++ b/common/cmdline.c @@ -73,6 +73,9 @@ string_cmd("com4", opt_com4); bool opt_fb_scroll = true; bool_cmd("fb_scroll", opt_fb_scroll); +unsigned long opt_reboot_timeout = -1; +ulong_cmd("reboot_timeout", opt_reboot_timeout); + const char *kernel_cmdline; void __text_init cmdline_parse(const char *cmdline) { diff --git a/common/kernel.c b/common/kernel.c index 180ae4a9..fe280ed0 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef KTF_PMU #include #endif @@ -44,9 +45,20 @@ void reboot(void) { } static void __noreturn echo_loop(void) { + long reboot_timeout = (long) opt_reboot_timeout; + time_t start_time = get_timer_ticks(); + + if (reboot_timeout == 0) + reboot(); + while (1) { io_delay(); keyboard_process_keys(); + + if (reboot_timeout > 0) { + if (get_timer_ticks() - start_time >= MS(opt_reboot_timeout)) + reboot(); + } } } diff --git a/include/cmdline.h b/include/cmdline.h index aa6a5188..56b2c107 100644 --- a/include/cmdline.h +++ b/include/cmdline.h @@ -68,6 +68,7 @@ extern bool opt_fpu; extern bool opt_qemu_console; extern bool opt_poweroff; extern bool opt_fb_scroll; +extern unsigned long opt_reboot_timeout; extern const char *kernel_cmdline;