]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/BdsLib: Fix booting with partial paths
authorMark Salter <msalter@redhat.com>
Thu, 8 May 2014 15:09:27 +0000 (15:09 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 8 May 2014 15:09:27 +0000 (15:09 +0000)
Boot entries created by efibootmgr may contain a partial device path
to the EFI application to boot. These entries begin with a partition
device path whereas entries created via ARM Boot Manager contain a
full path to the EFI application. The ARM BDS code will fill in the
missing parts of this partial device path as it does for removeable
device paths. This allows the application to be loaded and started.
However, the current code passes the original partial device path to
gBS->LoadImage() and thus LoadImage is unable to find a DeviceHandle
for the path. This means the application being booted cannot find the
boot device from the Loaded Image Protocol structure. In the case of
grub, this prevents the grub config file from being found. This patch
fixes this by making sure the full path is propagated back to the
caller of gBS->LoadImage() so that a proper DeviceHandle gets passed
to the application being booted.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15518 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Library/BdsLib/BdsFilePath.c

index 25f92725f538d62651b4ea071b844f29fd51c982..487bd7654cebe985c36eb642af8d6afef17e1b4d 100644 (file)
@@ -300,35 +300,24 @@ TryRemovableDevice (
   return Status;\r
 }\r
 \r
-/**\r
-  Connect a Device Path and return the handle of the driver that support this DevicePath\r
-\r
-  @param  DevicePath            Device Path of the File to connect\r
-  @param  Handle                Handle of the driver that support this DevicePath\r
-  @param  RemainingDevicePath   Remaining DevicePath nodes that do not match the driver DevicePath\r
-\r
-  @retval EFI_SUCCESS           A driver that matches the Device Path has been found\r
-  @retval EFI_NOT_FOUND         No handles match the search.\r
-  @retval EFI_INVALID_PARAMETER DevicePath or Handle is NULL\r
-\r
-**/\r
+STATIC
 EFI_STATUS\r
-BdsConnectDevicePath (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,\r
-  OUT EFI_HANDLE                *Handle,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **RemainingDevicePath\r
+BdsConnectAndUpdateDevicePath (
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath,
+  OUT    EFI_HANDLE                *Handle,
+  OUT    EFI_DEVICE_PATH_PROTOCOL  **RemainingDevicePath
   )\r
 {\r
   EFI_DEVICE_PATH*            Remaining;\r
   EFI_DEVICE_PATH*            NewDevicePath;\r
   EFI_STATUS                  Status;\r
 \r
-  if ((DevicePath == NULL) || (Handle == NULL)) {\r
+  if ((DevicePath == NULL) || (*DevicePath == NULL) || (Handle == NULL)) {
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   do {\r
-    Remaining = DevicePath;\r
+    Remaining = *DevicePath;
     // The LocateDevicePath() function locates all devices on DevicePath that support Protocol and returns\r
     // the handle to the device that is closest to DevicePath. On output, the device path pointer is modified\r
     // to point to the remaining part of the device path\r
@@ -348,7 +337,7 @@ BdsConnectDevicePath (
   if (!EFI_ERROR (Status)) {\r
     // Now, we have got the whole Device Path connected, call again ConnectController to ensure all the supported Driver\r
     // Binding Protocol are connected (such as DiskIo and SimpleFileSystem)\r
-    Remaining = DevicePath;\r
+    Remaining = *DevicePath;
     Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &Remaining, Handle);\r
     if (!EFI_ERROR (Status)) {\r
       Status = gBS->ConnectController (*Handle, NULL, Remaining, FALSE);\r
@@ -371,9 +360,11 @@ BdsConnectDevicePath (
     //TODO: Should we just return success and leave the caller decide if it is the expected RemainingPath\r
     Status = EFI_SUCCESS;\r
   } else {\r
-    Status = TryRemovableDevice (DevicePath, Handle, &NewDevicePath);\r
+    Status = TryRemovableDevice (*DevicePath, Handle, &NewDevicePath);
     if (!EFI_ERROR (Status)) {\r
-      return BdsConnectDevicePath (NewDevicePath, Handle, RemainingDevicePath);\r
+      Status = BdsConnectAndUpdateDevicePath (&NewDevicePath, Handle, RemainingDevicePath);
+      *DevicePath = NewDevicePath;
+      return Status;
     }\r
   }\r
 \r
@@ -384,6 +375,28 @@ BdsConnectDevicePath (
   return Status;\r
 }\r
 \r
+/**
+  Connect a Device Path and return the handle of the driver that support this DevicePath
+
+  @param  DevicePath            Device Path of the File to connect
+  @param  Handle                Handle of the driver that support this DevicePath
+  @param  RemainingDevicePath   Remaining DevicePath nodes that do not match the driver DevicePath
+
+  @retval EFI_SUCCESS           A driver that matches the Device Path has been found
+  @retval EFI_NOT_FOUND         No handles match the search.
+  @retval EFI_INVALID_PARAMETER DevicePath or Handle is NULL
+
+**/\r
+EFI_STATUS
+BdsConnectDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,
+  OUT EFI_HANDLE                *Handle,
+  OUT EFI_DEVICE_PATH_PROTOCOL  **RemainingDevicePath
+  )
+{
+  return BdsConnectAndUpdateDevicePath (&DevicePath, Handle, RemainingDevicePath);
+}
+
 BOOLEAN\r
 BdsFileSystemSupport (\r
   IN EFI_DEVICE_PATH *DevicePath,\r
@@ -866,8 +879,8 @@ BDS_FILE_LOADER FileLoaders[] = {
 };\r
 \r
 EFI_STATUS\r
-BdsLoadImage (\r
-  IN     EFI_DEVICE_PATH       *DevicePath,\r
+BdsLoadImageAndUpdateDevicePath (
+  IN OUT EFI_DEVICE_PATH       **DevicePath,
   IN     EFI_ALLOCATE_TYPE     Type,\r
   IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
   OUT    UINTN                 *FileSize\r
@@ -878,15 +891,15 @@ BdsLoadImage (
   EFI_DEVICE_PATH *RemainingDevicePath;\r
   BDS_FILE_LOADER*  FileLoader;\r
 \r
-  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);\r
+  Status = BdsConnectAndUpdateDevicePath (DevicePath, &Handle, &RemainingDevicePath);
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   FileLoader = FileLoaders;\r
   while (FileLoader->Support != NULL) {\r
-    if (FileLoader->Support (DevicePath, Handle, RemainingDevicePath)) {\r
-      return FileLoader->LoadImage (DevicePath, Handle, RemainingDevicePath, Type, Image, FileSize);\r
+    if (FileLoader->Support (*DevicePath, Handle, RemainingDevicePath)) {
+      return FileLoader->LoadImage (*DevicePath, Handle, RemainingDevicePath, Type, Image, FileSize);
     }\r
     FileLoader++;\r
   }\r
@@ -894,6 +907,17 @@ BdsLoadImage (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+EFI_STATUS\r
+BdsLoadImage (
+  IN     EFI_DEVICE_PATH       *DevicePath,
+  IN     EFI_ALLOCATE_TYPE     Type,
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,
+  OUT    UINTN                 *FileSize
+  )
+{
+  return BdsLoadImageAndUpdateDevicePath (&DevicePath, Type, Image, FileSize);
+}
+
 /**\r
   Start an EFI Application from a Device Path\r
 \r
@@ -920,7 +944,7 @@ BdsStartEfiApplication (
   EFI_LOADED_IMAGE_PROTOCOL*   LoadedImage;\r
 \r
   // Find the nearest supported file loader\r
-  Status = BdsLoadImage (DevicePath, AllocateAnyPages, &BinaryBuffer, &BinarySize);\r
+  Status = BdsLoadImageAndUpdateDevicePath (&DevicePath, AllocateAnyPages, &BinaryBuffer, &BinarySize);
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r