]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/AndroidFastbootApp: remove dependency on deprecated BdsLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 10 Apr 2017 16:55:34 +0000 (17:55 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 19 Apr 2017 06:57:51 +0000 (07:57 +0100)
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 <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf
EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c

index 3e115171ce0164ef37572f75f09390163741d10a..8d2b23c6f8b8cd2ea99ee5af1025e7d151ac0e17 100644 (file)
@@ -30,7 +30,6 @@
 [LibraryClasses]\r
   BaseLib\r
   BaseMemoryLib\r
-  BdsLib\r
   DebugLib\r
   DevicePathLib\r
   DxeServicesTableLib\r
@@ -45,6 +44,7 @@
 [Protocols]\r
   gAndroidFastbootTransportProtocolGuid\r
   gAndroidFastbootPlatformProtocolGuid\r
+  gEfiLoadedImageProtocolGuid\r
   gEfiSimpleTextOutProtocolGuid\r
   gEfiSimpleTextInProtocolGuid\r
 \r
index 46a7ceb3a41c2ebd54a159f1d0ccf7988b1dfe60..f446cce2855aa7aec91f02a00a1f0881291fb625 100644 (file)
@@ -15,6 +15,7 @@
 #include "AndroidFastbootApp.h"\r
 \r
 #include <Protocol/DevicePath.h>\r
+#include <Protocol/LoadedImage.h>\r
 \r
 #include <Library/BdsLib.h>\r
 #include <Library/DevicePathLib.h>\r
@@ -50,6 +51,60 @@ STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =
   } // End\r
 };\r
 \r
+\r
+/**\r
+  Start an EFI Application from a Device Path\r
+\r
+  @param  ParentImageHandle     Handle of the calling image\r
+  @param  DevicePath            Location of the EFI Application\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+StartEfiApplication (\r
+  IN EFI_HANDLE                  ParentImageHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath,\r
+  IN UINTN                       LoadOptionsSize,\r
+  IN VOID*                       LoadOptions\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_HANDLE                   ImageHandle;\r
+  EFI_LOADED_IMAGE_PROTOCOL*   LoadedImage;\r
+\r
+  // Load the image from the device path with Boot Services function\r
+  Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, NULL, 0,\r
+                  &ImageHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Passed LoadOptions to the EFI Application\r
+  if (LoadOptionsSize != 0) {\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid,\r
+                    (VOID **) &LoadedImage);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    LoadedImage->LoadOptionsSize  = LoadOptionsSize;\r
+    LoadedImage->LoadOptions      = LoadOptions;\r
+  }\r
+\r
+  // Before calling the image, enable the Watchdog Timer for  the 5 Minute period\r
+  gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
+  // Start the image\r
+  Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
+  // Clear the Watchdog Timer after the image returns\r
+  gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
+\r
+  return Status;\r
+}\r
+\r
 EFI_STATUS\r
 BootAndroidBootImg (\r
   IN UINTN    BufferSize,\r
@@ -100,7 +155,7 @@ BootAndroidBootImg (
     LoadOptions = NewLoadOptions;\r
   }\r
 \r
-  Status = BdsStartEfiApplication (gImageHandle,\r
+  Status = StartEfiApplication (gImageHandle,\r
              (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r
              StrSize (LoadOptions),\r
              LoadOptions);\r