OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib

Replace the open coded sequence to load Linux on x86 with a short and
generic sequence invoking QemuLoadImageLib, which can be provided by
a generic version that only supports the LoadImage and StartImage boot
services, and one that incorporates the entire legacy loading sequence
as well.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Ard Biesheuvel 2020-02-29 10:33:21 +01:00 committed by mergify[bot]
parent de7c6081cb
commit 859b55443a
2 changed files with 14 additions and 132 deletions

View File

@ -49,7 +49,7 @@
NvVarsFileLib NvVarsFileLib
QemuFwCfgLib QemuFwCfgLib
QemuFwCfgS3Lib QemuFwCfgS3Lib
LoadLinuxLib QemuLoadImageLib
QemuBootOrderLib QemuBootOrderLib
ReportStatusCodeLib ReportStatusCodeLib
UefiLib UefiLib

View File

@ -9,11 +9,8 @@
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/LoadLinuxLib.h> #include <Library/QemuLoadImageLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/ReportStatusCodeLib.h> #include <Library/ReportStatusCodeLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
@ -23,120 +20,11 @@ TryRunningQemuKernel (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN KernelSize; EFI_HANDLE KernelImageHandle;
UINTN KernelInitialSize;
VOID *KernelBuf;
UINTN SetupSize;
VOID *SetupBuf;
UINTN CommandLineSize;
CHAR8 *CommandLine;
UINTN InitrdSize;
VOID* InitrdData;
SetupBuf = NULL; Status = QemuLoadKernelImage (&KernelImageHandle);
SetupSize = 0;
KernelBuf = NULL;
KernelInitialSize = 0;
CommandLine = NULL;
CommandLineSize = 0;
InitrdData = NULL;
InitrdSize = 0;
if (!QemuFwCfgIsAvailable ()) {
return EFI_NOT_FOUND;
}
QemuFwCfgSelectItem (QemuFwCfgItemKernelSize);
KernelSize = (UINTN) QemuFwCfgRead64 ();
QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize);
SetupSize = (UINTN) QemuFwCfgRead64 ();
if (KernelSize == 0 || SetupSize == 0) {
DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n"));
return EFI_NOT_FOUND;
}
SetupBuf = LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (SetupSize));
if (SetupBuf == NULL) {
DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel setup!\n"));
return EFI_OUT_OF_RESOURCES;
}
DEBUG ((EFI_D_INFO, "Setup size: 0x%x\n", (UINT32) SetupSize));
DEBUG ((EFI_D_INFO, "Reading kernel setup image ..."));
QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData);
QemuFwCfgReadBytes (SetupSize, SetupBuf);
DEBUG ((EFI_D_INFO, " [done]\n"));
Status = LoadLinuxCheckKernelSetup (SetupBuf, SetupSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeAndReturn; return Status;
}
Status = LoadLinuxInitializeKernelSetup (SetupBuf);
if (EFI_ERROR (Status)) {
goto FreeAndReturn;
}
KernelInitialSize = LoadLinuxGetKernelSize (SetupBuf, KernelSize);
if (KernelInitialSize == 0) {
Status = EFI_UNSUPPORTED;
goto FreeAndReturn;
}
KernelBuf = LoadLinuxAllocateKernelPages (
SetupBuf,
EFI_SIZE_TO_PAGES (KernelInitialSize));
if (KernelBuf == NULL) {
DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n"));
Status = EFI_OUT_OF_RESOURCES;
goto FreeAndReturn;
}
DEBUG ((EFI_D_INFO, "Kernel size: 0x%x\n", (UINT32) KernelSize));
DEBUG ((EFI_D_INFO, "Reading kernel image ..."));
QemuFwCfgSelectItem (QemuFwCfgItemKernelData);
QemuFwCfgReadBytes (KernelSize, KernelBuf);
DEBUG ((EFI_D_INFO, " [done]\n"));
QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize);
CommandLineSize = (UINTN) QemuFwCfgRead64 ();
if (CommandLineSize > 0) {
CommandLine = LoadLinuxAllocateCommandLinePages (
EFI_SIZE_TO_PAGES (CommandLineSize));
QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData);
QemuFwCfgReadBytes (CommandLineSize, CommandLine);
} else {
CommandLine = NULL;
}
Status = LoadLinuxSetCommandLine (SetupBuf, CommandLine);
if (EFI_ERROR (Status)) {
goto FreeAndReturn;
}
QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize);
InitrdSize = (UINTN) QemuFwCfgRead64 ();
if (InitrdSize > 0) {
InitrdData = LoadLinuxAllocateInitrdPages (
SetupBuf,
EFI_SIZE_TO_PAGES (InitrdSize)
);
DEBUG ((EFI_D_INFO, "Initrd size: 0x%x\n", (UINT32) InitrdSize));
DEBUG ((EFI_D_INFO, "Reading initrd image ..."));
QemuFwCfgSelectItem (QemuFwCfgItemInitrdData);
QemuFwCfgReadBytes (InitrdSize, InitrdData);
DEBUG ((EFI_D_INFO, " [done]\n"));
} else {
InitrdData = NULL;
}
Status = LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize);
if (EFI_ERROR (Status)) {
goto FreeAndReturn;
} }
// //
@ -147,22 +35,16 @@ TryRunningQemuKernel (
REPORT_STATUS_CODE (EFI_PROGRESS_CODE, REPORT_STATUS_CODE (EFI_PROGRESS_CODE,
(EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)); (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
Status = LoadLinux (KernelBuf, SetupBuf); //
// Start the image.
//
Status = QemuStartKernelImage (&KernelImageHandle);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: QemuStartKernelImage(): %r\n", __FUNCTION__,
Status));
}
FreeAndReturn: QemuUnloadKernelImage (KernelImageHandle);
if (SetupBuf != NULL) {
FreePages (SetupBuf, EFI_SIZE_TO_PAGES (SetupSize));
}
if (KernelBuf != NULL) {
FreePages (KernelBuf, EFI_SIZE_TO_PAGES (KernelInitialSize));
}
if (CommandLine != NULL) {
FreePages (CommandLine, EFI_SIZE_TO_PAGES (CommandLineSize));
}
if (InitrdData != NULL) {
FreePages (InitrdData, EFI_SIZE_TO_PAGES (InitrdSize));
}
return Status; return Status;
} }