ad4aff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad4aff
From: Matthew Garrett <mjg@redhat.com>
ad4aff
Date: Tue, 10 Jul 2012 11:58:52 -0400
ad4aff
Subject: [PATCH] Add support for Linux EFI stub loading.
ad4aff
ad4aff
Also:
ad4aff
ad4aff
commit 71c843745f22f81e16d259e2e19c99bf3c1855c1
ad4aff
Author: Colin Watson <cjwatson@ubuntu.com>
ad4aff
Date:   Tue Oct 23 10:40:49 2012 -0400
ad4aff
ad4aff
Don't allow insmod when secure boot is enabled.
ad4aff
ad4aff
Hi,
ad4aff
ad4aff
Fedora's patch to forbid insmod in UEFI Secure Boot environments is fine
ad4aff
as far as it goes.  However, the insmod command is not the only way that
ad4aff
modules can be loaded.  In particular, the 'normal' command, which
ad4aff
implements the usual GRUB menu and the fully-featured command prompt,
ad4aff
will implicitly load commands not currently loaded into memory.  This
ad4aff
permits trivial Secure Boot violations by writing commands implementing
ad4aff
whatever you want to do and pointing $prefix at the malicious code.
ad4aff
ad4aff
I'm currently test-building this patch (replacing your current
ad4aff
grub-2.00-no-insmod-on-sb.patch), but this should be more correct.  It
ad4aff
moves the check into grub_dl_load_file.
ad4aff
---
70dc03
 grub-core/Makefile.core.def       |  16 +-
ad4aff
 grub-core/kern/dl.c               |  21 +++
ad4aff
 grub-core/kern/efi/efi.c          |  28 ++++
ad4aff
 grub-core/kern/efi/mm.c           |  32 ++++
dbfd2e
 grub-core/loader/arm64/linux.c    | 118 +++++++-------
e01902
 grub-core/loader/arm64/xen_boot.c |   1 -
dbfd2e
 grub-core/loader/efi/linux.c      |  70 ++++++++
ad4aff
 grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++
ad4aff
 grub-core/loader/i386/pc/linux.c  |  10 +-
dbfd2e
 include/grub/arm/linux.h          |   9 +
dbfd2e
 include/grub/arm64/linux.h        |  10 ++
dbfd2e
 include/grub/efi/efi.h            |   7 +-
ad4aff
 include/grub/efi/linux.h          |  31 ++++
ad4aff
 include/grub/i386/linux.h         |   1 +
e01902
 14 files changed, 620 insertions(+), 69 deletions(-)
ad4aff
 create mode 100644 grub-core/loader/efi/linux.c
ad4aff
 create mode 100644 grub-core/loader/i386/efi/linux.c
ad4aff
 create mode 100644 include/grub/efi/linux.h
ad4aff
ad4aff
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
15a207
index 9590e87d9c0..0b4b0c2122d 100644
ad4aff
--- a/grub-core/Makefile.core.def
ad4aff
+++ b/grub-core/Makefile.core.def
15a207
@@ -1626,13 +1626,6 @@ module = {
ad4aff
   enable = i386_pc;
ad4aff
 };
ad4aff
 
ad4aff
-
ad4aff
-module = {
ad4aff
-  name = linux16;
ad4aff
-  common = loader/i386/pc/linux.c;
ad4aff
-  enable = x86;
ad4aff
-};
ad4aff
-
ad4aff
 module = {
ad4aff
   name = ntldr;
ad4aff
   i386_pc = loader/i386/pc/ntldr.c;
15a207
@@ -1685,7 +1678,9 @@ module = {
ad4aff
 
ad4aff
 module = {
ad4aff
   name = linux;
ad4aff
-  x86 = loader/i386/linux.c;
ad4aff
+  i386_pc = loader/i386/pc/linux.c;
ad4aff
+  x86_64_efi = loader/i386/efi/linux.c;
ad4aff
+  i386_efi = loader/i386/efi/linux.c;
ad4aff
   xen = loader/i386/xen.c;
ad4aff
   i386_pc = lib/i386/pc/vesa_modes_table.c;
ad4aff
   mips = loader/mips/linux.c;
15a207
@@ -1696,9 +1691,14 @@ module = {
15a207
   arm_efi = loader/arm64/linux.c;
15a207
   arm_uboot = loader/arm/linux.c;
ad4aff
   arm64 = loader/arm64/linux.c;
ad4aff
+  emu = loader/emu/linux.c;
ad4aff
+  fdt = lib/fdt.c;
ad4aff
+
ad4aff
   common = loader/linux.c;
ad4aff
   common = lib/cmdline.c;
ad4aff
   enable = noemu;
ad4aff
+
ad4aff
+  efi = loader/efi/linux.c;
ad4aff
 };
ad4aff
 
ad4aff
 module = {
ad4aff
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
ad4aff
index e394cd96f8c..04e804d1668 100644
ad4aff
--- a/grub-core/kern/dl.c
ad4aff
+++ b/grub-core/kern/dl.c
ad4aff
@@ -38,6 +38,14 @@
ad4aff
 #define GRUB_MODULES_MACHINE_READONLY
ad4aff
 #endif
ad4aff
 
ad4aff
+#ifdef GRUB_MACHINE_EMU
ad4aff
+#include <sys mman.h="">
ad4aff
+#endif
ad4aff
+
ad4aff
+#ifdef GRUB_MACHINE_EFI
ad4aff
+#include <grub efi="" efi.h="">
ad4aff
+#endif
ad4aff
+
ad4aff
 
ad4aff
 
ad4aff
 #pragma GCC diagnostic ignored "-Wcast-align"
ad4aff
@@ -686,6 +694,19 @@ grub_dl_load_file (const char *filename)
ad4aff
   void *core = 0;
ad4aff
   grub_dl_t mod = 0;
ad4aff
 
ad4aff
+#ifdef GRUB_MACHINE_EFI
ad4aff
+  if (grub_efi_secure_boot ())
ad4aff
+    {
ad4aff
+#if 0
ad4aff
+      /* This is an error, but grub2-mkconfig still generates a pile of
ad4aff
+       * insmod commands, so emitting it would be mostly just obnoxious. */
ad4aff
+      grub_error (GRUB_ERR_ACCESS_DENIED,
ad4aff
+		  "Secure Boot forbids loading module from %s", filename);
ad4aff
+#endif
ad4aff
+      return 0;
ad4aff
+    }
ad4aff
+#endif
ad4aff
+
ad4aff
   grub_boot_time ("Loading module %s", filename);
ad4aff
 
ad4aff
   file = grub_file_open (filename);
ad4aff
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
ad4aff
index 708581fcbde..c8a9d8307c0 100644
ad4aff
--- a/grub-core/kern/efi/efi.c
ad4aff
+++ b/grub-core/kern/efi/efi.c
ad4aff
@@ -273,6 +273,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
ad4aff
   return NULL;
ad4aff
 }
ad4aff
 
ad4aff
+grub_efi_boolean_t
ad4aff
+grub_efi_secure_boot (void)
ad4aff
+{
ad4aff
+  grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
ad4aff
+  grub_size_t datasize;
ad4aff
+  char *secure_boot = NULL;
ad4aff
+  char *setup_mode = NULL;
ad4aff
+  grub_efi_boolean_t ret = 0;
ad4aff
+
ad4aff
+  secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
ad4aff
+
ad4aff
+  if (datasize != 1 || !secure_boot)
ad4aff
+    goto out;
ad4aff
+
ad4aff
+  setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
ad4aff
+
ad4aff
+  if (datasize != 1 || !setup_mode)
ad4aff
+    goto out;
ad4aff
+
ad4aff
+  if (*secure_boot && !*setup_mode)
ad4aff
+    ret = 1;
ad4aff
+
ad4aff
+ out:
ad4aff
+  grub_free (secure_boot);
ad4aff
+  grub_free (setup_mode);
ad4aff
+  return ret;
ad4aff
+}
ad4aff
+
ad4aff
 #pragma GCC diagnostic ignored "-Wcast-align"
ad4aff
 
ad4aff
 /* Search the mods section from the PE32/PE32+ image. This code uses
ad4aff
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
15a207
index 42ad7c570a5..5cdf6c943f2 100644
ad4aff
--- a/grub-core/kern/efi/mm.c
ad4aff
+++ b/grub-core/kern/efi/mm.c
ad4aff
@@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
ad4aff
     }
ad4aff
 }
ad4aff
 
ad4aff
+/* Allocate pages below a specified address */
ad4aff
+void *
ad4aff
+grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
ad4aff
+			     grub_efi_uintn_t pages)
ad4aff
+{
ad4aff
+  grub_efi_status_t status;
ad4aff
+  grub_efi_boot_services_t *b;
ad4aff
+  grub_efi_physical_address_t address = max;
ad4aff
+
ad4aff
+  if (max > 0xffffffff)
ad4aff
+    return 0;
ad4aff
+
ad4aff
+  b = grub_efi_system_table->boot_services;
ad4aff
+  status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
ad4aff
+
ad4aff
+  if (status != GRUB_EFI_SUCCESS)
ad4aff
+    return 0;
ad4aff
+
ad4aff
+  if (address == 0)
ad4aff
+    {
ad4aff
+      /* Uggh, the address 0 was allocated... This is too annoying,
ad4aff
+	 so reallocate another one.  */
ad4aff
+      address = max;
ad4aff
+      status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
ad4aff
+      grub_efi_free_pages (0, pages);
ad4aff
+      if (status != GRUB_EFI_SUCCESS)
ad4aff
+	return 0;
ad4aff
+    }
ad4aff
+
ad4aff
+  return (void *) ((grub_addr_t) address);
ad4aff
+}
ad4aff
+
ad4aff
 /* Allocate pages. Return the pointer to the first of allocated pages.  */
ad4aff
 void *
ad4aff
 grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
ad4aff
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
dbfd2e
index 1f86229f86b..6c00af98dce 100644
ad4aff
--- a/grub-core/loader/arm64/linux.c
ad4aff
+++ b/grub-core/loader/arm64/linux.c
ad4aff
@@ -29,6 +29,7 @@
ad4aff
 #include <grub efi="" efi.h="">
ad4aff
 #include <grub efi="" fdtload.h="">
ad4aff
 #include <grub efi="" memory.h="">
ad4aff
+#include <grub efi="" linux.h="">
ad4aff
 #include <grub efi="" pe32.h="">
ad4aff
 #include <grub i18n.h="">
ad4aff
 #include <grub lib="" cmdline.h="">
ad4aff
@@ -40,6 +41,7 @@ static int loaded;
ad4aff
 
ad4aff
 static void *kernel_addr;
ad4aff
 static grub_uint64_t kernel_size;
ad4aff
+static grub_uint32_t handover_offset;
ad4aff
 
ad4aff
 static char *linux_args;
ad4aff
 static grub_uint32_t cmdline_size;
15a207
@@ -66,7 +68,8 @@ grub_armxx_efi_linux_check_image (struct linux_armxx_kernel_header * lh)
ad4aff
 static grub_err_t
ad4aff
 finalize_params_linux (void)
ad4aff
 {
ad4aff
-  int node, retval;
ad4aff
+  grub_efi_loaded_image_t *loaded_image = NULL;
ad4aff
+  int node, retval, len;
ad4aff
 
ad4aff
   void *fdt;
ad4aff
 
dbfd2e
@@ -101,79 +104,70 @@ finalize_params_linux (void)
ad4aff
   if (grub_fdt_install() != GRUB_ERR_NONE)
ad4aff
     goto failure;
ad4aff
 
ad4aff
-  return GRUB_ERR_NONE;
ad4aff
-
ad4aff
-failure:
ad4aff
-  grub_fdt_unload();
ad4aff
-  return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
ad4aff
-}
ad4aff
-
ad4aff
-grub_err_t
15a207
-grub_armxx_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
ad4aff
-{
ad4aff
-  grub_efi_memory_mapped_device_path_t *mempath;
ad4aff
-  grub_efi_handle_t image_handle;
ad4aff
-  grub_efi_boot_services_t *b;
ad4aff
-  grub_efi_status_t status;
ad4aff
-  grub_efi_loaded_image_t *loaded_image;
ad4aff
-  int len;
ad4aff
-
ad4aff
-  mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
ad4aff
-  if (!mempath)
ad4aff
-    return grub_errno;
ad4aff
-
ad4aff
-  mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
ad4aff
-  mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
ad4aff
-  mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
ad4aff
-  mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
ad4aff
-  mempath[0].start_address = addr;
ad4aff
-  mempath[0].end_address = addr + size;
ad4aff
-
ad4aff
-  mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
ad4aff
-  mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
ad4aff
-  mempath[1].header.length = sizeof (grub_efi_device_path_t);
ad4aff
-
ad4aff
-  b = grub_efi_system_table->boot_services;
ad4aff
-  status = b->load_image (0, grub_efi_image_handle,
ad4aff
-			  (grub_efi_device_path_t *) mempath,
ad4aff
-			  (void *) addr, size, &image_handle);
ad4aff
-  if (status != GRUB_EFI_SUCCESS)
ad4aff
-    return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
ad4aff
-
ad4aff
-  grub_dprintf ("linux", "linux command line: '%s'\n", args);
ad4aff
+  grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
ad4aff
+		fdt);
ad4aff
 
ad4aff
   /* Convert command line to UCS-2 */
ad4aff
-  loaded_image = grub_efi_get_loaded_image (image_handle);
ad4aff
+  loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
ad4aff
+  if (!loaded_image)
ad4aff
+    goto failure;
ad4aff
+
ad4aff
   loaded_image->load_options_size = len =
ad4aff
-    (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
ad4aff
+    (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t);
ad4aff
   loaded_image->load_options =
ad4aff
     grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
ad4aff
   if (!loaded_image->load_options)
ad4aff
-    return grub_errno;
ad4aff
+    return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
ad4aff
 
ad4aff
   loaded_image->load_options_size =
ad4aff
     2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
ad4aff
-			    (grub_uint8_t *) args, len, NULL);
ad4aff
+			    (grub_uint8_t *) linux_args, len, NULL);
ad4aff
 
ad4aff
-  grub_dprintf ("linux", "starting image %p\n", image_handle);
ad4aff
-  status = b->start_image (image_handle, 0, NULL);
ad4aff
+  return GRUB_ERR_NONE;
ad4aff
 
ad4aff
-  /* When successful, not reached */
ad4aff
-  b->unload_image (image_handle);
ad4aff
-  grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
ad4aff
-		       GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
ad4aff
+failure:
ad4aff
+  grub_fdt_unload();
ad4aff
+  return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
ad4aff
+}
ad4aff
 
ad4aff
-  return grub_errno;
ad4aff
+static void
ad4aff
+free_params (void)
ad4aff
+{
ad4aff
+  grub_efi_loaded_image_t *loaded_image = NULL;
ad4aff
+
ad4aff
+  loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
ad4aff
+  if (loaded_image)
ad4aff
+    {
ad4aff
+      if (loaded_image->load_options)
dbfd2e
+	grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options,
ad4aff
+			     GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
ad4aff
+      loaded_image->load_options = NULL;
ad4aff
+      loaded_image->load_options_size = 0;
ad4aff
+    }
ad4aff
+}
ad4aff
+
ad4aff
+grub_err_t
dbfd2e
+grub_armxx_efi_linux_boot_image (grub_addr_t addr, char *args)
ad4aff
+{
ad4aff
+  grub_err_t retval;
ad4aff
+
ad4aff
+  retval = finalize_params_linux ();
ad4aff
+  if (retval != GRUB_ERR_NONE)
ad4aff
+    return grub_errno;
ad4aff
+
ad4aff
+  grub_dprintf ("linux", "linux command line: '%s'\n", args);
ad4aff
+
dbfd2e
+  retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr);
ad4aff
+
ad4aff
+  /* Never reached... */
ad4aff
+  free_params();
ad4aff
+  return retval;
ad4aff
 }
ad4aff
 
ad4aff
 static grub_err_t
ad4aff
 grub_linux_boot (void)
ad4aff
 {
ad4aff
-  if (finalize_params_linux () != GRUB_ERR_NONE)
ad4aff
-    return grub_errno;
ad4aff
-
15a207
-  return (grub_armxx_efi_linux_boot_image((grub_addr_t)kernel_addr,
15a207
-                                          kernel_size, linux_args));
dbfd2e
+  return grub_armxx_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args);
ad4aff
 }
ad4aff
 
ad4aff
 static grub_err_t
dbfd2e
@@ -287,6 +281,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
ad4aff
 {
ad4aff
   grub_file_t file = 0;
15a207
   struct linux_armxx_kernel_header lh;
dbfd2e
+  struct grub_armxx_linux_pe_header *pe;
ad4aff
 
ad4aff
   grub_dl_ref (my_mod);
ad4aff
 
dbfd2e
@@ -331,6 +326,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
ad4aff
 
ad4aff
   grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
ad4aff
 
ad4aff
+  if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size))
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]);
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
ad4aff
+  handover_offset = pe->opt.entry_addr;
ad4aff
+
ad4aff
   cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
ad4aff
   linux_args = grub_malloc (cmdline_size);
ad4aff
   if (!linux_args)
e01902
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
e01902
index 1003a0b9997..f35b16caa92 100644
e01902
--- a/grub-core/loader/arm64/xen_boot.c
e01902
+++ b/grub-core/loader/arm64/xen_boot.c
e01902
@@ -266,7 +266,6 @@ xen_boot (void)
e01902
     return err;
e01902
 
e01902
   return grub_armxx_efi_linux_boot_image (xen_hypervisor->start,
e01902
-					  xen_hypervisor->size,
e01902
 					  xen_hypervisor->cmdline);
e01902
 }
e01902
 
ad4aff
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
ad4aff
new file mode 100644
dbfd2e
index 00000000000..c24202a5dd1
ad4aff
--- /dev/null
ad4aff
+++ b/grub-core/loader/efi/linux.c
dbfd2e
@@ -0,0 +1,70 @@
ad4aff
+/*
ad4aff
+ *  GRUB  --  GRand Unified Bootloader
ad4aff
+ *  Copyright (C) 2014 Free Software Foundation, Inc.
ad4aff
+ *
ad4aff
+ *  GRUB is free software: you can redistribute it and/or modify
ad4aff
+ *  it under the terms of the GNU General Public License as published by
ad4aff
+ *  the Free Software Foundation, either version 3 of the License, or
ad4aff
+ *  (at your option) any later version.
ad4aff
+ *
ad4aff
+ *  GRUB is distributed in the hope that it will be useful,
ad4aff
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ad4aff
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ad4aff
+ *  GNU General Public License for more details.
ad4aff
+ *
ad4aff
+ *  You should have received a copy of the GNU General Public License
ad4aff
+ *  along with GRUB.  If not, see <http: www.gnu.org="" licenses=""/>.
ad4aff
+ */
ad4aff
+
ad4aff
+#include <grub err.h="">
ad4aff
+#include <grub mm.h="">
ad4aff
+#include <grub types.h="">
ad4aff
+#include <grub cpu="" linux.h="">
ad4aff
+#include <grub efi="" efi.h="">
ad4aff
+#include <grub efi="" pe32.h="">
ad4aff
+#include <grub efi="" linux.h="">
ad4aff
+
ad4aff
+#define SHIM_LOCK_GUID \
ad4aff
+ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} }
ad4aff
+
ad4aff
+struct grub_efi_shim_lock
ad4aff
+{
ad4aff
+  grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size);
ad4aff
+};
ad4aff
+typedef struct grub_efi_shim_lock grub_efi_shim_lock_t;
ad4aff
+
ad4aff
+grub_efi_boolean_t
ad4aff
+grub_linuxefi_secure_validate (void *data, grub_uint32_t size)
ad4aff
+{
ad4aff
+  grub_efi_guid_t guid = SHIM_LOCK_GUID;
ad4aff
+  grub_efi_shim_lock_t *shim_lock;
ad4aff
+
ad4aff
+  shim_lock = grub_efi_locate_protocol(&guid, NULL);
ad4aff
+
ad4aff
+  if (!shim_lock)
ad4aff
+    return 1;
ad4aff
+
ad4aff
+  if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS)
ad4aff
+    return 1;
ad4aff
+
ad4aff
+  return 0;
ad4aff
+}
ad4aff
+
dbfd2e
+#pragma GCC diagnostic push
dbfd2e
+#pragma GCC diagnostic ignored "-Wcast-align"
dbfd2e
+
ad4aff
+typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
ad4aff
+
ad4aff
+grub_err_t
ad4aff
+grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
ad4aff
+		     void *kernel_params)
ad4aff
+{
ad4aff
+  handover_func hf;
ad4aff
+
ad4aff
+  hf = (handover_func)((char *)kernel_addr + offset);
ad4aff
+  hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
ad4aff
+
ad4aff
+  return GRUB_ERR_BUG;
ad4aff
+}
dbfd2e
+
dbfd2e
+#pragma GCC diagnostic pop
ad4aff
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
ad4aff
new file mode 100644
ad4aff
index 00000000000..3db82e782df
ad4aff
--- /dev/null
ad4aff
+++ b/grub-core/loader/i386/efi/linux.c
ad4aff
@@ -0,0 +1,335 @@
ad4aff
+/*
ad4aff
+ *  GRUB  --  GRand Unified Bootloader
ad4aff
+ *  Copyright (C) 2012  Free Software Foundation, Inc.
ad4aff
+ *
ad4aff
+ *  GRUB is free software: you can redistribute it and/or modify
ad4aff
+ *  it under the terms of the GNU General Public License as published by
ad4aff
+ *  the Free Software Foundation, either version 3 of the License, or
ad4aff
+ *  (at your option) any later version.
ad4aff
+ *
ad4aff
+ *  GRUB is distributed in the hope that it will be useful,
ad4aff
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ad4aff
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ad4aff
+ *  GNU General Public License for more details.
ad4aff
+ *
ad4aff
+ *  You should have received a copy of the GNU General Public License
ad4aff
+ *  along with GRUB.  If not, see <http: www.gnu.org="" licenses=""/>.
ad4aff
+ */
ad4aff
+
ad4aff
+#include <grub loader.h="">
ad4aff
+#include <grub file.h="">
ad4aff
+#include <grub err.h="">
ad4aff
+#include <grub types.h="">
ad4aff
+#include <grub mm.h="">
ad4aff
+#include <grub cpu="" linux.h="">
ad4aff
+#include <grub command.h="">
ad4aff
+#include <grub i18n.h="">
ad4aff
+#include <grub lib="" cmdline.h="">
ad4aff
+#include <grub efi="" efi.h="">
ad4aff
+#include <grub efi="" linux.h="">
ad4aff
+
ad4aff
+GRUB_MOD_LICENSE ("GPLv3+");
ad4aff
+
ad4aff
+static grub_dl_t my_mod;
ad4aff
+static int loaded;
ad4aff
+static void *kernel_mem;
ad4aff
+static grub_uint64_t kernel_size;
ad4aff
+static grub_uint8_t *initrd_mem;
ad4aff
+static grub_uint32_t handover_offset;
ad4aff
+struct linux_kernel_params *params;
ad4aff
+static char *linux_cmdline;
ad4aff
+
ad4aff
+#define BYTES_TO_PAGES(bytes)   (((bytes) + 0xfff) >> 12)
ad4aff
+
ad4aff
+static grub_err_t
ad4aff
+grub_linuxefi_boot (void)
ad4aff
+{
ad4aff
+  int offset = 0;
ad4aff
+
ad4aff
+#ifdef __x86_64__
ad4aff
+  offset = 512;
ad4aff
+#endif
ad4aff
+  asm volatile ("cli");
ad4aff
+
ad4aff
+  return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset,
ad4aff
+			      params);
ad4aff
+}
ad4aff
+
ad4aff
+static grub_err_t
ad4aff
+grub_linuxefi_unload (void)
ad4aff
+{
ad4aff
+  grub_dl_unref (my_mod);
ad4aff
+  loaded = 0;
ad4aff
+  if (initrd_mem)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
ad4aff
+			 BYTES_TO_PAGES(params->ramdisk_size));
ad4aff
+  if (linux_cmdline)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
ad4aff
+			 linux_cmdline,
ad4aff
+			 BYTES_TO_PAGES(params->cmdline_size + 1));
ad4aff
+  if (kernel_mem)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
ad4aff
+			 BYTES_TO_PAGES(kernel_size));
ad4aff
+  if (params)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
ad4aff
+			 BYTES_TO_PAGES(16384));
ad4aff
+  return GRUB_ERR_NONE;
ad4aff
+}
ad4aff
+
ad4aff
+static grub_err_t
ad4aff
+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
ad4aff
+                 int argc, char *argv[])
ad4aff
+{
ad4aff
+  grub_file_t *files = 0;
ad4aff
+  int i, nfiles = 0;
ad4aff
+  grub_size_t size = 0;
ad4aff
+  grub_uint8_t *ptr;
ad4aff
+
ad4aff
+  if (argc == 0)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (!loaded)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  files = grub_zalloc (argc * sizeof (files[0]));
ad4aff
+  if (!files)
ad4aff
+    goto fail;
ad4aff
+
ad4aff
+  for (i = 0; i < argc; i++)
ad4aff
+    {
ad4aff
+      grub_file_filter_disable_compression ();
ad4aff
+      files[i] = grub_file_open (argv[i]);
ad4aff
+      if (! files[i])
ad4aff
+        goto fail;
ad4aff
+      nfiles++;
ad4aff
+      size += ALIGN_UP (grub_file_size (files[i]), 4);
ad4aff
+    }
ad4aff
+
ad4aff
+  initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size));
ad4aff
+  if (!initrd_mem)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  params->ramdisk_size = size;
ad4aff
+  params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem;
ad4aff
+
ad4aff
+  ptr = initrd_mem;
ad4aff
+
ad4aff
+  for (i = 0; i < nfiles; i++)
ad4aff
+    {
ad4aff
+      grub_ssize_t cursize = grub_file_size (files[i]);
ad4aff
+      if (grub_file_read (files[i], ptr, cursize) != cursize)
ad4aff
+        {
ad4aff
+          if (!grub_errno)
ad4aff
+            grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
ad4aff
+                        argv[i]);
ad4aff
+          goto fail;
ad4aff
+        }
ad4aff
+      ptr += cursize;
ad4aff
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
ad4aff
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
ad4aff
+    }
ad4aff
+
ad4aff
+  params->ramdisk_size = size;
ad4aff
+
ad4aff
+ fail:
ad4aff
+  for (i = 0; i < nfiles; i++)
ad4aff
+    grub_file_close (files[i]);
ad4aff
+  grub_free (files);
ad4aff
+
ad4aff
+  if (initrd_mem && grub_errno)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
ad4aff
+			 BYTES_TO_PAGES(size));
ad4aff
+
ad4aff
+  return grub_errno;
ad4aff
+}
ad4aff
+
ad4aff
+static grub_err_t
ad4aff
+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
ad4aff
+		int argc, char *argv[])
ad4aff
+{
ad4aff
+  grub_file_t file = 0;
ad4aff
+  struct linux_kernel_header lh;
ad4aff
+  grub_ssize_t len, start, filelen;
ad4aff
+  void *kernel = NULL;
ad4aff
+
ad4aff
+  grub_dl_ref (my_mod);
ad4aff
+
ad4aff
+  if (argc == 0)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  file = grub_file_open (argv[0]);
ad4aff
+  if (! file)
ad4aff
+    goto fail;
ad4aff
+
ad4aff
+  filelen = grub_file_size (file);
ad4aff
+
ad4aff
+  kernel = grub_malloc(filelen);
ad4aff
+
ad4aff
+  if (!kernel)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (grub_file_read (file, kernel, filelen) != filelen)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]);
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (! grub_linuxefi_secure_validate (kernel, filelen))
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"),
ad4aff
+		  argv[0]);
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384));
ad4aff
+
ad4aff
+  if (! params)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  grub_memset (params, 0, 16384);
ad4aff
+
ad4aff
+  grub_memcpy (&lh, kernel, sizeof (lh));
ad4aff
+
ad4aff
+  if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_OS, N_("invalid magic number"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (lh.setup_sects > GRUB_LINUX_MAX_SETUP_SECTS)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_OS, N_("too many setup sectors"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (lh.version < grub_cpu_to_le16 (0x020b))
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_OS, N_("kernel too old"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (!lh.handover_offset)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support EFI handover"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  grub_dprintf ("linux", "setting up cmdline\n");
ad4aff
+  linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
ad4aff
+					 BYTES_TO_PAGES(lh.cmdline_size + 1));
ad4aff
+
ad4aff
+  if (!linux_cmdline)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
ad4aff
+  grub_create_loader_cmdline (argc, argv,
ad4aff
+                              linux_cmdline + sizeof (LINUX_IMAGE) - 1,
ad4aff
+			      lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1));
ad4aff
+
ad4aff
+  lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
ad4aff
+
ad4aff
+  handover_offset = lh.handover_offset;
ad4aff
+
ad4aff
+  start = (lh.setup_sects + 1) * 512;
ad4aff
+  len = grub_file_size(file) - start;
ad4aff
+
ad4aff
+  kernel_mem = grub_efi_allocate_pages_max(lh.pref_address,
ad4aff
+					   BYTES_TO_PAGES(lh.init_size));
ad4aff
+
ad4aff
+  if (!kernel_mem)
ad4aff
+    kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
ad4aff
+					     BYTES_TO_PAGES(lh.init_size));
ad4aff
+
ad4aff
+  if (!kernel_mem)
ad4aff
+    {
ad4aff
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
ad4aff
+      goto fail;
ad4aff
+    }
ad4aff
+
ad4aff
+  grub_memcpy (kernel_mem, (char *)kernel + start, len);
ad4aff
+  grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
ad4aff
+  loaded=1;
ad4aff
+
ad4aff
+  lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
ad4aff
+  grub_memcpy (params, &lh, 2 * 512);
ad4aff
+
ad4aff
+  params->type_of_loader = 0x21;
ad4aff
+
ad4aff
+ fail:
ad4aff
+
ad4aff
+  if (file)
ad4aff
+    grub_file_close (file);
ad4aff
+
ad4aff
+  if (kernel)
ad4aff
+    grub_free (kernel);
ad4aff
+
ad4aff
+  if (grub_errno != GRUB_ERR_NONE)
ad4aff
+    {
ad4aff
+      grub_dl_unref (my_mod);
ad4aff
+      loaded = 0;
ad4aff
+    }
ad4aff
+
ad4aff
+  if (linux_cmdline && !loaded)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
ad4aff
+			 linux_cmdline,
ad4aff
+			 BYTES_TO_PAGES(lh.cmdline_size + 1));
ad4aff
+
ad4aff
+  if (kernel_mem && !loaded)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
ad4aff
+			 BYTES_TO_PAGES(kernel_size));
ad4aff
+
ad4aff
+  if (params && !loaded)
ad4aff
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
ad4aff
+			 BYTES_TO_PAGES(16384));
ad4aff
+
ad4aff
+  return grub_errno;
ad4aff
+}
ad4aff
+
ad4aff
+static grub_command_t cmd_linux, cmd_initrd;
ad4aff
+static grub_command_t cmd_linuxefi, cmd_initrdefi;
ad4aff
+
ad4aff
+GRUB_MOD_INIT(linux)
ad4aff
+{
ad4aff
+  cmd_linux =
ad4aff
+    grub_register_command ("linux", grub_cmd_linux,
ad4aff
+                           0, N_("Load Linux."));
ad4aff
+  cmd_linuxefi =
ad4aff
+    grub_register_command ("linuxefi", grub_cmd_linux,
ad4aff
+                           0, N_("Load Linux."));
ad4aff
+  cmd_initrd =
ad4aff
+    grub_register_command ("initrd", grub_cmd_initrd,
ad4aff
+                           0, N_("Load initrd."));
ad4aff
+  cmd_initrdefi =
ad4aff
+    grub_register_command ("initrdefi", grub_cmd_initrd,
ad4aff
+                           0, N_("Load initrd."));
ad4aff
+  my_mod = mod;
ad4aff
+}
ad4aff
+
ad4aff
+GRUB_MOD_FINI(linux)
ad4aff
+{
ad4aff
+  grub_unregister_command (cmd_linux);
ad4aff
+  grub_unregister_command (cmd_linuxefi);
ad4aff
+  grub_unregister_command (cmd_initrd);
ad4aff
+  grub_unregister_command (cmd_initrdefi);
ad4aff
+}
ad4aff
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
ad4aff
index b69cb7a3a7f..a3c87cf2fc2 100644
ad4aff
--- a/grub-core/loader/i386/pc/linux.c
ad4aff
+++ b/grub-core/loader/i386/pc/linux.c
ad4aff
@@ -468,14 +468,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
ad4aff
   return grub_errno;
