]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
EmbeddedPkg/AndroidFastbootApp: remove dependency on deprecated BdsLib
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / Arm / BootAndroidBootImg.c
index 04ad9c05db4b433f33c8db10342528e2d38f0308..f446cce2855aa7aec91f02a00a1f0881291fb625 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2013-2015, ARM Ltd. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 #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
-\r
-#include <Guid/ArmGlobalVariableHob.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
 \r
 // Device Path representing an image in memory\r
 #pragma pack(1)\r
@@ -46,18 +47,70 @@ STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
-    0\r
+    { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
   } // 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
   IN VOID    *Buffer\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL           *FdtDevicePath;\r
   EFI_STATUS                          Status;\r
   CHAR8                               KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];\r
   VOID                               *Kernel;\r
@@ -65,7 +118,7 @@ BootAndroidBootImg (
   VOID                               *Ramdisk;\r
   UINTN                               RamdiskSize;\r
   MEMORY_DEVICE_PATH                  KernelDevicePath;\r
-  MEMORY_DEVICE_PATH*                 RamdiskDevicePath;\r
+  CHAR16                              *LoadOptions, *NewLoadOptions;\r
 \r
   Status = ParseAndroidBootImg (\r
             Buffer,\r
@@ -86,42 +139,38 @@ BootAndroidBootImg (
   KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;\r
   KernelDevicePath.Node1.EndingAddress   = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;\r
 \r
-  RamdiskDevicePath = NULL;\r
-  if (RamdiskSize != 0) {\r
-    RamdiskDevicePath = (MEMORY_DEVICE_PATH*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL*) &MemoryDevicePathTemplate);\r
-\r
-    RamdiskDevicePath->Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk;\r
-    RamdiskDevicePath->Node1.EndingAddress   = ((EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk) + RamdiskSize;\r
+  // Initialize Linux command line\r
+  LoadOptions = CatSPrint (NULL, L"%a", KernelArgs);\r
+  if (LoadOptions == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  // Get the default FDT device path\r
-  Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid,\r
-             NULL, 0, (VOID **)&FdtDevicePath);\r
-  if (Status == EFI_NOT_FOUND) {\r
-    DEBUG ((EFI_D_ERROR, "Error: Please update FDT path in boot manager\n"));\r
-    return EFI_DEVICE_ERROR;\r
+  if (RamdiskSize != 0) {\r
+    NewLoadOptions = CatSPrint (LoadOptions, L" initrd=0x%x,0x%x",\r
+                       (UINTN)Ramdisk, RamdiskSize);\r
+    FreePool (LoadOptions);\r
+    if (NewLoadOptions == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    LoadOptions = NewLoadOptions;\r
   }\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = BdsBootLinuxFdt (\r
-              (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r
-              (EFI_DEVICE_PATH_PROTOCOL *) RamdiskDevicePath,\r
-              KernelArgs,\r
-              FdtDevicePath\r
-              );\r
+\r
+  Status = StartEfiApplication (gImageHandle,\r
+             (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r
+             StrSize (LoadOptions),\r
+             LoadOptions);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r
-    return EFI_DEVICE_ERROR;\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto FreeLoadOptions;\r
   }\r
 \r
-  if (RamdiskDevicePath) {\r
-    FreePool (RamdiskDevicePath);\r
-  }\r
-\r
-  FreePool (FdtDevicePath);\r
-\r
   // If we got here we do a confused face because BootLinuxFdt returned,\r
   // reporting success.\r
   DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r
   return EFI_SUCCESS;\r
+\r
+FreeLoadOptions:\r
+  FreePool (LoadOptions);\r
+  return Status;\r
 }\r