/* fwsetup.c - Reboot into firmware setup menu. */
/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2012 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
static VasEBoot_efi_boolean_t efifwsetup_is_supported (void);
static VasEBoot_err_t
VasEBoot_cmd_fwsetup (VasEBoot_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
VasEBoot_efi_uint64_t *old_os_indications;
VasEBoot_efi_uint64_t os_indications = VAS_EBOOT_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
VasEBoot_err_t status;
VasEBoot_size_t oi_size;
static VasEBoot_guid_t global = VAS_EBOOT_EFI_GLOBAL_VARIABLE_GUID;
if (argc >= 1 && VasEBoot_strcmp(args[0], "--is-supported") == 0)
return !efifwsetup_is_supported ();
if (!efifwsetup_is_supported ())
return VasEBoot_error (VAS_EBOOT_ERR_INVALID_COMMAND,
N_("reboot to firmware setup is not supported by the current firmware"));
VasEBoot_efi_get_variable ("OsIndications", &global, &oi_size,
(void **) &old_os_indications);
if (old_os_indications != NULL && oi_size == sizeof (os_indications))
os_indications |= *old_os_indications;
VasEBoot_free (old_os_indications);
status = VasEBoot_efi_set_variable ("OsIndications", &global, &os_indications,
sizeof (os_indications));
if (status != VAS_EBOOT_ERR_NONE)
return status;
VasEBoot_reboot ();
return VAS_EBOOT_ERR_BUG;
}
static VasEBoot_command_t cmd = NULL;
static VasEBoot_efi_boolean_t
efifwsetup_is_supported (void)
{
VasEBoot_efi_uint64_t *os_indications_supported = NULL;
VasEBoot_size_t oi_size = 0;
static VasEBoot_guid_t global = VAS_EBOOT_EFI_GLOBAL_VARIABLE_GUID;
VasEBoot_efi_boolean_t ret = 0;
VasEBoot_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
(void **) &os_indications_supported);
if (!os_indications_supported)
goto done;
if (*os_indications_supported & VAS_EBOOT_EFI_OS_INDICATIONS_BOOT_TO_FW_UI)
ret = 1;
done:
VasEBoot_free (os_indications_supported);
return ret;
}
VAS_EBOOT_MOD_INIT (efifwsetup)
{
cmd = VasEBoot_register_command ("fwsetup", VasEBoot_cmd_fwsetup, NULL,
N_("Reboot into firmware setup menu."));
}
VAS_EBOOT_MOD_FINI (efifwsetup)
{
if (cmd)
VasEBoot_unregister_command (cmd);
}