nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0033-grub-core-Makefile.core.def-efifwsetup-New-module.patch

f96e0b
From 9e9382ece3511ff530cfb3e1c1e7a7dbaa3416b6 Mon Sep 17 00:00:00 2001
f96e0b
From: Peter Jones <pjones@redhat.com>
f96e0b
Date: Sat, 8 Sep 2012 09:40:24 +0200
f96e0b
Subject: [PATCH 033/482] 	* grub-core/Makefile.core.def (efifwsetup):
f96e0b
 New module. 	* grub-core/commands/efi/efifwsetup.c: New file. 	*
f96e0b
 grub-core/kern/efi/efi.c (grub_efi_set_variable): New function 	*
f96e0b
 include/grub/efi/api.h (GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI): 	New
f96e0b
 define. 	* include/grub/efi/efi.h (grub_efi_set_variable): New proto.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                           |  9 ++++
f96e0b
 grub-core/Makefile.core.def         |  6 +++
f96e0b
 grub-core/commands/efi/efifwsetup.c | 90 +++++++++++++++++++++++++++++++++++++
f96e0b
 grub-core/kern/efi/efi.c            | 30 +++++++++++++
f96e0b
 include/grub/efi/api.h              |  2 +
f96e0b
 include/grub/efi/efi.h              |  5 +++
f96e0b
 6 files changed, 142 insertions(+)
f96e0b
 create mode 100644 grub-core/commands/efi/efifwsetup.c
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 10b1ab3..e8f0577 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,12 @@
f96e0b
+2012-09-08  Peter Jones <pjones@redhat.com>
f96e0b
+
f96e0b
+	* grub-core/Makefile.core.def (efifwsetup): New module.
f96e0b
+	* grub-core/commands/efi/efifwsetup.c: New file.
f96e0b
+	* grub-core/kern/efi/efi.c (grub_efi_set_variable): New function
f96e0b
+	* include/grub/efi/api.h (GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI):
f96e0b
+	New define.
f96e0b
+	* include/grub/efi/efi.h (grub_efi_set_variable): New proto.
f96e0b
+
f96e0b
 2012-09-05  Jiri Slaby <jslaby@suse.cz>
f96e0b
 
f96e0b
 	* configure.ac: Add SuSe path.
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index de702d6..7a7b97a 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -575,6 +575,12 @@ module = {
f96e0b
 };
f96e0b
 
f96e0b
 module = {
f96e0b
+  name = efifwsetup;
f96e0b
+  efi = commands/efi/efifwsetup.c;
f96e0b
+  enable = efi;
f96e0b
+};
f96e0b
+
f96e0b
+module = {
f96e0b
   name = blocklist;
f96e0b
   common = commands/blocklist.c;
f96e0b
 };
f96e0b
diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c
f96e0b
new file mode 100644
f96e0b
index 0000000..7a137a7
f96e0b
--- /dev/null
f96e0b
+++ b/grub-core/commands/efi/efifwsetup.c
f96e0b
@@ -0,0 +1,90 @@
f96e0b
+/* fwsetup.c - Reboot into firmware setup menu. */
f96e0b
+/*
f96e0b
+ *  GRUB  --  GRand Unified Bootloader
f96e0b
+ *  Copyright (C) 2012  Free Software Foundation, Inc.
f96e0b
+ *
f96e0b
+ *  GRUB is free software: you can redistribute it and/or modify
f96e0b
+ *  it under the terms of the GNU General Public License as published by
f96e0b
+ *  the Free Software Foundation, either version 3 of the License, or
f96e0b
+ *  (at your option) any later version.
f96e0b
+ *
f96e0b
+ *  GRUB is distributed in the hope that it will be useful,
f96e0b
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
f96e0b
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f96e0b
+ *  GNU General Public License for more details.
f96e0b
+ *
f96e0b
+ *  You should have received a copy of the GNU General Public License
f96e0b
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
f96e0b
+ */
f96e0b
+
f96e0b
+#include <grub/types.h>
f96e0b
+#include <grub/mm.h>
f96e0b
+#include <grub/misc.h>
f96e0b
+#include <grub/efi/api.h>
f96e0b
+#include <grub/efi/efi.h>
f96e0b
+#include <grub/command.h>
f96e0b
+#include <grub/i18n.h>
f96e0b
+
f96e0b
+GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
f96e0b
+		  int argc __attribute__ ((unused)),
f96e0b
+		  char **args __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  grub_efi_uint64_t *old_os_indications;
f96e0b
+  grub_efi_uint64_t os_indications = GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
f96e0b
+  grub_err_t status;
f96e0b
+  grub_size_t oi_size;
f96e0b
+  grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
f96e0b
+
f96e0b
+  old_os_indications = grub_efi_get_variable ("OsIndications", &global,
f96e0b
+					      &oi_size);
f96e0b
+
f96e0b
+  if (old_os_indications != NULL && oi_size == sizeof (os_indications))
f96e0b
+    os_indications |= *old_os_indications;
f96e0b
+
f96e0b
+  status = grub_efi_set_variable ("OsIndications", &global, &os_indications,
f96e0b
+				  sizeof (os_indications));
f96e0b
+  if (status != GRUB_ERR_NONE)
f96e0b
+    return status;
f96e0b
+
f96e0b
+  grub_reboot ();
f96e0b
+
f96e0b
+  return GRUB_ERR_BUG;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_command_t cmd = NULL;
f96e0b
+
f96e0b
+static grub_efi_boolean_t
f96e0b
+efifwsetup_is_supported (void)
f96e0b
+{
f96e0b
+  grub_efi_uint64_t *os_indications_supported = NULL;
f96e0b
+  grub_size_t oi_size = 0;
f96e0b
+  grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
f96e0b
+
f96e0b
+  os_indications_supported = grub_efi_get_variable ("OsIndicationsSupported",
f96e0b
+						    &global, &oi_size);
f96e0b
+
f96e0b
+  if (!os_indications_supported)
f96e0b
+    return 0;
f96e0b
+
f96e0b
+  if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI)
f96e0b
+    return 1;
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_INIT (efifwsetup)
f96e0b
+{
f96e0b
+  if (efifwsetup_is_supported ())
f96e0b
+    cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL,
f96e0b
+				 N_("Reboot into firmware setup menu."));
f96e0b
+
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_FINI (efifwsetup)
f96e0b
+{
f96e0b
+  if (cmd)
f96e0b
+    grub_unregister_command (cmd);
f96e0b
+}
f96e0b
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
f96e0b
index 02d2f9a..e8a62ec 100644
f96e0b
--- a/grub-core/kern/efi/efi.c
f96e0b
+++ b/grub-core/kern/efi/efi.c
f96e0b
@@ -181,6 +181,36 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
f96e0b
   return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed");
