summaryrefslogtreecommitdiff
path: root/shim.c
diff options
context:
space:
mode:
authorGary Ching-Pang Lin <glin@suse.com>2013-01-14 16:53:19 +0800
committerPeter Jones <pjones@redhat.com>2013-04-30 09:45:45 -0400
commit9754732ca13929fa33be018ff2b35b127f582df0 (patch)
tree480c13fd3a35055557089a554d0607e874648d6c /shim.c
parent53ba265dcb05825a3bad7be0853f596705f5b9d9 (diff)
downloadefi-boot-shim-9754732ca13929fa33be018ff2b35b127f582df0.tar.gz
efi-boot-shim-9754732ca13929fa33be018ff2b35b127f582df0.zip
Adopt the UEFI shell style LoadOptions
The previous commit, 14d4b8e, caused shim failed to parse the name of the 2nd stage loader in UEFI shell. Amend parsing of the name the 2nd stage loader to be compatible with UEFI shell. To create an boot entry for elilo.efi: # efibootmgr -c -L "shim elilo" -l "efi\\shim.efi" -u "shim.efi elilo.efi"
Diffstat (limited to 'shim.c')
-rw-r--r--shim.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/shim.c b/shim.c
index d1071d68..0113ed5e 100644
--- a/shim.c
+++ b/shim.c
@@ -1329,9 +1329,10 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
{
EFI_STATUS status;
EFI_LOADED_IMAGE *li;
- CHAR16 *bootpath = NULL;
CHAR16 *start = NULL, *c;
int i, remaining_size = 0;
+ CHAR16 *loader_str = NULL;
+ int loader_len = 0;
second_stage = DEFAULT_LOADER;
load_options = NULL;
@@ -1353,6 +1354,11 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
return EFI_BAD_BUFFER_SIZE;
}
+ /*
+ * UEFI shell copies the whole line of the command into LoadOptions.
+ * We ignore the string before the first L' ', i.e. the name of this
+ * program.
+ */
for (i = 0; i < li->LoadOptionsSize; i += 2) {
c = (CHAR16 *)(li->LoadOptions + i);
if (*c == L' ') {
@@ -1363,11 +1369,30 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
}
}
- bootpath = DevicePathToStr(li->FilePath);
- if (!StrCaseCmp(bootpath, (CHAR16 *)li->LoadOptions))
- second_stage = (CHAR16 *)li->LoadOptions;
+ if (!start || remaining_size <= 0)
+ return EFI_SUCCESS;
- if (start && remaining_size > 0) {
+ for (i = 0; start[i] != '\0'; i++) {
+ if (start[i] == L' ' || start[i] == L'\0')
+ break;
+ loader_len++;
+ }
+
+ /*
+ * Setup the name of the alternative loader and the LoadOptions for
+ * the loader
+ */
+ if (loader_len > 0) {
+ loader_str = AllocatePool((loader_len + 1) * sizeof(CHAR16));
+ if (!loader_str) {
+ Print(L"Failed to allocate loader string\n");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ for (i = 0; i < loader_len; i++)
+ loader_str[i] = start[i];
+ loader_str[loader_len] = L'\0';
+
+ second_stage = loader_str;
load_options = start;
load_options_size = remaining_size;
}
@@ -1444,5 +1469,11 @@ EFI_STATUS efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *passed_systab)
uefi_call_wrapper(BS->UninstallProtocolInterface, 3, handle,
&shim_lock_guid, &shim_lock_interface);
+ /*
+ * Free the space allocated for the alternative 2nd stage loader
+ */
+ if (load_options_size > 0)
+ FreePool(second_stage);
+
return efi_status;
}