grub-efi: rebased to 2.02

Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
This commit is contained in:
Lans Zhang
2017-07-12 15:36:46 +08:00
parent bd15d9c37b
commit 480f1f03a0
4 changed files with 24 additions and 110 deletions
@@ -1,62 +0,0 @@
From 9517b3173af961ea66721cfc48cd47e50a704388 Mon Sep 17 00:00:00 2001
From: Lans Zhang <jia.zhang@windriver.com>
Date: Wed, 4 Nov 2015 17:17:06 +0800
Subject: [PATCH] Work around the failure of ExitBootServices()
ExitBootServices() will fail if any of the event handlers change
the memory map. In which case, we must be prepared to retry, but
only once so that we're guaranteed to exit on repeated failures
instead of spinning forever. This fix refers to the workaround
made by Linux kernel.
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
---
grub-core/kern/efi/mm.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 461deb0..7620a47 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -158,6 +158,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;
+ int called_exit = 0;
#if defined (__i386__) || defined (__x86_64__)
const grub_uint16_t apple[] = { 'A', 'p', 'p', 'l', 'e' };
@@ -167,6 +168,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
apple, sizeof (apple)) == 0);
#endif
+get_mem_map:
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
&finish_desc_size, &finish_desc_version) < 0)
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
@@ -186,7 +188,21 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
finish_key);
if (status != GRUB_EFI_SUCCESS)
- return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
+ {
+ /*
+ * ExitBootServices() will fail if any of the event
+ * handlers change the memory map. In which case, we
+ * must be prepared to retry, but only once so that
+ * we're guaranteed to exit on repeated failures instead
+ * of spinning forever.
+ */
+ if (called_exit)
+ return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
+
+ called_exit = 1;
+ grub_free (finish_mmap_buf);
+ goto get_mem_map;
+ }
grub_efi_is_finished = 1;
if (outbuf_size)
--
1.9.1
@@ -1,7 +1,7 @@
From e7b2efacc2d3acb48761aa2d62f943310fd70100 Mon Sep 17 00:00:00 2001
From 7f3d421111fce69d73c392b2cacc4a4bc3ff3c24 Mon Sep 17 00:00:00 2001
From: Lans Zhang <jia.zhang@windriver.com>
Date: Mon, 25 Apr 2016 11:35:14 +0800
Subject: [PATCH] Fix 32-bit build failures
Date: Wed, 12 Jul 2017 15:25:15 +0800
Subject: [PATCH] efi-chainloader: implemented for 32-bit
Upstream-Status: Pending
@@ -22,13 +22,13 @@ Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
create mode 100644 grub-core/kern/i386/efi/callwrap.S
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 39e77a4..0a78137 100644
index cc0b337..a82c1f3 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -135,6 +135,7 @@ kernel = {
efi = term/efi/console.c;
@@ -186,6 +186,7 @@ kernel = {
i386_coreboot = kern/i386/tsc_pmtimer.c;
x86_64_efi = kern/i386/tsc_pmtimer.c;
i386_efi = kern/i386/tsc.c;
+ i386_efi = kern/i386/efi/callwrap.S;
i386_efi = kern/i386/efi/init.c;
i386_efi = bus/pci.c;
@@ -90,10 +90,10 @@ index 0000000..c683444
+ .data
+saved_sp: .long 0
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
index 83769a2..e3d1138 100644
index 0030268..2b5e464 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -149,7 +149,7 @@ grub_shim_image_is_loadable (union grub_shim_optional_header_union *pe_hdr)
@@ -153,7 +153,7 @@ grub_shim_image_is_loadable (union grub_shim_optional_header_union *pe_hdr)
/*
* Perform basic bounds checking of the intra-image pointers
*/
@@ -102,7 +102,7 @@ index 83769a2..e3d1138 100644
grub_shim_image_address (grub_addr_t image, grub_uint32_t size, grub_uint32_t addr)
{
if (addr > size)
@@ -208,12 +208,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
@@ -212,12 +212,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
* yield the next entry in the array.
*/
reloc_base = (struct grub_image_base_relocation *)
@@ -117,7 +117,7 @@ index 83769a2..e3d1138 100644
section->raw_data_offset
+ section->virtual_size - 1);
@@ -254,7 +254,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
@@ -258,7 +258,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
}
fixup_base = (grub_uint8_t *)
@@ -126,7 +126,7 @@ index 83769a2..e3d1138 100644
size,
reloc_base->virtual_address);
if (!fixup_base)
@@ -333,12 +333,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
@@ -337,12 +337,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
* Read the binary header and grab appropriate information from it
*/
static grub_err_t
@@ -141,7 +141,7 @@ index 83769a2..e3d1138 100644
if (datasize < sizeof (pe_hdr->pe32))
{
@@ -393,7 +393,7 @@ grub_shim_read_header(grub_efi_physical_address_t data, grub_uint32_t datasize,
@@ -397,7 +397,7 @@ grub_shim_read_header(grub_efi_physical_address_t data, grub_uint32_t datasize,
+ sizeof (grub_efi_uint32_t)
+ sizeof (struct grub_pe32_coff_header)
+ pe_hdr->pe32.file_hdr.optional_header_size;
@@ -150,7 +150,7 @@ index 83769a2..e3d1138 100644
/ sizeof (struct grub_pe32_section_table)
<= context->num_sections)
{
@@ -530,7 +530,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
@@ -534,7 +534,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
}
/* TODO: do we need the double cast? */
@@ -159,7 +159,7 @@ index 83769a2..e3d1138 100644
(void *) ((grub_addr_t) addr), context->header_size);
reloc_base = (grub_int8_t *) grub_shim_image_address (shim_buffer, size,
@@ -553,10 +553,10 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
@@ -557,10 +557,10 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
sect_size = section->raw_data_size;
base = (grub_int8_t *)
@@ -172,7 +172,7 @@ index 83769a2..e3d1138 100644
section->virtual_address
+ sect_size - 1);
@@ -619,7 +619,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
@@ -623,7 +623,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
if (context->reloc_dir->size && reloc_section)
{
status = grub_shim_relocate_coff (context, reloc_section,
@@ -181,7 +181,7 @@ index 83769a2..e3d1138 100644
if (status != GRUB_ERR_NONE)
{
grub_printf("Relocation failed: [%u]\n", status);
@@ -627,7 +627,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
@@ -631,7 +631,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
goto fail;
}
}
@@ -190,7 +190,7 @@ index 83769a2..e3d1138 100644
context->image_size,
context->entry_point);
if (!shim_entry_point)
@@ -696,8 +696,8 @@ grub_chainloader_boot (void)
@@ -700,8 +700,8 @@ grub_chainloader_boot (void)
saved_exit = grub_efi_system_table->boot_services->exit;
grub_efi_system_table->boot_services->exit = efi_shim_exit;
status = efi_call_foo(shim_entry_point,
@@ -201,7 +201,7 @@ index 83769a2..e3d1138 100644
grub_efi_system_table->boot_services->exit = saved_exit;
loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
@@ -970,7 +970,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
@@ -1013,7 +1013,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
if (shim_used)
{
grub_memcpy(&shim_li_bak, loaded_image, sizeof(shim_li_bak));
@@ -211,10 +211,10 @@ index 83769a2..e3d1138 100644
}
else
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 374d88b..22b3543 100644
index af1c603..89f0404 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -1437,10 +1437,6 @@ typedef struct grub_efi_block_io grub_efi_block_io_t;
@@ -1731,10 +1731,6 @@ typedef struct grub_efi_block_io grub_efi_block_io_t;
grub_uint64_t EXPORT_FUNC(efi_wrap_0) (void *func);
grub_uint64_t EXPORT_FUNC(efi_wrap_1) (void *func, grub_uint64_t arg1);
@@ -225,7 +225,7 @@ index 374d88b..22b3543 100644
grub_uint64_t EXPORT_FUNC(efi_wrap_2) (void *func, grub_uint64_t arg1,
grub_uint64_t arg2);
grub_uint64_t EXPORT_FUNC(efi_wrap_3) (void *func, grub_uint64_t arg1,
@@ -1467,4 +1463,8 @@ grub_uint64_t EXPORT_FUNC(efi_wrap_10) (void *func, grub_uint64_t arg1,
@@ -1761,4 +1757,8 @@ grub_uint64_t EXPORT_FUNC(efi_wrap_10) (void *func, grub_uint64_t arg1,
grub_uint64_t arg10);
#endif
@@ -248,5 +248,5 @@ index 4b92a00..9fac90b 100644
grub_efi_uintn_t header_size;
grub_efi_uint16_t image_type;
--
1.9.1
2.7.5
@@ -1,22 +0,0 @@
---
grub-core/term/efi/console.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
--- a/grub-core/term/efi/console.c
+++ b/grub-core/term/efi/console.c
@@ -124,9 +124,12 @@ grub_console_getkey (struct grub_term_in
if (status != GRUB_EFI_SUCCESS)
return GRUB_TERM_NO_KEY;
- if (key.scan_code == 0)
- return key.unicode_char;
- else if (key.scan_code < ARRAY_SIZE (efi_codes))
+ if (key.scan_code == 0) {
+ if (key.unicode_char < 0x20 && key.unicode_char != 0 && key.unicode_char != '\t' && key.unicode_char != '\b' && key.unicode_char != '\n' && key.unicode_char != '\r')
+ return GRUB_TERM_CTRL | (key.unicode_char - 1 + 'a');
+ else
+ return key.unicode_char;
+ } else if (key.scan_code < ARRAY_SIZE (efi_codes))
return efi_codes[key.scan_code];
return GRUB_TERM_NO_KEY;
@@ -15,10 +15,8 @@ SRC_URI += "\
file://chainloader-handle-the-unauthenticated-image-by-shim.patch \
file://chainloader-Don-t-check-empty-section-in-file-like-..patch \
file://chainloader-Actually-find-the-relocations-correctly-.patch \
file://efi-chainloader-implemented-for-32-bit.patch \
file://Grub-get-and-set-efi-variables.patch \
file://Fix-32-bit-build-failures.patch;apply=0 \
file://Work-around-the-failure-of-ExitBootServices.patch;apply=0 \
file://serial-redirect-control-x-fix.patch;apply=0 \
file://mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch;apply=0 \
file://grub-efi.cfg \
file://boot-menu.inc \