From 3a3955d83c2bbbdc205ead4ecea682967bf94bc9 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Fri, 12 Apr 2019 08:51:39 +0300 Subject: [PATCH] OcBootManagementLib: Skip self entry --- Include/Library/OcBootManagementLib.h | 6 +++++- .../OcBootManagementLib/OcBootManagementLib.c | 20 +++++++++++++++++-- Tests/BlessTest/BlessTest.c | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Include/Library/OcBootManagementLib.h b/Include/Library/OcBootManagementLib.h index 743d82ac..aabc3fdc 100755 --- a/Include/Library/OcBootManagementLib.h +++ b/Include/Library/OcBootManagementLib.h @@ -122,6 +122,7 @@ OcFillBootEntry ( @param[out] BootEntries List of boot entries (allocated from pool). @param[out] Count Number of boot entries. @param[out] AllocCount Number of allocated boot entries. + @param[in] LoadHandle Load handle to skip. @param[in] Describe Automatically fill description fields @retval EFI_SUCCESS Executed successfully and found entries. @@ -133,6 +134,7 @@ OcScanForBootEntries ( OUT OC_BOOT_ENTRY **BootEntries, OUT UINTN *Count, OUT UINTN *AllocCount OPTIONAL, + IN EFI_HANDLE LoadHandle OPTIONAL, IN BOOLEAN Describe ); @@ -257,6 +259,7 @@ EFI_STATUS @param[in] TimeOutSeconds Default entry selection timeout (pass 0 to ignore). @param[in] StartImage Image starting routine used. @param[in] ShowPicker Show boot menu or just boot the default option. + @param[in] LoadHandle Load handle, skips main handle on this handle. @retval does not return unless a fatal error happened. **/ @@ -266,7 +269,8 @@ OcRunSimpleBootPicker ( IN UINT32 BootPolicy, IN UINT32 TimeoutSeconds, IN OC_IMAGE_START StartImage, - IN BOOLEAN ShowPicker + IN BOOLEAN ShowPicker, + IN EFI_HANDLE LoadHandle OPTIONAL ); #endif // OC_BOOT_MANAGEMENT_LIB_H diff --git a/Library/OcBootManagementLib/OcBootManagementLib.c b/Library/OcBootManagementLib/OcBootManagementLib.c index fd2536a1..204ea64f 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.c +++ b/Library/OcBootManagementLib/OcBootManagementLib.c @@ -774,6 +774,7 @@ OcScanForBootEntries ( OUT OC_BOOT_ENTRY **BootEntries, OUT UINTN *Count, OUT UINTN *AllocCount OPTIONAL, + IN EFI_HANDLE LoadHandle OPTIONAL, IN BOOLEAN Describe ) { @@ -784,6 +785,7 @@ OcScanForBootEntries ( OC_BOOT_ENTRY *Entries; UINTN EntryIndex; CHAR16 *DevicePath; + UINTN EntryCount; Status = gBS->LocateHandleBuffer ( ByProtocol, @@ -811,13 +813,25 @@ OcScanForBootEntries ( EntryIndex = 0; for (Index = 0; Index < NoHandles; ++Index) { - EntryIndex += OcFillBootEntry ( + EntryCount = OcFillBootEntry ( BootPolicy, Policy, Handles[Index], &Entries[EntryIndex], &Entries[EntryIndex+1] ); + + if (LoadHandle == Handles[Index] && EntryCount > 0) { + DEBUG ((DEBUG_INFO, "Skipping self load handle entry %p\n", LoadHandle)); + --EntryCount; + CopyMem ( + &Entries[EntryIndex+1], + &Entries[EntryIndex], + sizeof (Entries[EntryIndex]) * EntryCount + ); + } + + EntryIndex += EntryCount; } FreePool (Handles); @@ -971,7 +985,8 @@ OcRunSimpleBootPicker ( IN UINT32 BootPolicy, IN UINT32 TimeoutSeconds, IN OC_IMAGE_START StartImage, - IN BOOLEAN ShowPicker + IN BOOLEAN ShowPicker, + IN EFI_HANDLE LoadHandle OPTIONAL ) { EFI_STATUS Status; @@ -1007,6 +1022,7 @@ OcRunSimpleBootPicker ( &Entries, &EntryCount, NULL, + LoadHandle, TRUE ); diff --git a/Tests/BlessTest/BlessTest.c b/Tests/BlessTest/BlessTest.c index 057e72f9..7c255edf 100644 --- a/Tests/BlessTest/BlessTest.c +++ b/Tests/BlessTest/BlessTest.c @@ -86,6 +86,7 @@ TestBless ( &Entries, &EntryCount, NULL, + NULL, TRUE ); -- GitLab