1 /* fwsetup.c - Reboot into firmware setup menu. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2012 Free Software Foundation, Inc.
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.
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.
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/>.
20 #include <grub/types.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>
28 GRUB_MOD_LICENSE ("GPLv3+");
31 grub_cmd_fwsetup (grub_command_t cmd
__attribute__ ((unused
)),
32 int argc
__attribute__ ((unused
)),
33 char **args
__attribute__ ((unused
)))
35 grub_efi_uint64_t
*old_os_indications
;
36 grub_efi_uint64_t os_indications
= GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
39 grub_efi_guid_t global
= GRUB_EFI_GLOBAL_VARIABLE_GUID
;
41 old_os_indications
= grub_efi_get_variable ("OsIndications", &global
,
44 if (old_os_indications
!= NULL
&& oi_size
== sizeof (os_indications
))
45 os_indications
|= *old_os_indications
;
47 status
= grub_efi_set_variable ("OsIndications", &global
, &os_indications
,
48 sizeof (os_indications
));
49 if (status
!= GRUB_ERR_NONE
)
57 static grub_command_t cmd
= NULL
;
59 static grub_efi_boolean_t
60 efifwsetup_is_supported (void)
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
;
66 os_indications_supported
= grub_efi_get_variable ("OsIndicationsSupported",
69 if (!os_indications_supported
)
72 if (*os_indications_supported
& GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI
)
78 GRUB_MOD_INIT (efifwsetup
)
80 if (efifwsetup_is_supported ())
81 cmd
= grub_register_command ("fwsetup", grub_cmd_fwsetup
, NULL
,
82 N_("Reboot into firmware setup menu."));
86 GRUB_MOD_FINI (efifwsetup
)
89 grub_unregister_command (cmd
);