The same boot file may have two different device paths. One is its FV
File device path, another is LoadFile FV device path. These two paths
includes the same NameGuid. So, EfiBootManagerFindLoadOption() is updated
to compare their NameGuid.

Cc: Ruiyu Ni <ruiyu...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming....@intel.com>
---
 .../Library/UefiBootManagerLib/BmLoadOption.c      | 44 ++++++++++++++++++++--
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
index 9af98de..f9650ff 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
@@ -506,6 +506,29 @@ EfiBootManagerInitializeLoadOption (
   return EFI_SUCCESS;
 }
 
+/**
+  Find NameGuid from the input device path.
+
+  @param  DevicePath     Input device path.
+
+  @retval NULL      NameGuid can't be found in the input device path.
+  @retval NameGuid  Pointer to NameGuid found in the input device path.
+**/
+EFI_GUID *
+BmFileNameGuidFromFilePath (
+  EFI_DEVICE_PATH_PROTOCOL     *DevicePath
+)
+{
+  EFI_HANDLE                      FvHandle;
+  EFI_STATUS                      Status;
+
+  Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, 
&DevicePath, &FvHandle);
+  if (!EFI_ERROR (Status)) {
+    return EfiGetNameGuidFromFwVolDevicePathNode ((CONST 
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);
+  }
+
+  return NULL;
+}
 
 /**
   Return the index of the load option in the load option array.
@@ -529,15 +552,30 @@ EfiBootManagerFindLoadOption (
   )
 {
   UINTN                             Index;
+  EFI_GUID                          *KeyNameGuid;
+  EFI_GUID                          *NameGuid;
+
+  KeyNameGuid = NULL;
+  if (Key->OptionType == LoadOptionTypeBoot) {
+    KeyNameGuid = BmFileNameGuidFromFilePath (Key->FilePath);
+  }
 
   for (Index = 0; Index < Count; Index++) {
-    if ((Key->OptionType == Array[Index].OptionType) &&
-        (Key->Attributes == Array[Index].Attributes) &&
+    if (Key->OptionType == Array[Index].OptionType) {
+      if ((Key->Attributes == Array[Index].Attributes) &&
         (StrCmp (Key->Description, Array[Index].Description) == 0) &&
         (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize 
(Key->FilePath)) == 0) &&
         (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&
         (CompareMem (Key->OptionalData, Array[Index].OptionalData, 
Key->OptionalDataSize) == 0)) {
-      return (INTN) Index;
+        return (INTN) Index;
+      }
+
+      if (KeyNameGuid != NULL) {
+        NameGuid = BmFileNameGuidFromFilePath (Array[Index].FilePath);
+        if ((NameGuid != NULL) && CompareGuid (KeyNameGuid, NameGuid)) {
+          return (INTN) Index;
+        }
+      }
     }
   }
 
-- 
2.8.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to