Skip to contentSkip to conversation

efi: stop hw watchdog during EBS

PATCH In review Casey Connolly 5 participants 9 messages Jan 19 – Jan 20

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi: stop hw watchdog during EBS

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---
 lib/efi_loader/efi_boottime.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index ddc935d22409..c34616db578a 100644
@@ -21,8 +21,9 @@
 #include <time.h>
 #include <u-boot/crc.h>
 #include <usb.h>
 #include <watchdog.h>
+#include <wdt.h>
 #include <asm/global_data.h>
 #include <linux/libfdt_env.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
 	efi_update_table_header_crc32(&systab.hdr);
 
 	/* Give the payload some time to boot */
 	efi_set_watchdog(0);
+	if (CONFIG_IS_ENABLED(WDT))
+		wdt_stop_all();
 	schedule();
 out:
 	if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
 		if (ret != EFI_SUCCESS)
Signature · 1 line
2.52.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Casey Connolly

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

Quoted 8 lines

As with the EFI watchdog, stop any hardware watchdogs as well.

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---

Quoted 31 lines
 lib/efi_loader/efi_boottime.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_boottime.c +3 -1
index ddc935d22409..c34616db578a 100644
@@ -21,8 +21,9 @@
 #include <time.h>
 #include <u-boot/crc.h>
 #include <usb.h>
 #include <watchdog.h>
+#include <wdt.h>
 #include <asm/global_data.h>
 #include <linux/libfdt_env.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
        efi_update_table_header_crc32(&systab.hdr);
 
        /* Give the payload some time to boot */
        efi_set_watchdog(0);
+       if (CONFIG_IS_ENABLED(WDT))
+               wdt_stop_all();
        schedule();
 out:
        if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
                if (ret != EFI_SUCCESS)
--

2.52.0

#2 lore raw
In reply to Casey Connolly
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog. I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken. Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

Quoted 38 lines

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---
 lib/efi_loader/efi_boottime.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index ddc935d22409..c34616db578a 100644
@@ -21,8 +21,9 @@
 #include <time.h>
 #include <u-boot/crc.h>
 #include <usb.h>
 #include <watchdog.h>
+#include <wdt.h>
 #include <asm/global_data.h>
 #include <linux/libfdt_env.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
 	efi_update_table_header_crc32(&systab.hdr);
 
 	/* Give the payload some time to boot */
 	efi_set_watchdog(0);
+	if (CONFIG_IS_ENABLED(WDT))
+		wdt_stop_all();
 	schedule();
 out:
 	if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
 		if (ret != EFI_SUCCESS)
Signature · 1 line
2.52.0
#3 lore raw
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog. I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken. Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Best regards

Heinrich

Quoted 39 lines
Quoted 39 lines

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---
  lib/efi_loader/efi_boottime.c | 3 +++
  1 file changed, 3 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index ddc935d22409..c34616db578a 100644
@@ -21,8 +21,9 @@
  #include <time.h>
  #include <u-boot/crc.h>
  #include <usb.h>
  #include <watchdog.h>
+#include <wdt.h>
  #include <asm/global_data.h>
  #include <linux/libfdt_env.h>
 
  DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
  	efi_update_table_header_crc32(&systab.hdr);
 
  	/* Give the payload some time to boot */
  	efi_set_watchdog(0);
+	if (CONFIG_IS_ENABLED(WDT))
+		wdt_stop_all();
  	schedule();
  out:
  	if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
  		if (ret != EFI_SUCCESS)
Signature · 1 line
2.52.0
#4 lore raw
Quoted 23 lines · Heinrich Schuchardt
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog.  I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken.  Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Quoted 7 lines

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Hmm, thanks for the suggestions. I considered doing this in some platform-specific way, but I don't think it's correct for U-Boot's default behaviour to leave watchdogs enabled, I haven't gone digging through the EFI spec but I would imagine it's not EFI compliant either?

I can totally understand why it would be desirable to leave the watchdog enabled, but I think boards that want/need that should have to opt-in rather than it being the upstream default.

Would you be ok with adding a new config option:
CONFIG_WATCHDOG_LEAVE_ENABLED or something along those lines? I'd rather avoid adding platform-specific workarounds to U-Boot's default behaviour like this.>

Quoted 44 lines

Best regards

Heinrich

Quoted 39 lines
Quoted 39 lines

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---
  lib/efi_loader/efi_boottime.c | 3 +++

  1 file changed, 3 insertions(+)
