From d948fe96a570b610383111df87076e75188694d4 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Sun, 26 Jul 2015 08:07:15 +0000 Subject: MdeModulePkg: Make boot option description unique 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 Cc: Eric Dong Reviewed-by: Eric Dong git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18062 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'MdeModulePkg/Library') diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 2c38aa8275..f68c25e219 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1868,6 +1868,66 @@ BmMatchPartitionDevicePathNode ( ); } +/** + Enumerate all boot option descriptions and append " 2"/" 3"/... to make + unique description. + + @param BootOptions Array of boot options. + @param BootOptionCount Count of boot options. +**/ +VOID +BmMakeBootOptionDescriptionUnique ( + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions, + UINTN BootOptionCount + ) +{ + UINTN Base; + UINTN Index; + UINTN DescriptionSize; + UINTN MaxSuffixSize; + BOOLEAN *Visited; + UINTN MatchCount; + + if (BootOptionCount == 0) { + return; + } + + // + // Calculate the maximum buffer size for the number suffix. + // The initial sizeof (CHAR16) is for the blank space before the number. + // + MaxSuffixSize = sizeof (CHAR16); + for (Index = BootOptionCount; Index != 0; Index = Index / 10) { + MaxSuffixSize += sizeof (CHAR16); + } + + Visited = AllocateZeroPool (sizeof (BOOLEAN) * BootOptionCount); + ASSERT (Visited != NULL); + + for (Base = 0; Base < BootOptionCount; Base++) { + if (!Visited[Base]) { + MatchCount = 1; + Visited[Base] = TRUE; + DescriptionSize = StrSize (BootOptions[Base].Description); + for (Index = Base + 1; Index < BootOptionCount; Index++) { + if (!Visited[Index] && StrCmp (BootOptions[Base].Description, BootOptions[Index].Description) == 0) { + Visited[Index] = TRUE; + MatchCount++; + FreePool (BootOptions[Index].Description); + BootOptions[Index].Description = AllocatePool (DescriptionSize + MaxSuffixSize); + UnicodeSPrint ( + BootOptions[Index].Description, DescriptionSize + MaxSuffixSize, + L"%s %d", + BootOptions[Base].Description, MatchCount + ); + } + } + } + } + + FreePool (Visited); +} + /** Emuerate all possible bootable medias in the following order: 1. Removable BlockIo - The boot option only points to the removable media @@ -2054,6 +2114,7 @@ BmEnumerateBootOptions ( FreePool (Handles); } + BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount); return BootOptions; } -- cgit v1.2.3