From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YGJW9-00066p-SV for mharc-grub-devel@gnu.org; Tue, 27 Jan 2015 22:42:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGJW8-00063i-6F for grub-devel@gnu.org; Tue, 27 Jan 2015 22:42:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGJW3-0004vq-Dg for grub-devel@gnu.org; Tue, 27 Jan 2015 22:42:12 -0500 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]:33006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGJW3-0004vd-6p for grub-devel@gnu.org; Tue, 27 Jan 2015 22:42:07 -0500 Received: by mail-lb0-f181.google.com with SMTP id u10so16529336lbd.12 for ; Tue, 27 Jan 2015 19:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=rKSs9hZ6QLs1YmMwggZAMEva5W+WfMaVuk8TeNuI2SU=; b=q5Ep61w+wvlvzYmbpRugccMjLWlZYpIGJITFI95xK1kbnOQWLKQLtjyZxpLAWrrvM9 DOGCiYkzjMJeJVY8E91PyLC5Nm6MRFKmLyW28wN0deEwB8pOELxp/OJYxKQYn6uzhM8C CnNAT9maArqZKKxgCSdKzn+i+qsiZ6uEcdWZju82Fl52cqNvPpOxlOvyAqjghB55RRK0 hpkO+cDE7E2SRyk9RzVG3fh6dlpmWMtTPjenYjzQ+FAsMNeO7yj5puijfkYwwfu6FrD2 FIEtt+dVDgc72PXTwfMZCM/enCZf/yvKQQgOTHiz4lX6liogmcpCumF2Y+xJD2XXCTJm 2HqQ== X-Received: by 10.152.197.5 with SMTP id iq5mr5492130lac.6.1422416524899; Tue, 27 Jan 2015 19:42:04 -0800 (PST) Received: from opensuse.site (ppp91-76-14-38.pppoe.mtu-net.ru. [91.76.14.38]) by mx.google.com with ESMTPSA id lk6sm966795lac.1.2015.01.27.19.42.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jan 2015 19:42:04 -0800 (PST) Date: Wed, 28 Jan 2015 06:42:01 +0300 From: Andrei Borzenkov To: Steve McIntyre Subject: Re: [PATCH] Add support for running a 64-bit Linux kernel on a 32-bit EFI Message-ID: <20150128064201.644640cc@opensuse.site> In-Reply-To: <20150128005625.GC20325@einval.com> References: <20150128005625.GC20325@einval.com> X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.25; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::235 Cc: grub-devel@gnu.org 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: Wed, 28 Jan 2015 03:42:13 -0000 =D0=92 Wed, 28 Jan 2015 00:56:30 +0000 Steve McIntyre =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > Hi folks, >=20 > I've been working in Debian on adding support for amd64 platforms > which are shipped with 32-bit UEFI firmware, such as the Asus X205TA > and other Bay Trail machines. As part of that, I've had a patch > accepted by the Linux EFI maintainers [1] to expose the size of the > underlying firmware to userland via a new sysfs file. It should make > mainline Linux very soon. >=20 > Using that patch as a basis, I've patched grub to use the new sysfs > interface to work out the correct default x86 platform to match the > firmware. Colin's happy with the patch and has just accepted it for > Debian's grub package for now; I promised to submit it upstream for > review, so here it is. :-) >=20 > Feedback welcome please! >=20 > [1] http://article.gmane.org/gmane.linux.kernel.efi/5229 >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Some platforms might be capable of running a 64-bit Linux kernel but > only use a 32-bit EFI. To support such systems, it is necessary to > work out the size of the firmware rather than just the size of the > kernel. To enable that, there is now an extra EFI sysfs file to > describe the underlying firmware. Read that if possible, otherwise > fall back to the kernel type as before. >=20 > Signed-off-by: Steve McIntyre > --- > grub-core/osdep/linux/platform.c | 38 ++++++++++++++++++++++++++++++++= +++++- > 1 file changed, 37 insertions(+), 1 deletion(-) >=20 > diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/pla= tform.c > index 4b9f6ef..5668ae5 100644 > --- a/grub-core/osdep/linux/platform.c > +++ b/grub-core/osdep/linux/platform.c > @@ -60,6 +60,42 @@ is_64_kernel (void) > return strcmp (un.machine, "x86_64") =3D=3D 0; > } > =20 > +static int > +read_platform_size (void) > +{ > + FILE *fp; > + char *buf =3D NULL; > + size_t len =3D 0; > + int ret =3D 0; > + > + /* Newer kernels can tell us directly about the size of the > + * underlying firmware - let's see if that interface is there. */ > + fp =3D grub_util_fopen ("/sys/firmware/efi/fw_platform_size", "r"); > + if (fp !=3D NULL) > + { > + if (getline (&buf, &len, fp) > 0) size >=3D 2 > + { > + if (strncmp (buf, "32", 2) =3D=3D 0) > + ret =3D 32; > + else if (strncmp (buf, "64", 2) =3D=3D 0) > + ret =3D 64; > + } > + free (buf); > + fclose (fp); > + } > + > + if (ret =3D=3D 0) > + /* Unrecognised - fall back to matching the kernel size instead */ > + { I usually prefer comments inside braces and indented accordingly. Could you send it suitable for git am? Mentioning platforms in commit message would be useful for reference. BTW, re subject - this is about installing 32 bit EFI grub on 64 bit Linux, not running, right? It already should be able to run kernel if installed appropriately manually. > + if (is_64_kernel ()) > + ret =3D 64; > + else > + ret =3D 32; > + } > + > + return ret; > +} > + > const char * > grub_install_get_default_x86_platform (void) > {=20 > @@ -77,7 +113,7 @@ grub_install_get_default_x86_platform (void) > if (is_not_empty_directory ("/sys/firmware/efi")) > { > grub_util_info ("...found"); > - if (is_64_kernel ()) > + if (read_platform_size() =3D=3D 64) > return "x86_64-efi"; > else > return "i386-efi";