MdeModulePkg/BM: Update boot options on device change

Register an event to trigger when a block device is added or removed
that will update the list of boot options. Use a refreshguid to force
the form to display the changes if it already open.
This commit is contained in:
Tim Crawford
2020-11-03 14:19:21 -07:00
parent 06cc698885
commit 05aa27ef23
4 changed files with 53 additions and 13 deletions

View File

@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "BootManager.h"
#include <Protocol/BlockIo.h>
UINT16 mKeyInput;
EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;
//
@ -27,6 +29,10 @@ UINT32 mBmSetupVerticalResolution = 0;
BOOLEAN mBmModeInitialized = FALSE;
STATIC EFI_EVENT mBmRefreshEvent;
STATIC CONST EFI_GUID mBmRefreshGuid = BOOT_MANAGER_REFRESH_GUID;
STATIC VOID *mBlockIoRegistration; // Unused
CHAR16 *mDeviceTypeStr[] = {
L"Legacy BEV",
L"Legacy Floppy",
@ -488,19 +494,6 @@ UpdateBootManager (
DeviceType = (UINT16) -1;
//
// for better user experience
// 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option
// 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option
//
EfiBootManagerRefreshAllBootOption ();
//
// BdsDxe doesn't group the legacy boot options for the same device type
// It's UI's choice.
//
GroupMultipleLegacyBootOption4SameType ();
BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
HiiHandle = gBootManagerPrivate.HiiHandle;
@ -843,6 +836,26 @@ BootManagerCallback (
return EFI_SUCCESS;
}
STATIC
VOID
EFIAPI
RefreshBootOptions(
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_TPL OldTpl = gBS->RaiseTPL(TPL_CALLBACK);
EfiBootManagerRefreshAllBootOption();
// BdsDxe doesn't group the legacy boot options for the same device type. It's UI's choice.
GroupMultipleLegacyBootOption4SameType();
UpdateBootManager();
gBS->RestoreTPL (OldTpl);
}
/**
Install Boot Manager Menu driver.
@ -891,6 +904,23 @@ BootManagerUiLibConstructor (
BmInitialBootModeInfo ();
Status = gBS->CreateEventEx(
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
RefreshBootOptions,
NULL,
&mBmRefreshGuid,
&mBmRefreshEvent
);
ASSERT_EFI_ERROR(Status);
Status = gBS->RegisterProtocolNotify (
&gEfiBlockIoProtocolGuid,
mBmRefreshEvent,
&mBlockIoRegistration
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}
@ -911,6 +941,8 @@ BootManagerUiLibDestructor (
{
EFI_STATUS Status;
gBS->CloseEvent(mBmRefreshEvent);
Status = gBS->UninstallMultipleProtocolInterfaces (
gBootManagerPrivate.DriverHandle,
&gEfiDevicePathProtocolGuid,

View File

@ -46,6 +46,11 @@ typedef struct {
0x847bc3fe, 0xb974, 0x446d, {0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b} \
}
#define BOOT_MANAGER_REFRESH_GUID \
{ \
0x7648C827, 0xBE32, 0x44D2, { 0xA1, 0x33, 0xF1, 0x7F, 0x93, 0x76, 0xC7, 0x00 } \
}
#define BOOT_MANAGER_FORM_ID 0x1030
#define LABEL_BOOT_OPTION 0x00

View File

@ -51,6 +51,7 @@
gEfiHiiConfigAccessProtocolGuid ## CONSUMES
gEfiDevicePathToTextProtocolGuid ## CONSUMES
gEdkiiFormBrowserEx2ProtocolGuid ## CONSUMES
gEfiBlockIoProtocolGuid
[FeaturePcd]

View File

@ -7,6 +7,7 @@
//
//**/
#define FORMSET_GUID { 0x847bc3fe, 0xb974, 0x446d, 0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b }
#define BOOT_MANAGER_REFRESH_GUID { 0x7648C827, 0xBE32, 0x44D2, { 0xA1, 0x33, 0xF1, 0x7F, 0x93, 0x76, 0xC7, 0x00 }}
#define BOOT_MANAGER_FORM_ID 0x1030
@ -21,6 +22,7 @@ formset
form formid = BOOT_MANAGER_FORM_ID,
title = STRING_TOKEN(STR_BM_BANNER);
refreshguid = BOOT_MANAGER_REFRESH_GUID;
//
//Add this invisable text in order to indicate enter Boot Manager form.