lib/efi_loader/ renamed from lib/efi_loader/efi_boottime.c +0 -0

efi_boottime.c
index ddc935d22409..c34616db578a 100644

lib/efi_loader/efi_boottime.c +3 -0
@@ -21,8 +21,9 @@
   #include <time.h>
   #include <u-boot/crc.h>
   #include <usb.h>
   #include <watchdog.h>
+#include <wdt.h>
   #include <asm/global_data.h>
   #include <linux/libfdt_env.h>
     DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI
 efi_exit_boot_services(efi_handle_t image_handle,
       efi_update_table_header_crc32(&systab.hdr);
         /* Give the payload some time to boot */
       efi_set_watchdog(0);
+    if (CONFIG_IS_ENABLED(WDT))
+        wdt_stop_all();
       schedule();

  out:
      if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
          if (ret != EFI_SUCCESS)
--
2.52.0

Signature · 1 line
// Casey (she/her)
#5 lore raw
Quoted 39 lines · Casey Connolly
Quoted 23 lines · Heinrich Schuchardt
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog.  I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken.  Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Quoted 7 lines

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Hmm, thanks for the suggestions. I considered doing this in some platform-specific way, but I don't think it's correct for U-Boot's default behaviour to leave watchdogs enabled, I haven't gone digging through the EFI spec but I would imagine it's not EFI compliant either?

Quoted 8 lines

I can totally understand why it would be desirable to leave the watchdog enabled, but I think boards that want/need that should have to opt-in rather than it being the upstream default.

Would you be ok with adding a new config option:
CONFIG_WATCHDOG_LEAVE_ENABLED or something along those lines? I'd rather avoid adding platform-specific workarounds to U-Boot's default behaviour like this.>

Why does CONFIG_WATCHDOG_AUTOSTART=n not work for your specific hardware?

Best regards

Heinrich

Quoted 45 lines
Quoted 44 lines

Best regards

Heinrich

Quoted 39 lines
Quoted 39 lines

---
Changes in v2:
* Fix compilation when CONFIG_WATCHDOG is disabled.

---
   lib/efi_loader/efi_boottime.c | 3 +++
   1 file changed, 3 insertions(+)
lib/efi_loader/ renamed from lib/efi_loader/efi_boottime.c +0 -0

efi_boottime.c
index ddc935d22409..c34616db578a 100644

lib/efi_loader/efi_boottime.c +3 -0
@@ -21,8 +21,9 @@
   #include <time.h>
   #include <u-boot/crc.h>
   #include <usb.h>
   #include <watchdog.h>
+#include <wdt.h>
   #include <asm/global_data.h>
   #include <linux/libfdt_env.h>
     DECLARE_GLOBAL_DATA_PTR;
@@ -2263,8 +2264,10 @@ static efi_status_t EFIAPI
 efi_exit_boot_services(efi_handle_t image_handle,
       efi_update_table_header_crc32(&systab.hdr);
         /* Give the payload some time to boot */
       efi_set_watchdog(0);
+    if (CONFIG_IS_ENABLED(WDT))
+        wdt_stop_all();
       schedule();
   out:
       if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
           if (ret != EFI_SUCCESS)
Signature · 1 line
2.52.0
#6 lore raw
In reply to Casey Connolly
Quoted 30 lines · Casey Connolly
Quoted 27 lines · Heinrich Schuchardt
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog.  I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken.  Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

Quoted 8 lines
Quoted 3 lines

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Hmm, thanks for the suggestions. I considered doing this in some platform-specific way, but I don't think it's correct for U-Boot's default behaviour to leave watchdogs enabled, I haven't gone digging through the EFI spec but I would imagine it's not EFI compliant either?

We've had some long discussions about this in the past. It's very much intentional that U-Boot leaves watchdogs running. As Heinrich noted (and is a summary of the older threads) some hardware doesn't even let you disable a watchdog. But it otherwise defeats the purpose of one to turn it off. Part of my feedback before was that the EFI spec needs to be addressed if it can't handle this correctly.

Signature · 1 line
Tom
#7 lore raw
Quoted 40 lines · Tom Rini
Quoted 30 lines · Casey Connolly
Quoted 27 lines · Heinrich Schuchardt
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog.  I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken.  Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

Quoted 8 lines
Quoted 3 lines

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Hmm, thanks for the suggestions. I considered doing this in some platform-specific way, but I don't think it's correct for U-Boot's default behaviour to leave watchdogs enabled, I haven't gone digging through the EFI spec but I would imagine it's not EFI compliant either?

Quoted 7 lines

We've had some long discussions about this in the past. It's very much intentional that U-Boot leaves watchdogs running. As Heinrich noted (and is a summary of the older threads) some hardware doesn't even let you disable a watchdog. But it otherwise defeats the purpose of one to turn it off. Part of my feedback before was that the EFI spec needs to be addressed if it can't handle this correctly.

The UEFI specification explicitly requires a 5 min watchdog to be enabled when starting an EFI binary. It should be disabled when returning to the boot manager. See chapter 7.5.1 EFI_BOOT_SERVICES.SetWatchdogTimer().

In 7.4.6 EFI_BOOT_SERVICES.ExitBootServices() the specification requires that "the boot services watchdog timer is disabled".

Both has has been implemented in U-Boot as a software watchdog because some hardware watchdogs don't support 5 min intervals.

A watchdog for the phase after ExitBootServices() is not described.

Setting CONFIG_WATCHDOG_AUTOSTART=n would comply with the specification.

Best regards

Heinrich

#8 lore raw
Quoted 58 lines · Heinrich Schuchardt
Quoted 40 lines · Tom Rini
Quoted 30 lines · Casey Connolly
Quoted 27 lines · Heinrich Schuchardt
Quoted 10 lines · Mark Kettenis
Quoted 9 lines

From: Casey Connolly <[email protected]>
Date: Mon, 19 Jan 2026 22:09:25 +0100

Hardware watchdogs don't currently get stopped as part of ExitBootServices, this can result in resets during boot if the OS doesn't have a driver for the watchdog, or if the driver isn't loaded in time.

As with the EFI watchdog, stop any hardware watchdogs as well.

Quoted 8 lines

This has been discussed before and rejected on the grounds that this defeats the purpose of the watchdog. I think there was some consensus that an OS that doesn't have a driver for the watchdog or doesn't load it in time is broken. Some folks also pointed out that on some platforms it isn't possible to disable the watchdog.

Ultimately, I think EFI needs an API to control the hardware watchdog, such that an OS doesn't need a driver.

The hardware watchdog interrupting an OS if it is hanging is intended behavior. It is required for recovering from a failed capsule update.

Some watchdog timers have a maximum timeout that is too short for booting (e.g. 16s on some Sunxi boards). To avoid resets these options are available:

Quoted 8 lines
Quoted 3 lines

* Set CONFIG_WATCHDOG_AUTOSTART=n.
* Use device-tree property u-boot,noautostart.
* Use the wdt stop command in PREBOOT.

Hmm, thanks for the suggestions. I considered doing this in some platform-specific way, but I don't think it's correct for U-Boot's default behaviour to leave watchdogs enabled, I haven't gone digging through the EFI spec but I would imagine it's not EFI compliant either?

Quoted 7 lines

We've had some long discussions about this in the past. It's very much intentional that U-Boot leaves watchdogs running. As Heinrich noted (and is a summary of the older threads) some hardware doesn't even let you disable a watchdog. But it otherwise defeats the purpose of one to turn it off. Part of my feedback before was that the EFI spec needs to be addressed if it can't handle this correctly.

The UEFI specification explicitly requires a 5 min watchdog to be enabled when starting an EFI binary. It should be disabled when returning to the boot manager. See chapter 7.5.1 EFI_BOOT_SERVICES.SetWatchdogTimer().

In 7.4.6 EFI_BOOT_SERVICES.ExitBootServices() the specification requires that "the boot services watchdog timer is disabled".

Quoted 6 lines

Both has has been implemented in U-Boot as a software watchdog because some hardware watchdogs don't support 5 min intervals.

A watchdog for the phase after ExitBootServices() is not described.

Setting CONFIG_WATCHDOG_AUTOSTART=n would comply with the specification.

I think both approaches have pros and cons.
There's a small period of time between the EFI stub (at least for linux ) calling EBS and the OS taking over, loading a watchdog driver and setting up keepalives.
Keeping the watchdog enabled, will obviously revive the board if something goes wrong between EBS and loading the driver. OTOH if the hardware watchdog doesn't support big intervals between keepalives, you might end up rebooting for no reason. As you all mentioned this has been discussed extensively so I agree not too change the current behavior after all.

Regards
/Ilias

Quoted 4 lines

Best regards

Heinrich