-.\" $OpenBSD: boot.8,v 1.34 2023/02/23 19:48:21 miod Exp $
+.\" $OpenBSD: boot.8,v 1.35 2024/04/25 18:31:49 kn Exp $
.\"
.\" Copyright (c) 1997-2001 Michael Shalayeff
.\" All rights reserved.
.\" THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\"
-.Dd $Mdocdate: February 23 2023 $
+.Dd $Mdocdate: April 25 2024 $
.Dt BOOT 8 amd64
.Os
.Sh NAME
.Ar mode
is not given,
a list of available modes is shown.
+.It Ic idle Op Ar secs
+On
+.Xr efi 4
+systems,
+sets the timeout in seconds to power down the machine,
+if no input has been given at the
+.Xr softraid 4
+passphrase prompt.
+A value of 0 unsets the timeout.
+If
+.Ar secs
+is not given,
+the current timeout is shown.
.It Ic memory
If used without any arguments, this command will print out
the memory configuration as determined through BIOS routines.
.Xr gzip 1 ,
.Xr autoconf 4 ,
.Xr ddb 4 ,
+.Xr efi 4 ,
.Xr softraid 4 ,
.Xr biosboot 8 ,
.Xr boot_amd64 8 ,
-# $OpenBSD: Makefile.common,v 1.22 2021/11/14 21:51:48 guenther Exp $
+# $OpenBSD: Makefile.common,v 1.23 2024/04/25 18:31:49 kn Exp $
S= ${.CURDIR}/../../../../..
SADIR= ${.CURDIR}/../..
COPTS+= -fshort-wchar -fPIC -mno-red-zone
.if ${SOFTRAID:L} == "yes"
COPTS+= -DSOFTRAID
+COPTS+= -DIDLE_POWEROFF
.endif
COPTS+= -D_STANDALONE -nostdinc -fno-builtin
-/* $OpenBSD: cmd_i386.c,v 1.1 2019/05/10 21:20:42 mlarkin Exp $ */
+/* $OpenBSD: cmd_i386.c,v 1.2 2024/04/25 18:31:49 kn Exp $ */
/*
* Copyright (c) 1997-1999 Michael Shalayeff
{ "poweroff", CMDT_CMD, Xpoweroff_efi },
#ifdef DEBUG
{ "regs", CMDT_CMD, Xregs },
+#endif
+#ifdef IDLE_POWEROFF
+ { "idle", CMDT_CMD, Xidle_efi },
#endif
{ NULL, 0 }
};
-/* $OpenBSD: conf.c,v 1.42 2023/07/22 10:11:19 jsg Exp $ */
+/* $OpenBSD: conf.c,v 1.43 2024/04/25 18:31:49 kn Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include "efidev.h"
#include "efipxe.h"
-const char version[] = "3.65";
+const char version[] = "3.66";
#ifdef EFI_DEBUG
int debug = 0;
-/* $OpenBSD: efiboot.c,v 1.41 2023/01/02 22:41:17 kettenis Exp $ */
+/* $OpenBSD: efiboot.c,v 1.42 2024/04/25 18:31:49 kn Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
sleep(u_int i)
{
time_t t;
+ u_int intr = 0;
/*
* Loop for the requested number of seconds, polling,
* so that it may handle interrupts.
*/
- for (t = getsecs() + i; getsecs() < t; cnischar())
+ for (t = getsecs() + i; intr == 0 && getsecs() < t; intr = cnischar())
;
+ return intr;
+}
+
+#ifdef IDLE_POWEROFF
+CHAR16 *idle_name = L"IdlePoweroff";
+EFI_STATUS idle_status;
+/* randomly generated f948e8a9-0570-4338-ad10-29f4cf12849d */
+EFI_GUID openbsd_guid = { 0xf948e8a9, 0x0570, 0x4338,
+ { 0xad, 0x10, 0x29, 0xf4, 0xcf, 0x12, 0x84, 0x9d } };
+/* Non-Volatile, Boot Service Access, Runtime Service Access */
+UINT32 idle_attrs = 0x1 | 0x2 | 0x4;
+UINT16 idle_secs;
+UINTN idle_sz = sizeof(idle_secs);
+
+int
+get_idle_timeout(void)
+{
+ idle_status = RS->GetVariable(idle_name, &openbsd_guid, NULL,
+ &idle_sz, &idle_secs);
+ if (idle_status != EFI_SUCCESS) {
+ if (idle_status != EFI_NOT_FOUND) {
+ printf("%s: %d\n", __func__, idle_status);
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
+}
+
+int
+set_idle_timeout(int secs)
+{
+ idle_secs = secs;
+ idle_sz = idle_secs > 0 ? sizeof(idle_secs) : 0;
+ idle_status = RS->SetVariable(idle_name, &openbsd_guid, idle_attrs,
+ idle_sz, &idle_secs);
+ if (idle_status != EFI_SUCCESS) {
+ printf("%s: %d\n", __func__, idle_status);
+ return -1;
+ }
return 0;
}
+/* see lib/libsa/softraid.c sr_crypto_passphrase_decrypt() */
+void
+idle_poweroff(void)
+{
+ if (get_idle_timeout() == 0 && sleep(idle_secs) == 0) {
+ printf("\nno input after %us, powering off...\n", idle_secs);
+ Xpoweroff_efi();
+ }
+}
+#endif /* IDLE_POWEROFF */
+
/***********************************************************************
* Commands
***********************************************************************/
return (0);
}
+
+#ifdef IDLE_POWEROFF
+int
+Xidle_efi(void)
+{
+ if (cmd.argc >= 2) {
+ int secs;
+
+ secs = strtol(cmd.argv[1], NULL, 10);
+ if (0 <= secs && secs < UINT16_MAX)
+ set_idle_timeout(secs);
+ } else {
+ if (get_idle_timeout() == 0)
+ printf("Timeout = %us\n", idle_secs);
+ }
+ return 0;
+}
+#endif /* IDLE_POWEROFF */
-/* $OpenBSD: efiboot.h,v 1.5 2022/07/11 19:45:02 kettenis Exp $ */
+/* $OpenBSD: efiboot.h,v 1.6 2024/04/25 18:31:49 kn Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
void efi_setconsdev(void);
int Xpoweroff_efi(void);
+#ifdef IDLE_POWEROFF
+int Xidle_efi(void);
+#endif
extern void (*run_i386)(u_long, u_long, int, int, int, int, int, int, int, int)
__attribute__ ((noreturn));
-/* $OpenBSD: softraid.c,v 1.6 2024/03/24 05:50:20 jsg Exp $ */
+/* $OpenBSD: softraid.c,v 1.7 2024/04/25 18:31:49 kn Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
for (;;) {
printf("Passphrase: ");
+#ifdef IDLE_POWEROFF
+extern int idle_poweroff(void);
+ idle_poweroff();
+#endif /* IDLE_POWEROFF */
for (i = 0; i < PASSPHRASE_LENGTH - 1; i++) {
c = cngetc();
if (c == '\r' || c == '\n') {