From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=rSP6Uej8; spf=pass (domain: linaro.org, ip: 209.85.128.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wm1-f66.google.com with SMTP id p9so1249360wmc.2 for ; Wed, 04 Mar 2020 01:52:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+ic7I+c0yrtjpEXgSs16e2iaPqoyrn+TEOnW7x+9NvU=; b=rSP6Uej8iYpNco/34uIk3gAmQ+WNDicaKf/hVKf4MN/QcY2tb+IyEhP6diQTwc2RnB cNktpE2P/jZepT1prPsVqgRb5A3+V87gjztr+pVa7Ba3e/gBz6BA19YMgDHVY3uwzqMp bY+U0m9IxiyICrTOHKxH+126sKbbJvzBWWa7Kr2rC2JwlQGbCnGkCZeSQ9idCLvw4z3h nLrJ5PrtdsjGcq/owmsuIfZU6SgdiYBLgvMvSxuTmu4B7Cb1/bIoyKsHV7brFiZIT/tG dNY1eC0WPaWNEW7EBBeRQbSmUSvVd7pnJEYBw5vlh4y1RAxmarNuklzIzBmxkDUVsiGQ IQJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+ic7I+c0yrtjpEXgSs16e2iaPqoyrn+TEOnW7x+9NvU=; b=F8pP2vMzcH6/500JGc+xwu3LKY9fIoM6sSDfh7z5gbGlpidEv46SL/WcElXY+kAIgg A9HY12gAd6mjFtoGzxp2Cw9/gDTToYtWBBsjYvnFRizu3cRANQ3ch4W5c1zuXQj9JVrE QJ+UDVIBykeMqP/SNwuRRp+Ky1Dr4my4IGH+iGmf0l2GLA8xgNp45jC9X63NSKaonmgz kFn7DdnXKMtltgkIJHkj4gknxIIVKfsRz5ZiRi94JSMqKzhiWwqjdC72Vdga9njIwxMT HnfpKV1vazZ9wPn54JSFQZqgjPqPJ7EoUNyxtZUg2+uyNAzMYD0ysn5NauCDyb4x3+S8 SNHg== X-Gm-Message-State: ANhLgQ1hVtkWy4L2YRP3u7BZCnclI6zaZHimZXi/j278ybnNZtrwm0Dh eNnttBiP4NYdLUIcacHrHKHLq0+2SoREzQ== 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200304095233.21046-1-ard.biesheuvel@linaro.org> References: <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 --- 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 #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; } - -- 2.17.1