]> git.proxmox.com Git - grub2.git/blob - grub-core/commands/efi/efifwsetup.c
lsefisystab: add missing comma after 7994077
[grub2.git] / grub-core / commands / efi / efifwsetup.c
1 /* fwsetup.c - Reboot into firmware setup menu. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2012 Free Software Foundation, Inc.
5 *
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <grub/types.h>
21 #include <grub/mm.h>
22 #include <grub/misc.h>
23 #include <grub/efi/api.h>
24 #include <grub/efi/efi.h>
25 #include <grub/command.h>
26 #include <grub/i18n.h>
27
28 GRUB_MOD_LICENSE ("GPLv3+");
29
30 static grub_err_t
31 grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
32 int argc __attribute__ ((unused)),
33 char **args __attribute__ ((unused)))
34 {
35 grub_efi_uint64_t *old_os_indications;
36 grub_efi_uint64_t os_indications = GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
37 grub_err_t status;
38 grub_size_t oi_size;
39 grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
40
41 old_os_indications = grub_efi_get_variable ("OsIndications", &global,
42 &oi_size);
43
44 if (old_os_indications != NULL && oi_size == sizeof (os_indications))
45 os_indications |= *old_os_indications;
46
47 status = grub_efi_set_variable ("OsIndications", &global, &os_indications,
48 sizeof (os_indications));
49 if (status != GRUB_ERR_NONE)
50 return status;
51
52 grub_reboot ();
53
54 return GRUB_ERR_BUG;
55 }
56
57 static grub_command_t cmd = NULL;
58
59 static grub_efi_boolean_t
60 efifwsetup_is_supported (void)
61 {
62 grub_efi_uint64_t *os_indications_supported = NULL;
63 grub_size_t oi_size = 0;
64 grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
65
66 os_indications_supported = grub_efi_get_variable ("OsIndicationsSupported",
67 &global, &oi_size);
68
69 if (!os_indications_supported)
70 return 0;
71
72 if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI)
73 return 1;
74
75 return 0;
76 }
77
78 GRUB_MOD_INIT (efifwsetup)
79 {
80 if (efifwsetup_is_supported ())
81 cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL,
82 N_("Reboot into firmware setup menu."));
83
84 }
85
86 GRUB_MOD_FINI (efifwsetup)
87 {
88 if (cmd)
89 grub_unregister_command (cmd);
90 }