From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web10.12047.1583413053269066485 for ; Thu, 05 Mar 2020 04:57:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hCmyZ1i+; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583413052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a0bn82EeMhzb27JI4vxJWUddAqg24Hq2hpDTD5dc2/M=; b=hCmyZ1i+WtuLi4dzTzKUGArEEgO7cjLipnedFKRq0fJTCtqS23ocNtqhUINbTbHZ7//6/O sz14S3ch2PV9qPLKeho7Q5te2lIOd34sk8KrrVWnqKst7JfPjusTYgbRkldgQ2MzLwLwlZ Q0zcJA8jlAx1+4lLs9y6dyGwaB3X+sA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-t1p5h6X_M_WDoEchI5f32g-1; Thu, 05 Mar 2020 07:57:28 -0500 X-MC-Unique: t1p5h6X_M_WDoEchI5f32g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 581841005510; Thu, 5 Mar 2020 12:57:27 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-216.ams2.redhat.com [10.36.117.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8496889F1C; Thu, 5 Mar 2020 12:57:26 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v2 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib To: devel@edk2.groups.io, ard.biesheuvel@linaro.org References: <20200304095233.21046-1-ard.biesheuvel@linaro.org> <20200304095233.21046-13-ard.biesheuvel@linaro.org> From: "Laszlo Ersek" Message-ID: <20c9c796-94de-697a-4dc7-89408ddb7348@redhat.com> Date: Thu, 5 Mar 2020 13:57:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200304095233.21046-13-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 03/04/20 10:52, Ard Biesheuvel wrote: > 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 > --- > OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 +- > OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c | 144 ++------------------ > 2 files changed, 14 insertions(+), 132 deletions(-) Reviewed-by: Laszlo Ersek Thanks, Laszlo > > 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 > #include > -#include > -#include > -#include > +#include > #include > -#include > #include > > > @@ -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; > } > - >