Skip to content

Commit e36f622

Browse files
committed
System76PayloadPkg: Customize BootManagerUiLib
Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent 2c140ee commit e36f622

6 files changed

Lines changed: 88 additions & 110 deletions

File tree

System76PayloadPkg/Library/BootManagerUiLib/BootManager.c

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
77
**/
88

99
#include "BootManager.h"
10+
#include <Protocol/BlockIo.h>
1011
#include <Protocol/LoadedImage.h>
1112

1213
UINT16 mKeyInput;
@@ -28,6 +29,10 @@ UINT32 mBmSetupVerticalResolution = 0;
2829

2930
BOOLEAN mBmModeInitialized = FALSE;
3031

32+
STATIC EFI_EVENT mBmRefreshEvent;
33+
STATIC CONST EFI_GUID mBmRefreshGuid = BOOT_MANAGER_REFRESH_GUID;
34+
STATIC VOID *mBlockIoRegistration; // Unused
35+
3136
CHAR16 *mDeviceTypeStr[] = {
3237
L"Legacy BEV",
3338
L"Legacy Floppy",
@@ -497,22 +502,10 @@ UpdateBootManager (
497502
EFI_STATUS Status;
498503
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
499504
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
505+
UINTN OptionCount = 0;
500506

501507
DeviceType = (UINT16)-1;
502508

503-
//
504-
// for better user experience
505-
// 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option
506-
// 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option
507-
//
508-
EfiBootManagerRefreshAllBootOption ();
509-
510-
//
511-
// BdsDxe doesn't group the legacy boot options for the same device type
512-
// It's UI's choice.
513-
//
514-
GroupMultipleLegacyBootOption4SameType ();
515-
516509
BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
517510

518511
HiiHandle = gBootManagerPrivate.HiiHandle;
@@ -580,6 +573,8 @@ UpdateBootManager (
580573
continue;
581574
}
582575

576+
OptionCount++;
577+
583578
//
584579
// Group the legacy boot option in the sub title created dynamically
585580
//
@@ -635,6 +630,10 @@ UpdateBootManager (
635630
);
636631
}
637632

633+
if (OptionCount == 0) {
634+
HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_NO_BOOTABLE_MEDIA), 0, 0, 0);
635+
}
636+
638637
if (NeedEndOp) {
639638
HiiCreateEndOpCode (StartOpCodeHandle);
640639
}
@@ -885,6 +884,26 @@ BootManagerCallback (
885884
return EFI_SUCCESS;
886885
}
887886

887+
STATIC
888+
VOID
889+
EFIAPI
890+
RefreshBootOptions(
891+
IN EFI_EVENT Event,
892+
IN VOID *Context
893+
)
894+
{
895+
EFI_TPL OldTpl = gBS->RaiseTPL(TPL_CALLBACK);
896+
897+
EfiBootManagerRefreshAllBootOption();
898+
899+
// BdsDxe doesn't group the legacy boot options for the same device type. It's UI's choice.
900+
GroupMultipleLegacyBootOption4SameType();
901+
902+
UpdateBootManager();
903+
904+
gBS->RestoreTPL (OldTpl);
905+
}
906+
888907
/**
889908
890909
Install Boot Manager Menu driver.
@@ -933,6 +952,23 @@ BootManagerUiLibConstructor (
933952

934953
BmInitialBootModeInfo ();
935954

955+
Status = gBS->CreateEventEx(
956+
EVT_NOTIFY_SIGNAL,
957+
TPL_CALLBACK,
958+
RefreshBootOptions,
959+
NULL,
960+
&mBmRefreshGuid,
961+
&mBmRefreshEvent
962+
);
963+
ASSERT_EFI_ERROR(Status);
964+
965+
Status = gBS->RegisterProtocolNotify (
966+
&gEfiBlockIoProtocolGuid,
967+
mBmRefreshEvent,
968+
&mBlockIoRegistration
969+
);
970+
ASSERT_EFI_ERROR (Status);
971+
936972
return EFI_SUCCESS;
937973
}
938974

@@ -953,6 +989,8 @@ BootManagerUiLibDestructor (
953989
{
954990
EFI_STATUS Status;
955991

992+
gBS->CloseEvent(mBmRefreshEvent);
993+
956994
Status = gBS->UninstallMultipleProtocolInterfaces (
957995
gBootManagerPrivate.DriverHandle,
958996
&gEfiDevicePathProtocolGuid,

System76PayloadPkg/Library/BootManagerUiLib/BootManager.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/** @file
2-
The boot manager reference implementation
3-
4-
Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
5-
SPDX-License-Identifier: BSD-2-Clause-Patent
6-
7-
**/
1+
// SPDX-License-Identifier: BSD-2-Clause-Patent
2+
// SPDX-FileCopyrightText: Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
3+
// SPDX-FileCopyrightText: 2025 System76, Inc.
84

