]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
MdeModulePkg/Bds: Refine the code to load file from FV.
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmBoot.c
index 7297a1ddda2f7e7159b9a3ce29ddffaafdd05caf..a6826f61ae041b79807dc1f412ff1fa4a69b19de 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Library functions which relates with booting.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -244,15 +244,15 @@ BmFindBootOptionInVariable (
 \r
   FV address may change across reboot. This routine promises the FV file device path is right.\r
 \r
-  @param  DevicePath   The Memory Mapped Device Path to get the file buffer.\r
+  @param  FilePath     The Memory Mapped Device Path to get the file buffer.\r
   @param  FullPath     Receive the updated FV Device Path pointint to the file.\r
   @param  FileSize     Receive the file buffer size.\r
 \r
   @return  The file buffer.\r
 **/\r
 VOID *\r
-BmGetFileBufferByMemmapFv (\r
-  IN EFI_DEVICE_PATH_PROTOCOL      *DevicePath,\r
+BmGetFileBufferByFvFilePath (\r
+  IN EFI_DEVICE_PATH_PROTOCOL      *FilePath,\r
   OUT EFI_DEVICE_PATH_PROTOCOL     **FullPath,\r
   OUT UINTN                        *FileSize\r
   )\r
@@ -267,18 +267,28 @@ BmGetFileBufferByMemmapFv (
   EFI_HANDLE                    *FvHandles;\r
   EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;\r
   VOID                          *FileBuffer;\r
-  \r
-  FvFileNode = DevicePath;\r
+\r
+  //\r
+  // Get the file buffer by using the exactly FilePath.\r
+  //\r
+  FvFileNode = FilePath;\r
   Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &FvFileNode, &FvHandle);\r
   if (!EFI_ERROR (Status)) {\r
-    FileBuffer = GetFileBufferByFilePath (TRUE, DevicePath, FileSize, &AuthenticationStatus);\r
+    FileBuffer = GetFileBufferByFilePath (TRUE, FilePath, FileSize, &AuthenticationStatus);\r
     if (FileBuffer != NULL) {\r
-      *FullPath = DuplicateDevicePath (DevicePath);\r
+      *FullPath = DuplicateDevicePath (FilePath);\r
     }\r
     return FileBuffer;\r
   }\r
 \r
-  FvFileNode = NextDevicePathNode (DevicePath);\r
+  //\r
+  // Only wide match other FVs if it's a memory mapped FV file path.\r
+  //\r
+  if ((DevicePathType (FilePath) != HARDWARE_DEVICE_PATH) || (DevicePathSubType (FilePath) != HW_MEMMAP_DP)) {\r
+    return NULL;\r
+  }\r
+\r
+  FvFileNode = NextDevicePathNode (FilePath);\r
 \r
   //\r
   // Firstly find the FV file in current FV\r
@@ -289,7 +299,7 @@ BmGetFileBufferByMemmapFv (
          (VOID **) &LoadedImage\r
          );\r
   NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), FvFileNode);\r
-  FileBuffer = BmGetFileBufferByMemmapFv (NewDevicePath, FullPath, FileSize);\r
+  FileBuffer = BmGetFileBufferByFvFilePath (NewDevicePath, FullPath, FileSize);\r
   FreePool (NewDevicePath);\r
 \r
   if (FileBuffer != NULL) {\r
@@ -314,7 +324,7 @@ BmGetFileBufferByMemmapFv (
       continue;\r
     }\r
     NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (FvHandles[Index]), FvFileNode);\r
-    FileBuffer = BmGetFileBufferByMemmapFv (NewDevicePath, FullPath, FileSize);\r
+    FileBuffer = BmGetFileBufferByFvFilePath (NewDevicePath, FullPath, FileSize);\r
     FreePool (NewDevicePath);\r
   }\r
   \r
@@ -325,29 +335,36 @@ BmGetFileBufferByMemmapFv (
 }\r
 \r
 /**\r
-  Check if it's a Memory Mapped FV Device Path.\r
+  Check if it's a Device Path pointing to FV file.\r
   \r
   The function doesn't garentee the device path points to existing FV file.\r
 \r
   @param  DevicePath     Input device path.\r
 \r
-  @retval TRUE   The device path is a Memory Mapped FV Device Path.\r
-  @retval FALSE  The device path is NOT a Memory Mapped FV Device Path.\r
+  @retval TRUE   The device path is a FV File Device Path.\r
+  @retval FALSE  The device path is NOT a FV File Device Path.\r
 **/\r
 BOOLEAN\r
-BmIsMemmapFvFilePath (\r
+BmIsFvFilePath (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL   *FileNode;\r
+  EFI_STATUS                     Status;\r
+  EFI_HANDLE                     Handle;\r
+  EFI_DEVICE_PATH_PROTOCOL       *Node;\r
+\r
+  Node = DevicePath;\r
+  Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &Node, &Handle);\r
+  if (!EFI_ERROR (Status)) {\r
+    return TRUE;\r
+  }\r
 \r
   if ((DevicePathType (DevicePath) == HARDWARE_DEVICE_PATH) && (DevicePathSubType (DevicePath) == HW_MEMMAP_DP)) {\r
-    FileNode = NextDevicePathNode (DevicePath);\r
-    if ((DevicePathType (FileNode) == MEDIA_DEVICE_PATH) && (DevicePathSubType (FileNode) == MEDIA_PIWG_FW_FILE_DP)) {\r
-      return IsDevicePathEnd (NextDevicePathNode (FileNode));\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+    if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MEDIA_PIWG_FW_FILE_DP)) {\r
+      return IsDevicePathEnd (NextDevicePathNode (DevicePath));\r
     }\r
   }\r
-\r
   return FALSE;\r
 }\r
 \r
@@ -1598,10 +1615,10 @@ BmGetLoadOptionBuffer (
   }\r
 \r
   //\r
-  // Fix up the boot option path if it points to a FV in memory map style of device path\r
+  // Get file buffer from FV file path.\r
   //\r
-  if (BmIsMemmapFvFilePath (FilePath)) {\r
-    return BmGetFileBufferByMemmapFv (FilePath, FullPath, FileSize);\r
+  if (BmIsFvFilePath (FilePath)) {\r
+    return BmGetFileBufferByFvFilePath (FilePath, FullPath, FileSize);\r
   }\r
 \r
   //\r