Module Name:    src
Committed By:   jmcneill
Date:           Sun Jun 20 19:10:47 UTC 2021

Modified Files:
        src/sys/stand/efiboot: Makefile.efiboot efiblock.c efiboot.h version
Added Files:
        src/sys/stand/efiboot: efiwatchdog.c

Log Message:
Add support for the boot services watchdog and pet it on every block I/O
access. For slow media (like ISO image redirection on Lenovo HR330A BMC)
this is needed because otherwise the default watchdog timeout fires before
we can finish loading the kernel from install media.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiwatchdog.c
cvs rdiff -u -r1.25 -r1.26 src/sys/stand/efiboot/version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.21 src/sys/stand/efiboot/Makefile.efiboot:1.22
--- src/sys/stand/efiboot/Makefile.efiboot:1.21	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.21 2021/05/27 06:54:45 mrg Exp $
+# $NetBSD: Makefile.efiboot,v 1.22 2021/06/20 19:10:47 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -24,7 +24,8 @@ SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
 		module.c overlay.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c \
-		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
+		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c efiwatchdog.c \
+	       	smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.11 src/sys/stand/efiboot/efiblock.c:1.12
--- src/sys/stand/efiboot/efiblock.c:1.11	Wed May 26 09:42:36 2021
+++ src/sys/stand/efiboot/efiblock.c	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.11 2021/05/26 09:42:36 mrg Exp $ */
+/* $NetBSD: efiblock.c,v 1.12 2021/06/20 19:10:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -38,6 +38,9 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+#define	EFI_BLOCK_TIMEOUT	120
+#define	EFI_BLOCK_TIMEOUT_CODE	0x810c0000
+
 /*
  * The raidframe support is basic.  Ideally, it should be expanded to
  * consider raid volumes a first-class citizen like the x86 efiboot does,
@@ -605,6 +608,8 @@ efi_block_strategy(void *devdata, int rw
 	if (rw != F_READ)
 		return EROFS;
 
+	efi_set_watchdog(EFI_BLOCK_TIMEOUT, EFI_BLOCK_TIMEOUT_CODE);
+
 	switch (bpart->type) {
 	case EFI_BLOCK_PART_DISKLABEL:
 		if (bpart->bdev->bio->Media->BlockSize != bpart->disklabel.secsize) {

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.14 src/sys/stand/efiboot/efiboot.h:1.15
--- src/sys/stand/efiboot/efiboot.h:1.14	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/efiboot.h	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.14 2020/10/11 14:03:33 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.15 2021/06/20 19:10:47 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -104,6 +104,9 @@ extern struct netif_driver efinetif;
 void efi_pxe_probe(void);
 bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32);
 
+/* efiwatchdog.c */
+void efi_set_watchdog(uint32_t, uint64_t);
+
 /* exec.c */
 int exec_netbsd(const char *, const char *);
 

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.25 src/sys/stand/efiboot/version:1.26
--- src/sys/stand/efiboot/version:1.25	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/version	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.25 2021/05/27 06:54:45 mrg Exp $
+$NetBSD: version,v 1.26 2021/06/20 19:10:47 jmcneill Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -29,3 +29,4 @@ is taken as the current.
 2.6:	Disable ACPI support when booting big endian kernels.
 2.7:	Add basic support for booting from RAID1 volumes.
 2.8:	Add bi-endian disklabel and FFS support.
+2.9:	Watchdog support.

Added files:

Index: src/sys/stand/efiboot/efiwatchdog.c
diff -u /dev/null src/sys/stand/efiboot/efiwatchdog.c:1.1
--- /dev/null	Sun Jun 20 19:10:47 2021
+++ src/sys/stand/efiboot/efiwatchdog.c	Sun Jun 20 19:10:47 2021
@@ -0,0 +1,40 @@
+/* $NetBSD: efiwatchdog.c,v 1.1 2021/06/20 19:10:47 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill <jmcne...@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+
+#include "efiboot.h"
+
+/*
+ * Set the system watchdog timer.
+ */
+void
+efi_set_watchdog(uint32_t timeout, uint64_t code)
+{
+	uefi_call_wrapper(BS->SetWatchdogTimer, 4, timeout, code, 0, NULL);
+}

Reply via email to