boot command: Allow to enable watchdog
Enabling the watchdog before booting the kernel is a common usecase. Add an option to the boot command and also add a global variable for it to make it configurable easily. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
aba382e7af
commit
fe36276112
1 changed files with 25 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <environment.h>
|
#include <environment.h>
|
||||||
#include <globalvar.h>
|
#include <globalvar.h>
|
||||||
#include <magicvar.h>
|
#include <magicvar.h>
|
||||||
|
#include <watchdog.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <readkey.h>
|
#include <readkey.h>
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
@ -24,6 +25,7 @@
|
||||||
#include <clock.h>
|
#include <clock.h>
|
||||||
#include <boot.h>
|
#include <boot.h>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
|
#include <init.h>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <complete.h>
|
#include <complete.h>
|
||||||
|
@ -71,10 +73,28 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int boot_watchdog_timeout;
|
||||||
|
|
||||||
|
static int init_boot_watchdog_timeout(void)
|
||||||
|
{
|
||||||
|
return globalvar_add_simple_int("boot.watchdog_timeout",
|
||||||
|
&boot_watchdog_timeout, "%u");
|
||||||
|
}
|
||||||
|
late_initcall(init_boot_watchdog_timeout);
|
||||||
|
|
||||||
|
BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
|
||||||
|
"Watchdog enable timeout in seconds before booting");
|
||||||
|
|
||||||
static int boot_entry(struct blspec_entry *be)
|
static int boot_entry(struct blspec_entry *be)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
|
||||||
|
ret = watchdog_set_timeout(boot_watchdog_timeout);
|
||||||
|
if (ret)
|
||||||
|
pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
|
||||||
|
}
|
||||||
|
|
||||||
if (be->scriptpath) {
|
if (be->scriptpath) {
|
||||||
ret = boot_script(be->scriptpath);
|
ret = boot_script(be->scriptpath);
|
||||||
} else {
|
} else {
|
||||||
|
@ -375,7 +395,7 @@ static int do_boot(int argc, char *argv[])
|
||||||
dryrun = 0;
|
dryrun = 0;
|
||||||
timeout = -1;
|
timeout = -1;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "vldmt:")) > 0) {
|
while ((opt = getopt(argc, argv, "vldmt:w:")) > 0) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
|
@ -392,6 +412,9 @@ static int do_boot(int argc, char *argv[])
|
||||||
case 't':
|
case 't':
|
||||||
timeout = simple_strtoul(optarg, NULL, 0);
|
timeout = simple_strtoul(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
boot_watchdog_timeout = simple_strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,6 +500,7 @@ BAREBOX_CMD_HELP_OPT ("-v","Increase verbosity")
|
||||||
BAREBOX_CMD_HELP_OPT ("-d","Dryrun. See what happens but do no actually boot")
|
BAREBOX_CMD_HELP_OPT ("-d","Dryrun. See what happens but do no actually boot")
|
||||||
BAREBOX_CMD_HELP_OPT ("-l","List available boot sources")
|
BAREBOX_CMD_HELP_OPT ("-l","List available boot sources")
|
||||||
BAREBOX_CMD_HELP_OPT ("-m","Show a menu with boot options")
|
BAREBOX_CMD_HELP_OPT ("-m","Show a menu with boot options")
|
||||||
|
BAREBOX_CMD_HELP_OPT ("-w SECS","Start watchdog with timeout SECS before booting")
|
||||||
BAREBOX_CMD_HELP_OPT ("-t SECS","specify timeout in SECS")
|
BAREBOX_CMD_HELP_OPT ("-t SECS","specify timeout in SECS")
|
||||||
BAREBOX_CMD_HELP_END
|
BAREBOX_CMD_HELP_END
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue