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

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