From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1a4Wz8-0004Ej-OH for mharc-grub-devel@gnu.org; Thu, 03 Dec 2015 11:43:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4Wz4-0004DN-Uz for grub-devel@gnu.org; Thu, 03 Dec 2015 11:43:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4Wyz-0000ef-Oq for grub-devel@gnu.org; Thu, 03 Dec 2015 11:43:54 -0500 Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]:35001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4Wyz-0000e8-EL for grub-devel@gnu.org; Thu, 03 Dec 2015 11:43:49 -0500 Received: by lbcdv4 with SMTP id dv4so5143988lbc.2 for ; Thu, 03 Dec 2015 08:43:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=ZVDDAnzt2lUEiZvV4fTSXefSCUnPjngqnnKXEOjBN3w=; b=BZatr6MkKTSk4smllVCc7kaUOVXmdZW9spsin5edinXZsvJVPHQf1plRlW1b8V2nre //cILJCUKXWGzIuv//Tg9MNw2Rs8lvne/ZY1sUZ7/Fo1vyMjaw66w9wZE+EGyk9TJfV9 ayADo7hSQBx6c6RUgX7FO6nCoFxcA9XxYla8aw4LI6B4Zp49eg6Dl5sWrt3+ojoMsUAn Zs9Wklu1efhbhSj0DvfqBAydejqTrxxadPviy7RkFPU2ygF/kQz8u4e7qCBrmo+yLdJ5 3qeLQ8Z/ga+5IYbmwhEAtXCZqoFUwHQyE3/sdmN65lehJt7t1y867QEC31M6HlKreqa8 ZEaw== X-Received: by 10.112.167.131 with SMTP id zo3mr5840577lbb.91.1449161028338; Thu, 03 Dec 2015 08:43:48 -0800 (PST) Received: from [192.168.1.41] (ppp91-76-25-247.pppoe.mtu-net.ru. [91.76.25.247]) by smtp.gmail.com with ESMTPSA id m64sm1529579lfd.45.2015.12.03.08.43.46 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Dec 2015 08:43:47 -0800 (PST) Subject: Re: Grub get and set efi variables To: The development of GNU GRUB References: <563999B9.7020108@gmail.com> <5643845E.9060204@gmail.com> <5646B275.5040707@gmail.com> <56586384.1030504@gmail.com> <565ABE97.5060109@gmail.com> From: Andrei Borzenkov Message-ID: <56607141.8030209@gmail.com> Date: Thu, 3 Dec 2015 19:43:45 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::22b 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: Thu, 03 Dec 2015 16:43:56 -0000 02.12.2015 17:52, Ignat Korchagin пишет: > OK. Updated patch below: > > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > index 0cc40bb..aa7b927 100644 > --- a/grub-core/Makefile.core.def > +++ b/grub-core/Makefile.core.def > @@ -735,6 +735,12 @@ module = { > }; > > module = { > + name = efivar; > + efi = commands/efi/efivar.c; > + enable = efi; > +}; > + > +module = { > name = blocklist; > common = commands/blocklist.c; > }; > diff --git a/grub-core/commands/efi/efivar.c b/grub-core/commands/efi/efivar.c > new file mode 100644 > index 0000000..8acd0c2 > --- /dev/null > +++ b/grub-core/commands/efi/efivar.c > @@ -0,0 +1,238 @@ > +/* efivar.c - Read EFI global variables. */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2015 Free Software Foundation, Inc. > + * Copyright (C) 2015 CloudFlare, 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 const struct grub_arg_option options[] = { > + {"format", 'f', GRUB_ARG_OPTION_OPTIONAL, N_("Parse EFI_VAR in > specific format (hex, uint8, ascii, dump). Default: hex."), > N_("FORMAT"), ARG_TYPE_STRING}, > + {"set", 's', GRUB_ARG_OPTION_OPTIONAL, N_("Save parsed result to > environment variable (does not work with dump)."), N_("ENV_VAR"), > ARG_TYPE_STRING}, > + {0, 0, 0, 0, 0, 0} > +}; > + > +enum efi_var_type > + { > + EFI_VAR_ASCII = 0, > + EFI_VAR_UINT8, > + EFI_VAR_HEX, > + EFI_VAR_DUMP, > + EFI_VAR_INVALID = -1 > + }; > + > +static enum efi_var_type > +parse_efi_var_type (const char *type) > +{ > + if (!grub_strncmp (type, "ascii", sizeof("ascii"))) > + return EFI_VAR_ASCII; > + > + if (!grub_strncmp (type, "uint8", sizeof("uint8"))) > + return EFI_VAR_UINT8; > + > + if (!grub_strncmp (type, "hex", sizeof("hex"))) > + return EFI_VAR_HEX; > + > + if (!grub_strncmp (type, "dump", sizeof("dump"))) > + return EFI_VAR_DUMP; > + > + return EFI_VAR_INVALID; > +} > + This should be grub_strcmp everywhere, there is no reason to use grub_strncmp. > + > +GRUB_MOD_INIT (efivar) > +{ > + cmd = grub_register_extcmd ("get_efivar", grub_cmd_get_efi_var, 0, > N_("[-f FORMAT] [-s ENV_VAR] EFI_VAR"), > + N_("Read EFI variable and print it or save its contents to I believe it should be "content" (without final `s') but English is not native. Otherwise OK from my side. Could you also add documentation part for it?