From: SevenBits <sevenbitstech@gmail.com>
To: grub-devel@gnu.org
Subject: PATCH: added GRUB command to get and set (U)EFI firmware variables
Date: Mon, 25 Nov 2013 16:34:57 -0500 [thread overview]
Message-ID: <5293C281.4080601@gmail.com> (raw)
Hello everyone,
This patch adds two GRUB two commands to allow the user to get and set
the values of (U)EFI firmware variables. When dealing with (U)EFI
firmware with GRUB I decided this would be a useful tool to have for
both developers and end-users.
The first command, setefivariable, takes two parameters: the name of the
variable to set and its value. The second, getefivariable, also takes
two parameters: the name of the variable to retrieve and the name of the
GRUB environment variable in which you want to store the result. This
can then be checked using GRUB's built in 'if' statement and scripting
capability to allow unique booting capabilities based on whether, for
example, secure boot is enabled or the (U)EFI firmware is in setup mode.
Have a look and let me know what you think! The patch follows.
-- SevenBits
diff --git a/grub/grub-core/Makefile.core.def
b/grub-orig/grub-core/Makefile.core.def
index 177d6d6..5cd84b1 100644
--- a/grub/grub-core/Makefile.core.def
+++ b/grub-orig/grub-core/Makefile.core.def
@@ -1004,13 +1004,6 @@ module = {
};
module = {
- name = setvariable;
- common = commands/efi/setvariable.c;
- enable = i386_efi;
- enable = x86_64_efi;
-};
-
-module = {
name = pcidump;
common = commands/pcidump.c;
enable = pci;
diff --git a/grub/grub-core/commands/efi/setvariable.c
b/grub/grub-core/commands/efi/setvariable.c
deleted file mode 100644
index b0d0967..0000000
--- a/grub/grub-core/commands/efi/setvariable.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* setvariable.c - get and set efi firmware variables */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2013 Free Software Foundation, Inc.
- *
- * GRUB 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.
- *
- * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <grub/env.h>
-#include <grub/dl.h>
-#include <grub/misc.h>
-#include <grub/file.h>
-#include <grub/efi/efi.h>
-#include <grub/pci.h>
-#include <grub/command.h>
-#include <grub/i18n.h>
-
-GRUB_MOD_LICENSE ("GPLv3+");
-
-static grub_err_t
-grub_cmd_setefivariable (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
-{
- grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
- if (argc == 0)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi variable name
expected"));
- else if (argc == 1)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi variable name
value expected"));
-
- grub_err_t status;
- grub_size_t arg_size = (grub_strlen(argv[1]) + 1) * sizeof(char);
-
- status = grub_efi_set_variable (argv[0], &global, argv[1], arg_size);
- if (status != GRUB_ERR_NONE)
- {
- grub_printf ("couldn't set efi variable");
- return status;
- }
- return 0;
-}
-
-static grub_err_t
-grub_cmd_getefivariable (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
-{
- grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
- if (argc == 0)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi variable name
expected"));
- else if (argc == 1)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi variable name
value expected"));
-
- grub_size_t var_size;
- grub_err_t status;
- char *value = (char*)grub_efi_get_variable (argv[0], &global,
&var_size);
- status = grub_env_set (argv[1], value);
- if (status != GRUB_ERR_NONE)
- {
- grub_printf ("couldn't set environment variable");
- return status;
- }
- return 0;
-}
-
-static grub_command_t cmd_setefivariable, cmd_getefivariable;
-
-GRUB_MOD_INIT(loadbios)
-{
- cmd_setefivariable = grub_register_command ("setefivariable",
grub_cmd_setefivariable,
- N_("NAME VALUE"),
- N_("Set an EFI firmware variable "
- "which can be stored and retrieved "
- "from between sessions."));
-
- cmd_getefivariable = grub_register_command ("getefivariable",
grub_cmd_getefivariable,
- N_("NAME ENV_VARIABLE"),
- N_("Gets an EFI firmware variable "
- "and stores it as a GRUB environment "
- "variable named ENV_VARIABLE."));
-}
-
-GRUB_MOD_FINI(loadbios)
-{
- grub_unregister_command (cmd_setefivariable);
- grub_unregister_command (cmd_getefivariable);
-}
next reply other threads:[~2013-11-25 21:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-25 21:34 SevenBits [this message]
2013-11-25 21:41 ` PATCH: added GRUB command to get and set (U)EFI firmware variables Vladimir 'phcoder' Serbinenko
2013-11-25 22:03 ` SevenBits
2013-11-25 22:07 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-25 22:28 ` SevenBits
2013-11-26 0:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-27 18:44 ` SevenBits
2013-11-27 18:57 ` Andrey Borzenkov
2013-11-27 20:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-28 15:33 ` SevenBits
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5293C281.4080601@gmail.com \
--to=sevenbitstech@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).