grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add support for running a 64-bit Linux kernel on a 32-bit EFI
@ 2015-01-28  0:56 Steve McIntyre
  2015-01-28  3:42 ` Andrei Borzenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Steve McIntyre @ 2015-01-28  0:56 UTC (permalink / raw)
  To: grub-devel

Hi folks,

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.

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. :-)

Feedback welcome please!

[1] http://article.gmane.org/gmane.linux.kernel.efi/5229

=====================================================================
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.

Signed-off-by: Steve McIntyre <steve@einval.com>
---
 grub-core/osdep/linux/platform.c |   38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.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") == 0;
 }
 
+static int
+read_platform_size (void)
+{
+  FILE *fp;
+  char *buf = NULL;
+  size_t len = 0;
+  int ret = 0;
+
+  /* Newer kernels can tell us directly about the size of the
+   * underlying firmware - let's see if that interface is there. */
+  fp = grub_util_fopen ("/sys/firmware/efi/fw_platform_size", "r");
+  if (fp != NULL)
+  {
+    if (getline (&buf, &len, fp) > 0)
+      {
+	if (strncmp (buf, "32", 2) == 0)
+	  ret = 32;
+	else if (strncmp (buf, "64", 2) == 0)
+	  ret = 64;
+      }
+    free (buf);
+    fclose (fp);
+  }
+
+  if (ret == 0)
+    /* Unrecognised - fall back to matching the kernel size instead */
+    {
+      if (is_64_kernel ())
+	ret = 64;
+      else
+	ret = 32;
+    }
+
+  return ret;
+}
+
 const char *
 grub_install_get_default_x86_platform (void)
 { 
@@ -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() == 64)
 	return "x86_64-efi";
       else
 	return "i386-efi";
-- 
1.7.10.4

-- 
Steve McIntyre, Cambridge, UK.                                steve@einval.com
"You can't barbecue lettuce!" -- Ellie Crane



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-02 16:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-28  0:56 [PATCH] Add support for running a 64-bit Linux kernel on a 32-bit EFI Steve McIntyre
2015-01-28  3:42 ` Andrei Borzenkov
2015-01-28 23:42   ` Steve McIntyre
2015-02-02 16:07     ` Steve McIntyre
2015-01-29  0:42   ` [PATCH] Recognise a 64-bit Linux kernel on a 32-bit EFI firmware Steve McIntyre

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).