summaryrefslogtreecommitdiff
path: root/include/os.h
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2022-09-27 11:54:04 +0200
committerStefan Roese <sr@denx.de>2022-10-24 11:10:21 +0200
commit10107efedd5ffe68b36a7d79bd561ee966cbb2f8 (patch)
tree28447d0025e3208adffdc591953ffcc45d9e7262 /include/os.h
parent27836705839c4751ac28239ee6fa1f3984e46d4d (diff)
sandbox: add SIGALRM-based watchdog device
In order to test that U-Boot actually maintains the watchdog device(s) during long-running busy-loops, such as those where we wait for the user to stop autoboot, we need a watchdog device that actually does something during those loops; we cannot test that behaviour via the DM test framework. So introduce a relatively simple watchdog device which is simply based on calling the host OS' alarm() function; that has the nice property that a new call to alarm() simply sets a new deadline, and alarm(0) cancels any existing alarm. These properties are precisely what we need to implement start/reset/stop. We install our own handler so that we get a known message printed if and when the watchdog fires, and by just invoking that handler directly, we get expire_now for free. The actual calls to the various OS functions (alarm, signal, raise) need to be done in os.c, and since the driver code cannot get access to the values of SIGALRM or SIG_DFL (that would require including a host header, and that's only os.c which can do that), we cannot simply do trivial wrappers for signal() and raise(), but instead create specialized functions just for use by this driver. Apart from enabling this driver for sandbox{,64}_defconfig, also enable the wdt command which was useful for hand-testing this new driver (especially with running u-boot under strace). Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Diffstat (limited to 'include/os.h')
-rw-r--r--include/os.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/os.h b/include/os.h
index 5b353ae9d9..54874f5e0e 100644
--- a/include/os.h
+++ b/include/os.h
@@ -109,6 +109,23 @@ int os_unlink(const char *pathname);
void os_exit(int exit_code) __attribute__((noreturn));
/**
+ * os_alarm() - access to the OS alarm() system call
+ */
+unsigned int os_alarm(unsigned int seconds);
+
+/**
+ * os_set_alarm_handler() - set handler for SIGALRM
+ *
+ * @handler: The handler function. Pass NULL for SIG_DFL.
+ */
+void os_set_alarm_handler(void (*handler)(int));
+
+/**
+ * os_raise_sigalrm() - do raise(SIGALRM)
+ */
+void os_raise_sigalrm(void);
+
+/**
* os_tty_raw() - put tty into raw mode to mimic serial console better
*
* @fd: File descriptor of stdin (normally 0)