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 8, 2023
1 parent 7501b51 commit a40e3db
Show file tree
Hide file tree
Showing 3 changed files with 13 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 = 0; /* Disabled by default */
ulong_cmd("reboot_timeout", opt_reboot_timeout);

const char *kernel_cmdline;

void __text_init cmdline_parse(const char *cmdline) {
Expand Down
9 changes: 9 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 @@ -47,9 +48,17 @@ void reboot(void) {
}

static void __noreturn echo_loop(void) {
time_t reboot_timeout = opt_reboot_timeout * 1000; /* ms */
time_t start_time = get_timer_ticks();

while (1) {
io_delay();
keyboard_process_keys();

if (reboot_timeout > 0) {
if (get_timer_ticks() - start_time >= 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 a40e3db

Please sign in to comment.