ad4aff
 }
ad4aff
 
ad4aff
-static grub_command_t cmd_linux, cmd_initrd;
ad4aff
+static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16;
ad4aff
 
ad4aff
 GRUB_MOD_INIT(linux16)
ad4aff
 {
ad4aff
   cmd_linux =
ad4aff
+    grub_register_command ("linux", grub_cmd_linux,
ad4aff
+			   0, N_("Load Linux."));
ad4aff
+  cmd_linux16 =
ad4aff
     grub_register_command ("linux16", grub_cmd_linux,
ad4aff
 			   0, N_("Load Linux."));
ad4aff
   cmd_initrd =
ad4aff
+    grub_register_command ("initrd", grub_cmd_initrd,
ad4aff
+			   0, N_("Load initrd."));
ad4aff
+  cmd_initrd16 =
ad4aff
     grub_register_command ("initrd16", grub_cmd_initrd,
ad4aff
 			   0, N_("Load initrd."));
ad4aff
   my_mod = mod;
ad4aff
@@ -484,5 +490,7 @@ GRUB_MOD_INIT(linux16)
ad4aff
 GRUB_MOD_FINI(linux16)
ad4aff
 {
ad4aff
   grub_unregister_command (cmd_linux);
ad4aff
+  grub_unregister_command (cmd_linux16);
ad4aff
   grub_unregister_command (cmd_initrd);
ad4aff
+  grub_unregister_command (cmd_initrd16);
ad4aff
 }
dbfd2e
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
dbfd2e
index 712ba17b9ba..5900fc8a40c 100644
dbfd2e
--- a/include/grub/arm/linux.h
dbfd2e
+++ b/include/grub/arm/linux.h
dbfd2e
@@ -20,6 +20,7 @@
dbfd2e
 #ifndef GRUB_ARM_LINUX_HEADER
dbfd2e
 #define GRUB_ARM_LINUX_HEADER 1
dbfd2e
 
dbfd2e
+#include <grub efi="" pe32.h="">
dbfd2e
 #include "system.h"
dbfd2e
 
dbfd2e
 #define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818
dbfd2e
@@ -34,9 +35,17 @@ struct linux_arm_kernel_header {
dbfd2e
   grub_uint32_t hdr_offset;
dbfd2e
 };
dbfd2e
 
dbfd2e
+struct grub_arm_linux_pe_header
dbfd2e
+{
dbfd2e
+  grub_uint32_t magic;
dbfd2e
+  struct grub_pe32_coff_header coff;
dbfd2e
+  struct grub_pe32_optional_header opt;
dbfd2e
+};
dbfd2e
+
dbfd2e
 #if defined(__arm__)
dbfd2e
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
dbfd2e
 # define linux_armxx_kernel_header linux_arm_kernel_header
dbfd2e
+# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
dbfd2e
 #endif
dbfd2e
 
dbfd2e
 #if defined GRUB_MACHINE_UBOOT
ad4aff
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
dbfd2e
index 8655067e039..7b533b57139 100644
ad4aff
--- a/include/grub/arm64/linux.h
ad4aff
+++ b/include/grub/arm64/linux.h
15a207
@@ -19,6 +19,8 @@
15a207
 #ifndef GRUB_ARM64_LINUX_HEADER
ad4aff
 #define GRUB_ARM64_LINUX_HEADER 1
ad4aff
 
ad4aff
+#include <grub efi="" pe32.h="">
15a207
+
ad4aff
 #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
ad4aff
 
15a207
 /* From linux/Documentation/arm64/booting.txt */
dbfd2e
@@ -36,9 +38,17 @@ struct linux_arm64_kernel_header
dbfd2e
   grub_uint32_t hdr_offset;	/* Offset of PE/COFF header */
dbfd2e
 };
