]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Make boot option description unique
authorRuiyu Ni <ruiyu.ni@intel.com>
Sun, 26 Jul 2015 08:07:15 +0000 (08:07 +0000)
committerjljusten <jljusten@Edk2>
Sun, 26 Jul 2015 08:07:15 +0000 (08:07 +0000)
When there are multiple network boot options, user will see multiple
"UEFI Network" boot options. It's hard to distinguish them using the
description.
The patch enhances the boot option generation logic to append " 2"
/" 3"/" 4"/... number suffix to the non-first network boot options.
So the 2nd one becomes "UEFI Network 2".

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18062 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

index 2c38aa827529f0da06be24f26fa82a320c8d25da..f68c25e21910ebfa1666e045d6fb459f5f6c42b6 100644 (file)
@@ -1868,6 +1868,66 @@ BmMatchPartitionDevicePathNode (
     );\r
 }\r
 \r
+/**\r
+  Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r
+  unique description.\r
+\r
+  @param BootOptions            Array of boot options.\r
+  @param BootOptionCount        Count of boot options.\r
+**/\r
+VOID\r
+BmMakeBootOptionDescriptionUnique (\r
+  EFI_BOOT_MANAGER_LOAD_OPTION         *BootOptions,\r
+  UINTN                                BootOptionCount\r
+  )\r
+{\r
+  UINTN                                Base;\r
+  UINTN                                Index;\r
+  UINTN                                DescriptionSize;\r
+  UINTN                                MaxSuffixSize;\r
+  BOOLEAN                              *Visited;\r
+  UINTN                                MatchCount;\r
+\r
+  if (BootOptionCount == 0) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Calculate the maximum buffer size for the number suffix.\r
+  // The initial sizeof (CHAR16) is for the blank space before the number.\r
+  //\r
+  MaxSuffixSize = sizeof (CHAR16);\r
+  for (Index = BootOptionCount; Index != 0; Index = Index / 10) {\r
+    MaxSuffixSize += sizeof (CHAR16);\r
+  }\r
+\r
+  Visited = AllocateZeroPool (sizeof (BOOLEAN) * BootOptionCount);\r
+  ASSERT (Visited != NULL);\r
+\r
+  for (Base = 0; Base < BootOptionCount; Base++) {\r
+    if (!Visited[Base]) {\r
+      MatchCount      = 1;\r
+      Visited[Base]   = TRUE;\r
+      DescriptionSize = StrSize (BootOptions[Base].Description);\r
+      for (Index = Base + 1; Index < BootOptionCount; Index++) {\r
+        if (!Visited[Index] && StrCmp (BootOptions[Base].Description, BootOptions[Index].Description) == 0) {\r
+          Visited[Index] = TRUE;\r
+          MatchCount++;\r
+          FreePool (BootOptions[Index].Description);\r
+          BootOptions[Index].Description = AllocatePool (DescriptionSize + MaxSuffixSize);\r
+          UnicodeSPrint (\r
+            BootOptions[Index].Description, DescriptionSize + MaxSuffixSize,\r
+            L"%s %d",\r
+            BootOptions[Base].Description, MatchCount\r
+            );\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  FreePool (Visited);\r
+}\r
+\r
 /**\r
   Emuerate all possible bootable medias in the following order:\r
   1. Removable BlockIo            - The boot option only points to the removable media\r
@@ -2054,6 +2114,7 @@ BmEnumerateBootOptions (
     FreePool (Handles);\r
   }\r
 \r
+  BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount);\r
   return BootOptions;\r
 }\r
 \r