1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/** @file
Boot Discovery Policy UI for Boot Maintenance menu.
Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2021, Semihalf All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Guid/BootDiscoveryPolicy.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Include/Library/PcdLib.h>
///
/// HII specific Vendor Device Path definition.
///
typedef struct {
VENDOR_DEVICE_PATH VendorDevicePath;
EFI_DEVICE_PATH_PROTOCOL End;
} HII_VENDOR_DEVICE_PATH;
extern UINT8 BootDiscoveryPolicyUiLibVfrBin[];
EFI_HII_HANDLE mBPHiiHandle = NULL;
EFI_HANDLE mBPDriverHandle = NULL;
STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8)(sizeof (VENDOR_DEVICE_PATH)),
(UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
}
},
BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
(UINT8)(END_DEVICE_PATH_LENGTH),
(UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
}
}
};
/**
Initialize Boot Maintenance Menu library.
@param ImageHandle The image handle.
@param SystemTable The system table.
@retval EFI_SUCCESS Install Boot manager menu success.
@retval Other Return error status.gBPDisplayLibGuid
**/
EFI_STATUS
EFIAPI
BootDiscoveryPolicyUiLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINTN Size;
UINT32 BootDiscoveryPolicy;
Size = sizeof (UINT32);
Status = gRT->GetVariable (
BOOT_DISCOVERY_POLICY_VAR,
&gBootDiscoveryPolicyMgrFormsetGuid,
NULL,
&Size,
&BootDiscoveryPolicy
);
if (EFI_ERROR (Status)) {
Status = PcdSet32S (PcdBootDiscoveryPolicy, PcdGet32 (PcdBootDiscoveryPolicy));
ASSERT_EFI_ERROR (Status);
}
Status = gBS->InstallMultipleProtocolInterfaces (
&mBPDriverHandle,
&gEfiDevicePathProtocolGuid,
&mVendorDevicePath,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Publish our HII data
//
mBPHiiHandle = HiiAddPackages (
&gBootDiscoveryPolicyMgrFormsetGuid,
mBPDriverHandle,
BootDiscoveryPolicyUiLibVfrBin,
BootDiscoveryPolicyUiLibStrings,
NULL
);
if (mBPHiiHandle == NULL) {
gBS->UninstallMultipleProtocolInterfaces (
mBPDriverHandle,
&gEfiDevicePathProtocolGuid,
&mVendorDevicePath,
NULL
);
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Destructor of Boot Maintenance menu library.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The destructor completed successfully.
@retval Other value The destructor did not complete successfully.
**/
EFI_STATUS
EFIAPI
BootDiscoveryPolicyUiLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
if (mBPDriverHandle != NULL) {
gBS->UninstallProtocolInterface (
mBPDriverHandle,
&gEfiDevicePathProtocolGuid,
&mVendorDevicePath
);
mBPDriverHandle = NULL;
}
if (mBPHiiHandle != NULL) {
HiiRemovePackages (mBPHiiHandle);
mBPHiiHandle = NULL;
}
return EFI_SUCCESS;
}
|