Skip to content

Commit 178301b

Browse files
committed
Change default reboot to SOC reset from WDT reset
Fixes #460 Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 4e18aff commit 178301b

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

doc/config/runlevels.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,22 @@ sync(2) has been called, twice.
165165

166166
> "On Linux, sync is only guaranteed to schedule the dirty blocks for
167167
> writing; it can actually take a short time before all the blocks are
168-
> finally written.
168+
> finally written.
169+
170+
**Syntax:** `reboot-watchdog <on|off|true|false|1|0>`
171+
172+
Controls whether the system should reboot via the watchdog timer (WDT)
173+
or directly via the SoC/kernel. When enabled, Finit will:
174+
175+
1. Send `SIGPWR` to the registered watchdog daemon before shutdown
176+
2. Send `SIGTERM` to the watchdog daemon and wait up to 10 seconds
177+
for the watchdog to trigger a hardware reset
178+
179+
When disabled (default), Finit skips the watchdog reboot logic and
180+
calls the kernel's `reboot(2)` syscall directly for a clean SoC reboot.
181+
182+
*Default:* off (reboot via SoC)
183+
184+
> [!NOTE]
185+
> This setting only affects reboots. The watchdog daemon will still
186+
> run and monitor the system during normal operation.

doc/watchdog.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ many embedded systems this is crucial to ensure all circuits on the
1010
board are properly reset for the next boot, in effect ensuring the
1111
system works the same after both a power-on and reboot event.
1212

13+
> [!NOTE]
14+
> The watchdog reboot delegation can be enabled with the `reboot-watchdog`
15+
> configuration option in `/etc/finit.conf`. By default this is disabled
16+
> and the system reboots directly via the SoC using the kernel's `reboot(2)`
17+
> syscall. See [Runlevels](config/runlevels.md) for details.
18+
1319
The delegation is performed at the very last steps of system shutdown,
14-
if reboot has been selected and an elected watchdog is known, first a
15-
`SIGPWR` is sent to advise watchdogd of the pending reboot. Then, when
16-
the necessary steps of preparing the system for shutdown (umount etc.)
17-
are completed, Finit sends `SIGTERM` to watchdogd and puts itself in a
18-
10 sec timeout loop waiting for the WDT to reset the board. If a reset
19-
is not done before the timeout, Finit falls back to`reboot(RB_AUTOBOOT)`
20-
which tells the kernel to do the reboot.
20+
if reboot has been selected, `reboot-watchdog` is enabled, and an elected
21+
watchdog is known. First a `SIGPWR` is sent to advise watchdogd of the
22+
pending reboot. Then, when the necessary steps of preparing the system
23+
for shutdown (umount etc.) are completed, Finit sends `SIGTERM` to
24+
watchdogd and puts itself in a 10 sec timeout loop waiting for the WDT
25+
to reset the board. If a reset is not done before the timeout, Finit
26+
falls back to `reboot(RB_AUTOBOOT)` which tells the kernel to do the
27+
reboot.
2128

2229
An external watchdog service can also be used. The more advanced cousin
2330
[watchdogd](https://github.com/troglobit/watchdogd/) is the recommended

src/conf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int single = 0; /* single user mode from kernel cmdline */
6060
int bootstrap = 1; /* set while bootstrapping (for TTYs) */
6161
int kerndebug = 0; /* set if /proc/sys/kernel/printk > 7 */
6262
int syncsec = 0; /* reboot delay */
63+
int wdtreboot = 0; /* reboot via watchdog, default: SOC */
6364
int readiness = SVC_NOTIFY_PID;
6465
char *finit_conf= NULL;
6566
char *finit_rcsd= NULL;
@@ -1034,6 +1035,11 @@ static int parse_static(char *line, int is_rcsd)
10341035
return 0;
10351036
}
10361037

1038+
if (MATCH_CMD(line, "reboot-watchdog ", x)) {
1039+
wdtreboot = get_bool(strip_line(x), 0);
1040+
return 0;
1041+
}
1042+
10371043
/*
10381044
* Periodic check and instability index leveler, seconds
10391045
*/

src/conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern int single;
3737
extern int bootstrap;
3838
extern int kerndebug;
3939
extern int syncsec;
40+
extern int wdtreboot;
4041
extern int readiness;
4142
extern char *fstab;
4243
extern char *sdown;

src/sig.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void do_shutdown(shutop_t op)
358358
return;
359359
}
360360

361-
if (wdog) {
361+
if (wdtreboot && wdog) {
362362
print(kill(wdog->pid, SIGPWR) == 1, "Advising watchdog, system going down");
363363
do_sleep(2);
364364
}
@@ -405,17 +405,17 @@ void do_shutdown(shutop_t op)
405405

406406
/* Reboot via watchdog or kernel, or shutdown? */
407407
if (op == SHUT_REBOOT) {
408-
print(0, "Rebooting ...");
409-
if (wdog && wdog->pid > 1) {
408+
if (wdtreboot && wdog && wdog->pid > 1) {
410409
int timeout = 10;
411410

412411
/* Wait here until the WDT reboots, or timeout with fallback */
412+
print(0, "Rebooting using WDT, please wait ...");
413413
print(kill(wdog->pid, SIGTERM) == 1, "Pending watchdog reboot");
414414
while (timeout--)
415415
do_sleep(1);
416416
}
417417

418-
dbg("Rebooting ...");
418+
print(0, "Rebooting ...");
419419
reboot(RB_AUTOBOOT);
420420
} else if (op == SHUT_OFF) {
421421
print(0, "Powering down ...");

0 commit comments

Comments
 (0)