From patchwork Mon Apr 10 16:55:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 97185 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1445726qgd; Mon, 10 Apr 2017 09:55:46 -0700 (PDT) X-Received: by 10.99.158.2 with SMTP id s2mr57573315pgd.15.1491843346557; Mon, 10 Apr 2017 09:55:46 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id p75si14153245pfk.2.2017.04.10.09.55.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 09:55:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6AD4E2194235A; Mon, 10 Apr 2017 09:55:45 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wr0-x232.google.com (mail-wr0-x232.google.com [IPv6:2a00:1450:400c:c0c::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A18BD21A04817 for ; Mon, 10 Apr 2017 09:55:44 -0700 (PDT) Received: by mail-wr0-x232.google.com with SMTP id o21so124749545wrb.2 for ; Mon, 10 Apr 2017 09:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4dTSXB49HBM0AdWiu5lCl/DhOP6g7mG95BHVCgAumVQ=; b=f752UEtTLz+KcOsELtVlYNGK18sIdUVUelhOroI51hDabQnXUuKumxSZVAhtNKhjtb xVrs5ibx1IEj56XKPWyyg+ZDut5KDsHrA91tzlvV9JyHX67D6f4HZ1D7sGJFggKD+Nbx pxJLgvU0BMsJq4nS58Nsdq4cqpoVsy+KxW2cA= 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; bh=4dTSXB49HBM0AdWiu5lCl/DhOP6g7mG95BHVCgAumVQ=; b=eYZRAiYhGsLTlkL5MUYnNUy9cSyex5V3Kfas196cVkZJNMHerFNuGmsANCz/w8kTMu j3ptlBb6wgb8RzRGvF2t+R9CaCAqcJcLryv0NXS45w/PGN6WGDyEv79ytKUeBRGacbEx Z8ozTIjmpLeS2xoxXWrDZ/6lm13YF9l5WslkHkU/2ce37dt7DHyGhr5SNMmeumMYz6Bs Rf1tZACEaDitkyeA2IjImJdnTSq1RRrqWfWxUpPJ5e1Cc99TAFyj9oye5oo0abcYgtMW lft1q7o9P8DsNO8dU2FDO2NczHNEARF7V0ilXudnCKdkNt+7OHY6KmAhLXHrMhXMyoHt mwNQ== X-Gm-Message-State: AFeK/H08N//rLUbb/RMNoyfEUl1tbMTFQFmSyJ7EJ8kfWQKrK/5VTnARp5OV4GaOm2eare3F X-Received: by 10.223.176.202 with SMTP id j10mr31781956wra.10.1491843342886; Mon, 10 Apr 2017 09:55:42 -0700 (PDT) Received: from localhost.localdomain ([196.85.182.219]) by smtp.gmail.com with ESMTPSA id o15sm18043685wra.61.2017.04.10.09.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 09:55:41 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Mon, 10 Apr 2017 17:55:34 +0100 Message-Id: <20170410165534.22292-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [edk2] [RFT PATCH] EmbeddedPkg/AndroidFastbootApp: remove dependency on deprecated BdsLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ryan.harkin@linaro.org, haojian.zhuang@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" One of the last remaining modules with a dependency on the deprecated BdsLib implementation from ArmPkg is the Android fastboot application. Its only dependency on BdsLib is BdsStartEfiApplication(), which is used in the most peculiar way: the fastboot app loads the kernel image into memory, and creates a MemoryMapped() device path for it. It then proceeds and calls BdsStartEfiApplication(), which explicitly loads the contents of the devicepath into memory, creating a second in-memory copy of the kernel image, after which it invokes gBS->LoadImage() with a buffer address and size (while it is perfectly capable of loading from a devicepath directly) Since we know the device path is fully qualified and connected, and does not require any of the additional processing that BdsStartEfiApplication() does when dereferencing a device path, we should be able to pass this devicepath into LoadImage() directly. So create a simplified local clone of BdsStartEfiApplication(), and drop the dependency on BdsLib. Signed-off-by: Ard Biesheuvel --- EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf | 2 +- EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c | 57 +++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) -- 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf index 3e115171ce01..8d2b23c6f8b8 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf @@ -30,7 +30,6 @@ [Sources.ARM, Sources.AARCH64] [LibraryClasses] BaseLib BaseMemoryLib - BdsLib DebugLib DevicePathLib DxeServicesTableLib @@ -45,6 +44,7 @@ [LibraryClasses] [Protocols] gAndroidFastbootTransportProtocolGuid gAndroidFastbootPlatformProtocolGuid + gEfiLoadedImageProtocolGuid gEfiSimpleTextOutProtocolGuid gEfiSimpleTextInProtocolGuid diff --git a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c index 46a7ceb3a41c..f446cce2855a 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c +++ b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c @@ -15,6 +15,7 @@ #include "AndroidFastbootApp.h" #include +#include #include #include @@ -50,6 +51,60 @@ STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate = } // End }; + +/** + Start an EFI Application from a Device Path + + @param ParentImageHandle Handle of the calling image + @param DevicePath Location of the EFI Application + + @retval EFI_SUCCESS All drivers have been connected + @retval EFI_NOT_FOUND The Linux kernel Device Path has not been found + @retval EFI_OUT_OF_RESOURCES There is not enough resource memory to store the matching results. + +**/ +STATIC +EFI_STATUS +StartEfiApplication ( + IN EFI_HANDLE ParentImageHandle, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN UINTN LoadOptionsSize, + IN VOID* LoadOptions + ) +{ + EFI_STATUS Status; + EFI_HANDLE ImageHandle; + EFI_LOADED_IMAGE_PROTOCOL* LoadedImage; + + // Load the image from the device path with Boot Services function + Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, NULL, 0, + &ImageHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + // Passed LoadOptions to the EFI Application + if (LoadOptionsSize != 0) { + Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage); + if (EFI_ERROR (Status)) { + return Status; + } + + LoadedImage->LoadOptionsSize = LoadOptionsSize; + LoadedImage->LoadOptions = LoadOptions; + } + + // Before calling the image, enable the Watchdog Timer for the 5 Minute period + gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); + // Start the image + Status = gBS->StartImage (ImageHandle, NULL, NULL); + // Clear the Watchdog Timer after the image returns + gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); + + return Status; +} + EFI_STATUS BootAndroidBootImg ( IN UINTN BufferSize, @@ -100,7 +155,7 @@ BootAndroidBootImg ( LoadOptions = NewLoadOptions; } - Status = BdsStartEfiApplication (gImageHandle, + Status = StartEfiApplication (gImageHandle, (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath, StrSize (LoadOptions), LoadOptions);