OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ControlMsrE2.c
Go to the documentation of this file.
1
15#include "ControlMsrE2.h"
16
17//
18// Maximum search contexts and matched options allowed
19//
20#define CONTEXTS_MAX 8
21#define OPTIONS_MAX 9
22
23VOID
25 IN EFI_HII_HANDLE *HiiHandles,
26 IN EFI_HII_PACKAGE_LIST_HEADER **ListHeaders,
27 IN UINT32 ListHeaderCount,
28 IN EFI_STRING SearchString
29 )
30{
31 UINT16 OptionsCount;
32 UINT16 ContextsCount;
34 UINT32 ListHeaderIndex;
35 EFI_IFR_OP_HEADER *IfrHeader;
36 EFI_HII_PACKAGE_HEADER *PkgHeader;
37 BOOLEAN Stop;
38 UINT32 ContextIndex;
39 UINT16 Index;
40 CHAR16 Key;
41
42 OptionsCount = 0;
43 ContextsCount = 0;
44
45 for (ListHeaderIndex = 0; HiiHandles[ListHeaderIndex] != NULL && ContextsCount < CONTEXTS_MAX; ++ListHeaderIndex) {
46 ListHeaders[ListHeaderIndex] = HiiExportPackageLists (HiiHandles[ListHeaderIndex]);
47
48 if (ListHeaders[ListHeaderIndex] == NULL) {
49 continue;
50 }
51
52 DEBUG ((
53 DEBUG_INFO,
54 "Package List: %g\n",
55 &ListHeaders[ListHeaderIndex]->PackageListGuid
56 ));
57
58 PkgHeader = PADD (ListHeaders[ListHeaderIndex], sizeof (EFI_HII_PACKAGE_LIST_HEADER));
59
60 while (ContextsCount < CONTEXTS_MAX) {
61 DEBUG ((DEBUG_INFO, "Package Type: %02X ", PkgHeader->Type));
62
63 if (PkgHeader->Type == EFI_HII_PACKAGE_END) {
64 break;
65 }
66
67 if (PkgHeader->Type == EFI_HII_PACKAGE_FORMS) {
68 IfrHeader = PADD (PkgHeader, sizeof (EFI_HII_PACKAGE_HEADER));
69 //
70 // Form Definition must start with FORM_SET_OP
71 //
72 if (IfrHeader->OpCode == EFI_IFR_FORM_SET_OP) {
73 DEBUG ((
74 DEBUG_INFO,
75 "Form: %g\n",
76 &((EFI_IFR_FORM_SET *)IfrHeader)->Guid
77 ));
78
79 if (IfrHeader->Length >= sizeof (GUID) + sizeof (EFI_IFR_FORM_SET)) {
80 DEBUG ((
81 DEBUG_INFO,
82 "Class Guid: %g\n",
83 PADD (IfrHeader, sizeof (EFI_IFR_FORM_SET))
84 ));
85
86 //
87 // Checkup for Setup Form
88 //
89 if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, PADD (IfrHeader, sizeof (EFI_IFR_FORM_SET)))) {
90 Contexts[ContextsCount].SearchText = SearchString;
91 Contexts[ContextsCount].EfiHandle = HiiHandles[ListHeaderIndex];
92 Contexts[ContextsCount].ListHeader = ListHeaders[ListHeaderIndex];
93 Contexts[ContextsCount].PkgHeader = PkgHeader;
94 Contexts[ContextsCount].FirstIfrHeader = PADD (IfrHeader, IfrHeader->Length);
95 Contexts[ContextsCount].IfrVarStore = NULL;
96 Contexts[ContextsCount].IfrOneOf = NULL;
97 Contexts[ContextsCount].StopAt = DONT_STOP_AT;
98 Contexts[ContextsCount].Count = OptionsCount;
99
101 Contexts[ContextsCount].FirstIfrHeader,
102 EFI_IFR_ONE_OF_OP,
103 NULL,
104 &Contexts[ContextsCount],
106 );
107
108 if (Contexts[ContextsCount].Count != OptionsCount) {
109 OptionsCount = Contexts[ContextsCount].Count;
110 ++ContextsCount;
111 }
112 }
113 }
114 }
115 }
116
117 PkgHeader = PADD (PkgHeader, PkgHeader->Length);
118 }
119
120 DEBUG ((DEBUG_INFO, "\n"));
121 }
122
123 DEBUG ((DEBUG_INFO, "Context Count: %x Options Count %x\n", ContextsCount, OptionsCount));
124
125 if ((OptionsCount > OPTIONS_MAX) || (ContextsCount == CONTEXTS_MAX)) {
126 Print (L"Too many corresponding BIOS Options found. Try a different search string using interactive mode.\n");
127 } else if (OptionsCount == 0) {
128 Print (L"No corresponding BIOS Options found. Try a different search string using interactive mode.\n");
129 } else {
130 Key = '1';
131
132 if (OptionsCount > 1) {
133 do {
134 Print (L"\nEnter choice (1..%x) ? ", OptionsCount);
135 Key = ReadAnyKey ();
136 } while ((Key != CHAR_ESC) && ((Key < '1') || (Key > '0' + OptionsCount)));
137
138 Print (L"\n");
139 }
140
141 if (Key != CHAR_ESC) {
142 Index = Key - '0';
143
144 for (ContextIndex = 0; ContextIndex < ContextsCount; ++ContextIndex) {
145 if (Contexts[ContextIndex].Count >= Index) {
146 Contexts[ContextIndex].Count = ContextIndex == 0 ? 0 : Contexts[ContextIndex - 1].Count;
147 Contexts[ContextIndex].StopAt = Index;
148 Contexts[ContextIndex].IfrOneOf = NULL;
149
151 Contexts[ContextIndex].FirstIfrHeader,
152 EFI_IFR_ONE_OF_OP,
153 &Stop,
154 &Contexts[ContextIndex],
156 );
157
158 if (Contexts[ContextIndex].IfrOneOf != NULL) {
159 HandleIfrVariable (&Contexts[ContextIndex]);
160 }
161
162 break;
163 }
164 }
165 }
166 }
167
168 for (ListHeaderIndex = 0; ListHeaderIndex < ListHeaderCount; ++ListHeaderIndex) {
169 if (ListHeaders[ListHeaderIndex] != NULL) {
170 FreePool (ListHeaders[ListHeaderIndex]);
171 }
172 }
173}
174
175EFI_STATUS
177 IN EFI_STRING SearchString
178 )
179{
180 EFI_HII_HANDLE *HiiHandles;
181 EFI_HII_PACKAGE_LIST_HEADER **ListHeaders;
182 UINT32 ListHeaderCount;
183
184 Print (L"\nBIOS Options:\n");
185
186 HiiHandles = HiiGetHiiHandles (NULL);
187 if (HiiHandles == NULL) {
188 Print (L"Could not retrieve HiiHandles.\n");
189 return EFI_OUT_OF_RESOURCES;
190 }
191
192 for (ListHeaderCount = 0; HiiHandles[ListHeaderCount] != NULL; ++ListHeaderCount) {
193 }
194
195 //
196 // Keep list alive 'til program finishes.
197 // So that all lists can be searched, the results be displayed together.
198 // And from all those one Option will be selected to be changed
199 //
200 ListHeaders = AllocatePool (sizeof (*ListHeaders) * ListHeaderCount);
201 if (ListHeaders == NULL) {
202 Print (L"Could not allocate memory for ListHeaders.\n");
203 FreePool (HiiHandles);
204 return EFI_OUT_OF_RESOURCES;
205 }
206
207 IterateListHeaders (HiiHandles, ListHeaders, ListHeaderCount, SearchString);
208
209 FreePool (ListHeaders);
210 FreePool (HiiHandles);
211 return EFI_SUCCESS;
212}
213
214EFI_STATUS
215EFIAPI
217 IN EFI_HANDLE ImageHandle,
218 IN EFI_SYSTEM_TABLE *SystemTable
219 )
220{
221 EFI_STATUS Status;
222 EFI_STRING SearchString;
223
224 Status = InterpretArguments ();
225 if (!EFI_ERROR (Status)) {
226 Status = VerifyMSRE2 ();
227 if (!EFI_ERROR (Status)) {
228 if (mArgumentFlags != ARG_VERIFY) {
229 SearchString = AllocateCopyPool (L_STR_SIZE (L"cfg"), L"cfg");
230 if (SearchString != NULL) {
232 ModifySearchString (&SearchString);
233 }
234
235 Status = SearchForString (SearchString);
236 FreePool (SearchString);
237 } else {
238 Print (L"Could not allocate memory for SearchString\n");
239 Status = EFI_OUT_OF_RESOURCES;
240 }
241 }
242 } else {
243 Print (L"Unable to verify MSR 0xE2 - %r\n", Status);
244 }
245 }
246
247 Print (L"Press any key.\n");
248 ReadAnyKey ();
249
250 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
251
252 return Status;
253}
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define CONTEXTS_MAX
EFI_STATUS SearchForString(IN EFI_STRING SearchString)
VOID IterateListHeaders(IN EFI_HII_HANDLE *HiiHandles, IN EFI_HII_PACKAGE_LIST_HEADER **ListHeaders, IN UINT32 ListHeaderCount, IN EFI_STRING SearchString)
#define OPTIONS_MAX
@ ARG_VERIFY
@ ARG_INTERACTIVE
VOID HandleIfrOption(IN EFI_IFR_OP_HEADER *IfrHeader, IN OUT BOOLEAN *Stop OPTIONAL, IN OUT VOID *Context)
#define DONT_STOP_AT
CHAR16 ReadAnyKey(VOID)
EFI_IFR_OP_HEADER * IterateOpCode(IN EFI_IFR_OP_HEADER *Header, IN UINT8 OpCode, IN OUT BOOLEAN *Stop OPTIONAL, IN VOID *Context, IN OP_CODE_HANDLER Handler)
EFI_STATUS InterpretArguments(VOID)
VOID ModifySearchString(IN OUT EFI_STRING *SearchString)
VOID HandleIfrVariable(IN OUT ONE_OF_CONTEXT *Context)
#define CHAR_ESC
EFI_STATUS EFIAPI VerifyMSRE2(VOID)
Definition VerifyMsrE2.c:61
EFI_HII_PACKAGE_LIST_HEADER * HiiExportPackageLists(IN EFI_HII_HANDLE Handle)
UINTN mArgumentFlags
#define PADD(x, y)
EFI_SYSTEM_TABLE * gST
#define L_STR_SIZE(String)
Definition OcStringLib.h:35
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
EFI_IFR_ONE_OF * IfrOneOf
EFI_HII_PACKAGE_LIST_HEADER * ListHeader
EFI_IFR_VARSTORE * IfrVarStore
EFI_IFR_OP_HEADER * FirstIfrHeader
EFI_STRING SearchText
EFI_HII_PACKAGE_HEADER * PkgHeader
EFI_HII_HANDLE EfiHandle