nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0497-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch

b71686
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b71686
From: Peter Jones <pjones@redhat.com>
b71686
Date: Thu, 13 Sep 2018 14:42:34 -0400
b71686
Subject: [PATCH] x86-efi: Re-arrange grub_cmd_linux() a little bit.
b71686
b71686
This just helps the next patch be easier to read.
b71686
b71686
Signed-off-by: Peter Jones <pjones@redhat.com>
b71686
(cherry picked from commit 486cdd48889b30b03143c393e59a75ea040b5c40)
b71686
---
b71686
 grub-core/loader/i386/efi/linux.c | 75 +++++++++++++++++++++------------------
b71686
 1 file changed, 41 insertions(+), 34 deletions(-)
b71686
b71686
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
b71686
index 73cd838e9..c9650561f 100644
b71686
--- a/grub-core/loader/i386/efi/linux.c
b71686
+++ b/grub-core/loader/i386/efi/linux.c
b71686
@@ -258,32 +258,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
b71686
 	}
b71686
     }
b71686
 
b71686
-  params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
b71686
-					BYTES_TO_PAGES(sizeof(*params)));
b71686
-  if (!params)
b71686
-    params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
b71686
-					  BYTES_TO_PAGES(sizeof(*params)));
b71686
-  if (! params)
b71686
-    {
b71686
-      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
b71686
-      goto fail;
b71686
-    }
b71686
+  lh = (struct linux_i386_kernel_header *)kernel;
b71686
+  grub_dprintf ("linux", "original lh is at %p\n", kernel);
b71686
 
b71686
-  grub_dprintf ("linux", "params = %p\n", params);
b71686
-
b71686
-  grub_memset (params, 0, sizeof(*params));
b71686
-
b71686
-  setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
b71686
-  grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
b71686
-		MIN((grub_size_t)0x202+setup_header_end_offset,
b71686
-		    sizeof (*params)) - 0x1f1,
b71686
-		(grub_uint8_t *)kernel + 0x1f1,
b71686
-		(grub_uint8_t *)params + 0x1f1);
b71686
-  grub_memcpy ((grub_uint8_t *)params + 0x1f1,
b71686
-	       (grub_uint8_t *)kernel + 0x1f1,
b71686
-		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
b71686
-  lh = (struct linux_i386_kernel_header *)params;
b71686
-  grub_dprintf ("linux", "lh is at %p\n", lh);
b71686
   grub_dprintf ("linux", "checking lh->boot_flag\n");
b71686
   if (lh->boot_flag != grub_cpu_to_le16 (0xaa55))
b71686
     {
b71686
@@ -331,6 +308,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
b71686
     }
b71686
 #endif
b71686
 
b71686
+  params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
b71686
+					BYTES_TO_PAGES(sizeof(*params)));
b71686
+  if (!params)
b71686
+    params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
b71686
+					  BYTES_TO_PAGES(sizeof(*params)));
b71686
+  if (! params)
b71686
+    {
b71686
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
b71686
+      goto fail;
b71686
+    }
b71686
+
b71686
+  grub_dprintf ("linux", "params = %p\n", params);
b71686
+
b71686
+  grub_memset (params, 0, sizeof(*params));
b71686
+
b71686
+  setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
b71686
+  grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
b71686
+		MIN((grub_size_t)0x202+setup_header_end_offset,
b71686
+		    sizeof (*params)) - 0x1f1,
b71686
+		(grub_uint8_t *)kernel + 0x1f1,
b71686
+		(grub_uint8_t *)params + 0x1f1);
b71686
+  grub_memcpy ((grub_uint8_t *)params + 0x1f1,
b71686
+	       (grub_uint8_t *)kernel + 0x1f1,
b71686
+		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
b71686
+
b71686
+  lh = (struct linux_i386_kernel_header *)params;
b71686
+  grub_dprintf ("linux", "new lh is at %p\n", lh);
b71686
+
b71686
   grub_dprintf ("linux", "setting up cmdline\n");
b71686
   linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS,
b71686
 					      BYTES_TO_PAGES(lh->cmdline_size + 1));
b71686
@@ -356,8 +361,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
b71686
   grub_dprintf ("linux", "setting lh->cmd_line_ptr\n");
b71686
   lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
b71686
 
b71686
-  grub_dprintf ("linux", "computing handover offset\n");
b71686
   handover_offset = lh->handover_offset;
b71686
+  grub_dprintf("linux", "handover_offset: %08x\n", handover_offset);
b71686
 
b71686
   start = (lh->setup_sects + 1) * 512;
b71686
 
b71686
@@ -374,26 +379,28 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
b71686
       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
b71686
       goto fail;
b71686
     }
b71686
-
b71686
-  grub_dprintf ("linux", "kernel_mem = %lx\n", (unsigned long) kernel_mem);
b71686
+  grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem);
b71686
 
b71686
   grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
b71686
-  loaded=1;
b71686
+
b71686
+  loaded = 1;
b71686
+
b71686
   grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem);
b71686
   lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem;
b71686
 
b71686
   grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start);
b71686
 
b71686
-  grub_dprintf ("linux", "setting lh->type_of_loader\n");
b71686
   lh->type_of_loader = 0x6;
b71686
+  grub_dprintf ("linux", "setting lh->type_of_loader = 0x%02x\n",
b71686
+		lh->type_of_loader);
b71686
 
b71686
-  grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n");
b71686
   params->ext_loader_type = 0;
b71686
   params->ext_loader_ver = 2;
b71686
-  grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n",
b71686
-	       kernel_mem, handover_offset);
b71686
+  grub_dprintf ("linux",
b71686
+		"setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n",
b71686
+		params->ext_loader_type, params->ext_loader_ver);
b71686
 
b71686
- fail:
b71686
+fail:
b71686
   if (file)
b71686
     grub_file_close (file);
b71686