95
#ifndef _EFI_BOOT_MANAGER_H_
106
#define _EFI_BOOT_MANAGER_H_
@@ -38,19 +34,16 @@ typedef struct {
3834
} HII_VENDOR_DEVICE_PATH;
3935
#pragma pack()
4036

41-
//
42-
// These are defined as the same with vfr file
43-
//
44-
#define BOOT_MANAGER_FORMSET_GUID \
45-
{ \
46-
0x847bc3fe, 0xb974, 0x446d, {0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b} \
47-
}
37+
// XXX: Must match VFR
38+
39+
#define BOOT_MANAGER_FORMSET_GUID { 0x3f56106a, 0xa83f, 0x4417, { 0x90, 0x21, 0xc7, 0x77, 0x5c, 0x1d, 0x73, 0xfe }}
40+
#define BOOT_MANAGER_REFRESH_GUID { 0x7648c827, 0xbe32, 0x44d2, { 0xa1, 0x33, 0xf1, 0x7f, 0x93, 0x76, 0xc7, 0x00 }}
4841

49-
#define BOOT_MANAGER_FORM_ID 0x1000
42+
#define BOOT_MANAGER_FORM_ID 0x1030
5043

51-
#define LABEL_BOOT_OPTION 0x00
52-
#define LABEL_BOOT_OPTION_END 0x01
53-
#define MAX_STRING_LEN 200
44+
#define LABEL_BOOT_OPTION 0x00
45+
#define LABEL_BOOT_OPTION_END 0x01
46+
#define MAX_STRING_LEN 200
5447

5548
//
5649
// Variable created with this flag will be "Efi:...."
Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
1-
///** @file
2-
//
3-
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
41
// SPDX-License-Identifier: BSD-2-Clause-Patent
5-
//
6-
// Module Name:
7-
//
8-
// BootManagerStrings.uni
9-
//
10-
// Abstract:
11-
//
12-
// String definitions for Boot Manager formset.
13-
//
14-
// Revision History:
15-
//
16-
// --*/
2+
// SPDX-FileCopyrightText: 2025 System76, Inc.
173

18-
/=#
19-
#langdef en-US "English"
20-
#langdef fr-FR "Français"
21-
22-
#string STR_BM_BANNER #language en-US "Boot Manager"
23-
#language fr-FR "Boot Manager"
24-
#string STR_BOOT_MANAGER_HELP #language en-US "This selection will take you to the Boot Manager"
25-
#language fr-FR "This selection will take you to the Boot Manager"
26-
#string STR_HELP_FOOTER #language en-US "Use the <↑> and <↓> keys to choose a boot option, the <Enter> key to select a boot option, and the <Esc> key to exit the Boot Manager Menu."
27-
#language fr-FR "<↑> pour <↓> changer l'option, <ENTRER> choisir une option, <ESC> pour sortir"
28-
#string STR_AND #language en-US " and "
29-
#language fr-FR " et "
30-
#string STR_BOOT_OPTION_BANNER #language en-US "Boot Manager Menu"
31-
#language fr-FR "le Menu d'Option de Botte"
32-
#string STR_ANY_KEY_CONTINUE #language en-US "Press any key to continue..."
33-
#language fr-FR "Appuie n'importe quelle pour continuer..."
34-
#string STR_LAST_STRING #language en-US ""
35-
#language fr-FR ""
4+
#langdef en-US "English"
365

6+
#string STR_BM_BANNER #language en-US "One Time Boot"
7+
#string STR_BOOT_MANAGER_HELP #language en-US "Boot an entry one time"
8+
#string STR_ANY_KEY_CONTINUE #language en-US "Press any key to continue..."
9+
#string STR_NO_BOOTABLE_MEDIA #language en-US "No bootable media found"
10+
#string STR_EMPTY_STRING #language en-US ""

