From nobody Tue Feb 10 04:08:13 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+55393+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+55393+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583315579; cv=none; d=zohomail.com; s=zohoarc; b=modcgF8zlu5gIirYxakoGYKqypogQkS+QdIpc75+WmdGuO+NYebrGKNstkflNVkfjWqM4ysjRmLj1EmsHXndxd+gvUDaBqDUNa6eI08kx+VLmy/vexsajE4BS1gFhYQiX3HTScZR+Ec/Bd17YhK4DE1m8psp1FB5Sfk8N6u72rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583315579; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=TwS2kk2PDnNYifZkQntCiS3WfOrKegnUuPsfAilmKqY=; b=la5vWEhUKDGlXBawbK2zQtG0vngaT5CD9o1m1DOmY9N4H9SoQ74ep/iB/NqOPA7nlk2cobxiNXuDC8XDQM1PqxpCjAaMyBZyhMgOb/CQ9JEIVUu+YJwCThiVWD957WQchDsd5AUG+9F12kvSCeTSxWSB8SJ68aIGztr80P+vzgk= 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+55393+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 1583315579567870.4607426860163; Wed, 4 Mar 2020 01:52:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q6l8YY1788612xxAcgJYBaW0; Wed, 04 Mar 2020 01:52:58 -0800 X-Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web10.9184.1583315577942549486 for ; Wed, 04 Mar 2020 01:52:58 -0800 X-Received: by mail-wm1-f66.google.com with SMTP id p9so1249360wmc.2 for ; Wed, 04 Mar 2020 01:52:57 -0800 (PST) X-Gm-Message-State: zAp2ipyjXTK7gdrzEHa0mWT9x1787277AA= X-Google-Smtp-Source: ADFU+vsYFWd00wK3wdnzuZrUtT0HVCzKO55NrU9V1wHx4ofXITtULXwzRnYybwKnwIRgz3r0X+A1qA== X-Received: by 2002:a1c:7419:: with SMTP id p25mr2733379wmc.129.1583315576227; Wed, 04 Mar 2020 01:52:56 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id v16sm20781095wrp.84.2020.03.04.01.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 01:52:55 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib Date: Wed, 4 Mar 2020 10:52:31 +0100 Message-Id: <20200304095233.21046-13-ard.biesheuvel@linaro.org> In-Reply-To: <20200304095233.21046-1-ard.biesheuvel@linaro.org> References: <20200304095233.21046-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=1583315578; bh=nVSL9tnuT8AtacC8evakhHFXuGLPJVjrYFrs90X+9kE=; h=Cc:Date:From:Reply-To:Subject:To; b=ohpXwaU2uiKFihoS/PELMiBfR3XR9myyK1letR1xfcMHhDb1sevBWd4NKztF3W72heE vwSqCMCaoyqicz+OcTPX4mRD2oqV4KySQGiLPX7/SsqmZfkt6lm0iLPDVtzBBVKVJSVZy Ic5lj4X9xjCnZuQ5uBPfe1aW1lKRLXRN8sM= 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 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 @@ =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 (#55393): https://edk2.groups.io/g/devel/message/55393 Mute This Topic: https://groups.io/mt/71722806/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-