From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Cc: ryan.harkin@linaro.org, haojian.zhuang@linaro.org, Ard Biesheuvel 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: [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: , X-List-Received-Date: Mon, 10 Apr 2017 16:55:45 -0000 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(-) 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); -- 2.9.3