Module Name:    src
Committed By:   jmcneill
Date:           Sat Oct  9 13:09:17 UTC 2021

Modified Files:
        src/sys/stand/efiboot: boot.c

Log Message:
efiboot: add "setup" command

The "setup" command sets the 64-bit "OsIndications" variable to the value of
EFI_OS_INDICATIONS_BOOT_TO_FW_UI and requests a reboot. On firmware that
supports this, after reboot the user will be presented with the firmware
setup menu.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/stand/efiboot/boot.c

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.38 src/sys/stand/efiboot/boot.c:1.39
--- src/sys/stand/efiboot/boot.c:1.38	Wed Oct  6 10:13:19 2021
+++ src/sys/stand/efiboot/boot.c	Sat Oct  9 13:09:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.38 2021/10/06 10:13:19 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.39 2021/10/09 13:09:17 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -111,6 +111,7 @@ void	command_gop(char *);
 void	command_mem(char *);
 void	command_menu(char *);
 void	command_reset(char *);
+void	command_setup(char *);
 void	command_version(char *);
 void	command_quit(char *);
 
@@ -134,6 +135,7 @@ const struct boot_command commands[] = {
 	{ "menu",	command_menu,		"menu" },
 	{ "reboot",	command_reset,		"reboot|reset" },
 	{ "reset",	command_reset,		NULL },
+	{ "setup",	command_setup,		"setup" },
 	{ "version",	command_version,	"version" },
 	{ "ver",	command_version,	NULL },
 	{ "help",	command_help,		"help|?" },
@@ -355,6 +357,7 @@ command_version(char *arg)
 {
 	char pathbuf[80];
 	char *ufirmware;
+	const UINT64 *osindsup;
 	int rv;
 
 	printf("Version: %s (%s)\n", bootprog_rev, bootprog_kernrev);
@@ -371,6 +374,11 @@ command_version(char *arg)
 		printf("Config path: %s\n", pathbuf);
 	}
 
+	osindsup = LibGetVariable(L"OsIndicationsSupported", &EfiGlobalVariable);
+	if (osindsup != NULL) {
+		printf("UEFI OS indications supported: 0x%" PRIx64 "\n", *osindsup);
+	}
+
 #ifdef EFIBOOT_FDT
 	efi_fdt_show();
 #endif
@@ -394,6 +402,29 @@ command_reset(char *arg)
 	efi_reboot();
 }
 
+void
+command_setup(char *arg)
+{
+	EFI_STATUS status;
+	const UINT64 *osindsup;
+	UINT64 osind;
+
+	osindsup = LibGetVariable(L"OsIndicationsSupported", &EfiGlobalVariable);
+	if (osindsup == NULL || (*osindsup & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) == 0) {
+		printf("Not supported by firmware\n");
+		return;
+	}
+
+	osind = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
+	status = LibSetNVVariable(L"OsIndications", &EfiGlobalVariable, sizeof(osind), &osind);
+	if (EFI_ERROR(status)) {
+		printf("Failed to set OsIndications variable: %lu\n", (u_long)status);
+		return;
+	}
+
+	efi_reboot();
+}
+
 int
 set_default_device(const char *arg)
 {

Reply via email to