From d04bce2dd087a6e5f8337d067c4fb0b2968553ff Mon Sep 17 00:00:00 2001 From: Jack Ren Date: Sun, 20 May 2018 14:33:18 +0800 Subject: [PATCH] hv: don't use the EDK Shell API to get the cmdline EDK Shell API is not standard API defined by UEFI spec. The gnu-efi below v3.0 doesn't support EDK Shell API (for example, GetShellArgcArgv), that leads to the hypervisor unable to boot up when the host machine is installed with old gnu-efi. Signed-off-by: Jack Ren Signed-off-by: Jason Chen CJ Acked-by: Eddie Dong --- hypervisor/bsp/uefi/efi/boot.c | 55 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/hypervisor/bsp/uefi/efi/boot.c b/hypervisor/bsp/uefi/efi/boot.c index 9be26d41b..7158ea0dd 100644 --- a/hypervisor/bsp/uefi/efi/boot.c +++ b/hypervisor/bsp/uefi/efi/boot.c @@ -314,6 +314,11 @@ out: return err; } +static inline EFI_STATUS isspace(CHAR8 ch) +{ + return ((unsigned char)ch <= ' '); +} + /** * efi_main - The entry point for the OS loader image. * @image: firmware-allocated handle that identifies the image @@ -331,16 +336,15 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table) char *section; EFI_DEVICE_PATH *path; - INTN Argc, i, index; - CHAR16 **Argv; + INTN i, index; CHAR16 *bootloader_name = NULL; CHAR16 bootloader_param[] = L"bootloader="; EFI_HANDLE bootloader_image; CHAR16 *options = NULL; UINT32 options_size = 0; + CHAR16 *cmdline16, *n; InitializeLib(image, _table); - Argc = GetShellArgcArgv(image, &Argv); sys_table = _table; boot = sys_table->BootServices; @@ -359,6 +363,30 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table) if (options_size > 0) cmdline = ch16_2_ch8(options); + /* First check if we were given a bootloader name + * E.g.: "bootloader=\EFI\org.clearlinux\bootloaderx64.efi" + */ + cmdline16 = StrDuplicate(options); + bootloader_name = strstr_16(cmdline16, bootloader_param); + if (bootloader_name) + bootloader_name = bootloader_name + StrLen(bootloader_param); + + n = bootloader_name; + i = 0; + while (*n && !isspace((CHAR8)*n) && (*n < 0xff)) { + n++; i++; + } + *n++ = '\0'; + + if (!bootloader_name) { + /* + * If we reach this point, it means we did not receive a specific + * bootloader name to be used. Fall back to the default bootloader + * as specified in bsp_cfg.h + */ + bootloader_name = ch8_2_ch16(CONFIG_UEFI_OS_LOADER_NAME); + } + section = ".hv"; err = get_pe_section(info->ImageBase, section, &sec_addr, &sec_size); if (EFI_ERROR(err)) { @@ -380,27 +408,6 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table) goto failed; /* load and start the default bootloader */ - - /* First check if we were given a bootloader name - * E.g.: "bootloader=\EFI\org.clearlinux\bootloaderx64.efi" - */ - for (i = 0 ; i < Argc ; ++i) { - bootloader_name = strstr_16(Argv[i], bootloader_param); - if (bootloader_name) { - bootloader_name = bootloader_name + StrLen(bootloader_param); - break; - } - } - - if (!bootloader_name) { - /* - * If we reach this point, it means we did not receive a specific - * bootloader name to be used. Fall back to the default bootloader - * as specified in bsp_cfg.h - */ - bootloader_name = ch8_2_ch16(CONFIG_UEFI_OS_LOADER_NAME); - } - path = FileDevicePath(info->DeviceHandle, bootloader_name); if (!path) goto free_args;