From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: devel@edk2.groups.io
Cc: lersek@redhat.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v2 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib
Date: Wed, 4 Mar 2020 10:52:31 +0100 [thread overview]
Message-ID: <20200304095233.21046-13-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20200304095233.21046-1-ard.biesheuvel@linaro.org>
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>
---
OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 +-
OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c | 144 ++------------------
2 files changed, 14 insertions(+), 132 deletions(-)
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index f89cce187942..40ac5dd7f9d5 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -48,7 +48,7 @@ [LibraryClasses]
NvVarsFileLib
QemuFwCfgLib
QemuFwCfgS3Lib
- LoadLinuxLib
+ QemuLoadImageLib
QemuBootOrderLib
ReportStatusCodeLib
UefiLib
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c
index ddfef925edd3..c6255921779e 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c
@@ -9,11 +9,8 @@
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
-#include <Library/LoadLinuxLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/QemuFwCfgLib.h>
+#include <Library/QemuLoadImageLib.h>
#include <Library/ReportStatusCodeLib.h>
-#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
@@ -23,120 +20,11 @@ TryRunningQemuKernel (
)
{
EFI_STATUS Status;
- UINTN KernelSize;
- UINTN KernelInitialSize;
- VOID *KernelBuf;
- UINTN SetupSize;
- VOID *SetupBuf;
- UINTN CommandLineSize;
- CHAR8 *CommandLine;
- UINTN InitrdSize;
- VOID* InitrdData;
+ EFI_HANDLE KernelImageHandle;
- SetupBuf = NULL;
- 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)) {
- goto FreeAndReturn;
- }
-
- 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);
+ Status = QemuLoadKernelImage (&KernelImageHandle);
if (EFI_ERROR (Status)) {
- goto FreeAndReturn;
+ return Status;
}
//
@@ -147,22 +35,16 @@ TryRunningQemuKernel (
REPORT_STATUS_CODE (EFI_PROGRESS_CODE,
(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:
- 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));
- }
+ QemuUnloadKernelImage (KernelImageHandle);
return Status;
}
-
--
2.17.1
next prev parent reply other threads:[~2020-03-04 9:52 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-04 9:52 [PATCH v2 00/14] Ovmf: use LoadImage/StartImage for loading command line images Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 01/14] OvmfPkg: add GUID for the QEMU kernel loader fs media device path Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 02/14] OvmfPkg: export abstract QEMU blob filesystem in standalone driver Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class Ard Biesheuvel
2020-03-05 9:37 ` [edk2-devel] " Laszlo Ersek
2020-03-05 9:39 ` Laszlo Ersek
2020-03-05 10:22 ` Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 04/14] OvmfPkg: provide a generic implementation of QemuLoadImageLib Ard Biesheuvel
2020-03-05 9:51 ` [edk2-devel] " Laszlo Ersek
2020-03-05 11:29 ` Laszlo Ersek
2020-03-05 11:37 ` Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 05/14] ArmVirtPkg: incorporate the new QEMU kernel loader driver and library Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 06/14] ArmVirtPkg/PlatformBootManagerLib: switch to separate QEMU loader Ard Biesheuvel
2020-03-05 10:01 ` [edk2-devel] " Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 07/14] OvmfPkg/QemuKernelLoaderFsDxe: don't expose kernel command line Ard Biesheuvel
2020-03-04 9:52 ` [PATCH v2 08/14] OvmfPkg/QemuKernelLoaderFsDxe: add support for the kernel setup block Ard Biesheuvel
2020-03-05 10:12 ` [edk2-devel] " Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 09/14] OvmfPkg: create protocol and GUID header for legacy loaded images Ard Biesheuvel
2020-03-05 10:31 ` [edk2-devel] " Laszlo Ersek
2020-03-05 10:40 ` Ard Biesheuvel
2020-03-05 14:29 ` Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 10/14] OvmfPkg: implement QEMU loader library for X86 with legacy fallback Ard Biesheuvel
2020-03-05 12:33 ` [edk2-devel] " Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 11/14] OvmfPkg: add new QEMU kernel image loader components Ard Biesheuvel
2020-03-04 9:52 ` Ard Biesheuvel [this message]
2020-03-05 12:57 ` [edk2-devel] [PATCH v2 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 13/14] OvmfPkg/QemuKernelLoaderFsDxe: add support for new Linux initrd device path Ard Biesheuvel
2020-03-05 13:19 ` Laszlo Ersek
2020-03-04 9:52 ` [PATCH v2 14/14] OvmfPkg: use generic QEMU image loader for secure boot enabled builds Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200304095233.21046-13-ard.biesheuvel@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox