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