15a207
 
ad4aff
+struct grub_arm64_linux_pe_header
ad4aff
+{
ad4aff
+  grub_uint32_t magic;
ad4aff
+  struct grub_pe32_coff_header coff;
ad4aff
+  struct grub_pe64_optional_header opt;
ad4aff
+};
15a207
+
dbfd2e
 #if defined(__aarch64__)
dbfd2e
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
dbfd2e
 # define linux_armxx_kernel_header linux_arm64_kernel_header
dbfd2e
+# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
dbfd2e
 #endif
dbfd2e
 
ad4aff
 #endif /* ! GRUB_ARM64_LINUX_HEADER */
ad4aff
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
dbfd2e
index 2c6648d46fc..1061aee9726 100644
ad4aff
--- a/include/grub/efi/efi.h
ad4aff
+++ b/include/grub/efi/efi.h
ad4aff
@@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,
ad4aff
 				      grub_efi_uintn_t pages);
ad4aff
 void *
ad4aff
 EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
ad4aff
+void *
ad4aff
+EXPORT_FUNC(grub_efi_allocate_pages_max) (grub_efi_physical_address_t max,
ad4aff
+					  grub_efi_uintn_t pages);
ad4aff
 void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
ad4aff
 				       grub_efi_uintn_t pages);
15a207
 grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);
