From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1TAHzG-0000cj-Pu for mharc-grub-devel@gnu.org; Sat, 08 Sep 2012 06:10:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAHzD-0000ba-Oc for grub-devel@gnu.org; Sat, 08 Sep 2012 06:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAHzC-0004L2-3W for grub-devel@gnu.org; Sat, 08 Sep 2012 06:09:59 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:48960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAHzB-0004Ky-Pf for grub-devel@gnu.org; Sat, 08 Sep 2012 06:09:58 -0400 Received: by weys10 with SMTP id s10so260091wey.0 for ; Sat, 08 Sep 2012 03:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; bh=0nARlRoCxvzup+yx6ejmGVjSLArtb9ybmk3vYh1yvnw=; b=ApOuSAawNOg9cpP2BV/RW6PkCiOL9eCR/WmeTF2zjxb0jdmfKotMoABPCUBU49d6n/ CqP+z7cpVQdEUqPqQw+WNsIpXOBqfdas5lBj7gAB7Hr8rLKnxoJyZk2zl7hsnRVJ4PRP 4FL/LZqWF0kYMLQqpdhhH0ImUOMKQiim6WmNRWmriwlUawx2dxYhvMgvsFrrjLxBK01A wz6K/SYskDAz/PmO4H6SW69yh74nHQkiY0DF2Z4VzXbdqSC9EfNUHjgCh8LPROeW0P7a ZXcgSQitHfx1T5L6P5R/JtQnV0qTtw0LxTWF1qZ7uSQD6s/X4pyaDuyqzmXoxDH6Uax/ Dirg== Received: by 10.216.209.8 with SMTP id r8mr4876161weo.51.1347098994825; Sat, 08 Sep 2012 03:09:54 -0700 (PDT) Received: from debian.x201.phnet (68-124.62-81.cust.bluewin.ch. [81.62.124.68]) by mx.google.com with ESMTPS id el6sm4004931wib.8.2012.09.08.03.09.52 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 08 Sep 2012 03:09:53 -0700 (PDT) Message-ID: <504B196F.5090502@gmail.com> Date: Sat, 08 Sep 2012 12:09:51 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120817 Icedove/10.0.6 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [PATCH] Add support for entering the firmware setup screen. References: <1337869896-3671-1-git-send-email-pjones@redhat.com> In-Reply-To: <1337869896-3671-1-git-send-email-pjones@redhat.com> X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig459484C3C4D1A5EBCBAD09AF" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.169 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: Sat, 08 Sep 2012 10:10:01 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig459484C3C4D1A5EBCBAD09AF Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Patch committed. Please next time use indent when creating new files and follow ChangeLog style. On 24.05.2012 16:31, Peter Jones wrote: >=20 > diff --git a/ChangeLog b/ChangeLog > index ce52576..29ebcbd 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,11 @@ > +2012-05-24 Peter Jones > + > + * grub-core/Makefile.core.def: add efifwsetup module > + * grub-core/commands/efi/efifwsetup.c: add code for fwsetup command > + * grub-core/kern/efi/efi.c (grub_efi_set_variable): New function > + * include/grub/efi/api.h: add define for OsIndications variable > + * include/grub/efi/efi.h: export grub_efi_set_variable > + > 2012-04-18 Vladimir Serbinenko > =20 > * configure.ac: Bump to beta5. > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > index 000cf0d..d0c06d5 100644 > --- a/grub-core/Makefile.core.def > +++ b/grub-core/Makefile.core.def > @@ -576,6 +576,12 @@ module =3D { > }; > =20 > module =3D { > + name =3D efifwsetup; > + efi =3D commands/efi/efifwsetup.c; > + enable =3D efi; > +}; > + > +module =3D { > name =3D blocklist; > common =3D commands/blocklist.c; > }; > diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/e= fi/efifwsetup.c > new file mode 100644 > index 0000000..b1cf414 > --- /dev/null > +++ b/grub-core/commands/efi/efifwsetup.c > @@ -0,0 +1,88 @@ > +/* fwsetup.c - Reboot into firmware setup menu. */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2012 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 > + > +GRUB_MOD_LICENSE ("GPLv3+"); > + > +static grub_err_t > +grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), > + int argc __attribute__ ((unused)), > + char **args __attribute__ ((unused))) > +{ > + grub_efi_uint64_t *old_os_indications; > + grub_efi_uint64_t os_indications =3D GRUB_EFI_OS_INDICATIONS_BOOT_TO= _FW_UI; > + grub_err_t status; > + grub_size_t oi_size; > + grub_efi_guid_t global =3D GRUB_EFI_GLOBAL_VARIABLE_GUID; > + > + old_os_indications =3D grub_efi_get_variable("OsIndications", &globa= l, > + &oi_size); > + > + if (old_os_indications !=3D NULL && oi_size =3D=3D 8) > + os_indications |=3D *old_os_indications; > + > + status =3D grub_efi_set_variable("OsIndications", &global, &os_indic= ations, > + sizeof (os_indications)); > + if (status !=3D GRUB_ERR_NONE) > + return status; > + > + grub_reboot(); > + > + return GRUB_ERR_BUG; > +} > + > +static grub_command_t cmd =3D NULL; > + > +static grub_efi_boolean_t > +efifwsetup_is_supported(void) > +{ > + grub_efi_uint64_t *os_indications_supported =3D NULL; > + grub_size_t oi_size =3D 0; > + grub_efi_guid_t global =3D GRUB_EFI_GLOBAL_VARIABLE_GUID; > + > + os_indications_supported =3D grub_efi_get_variable("OsIndicationsSup= ported", > + &global, &oi_size); > + > + if (!os_indications_supported) > + return 0; > + > + if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_U= I) > + return 1; > + > + return 0; > +} > + > +GRUB_MOD_INIT(efifwsetup) > +{ > + if (efifwsetup_is_supported()) > + cmd =3D grub_register_command("fwsetup", grub_cmd_fwsetup, "", > + "Reboot into firmware setup menu."); > + > +} > + > +GRUB_MOD_FINI(efifwsetup) > +{ > + if (cmd) > + grub_unregister_command (cmd); > +} > diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c > index 6f12c76..7a418a6 100644 > --- a/grub-core/kern/efi/efi.c > +++ b/grub-core/kern/efi/efi.c > @@ -230,6 +230,36 @@ grub_efi_get_variable (const char *var, const grub= _efi_guid_t *guid, > return NULL; > } > =20 > +grub_err_t > +grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, > + void *data, grub_size_t datasize) > +{ > + grub_efi_status_t status; > + grub_efi_runtime_services_t *r; > + grub_efi_char16_t *var16; > + grub_size_t len, len16; > + > + len =3D grub_strlen (var); > + len16 =3D len * GRUB_MAX_UTF16_PER_UTF8; > + var16 =3D grub_malloc ((len16 + 1) * sizeof (var16[0])); > + if (!var16) > + return grub_errno; > + len16 =3D grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, le= n, NULL); > + var16[len16] =3D 0; > + > + r =3D grub_efi_system_table->runtime_services; > + > + grub_efi_uint32_t attributes =3D GRUB_EFI_VARIABLE_NON_VOLATILE | > + GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS | > + GRUB_EFI_VARIABLE_RUNTIME_ACCESS; > + > + status =3D efi_call_5 (r->set_variable, var16, guid, attributes, dat= asize,data); > + if (status =3D=3D GRUB_EFI_SUCCESS) > + return GRUB_ERR_NONE; > + > + return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", v= ar); > +} > + > grub_uint64_t > grub_rtc_get_time_ms (void) > { > diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h > index 26127de..a47a4e3 100644 > --- a/include/grub/efi/api.h > +++ b/include/grub/efi/api.h > @@ -58,6 +58,8 @@ > #define GRUB_EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010 > #define GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE 0x00000020 > =20 > +#define GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001ULL > + > #define GRUB_EFI_VARIABLE_NON_VOLATILE 0x0000000000000001 > #define GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002 > #define GRUB_EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 > diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h > index e67d92b..489cf9e 100644 > --- a/include/grub/efi/efi.h > +++ b/include/grub/efi/efi.h > @@ -64,6 +64,11 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address= _map) (grub_efi_uintn_t memo > void *EXPORT_FUNC (grub_efi_get_variable) (const char *variable, > const grub_efi_guid_t *guid, > grub_size_t *datasize_out); > +grub_err_t > +EXPORT_FUNC (grub_efi_set_variable) (const char *var, > + const grub_efi_guid_t *guid, > + void *data, > + grub_size_t datasize); > int > EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_pat= h_t *dp1, > const grub_efi_device_path_t *dp2); --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enig459484C3C4D1A5EBCBAD09AF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlBLGW8ACgkQNak7dOguQgm42AD/SYBQusujEdMt1sIY36FtoMHG JuO4vhyriVVZxwtU/NsA/AneaUVseHkMepYqQZZMU+MlZRWHie+nbZq7ZlUlZRfg =SSK2 -----END PGP SIGNATURE----- --------------enig459484C3C4D1A5EBCBAD09AF--