nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0228-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Thu, 16 Aug 2018 11:08:11 -0400
d9d99f
Subject: [PATCH] Make linux_arm_kernel_header.hdr_offset be at the right place
d9d99f
d9d99f
The kernel in front of me (slightly edited to make objdump work) looks like:
d9d99f
d9d99f
00000000  4d 5a 10 13 4d 5a 10 13  4d 5a 10 13 4d 5a 10 13  |MZ..MZ..MZ..MZ..|
d9d99f
00000010  4d 5a 10 13 4d 5a 10 13  4d 5a 10 13 00 00 a0 e1  |MZ..MZ..MZ......|
d9d99f
00000020  f6 03 00 ea 18 28 6f 01  00 00 00 00 00 32 74 00  |.....(o......2t.|
d9d99f
00000030  01 02 03 04 45 45 45 45  74 a2 00 00 40 00 00 00  |....EEEEt...@...|
d9d99f
00000040  50 45 00 00 4c 01 04 00  00 00 00 00 00 00 00 00  |PE..L...........|
d9d99f
00000050  00 00 00 00 90 00 06 03  0b 01 02 14 00 20 74 00  |............. t.|
d9d99f
00000060  00 14 00 00 00 00 00 00  b4 19 00 00 00 10 00 00  |................|
d9d99f
00000070  00 30 74 00 00 00 00 00  00 10 00 00 00 02 00 00  |.0t.............|
d9d99f
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
d9d99f
00000090  00 44 74 00 00 10 00 00  00 00 00 00 0a 00 00 00  |.Dt.............|
d9d99f
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
d9d99f
000000b0  00 00 00 00 06 00 00 00  00 00 00 00 00 00 00 00  |................|
d9d99f
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
d9d99f
*
d9d99f
d9d99f
(I don't know why the MZ header is there 7 times, but the offsets work out, so
d9d99f
it's merely a surprising distraction.)
d9d99f
d9d99f
If linux_arm_kernel_header.reserved2 is 16 bytes, that means hdr_offset is
d9d99f
here:
d9d99f
d9d99f
00000030  01 02 03 04 45 45 45 45  74 a2 00 00 40 00 00 00  |....EEEEt...@...|
d9d99f
00000040  50 45 00 00 4c 01 04 00  00 00 00 00 00 00 00 00  |PE..L...........|
d9d99f
          ^^^^^^^^^^^
d9d99f
d9d99f
But it's supposed to be 4 bytes before that.
d9d99f
d9d99f
This patch makes the reserved field be 3*32 instead of 4*32, and that means we
d9d99f
can find the PE header correcrtly at 0x40 by reading the value at 0x3c.
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/loader/efi/linux.c | 3 +++
d9d99f
 include/grub/arm/linux.h     | 2 +-
d9d99f
 2 files changed, 4 insertions(+), 1 deletion(-)
d9d99f
d9d99f
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
d9d99f
index 0622dfa48d4..b56ea0bc041 100644
d9d99f
--- a/grub-core/loader/efi/linux.c
d9d99f
+++ b/grub-core/loader/efi/linux.c
d9d99f
@@ -79,7 +79,10 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
d9d99f
   offset = 512;
d9d99f
 #endif
d9d99f
 
d9d99f
+  grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
d9d99f
+		kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params);
d9d99f
   hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
d9d99f
+  grub_dprintf ("linux", "handover_func() = %p\n", hf);
d9d99f
   hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
d9d99f
 
d9d99f
   return GRUB_ERR_BUG;
d9d99f
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
d9d99f
index 5900fc8a40c..bed308f22cb 100644
d9d99f
--- a/include/grub/arm/linux.h
d9d99f
+++ b/include/grub/arm/linux.h
d9d99f
@@ -31,7 +31,7 @@ struct linux_arm_kernel_header {
d9d99f
   grub_uint32_t magic;
d9d99f
   grub_uint32_t start; /* _start */
d9d99f
   grub_uint32_t end;   /* _edata */
d9d99f
-  grub_uint32_t reserved2[4];
d9d99f
+  grub_uint32_t reserved2[3];
d9d99f
   grub_uint32_t hdr_offset;
d9d99f
 };
d9d99f