System76PayloadPkg/Library/BootManagerUiLib/BootManagerUiLib.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
gEfiHiiConfigAccessProtocolGuid ## CONSUMES
5252
gEfiDevicePathToTextProtocolGuid ## CONSUMES
5353
gEdkiiFormBrowserEx2ProtocolGuid ## CONSUMES
54+
gEfiBlockIoProtocolGuid
5455

5556
[FeaturePcd]
5657

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
// /** @file
2-
// Boot Manager Library used by UiApp.
3-
//
4-
// Boot Manager Library used by UiApp.
5-
//
6-
// Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
7-
//
81
// SPDX-License-Identifier: BSD-2-Clause-Patent
9-
//
10-
// **/
11-
12-
#string STR_MODULE_ABSTRACT
13-
#language en-US
14-
"Boot Manager Library used by UiApp."
15-
16-
#string STR_MODULE_DESCRIPTION
17-
#language en-US
18-
"Boot Manager Library used by UiApp."
19-
2+
// SPDX-FileCopyrightText: 2025 System76, Inc.
203

4+
#string STR_MODULE_ABSTRACT #language en-US "Boot manager library"
5+
#string STR_MODULE_DESCRIPTION #language en-US "Boot manager library"
Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
///** @file
2-
//
3-
// Boot Manager formset.
4-
//
5-
// Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
6-
// SPDX-License-Identifier: BSD-2-Clause-Patent
7-
//
8-
//**/
9-
#define FORMSET_GUID { 0x847bc3fe, 0xb974, 0x446d, 0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b }
1+
// SPDX-License-Identifier: BSD-2-Clause-Patent
2+
// SPDX-FileCopyrightText: Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
3+
// SPDX-FileCopyrightText: 2025 System76, Inc.
104

11-
#define BOOT_MANAGER_FORM_ID 0x1000
5+
#define FORMSET_GUID { 0x3f56106a, 0xa83f, 0x4417, 0x90, 0x21, 0xc7, 0x77, 0x5c, 0x1d, 0x73, 0xfe }
6+
#define BOOT_MANAGER_REFRESH_GUID { 0x7648c827, 0xbe32, 0x44d2, { 0xa1, 0x33, 0xf1, 0x7f, 0x93, 0x76, 0xc7, 0x00 }}
127

13-
#define LABEL_BOOT_OPTION 0x00
14-
#define LABEL_BOOT_OPTION_END 0x01
8+
#define BOOT_MANAGER_FORM_ID 0x1030
9+
10+
#define LABEL_BOOT_OPTION 0x00
11+
#define LABEL_BOOT_OPTION_END 0x01
1512

1613
formset
1714
guid = FORMSET_GUID,
@@ -20,32 +17,22 @@ formset
2017
classguid = gEfiIfrFrontPageGuid,
2118

2219
form formid = BOOT_MANAGER_FORM_ID,
23-
title = STRING_TOKEN(STR_BM_BANNER);
24-
25-
subtitle text = STRING_TOKEN(STR_LAST_STRING);
26-
subtitle text = STRING_TOKEN(STR_BOOT_OPTION_BANNER);
27-
subtitle text = STRING_TOKEN(STR_LAST_STRING);
20+
title = STRING_TOKEN(STR_BM_BANNER);
21+
refreshguid = BOOT_MANAGER_REFRESH_GUID;
2822

29-
//
30-
//Add this invisable text in order to indicate enter Boot Manager form.
31-
//
23+
// Add this invisable text in order to indicate enter Boot Manager form.
3224
suppressif TRUE;
3325
text
34-
help = STRING_TOKEN(STR_LAST_STRING ),
35-
text = STRING_TOKEN(STR_LAST_STRING ),
26+
help = STRING_TOKEN(STR_EMPTY_STRING),
27+
text = STRING_TOKEN(STR_EMPTY_STRING),
3628
flags = INTERACTIVE,
3729
key = 0x1212;
3830
endif;
3931

40-
//
41-
// This is where we will dynamically add choices for the Boot Manager
42-
//
4332
label LABEL_BOOT_OPTION;
33+
// Dynamically generated values.
4434
label LABEL_BOOT_OPTION_END;
4535

46-
subtitle text = STRING_TOKEN(STR_LAST_STRING);
47-
subtitle text = STRING_TOKEN(STR_HELP_FOOTER);
48-
4936
endform;
5037

5138
endformset;

0 commit comments

Comments
 (0)