From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vl3uX-0006cj-KR for mharc-grub-devel@gnu.org; Mon, 25 Nov 2013 16:41:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl3uT-0006bu-V8 for grub-devel@gnu.org; Mon, 25 Nov 2013 16:41:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vl3uQ-0003bv-Rd for grub-devel@gnu.org; Mon, 25 Nov 2013 16:41:37 -0500 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]:35094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl3uQ-0003bm-GN for grub-devel@gnu.org; Mon, 25 Nov 2013 16:41:34 -0500 Received: by mail-we0-f179.google.com with SMTP id q59so4415985wes.38 for ; Mon, 25 Nov 2013 13:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=uVuCHT2zG9kQVLOM8ssRPWqmNDgy1zEc6goAzVgp0Io=; b=LxreW+VHhQVZjPIFYmYmMvxBTwHMEcPZg0B5aKyWXOMorX9GlutxGOGEiiwARsHCbf Z2/Ah30q6ByfHKb3k+sWUJMBQ54dU94INqcLKivQDhiKptH3DRh/raka7xI25m9tp0C2 H0XyOhdqmUbhTf4ibz5TvCpPR3h8X60Znu014tQLWT4CVFsUihbBm9WrJtIAlEa/2dYu 1uM344hqTnQEVvxP2lCoeOfdy77ZHAOVUozSqHIPDJTZrmCU9gAOzRj08lP8qx+b1Z02 13GCgsJRhZD6UW0qPYvPJ+oPFOdjc78+iGjo9gavBMkQ99QxajTKbqKfvw1MKn1U0Boc zJRg== MIME-Version: 1.0 X-Received: by 10.194.89.105 with SMTP id bn9mr303570wjb.82.1385415693487; Mon, 25 Nov 2013 13:41:33 -0800 (PST) Received: by 10.180.39.193 with HTTP; Mon, 25 Nov 2013 13:41:33 -0800 (PST) Received: by 10.180.39.193 with HTTP; Mon, 25 Nov 2013 13:41:33 -0800 (PST) In-Reply-To: <5293C281.4080601@gmail.com> References: <5293C281.4080601@gmail.com> Date: Mon, 25 Nov 2013 22:41:33 +0100 Message-ID: Subject: Re: PATCH: added GRUB command to get and set (U)EFI firmware variables From: "Vladimir 'phcoder' Serbinenko" To: The development of GNU GRUB Content-Type: multipart/alternative; boundary=047d7bf10aca46d5a704ec073a42 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::233 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 21:41:40 -0000 --047d7bf10aca46d5a704ec073a42 Content-Type: text/plain; charset=ISO-8859-1 please resend as proper and not as reverse patch. Anotjer issie that can be seen from description alone is that you don't allow to specify vendor uuid. it would be needed and slso it needs readable aliases for known types On Nov 25, 2013 10:35 PM, "SevenBits" wrote: > 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 . > - */ > - > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > - > -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); > -} > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > --047d7bf10aca46d5a704ec073a42 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

please resend as proper and not as reverse patch. Anotjer issie that can= be seen from description alone is that you don't allow to specify vend= or uuid. it would be needed and slso it needs readable aliases for known ty= pes

On Nov 25, 2013 10:35 PM, "SevenBits" = <sevenbitstech@gmail.com&= gt; wrote:
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 sc= ripting
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 =3D {
=A0};

=A0module =3D {
- =A0name =3D setvariable;
- =A0common =3D commands/efi/setvariable.c;
- =A0enable =3D i386_efi;
- =A0enable =3D x86_64_efi;
-};
-
-module =3D {
=A0 =A0name =3D pcidump;
=A0 =A0common =3D commands/pcidump.c;
=A0 =A0enable =3D 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 */
-/*
- * =A0GRUB =A0-- =A0GRand Unified Bootloader
- * =A0Copyright (C) 2013 =A0Free Software Foundation, Inc.
- *
- * =A0GRUB is free software: you can redistribute it and/or modify
- * =A0it under the terms of the GNU General Public License as published by=
- * =A0the Free Software Foundation, either version 3 of the License, or - * =A0(at your option) any later version.
- *
- * =A0GRUB is distributed in the hope that it will be useful,
- * =A0but WITHOUT ANY WARRANTY; without even the implied warranty of
- * =A0MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the
- * =A0GNU General Public License for more details.
- *
- * =A0You should have received a copy of the GNU General Public License - * =A0along with GRUB. =A0If 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)),
- =A0 =A0 =A0 =A0 =A0 int argc, char *argv[])
-{
- =A0 =A0grub_efi_guid_t global =3D GRUB_EFI_GLOBAL_VARIABLE_GUID;
- =A0 =A0if (argc =3D=3D 0)
- =A0 =A0 =A0 =A0return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi var= iable name
expected"));
- =A0 =A0else if (argc =3D=3D 1)
- =A0 =A0 =A0 =A0return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi var= iable name
value expected"));
-
- =A0 =A0grub_err_t status;
- =A0 =A0grub_size_t arg_size =3D (grub_strlen(argv[1]) + 1) * sizeof(char)= ;
-
- =A0 =A0status =3D grub_efi_set_variable (argv[0], &global, argv[1], a= rg_size);
- =A0 =A0if (status !=3D GRUB_ERR_NONE)
- =A0 =A0{
- =A0 =A0 =A0 =A0grub_printf ("couldn't set efi variable"); - =A0 =A0 =A0 =A0return status;
- =A0 =A0}
- =A0 =A0return 0;
-}
-
-static grub_err_t
-grub_cmd_getefivariable (grub_command_t cmd __attribute__ ((unused)),
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int argc, char *argv[])
-{
- =A0 =A0grub_efi_guid_t global =3D GRUB_EFI_GLOBAL_VARIABLE_GUID;
- =A0 =A0if (argc =3D=3D 0)
- =A0 =A0 =A0 =A0return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi var= iable name
expected"));
- =A0 =A0else if (argc =3D=3D 1)
- =A0 =A0 =A0 =A0return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("efi var= iable name
value expected"));
-
- =A0 =A0grub_size_t var_size;
- =A0 =A0grub_err_t status;
- =A0 =A0char *value =3D (char*)grub_efi_get_variable (argv[0], &global= ,
&var_size);
- =A0 =A0status =3D grub_env_set (argv[1], value);
- =A0 =A0if (status !=3D GRUB_ERR_NONE)
- =A0 =A0{
- =A0 =A0 =A0 =A0grub_printf ("couldn't set environment variable&q= uot;);
- =A0 =A0 =A0 =A0return status;
- =A0 =A0}
- =A0 =A0return 0;
-}
-
-static grub_command_t cmd_setefivariable, cmd_getefivariable;
-
-GRUB_MOD_INIT(loadbios)
-{
- =A0cmd_setefivariable =3D grub_register_command ("setefivariable&quo= t;,
grub_cmd_setefivariable,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0N_("NAME VALUE"),
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0N_("Set an EFI firmware varia= ble "
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"which can be sto= red and retrieved "
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"from between ses= sions."));
-
- =A0cmd_getefivariable =3D grub_register_command ("getefivariable&quo= t;,
grub_cmd_getefivariable,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0N_("NAME ENV_VARIABLE"),=
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0N_("Gets an EFI firmware vari= able "
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"and stores it as= a GRUB environment "
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"variable named E= NV_VARIABLE."));
-}
-
-GRUB_MOD_FINI(loadbios)
-{
- =A0grub_unregister_command (cmd_setefivariable);
- =A0grub_unregister_command (cmd_getefivariable);
-}

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
--047d7bf10aca46d5a704ec073a42--