From nobody Tue Feb 10 01:34:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55535+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55535+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415989; cv=none; d=zohomail.com; s=zohoarc; b=AhnOvZHLGoaCJvA+o6ESGgeBggqke7nM/6/xXyQiJWKujg7MIBmJ4lXxQwaigqNJDXAvUk9XaoSm24IbjEKJa2TxfBGCNOLrrcSkBVbRoTJOV2wkL/aoo8eMtJ7C3S/EI66PjYGqWxjdnROdkjTN0oMVEQldcPJeitp7pGzW9Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415989; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=PBaf8VhRdF+0JrS4cqWSHHhoxEXafl9s0Levy9mLhJM=; b=E3wk2X2XNCBLhc6jSde5UR+8B8aJWOkSpM7LKjI3eNgqkN/QmYo7GojS3vXYfqQmWNhsOLKca/FWGvsxivEAKpznOULkpLq8STy88Wmj/Pw2linzTphz24z0MHy//aTr1r1S51iMAwUXlYPx5ADIJh8O+P4HTi1iaiumJ/QP1Ls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55535+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158341598916023.97990245443873; Thu, 5 Mar 2020 05:46:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6xJMYY1788612xcUEmYNNlC5; Thu, 05 Mar 2020 05:46:28 -0800 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web10.12698.1583415987524382720 for ; Thu, 05 Mar 2020 05:46:27 -0800 X-Received: by mail-wr1-f68.google.com with SMTP id x7so7112023wrr.0 for ; Thu, 05 Mar 2020 05:46:27 -0800 (PST) X-Gm-Message-State: BrxxxaK9fmPWdV8XrNblsjSbx1787277AA= X-Google-Smtp-Source: ADFU+vtxOVCAtGyxpNxhgqq0Vsczk9sa6cjh2Qrb8pv8gMRmZRrUPzn4agopAcstgfXZAOa7Vs2WKA== X-Received: by 2002:a5d:5089:: with SMTP id a9mr10596594wrt.187.1583415985491; Thu, 05 Mar 2020 05:46:25 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id m19sm9278701wmc.34.2020.03.05.05.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:24 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib Date: Thu, 5 Mar 2020 14:46:05 +0100 Message-Id: <20200305134607.20125-13-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415988; bh=4W5F/lynfdcx01TiNxiXx+FwyeYWdSXbKZ+JvyGRdPY=; h=Cc:Date:From:Reply-To:Subject:To; b=TupCJ3goQiMY/iTKaurmmP40yaKzV/lLAJXJUC6LfjSlrZ6gWjflTrLSotQpzCbJhzz lUERQfBwM3k2DOJe9KOtjYDS+NOE6TqdupctmHD+ZNY/40trxa62div3Jv9E6YTx98qNu pi5TbcOMKiCS4pFAxUmZZlClxE+A05JDwrk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- 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 c479f113b92b..e470b9a6a3e5 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -49,7 +49,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 @@ =20 #include #include -#include -#include -#include +#include #include -#include #include =20 =20 @@ -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; =20 - SetupBuf =3D NULL; - SetupSize =3D 0; - KernelBuf =3D NULL; - KernelInitialSize =3D 0; - CommandLine =3D NULL; - CommandLineSize =3D 0; - InitrdData =3D NULL; - InitrdSize =3D 0; - - if (!QemuFwCfgIsAvailable ()) { - return EFI_NOT_FOUND; - } - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); - KernelSize =3D (UINTN) QemuFwCfgRead64 (); - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); - SetupSize =3D (UINTN) QemuFwCfgRead64 (); - - if (KernelSize =3D=3D 0 || SetupSize =3D=3D 0) { - DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n")); - return EFI_NOT_FOUND; - } - - SetupBuf =3D LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (Setup= Size)); - if (SetupBuf =3D=3D 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 =3D LoadLinuxCheckKernelSetup (SetupBuf, SetupSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - Status =3D LoadLinuxInitializeKernelSetup (SetupBuf); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - KernelInitialSize =3D LoadLinuxGetKernelSize (SetupBuf, KernelSize); - if (KernelInitialSize =3D=3D 0) { - Status =3D EFI_UNSUPPORTED; - goto FreeAndReturn; - } - - KernelBuf =3D LoadLinuxAllocateKernelPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (KernelInitialSize)); - if (KernelBuf =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n")); - Status =3D 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 =3D (UINTN) QemuFwCfgRead64 (); - - if (CommandLineSize > 0) { - CommandLine =3D LoadLinuxAllocateCommandLinePages ( - EFI_SIZE_TO_PAGES (CommandLineSize)); - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); - QemuFwCfgReadBytes (CommandLineSize, CommandLine); - } else { - CommandLine =3D NULL; - } - - Status =3D LoadLinuxSetCommandLine (SetupBuf, CommandLine); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); - InitrdSize =3D (UINTN) QemuFwCfgRead64 (); - - if (InitrdSize > 0) { - InitrdData =3D 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 =3D NULL; - } - - Status =3D LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize); + Status =3D QemuLoadKernelImage (&KernelImageHandle); if (EFI_ERROR (Status)) { - goto FreeAndReturn; + return Status; } =20 // @@ -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)); =20 - Status =3D LoadLinux (KernelBuf, SetupBuf); + // + // Start the image. + // + Status =3D QemuStartKernelImage (&KernelImageHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: QemuStartKernelImage(): %r\n", __FUNCTION__, + Status)); + } =20 -FreeAndReturn: - if (SetupBuf !=3D NULL) { - FreePages (SetupBuf, EFI_SIZE_TO_PAGES (SetupSize)); - } - if (KernelBuf !=3D NULL) { - FreePages (KernelBuf, EFI_SIZE_TO_PAGES (KernelInitialSize)); - } - if (CommandLine !=3D NULL) { - FreePages (CommandLine, EFI_SIZE_TO_PAGES (CommandLineSize)); - } - if (InitrdData !=3D NULL) { - FreePages (InitrdData, EFI_SIZE_TO_PAGES (InitrdSize)); - } + QemuUnloadKernelImage (KernelImageHandle); =20 return Status; } - --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55535): https://edk2.groups.io/g/devel/message/55535 Mute This Topic: https://groups.io/mt/71749527/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-