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

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