f96e0b
 }
f96e0b
 
f96e0b
+grub_err_t
f96e0b
+grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
f96e0b
+		      void *data, grub_size_t datasize)
f96e0b
+{
f96e0b
+  grub_efi_status_t status;
f96e0b
+  grub_efi_runtime_services_t *r;
f96e0b
+  grub_efi_char16_t *var16;
f96e0b
+  grub_size_t len, len16;
f96e0b
+
f96e0b
+  len = grub_strlen (var);
f96e0b
+  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
f96e0b
+  var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));
f96e0b
+  if (!var16)
f96e0b
+    return grub_errno;
f96e0b
+  len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
f96e0b
+  var16[len16] = 0;
f96e0b
+
f96e0b
+  r = grub_efi_system_table->runtime_services;
f96e0b
+
f96e0b
+  status = efi_call_5 (r->set_variable, var16, guid, 
f96e0b
+		       (GRUB_EFI_VARIABLE_NON_VOLATILE
f96e0b
+			| GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
f96e0b
+			| GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
f96e0b
+		       datasize, data);
f96e0b
+  if (status == GRUB_EFI_SUCCESS)
f96e0b
+    return GRUB_ERR_NONE;
f96e0b
+
f96e0b
+  return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
f96e0b
+}
f96e0b
+
f96e0b
 void *
f96e0b
 grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
f96e0b
 		       grub_size_t *datasize_out)
f96e0b
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
f96e0b
index 9e7a8d8..ae61730 100644
f96e0b
--- a/include/grub/efi/api.h
f96e0b
+++ b/include/grub/efi/api.h
f96e0b
@@ -58,6 +58,8 @@
f96e0b
 #define GRUB_EFI_OPEN_PROTOCOL_BY_DRIVER		0x00000010
f96e0b
 #define GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE		0x00000020
f96e0b
 
f96e0b
+#define GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI	0x0000000000000001ULL
f96e0b
+
f96e0b
 #define GRUB_EFI_VARIABLE_NON_VOLATILE		0x0000000000000001
f96e0b
 #define GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS	0x0000000000000002
f96e0b
 #define GRUB_EFI_VARIABLE_RUNTIME_ACCESS	0x0000000000000004
f96e0b
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
f96e0b
index e67d92b..489cf9e 100644
f96e0b
--- a/include/grub/efi/efi.h
f96e0b
+++ b/include/grub/efi/efi.h
f96e0b
@@ -64,6 +64,11 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
f96e0b
 void *EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
f96e0b
 					   const grub_efi_guid_t *guid,
f96e0b
 					   grub_size_t *datasize_out);
f96e0b
+grub_err_t
f96e0b
+EXPORT_FUNC (grub_efi_set_variable) (const char *var,
f96e0b
+				     const grub_efi_guid_t *guid,
f96e0b
+				     void *data,
f96e0b
+				     grub_size_t datasize);
f96e0b
 int
f96e0b
 EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
f96e0b
 					     const grub_efi_device_path_t *dp2);
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b