Skip to content

Commit

Permalink
cmdline: add reboot_timeout option
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wipawel committed Sep 7, 2023
1 parent 00a736e commit 4a5a3b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <percpu.h>
#include <sched.h>
#include <setup.h>
#include <time.h>
#ifdef KTF_PMU
#include <perfmon/pfmlib.h>
#endif
Expand All @@ -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();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions include/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4a5a3b2

Please sign in to comment.