15a207
@@ -82,6 +85,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
ad4aff
 				     const grub_efi_guid_t *guid,
ad4aff
 				     void *data,
ad4aff
 				     grub_size_t datasize);
ad4aff
+grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);
ad4aff
 int
ad4aff
 EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
ad4aff
 					     const grub_efi_device_path_t *dp2);
dbfd2e
@@ -95,8 +99,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
dbfd2e
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
dbfd2e
 #include <grub cpu="" linux.h="">
dbfd2e
 grub_err_t grub_armxx_efi_linux_check_image(struct linux_armxx_kernel_header *lh);
dbfd2e
-grub_err_t grub_armxx_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
dbfd2e
-                                           char *args);
dbfd2e
+grub_err_t grub_armxx_efi_linux_boot_image(grub_addr_t addr, char *args);
dbfd2e
 #endif
dbfd2e
 
dbfd2e
 grub_addr_t grub_efi_modules_addr (void);
ad4aff
diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h
ad4aff
new file mode 100644
ad4aff
index 00000000000..d9ede36773b
ad4aff
--- /dev/null
ad4aff
+++ b/include/grub/efi/linux.h
ad4aff
@@ -0,0 +1,31 @@
ad4aff
+/*
ad4aff
+ *  GRUB  --  GRand Unified Bootloader
ad4aff
+ *  Copyright (C) 2014  Free Software Foundation, Inc.
ad4aff
+ *
ad4aff
+ *  GRUB is free software: you can redistribute it and/or modify
ad4aff
+ *  it under the terms of the GNU General Public License as published by
ad4aff
+ *  the Free Software Foundation, either version 3 of the License, or
ad4aff
+ *  (at your option) any later version.
ad4aff
+ *
ad4aff
+ *  GRUB is distributed in the hope that it will be useful,
ad4aff
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ad4aff
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ad4aff
+ *  GNU General Public License for more details.
ad4aff
+ *
ad4aff
+ *  You should have received a copy of the GNU General Public License
ad4aff
+ *  along with GRUB.  If not, see <http: www.gnu.org="" licenses=""/>.
ad4aff
+ */
ad4aff
+#ifndef GRUB_EFI_LINUX_HEADER
ad4aff
+#define GRUB_EFI_LINUX_HEADER	1
ad4aff
+
ad4aff
+#include <grub efi="" api.h="">
ad4aff
+#include <grub err.h="">
ad4aff
+#include <grub symbol.h="">
ad4aff
+
ad4aff
+grub_efi_boolean_t
ad4aff
+EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size);
ad4aff
+grub_err_t
ad4aff
+EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
ad4aff
+				  void *kernel_param);
ad4aff
+
ad4aff
+#endif /* ! GRUB_EFI_LINUX_HEADER */
ad4aff
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
15a207
index 60c7c3b5e66..bb19dbd5a77 100644
ad4aff
--- a/include/grub/i386/linux.h
ad4aff
+++ b/include/grub/i386/linux.h
15a207
@@ -142,6 +142,7 @@ struct linux_i386_kernel_header
ad4aff
   grub_uint64_t setup_data;
ad4aff
   grub_uint64_t pref_address;
ad4aff
   grub_uint32_t init_size;
ad4aff
+  grub_uint32_t handover_offset;
ad4aff
 } GRUB_PACKED;
ad4aff
 
ad4aff
 /* Boot parameters for Linux based on 2.6.12. This is used by the setup