grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Error if efi_mmap_hi and efi_system_table_hi are needed but not


From: Peter Jones
Subject: [PATCH] Error if efi_mmap_hi and efi_system_table_hi are needed but not found.
Date: Wed, 30 May 2012 16:27:26 -0400

efi_mmap_hi and efi_system_table_hi were implemented when bootloader
version was 0x0208, so require that to access them, and also fail to
boot if they're needed but unsupported.  This way the bootloader will
give you an error instead of the system starting to boot and crashing.
---
 grub-core/loader/i386/linux.c |   30 +++++++++++++++++++++++++-----
 include/grub/i386/linux.h     |   13 ++++++++++++-
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 4c382b1..53aa14e 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -618,15 +618,23 @@ grub_linux_boot (void)
     efi_mmap_target = real_mode_target 
       + ((grub_uint8_t *) efi_mmap_buf - (grub_uint8_t *) real_mode_mem);
     /* Pass EFI parameters.  */
-    if (grub_le_to_cpu16 (params->version) >= 0x0206)
+    if (grub_le_to_cpu16 (params->version) >= 0x0208)
+      {
+       params->v0208.efi_mem_desc_size = efi_desc_size;
+       params->v0208.efi_mem_desc_version = efi_desc_version;
+       params->v0208.efi_mmap = efi_mmap_target;
+       params->v0208.efi_mmap_size = efi_mmap_size;
+
+#ifdef __x86_64__
+       params->v0206.efi_mmap_hi = (efi_mmap_target >> 32);
+#endif
+      }
+    else if (grub_le_to_cpu16 (params->version) >= 0x0206)
       {
        params->v0206.efi_mem_desc_size = efi_desc_size;
        params->v0206.efi_mem_desc_version = efi_desc_version;
        params->v0206.efi_mmap = efi_mmap_target;
        params->v0206.efi_mmap_size = efi_mmap_size;
-#ifdef __x86_64__
-       params->v0206.efi_mmap_hi = (efi_mmap_target >> 32);
-#endif
       }
     else if (grub_le_to_cpu16 (params->version) >= 0x0204)
       {
@@ -827,7 +835,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ 
((unused)),
   params->font_size = 16; /* XXX */
 
 #ifdef GRUB_MACHINE_EFI
-  if (grub_le_to_cpu16 (params->version) >= 0x0206)
+  if (grub_le_to_cpu16 (params->version < 0x0208) &&
+      ((efi_mmap_target >> 32) != 0 || (grub_efi_system_table >> 32) != 0))
+    {
+      return grub_error(GRUB_ERR_BAD_KERNEL,
+                       "kernel does not support 64-bit addressing");
+    }
+
+  if (grub_le_to_cpu16 (params->version) >= 0x0208)
     {
       params->v0206.efi_signature = GRUB_LINUX_EFI_SIGNATURE;
       params->v0206.efi_system_table = (grub_uint32_t) (unsigned long) 
grub_efi_system_table;
@@ -835,6 +850,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ 
((unused)),
       params->v0206.efi_system_table_hi = (grub_uint32_t) ((grub_uint64_t) 
grub_efi_system_table >> 32);
 #endif
     }
+  else if (grub_le_to_cpu16 (params->version) >= 0x0206)
+    {
+      params->v0206.efi_signature = GRUB_LINUX_EFI_SIGNATURE;
+      params->v0206.efi_system_table = (grub_uint32_t) (unsigned long) 
grub_efi_system_table;
+    }
   else if (grub_le_to_cpu16 (params->version) >= 0x0204)
     {
       params->v0204.efi_signature = GRUB_LINUX_EFI_SIGNATURE_0204;
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
index 8dde9c2..b2a92f6 100644
--- a/include/grub/i386/linux.h
+++ b/include/grub/i386/linux.h
@@ -246,9 +246,20 @@ struct linux_kernel_params
           grub_uint32_t efi_mem_desc_version;  /* 1cc */
           grub_uint32_t efi_mmap;              /* 1d0 */
           grub_uint32_t efi_mmap_size;         /* 1d4 */
+       } v0206;
+      struct
+        {
+          grub_uint32_t padding7_1;            /* 1b8 */
+          grub_uint32_t padding7_2;            /* 1bc */
+          grub_uint32_t efi_signature;         /* 1c0 */
+          grub_uint32_t efi_system_table;      /* 1c4 */
+          grub_uint32_t efi_mem_desc_size;     /* 1c8 */
+          grub_uint32_t efi_mem_desc_version;  /* 1cc */
+          grub_uint32_t efi_mmap;              /* 1d0 */
+          grub_uint32_t efi_mmap_size;         /* 1d4 */
           grub_uint32_t efi_system_table_hi;   /* 1d8 */
           grub_uint32_t efi_mmap_hi;           /* 1dc */
-        } v0206;
+        } v0208;
     };
 
   grub_uint32_t alt_mem;               /* 1e0 */
-- 
1.7.10.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]