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

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