]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c
MdeModulePkg/BootMaintenanceManagerUiLib: remove unused but set variable
[mirror_edk2.git] / MdeModulePkg / Library / BootMaintenanceManagerUiLib / BootMaintenanceManagerCustomizedUiSupport.c
1 /** @file
2 The functions for Boot Maintainence Main menu.
3
4 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "BootMaintenanceManager.h"
17 #include "BootMaintenanceManagerCustomizedUiSupport.h"
18
19 #define UI_HII_DRIVER_LIST_SIZE 0x8
20
21 typedef struct {
22 EFI_STRING_ID PromptId;
23 EFI_STRING_ID HelpId;
24 EFI_STRING_ID DevicePathId;
25 EFI_GUID FormSetGuid;
26 BOOLEAN EmptyLineAfter;
27 } UI_HII_DRIVER_INSTANCE;
28
29 UI_HII_DRIVER_INSTANCE *gHiiDriverList;
30
31
32 /**
33 Create the dynamic item to allow user to set the "BootNext" vaule.
34
35 @param CallbackData The BMM context data.
36
37 **/
38 VOID
39 BmmCreateBootNextMenu(
40 IN EFI_HII_HANDLE HiiHandle,
41 IN VOID *StartOpCodeHandle
42 )
43 {
44 BM_MENU_ENTRY *NewMenuEntry;
45 UINTN NumberOfOptions;
46 UINT16 Index;
47 VOID *OptionsOpCodeHandle;
48 CHAR16 *StringBuffer;
49 EFI_STRING_ID OptionId;
50
51 NumberOfOptions = BootOptionMenu.MenuNumber;
52 if (NumberOfOptions == 0) {
53 return;
54 }
55
56 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
57 ASSERT (OptionsOpCodeHandle != NULL);
58
59 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
60 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
61
62 StringBuffer = HiiGetString (HiiHandle, NewMenuEntry->DisplayStringToken, NULL);
63 ASSERT (StringBuffer != NULL);
64 OptionId = HiiSetString (HiiHandle, 0, StringBuffer, NULL);
65 FreePool (StringBuffer);
66
67 HiiCreateOneOfOptionOpCode (
68 OptionsOpCodeHandle,
69 OptionId,
70 0,
71 EFI_IFR_TYPE_NUM_SIZE_16,
72 Index
73 );
74 }
75
76 StringBuffer = HiiGetString (HiiHandle, STRING_TOKEN (STR_NONE), NULL);
77 ASSERT (StringBuffer != NULL);
78 OptionId = HiiSetString (HiiHandle, 0, StringBuffer, NULL);
79 FreePool (StringBuffer);
80
81 //
82 // Set no Boot Next Value as default.
83 //
84 HiiCreateOneOfOptionOpCode (
85 OptionsOpCodeHandle,
86 OptionId,
87 EFI_IFR_OPTION_DEFAULT,
88 EFI_IFR_TYPE_NUM_SIZE_16,
89 Index
90 );
91
92 HiiCreateOneOfOpCode (
93 StartOpCodeHandle,
94 (EFI_QUESTION_ID) BOOT_NEXT_QUESTION_ID,
95 VARSTORE_ID_BOOT_MAINT,
96 BOOT_NEXT_VAR_OFFSET,
97 STRING_TOKEN (STR_BOOT_NEXT),
98 STRING_TOKEN (STR_BOOT_NEXT_HELP),
99 0,
100 EFI_IFR_NUMERIC_SIZE_2,
101 OptionsOpCodeHandle,
102 NULL
103 );
104
105 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
106
107 }
108
109 /**
110 Create Time Out Menu in the page.
111
112 @param[in] HiiHandle The hii handle for the Uiapp driver.
113 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
114 @param[in] PromptId The Prompt string id.
115 @param[in] HelpId The help string id.
116 @param[in] FormId The Form id for the dest form.
117 @param[in] QuestionId The question id for this goto question.
118
119 **/
120 VOID
121 BmmCreateTimeOutMenu (
122 IN EFI_HII_HANDLE HiiHandle,
123 IN VOID *StartOpCodeHandle
124 )
125 {
126 HiiCreateNumericOpCode (
127 StartOpCodeHandle,
128 (EFI_QUESTION_ID) FORM_TIME_OUT_ID,
129 VARSTORE_ID_BOOT_MAINT,
130 BOOT_TIME_OUT_VAR_OFFSET,
131 STRING_TOKEN(STR_NUM_AUTO_BOOT),
132 STRING_TOKEN(STR_HLP_AUTO_BOOT),
133 EFI_IFR_FLAG_CALLBACK,
134 EFI_IFR_NUMERIC_SIZE_2 | EFI_IFR_DISPLAY_UINT_DEC,
135 0,
136 65535,
137 0,
138 NULL
139 );
140 }
141
142 /**
143 Create Boot Option menu in the page.
144
145 @param[in] HiiHandle The hii handle for the Uiapp driver.
146 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
147
148 **/
149 VOID
150 BmmCreateBootOptionMenu (
151 IN EFI_HII_HANDLE HiiHandle,
152 IN VOID *StartOpCodeHandle
153 )
154 {
155 HiiCreateGotoOpCode (
156 StartOpCodeHandle,
157 FORM_BOOT_SETUP_ID,
158 STRING_TOKEN (STR_FORM_BOOT_SETUP_TITLE),
159 STRING_TOKEN (STR_FORM_BOOT_SETUP_HELP),
160 EFI_IFR_FLAG_CALLBACK,
161 FORM_BOOT_SETUP_ID
162 );
163 }
164
165 /**
166 Create Driver Option menu in the page.
167
168 @param[in] HiiHandle The hii handle for the Uiapp driver.
169 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
170
171 **/
172 VOID
173 BmmCreateDriverOptionMenu (
174 IN EFI_HII_HANDLE HiiHandle,
175 IN VOID *StartOpCodeHandle
176 )
177 {
178 HiiCreateGotoOpCode (
179 StartOpCodeHandle,
180 FORM_DRIVER_SETUP_ID,
181 STRING_TOKEN (STR_FORM_DRIVER_SETUP_TITLE),
182 STRING_TOKEN (STR_FORM_DRIVER_SETUP_HELP),
183 EFI_IFR_FLAG_CALLBACK,
184 FORM_DRIVER_SETUP_ID
185 );
186 }
187
188 /**
189 Create Com Option menu in the page.
190
191 @param[in] HiiHandle The hii handle for the Uiapp driver.
192 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
193
194 **/
195 VOID
196 BmmCreateComOptionMenu (
197 IN EFI_HII_HANDLE HiiHandle,
198 IN VOID *StartOpCodeHandle
199 )
200 {
201 HiiCreateGotoOpCode (
202 StartOpCodeHandle,
203 FORM_CON_MAIN_ID,
204 STRING_TOKEN (STR_FORM_CON_MAIN_TITLE),
205 STRING_TOKEN (STR_FORM_CON_MAIN_HELP),
206 EFI_IFR_FLAG_CALLBACK,
207 FORM_CON_MAIN_ID
208 );
209 }
210
211 /**
212 Create Com Option menu in the page.
213
214 @param[in] HiiHandle The hii handle for the Uiapp driver.
215 @param[in] StartOpCodeHandle The opcode handle to save the new opcode.
216 @param[in] PromptId The Prompt string id.
217 @param[in] HelpId The help string id.
218 @param[in] FormId The Form id for the dest form.
219 @param[in] QuestionId The question id for this goto question.
220
221 **/
222 VOID
223 BmmCreateBootFromFileMenu (
224 IN EFI_HII_HANDLE HiiHandle,
225 IN VOID *StartOpCodeHandle
226 )
227 {
228 HiiCreateGotoOpCode (
229 StartOpCodeHandle,
230 FORM_MAIN_ID,
231 STRING_TOKEN (STR_BOOT_FROM_FILE),
232 STRING_TOKEN (STR_BOOT_FROM_FILE_HELP),
233 EFI_IFR_FLAG_CALLBACK,
234 KEY_VALUE_BOOT_FROM_FILE
235 );
236 }
237
238 /**
239 Create empty line menu in the front page.
240
241 @param HiiHandle The hii handle for the Uiapp driver.
242 @param StartOpCodeHandle The opcode handle to save the new opcode.
243
244 **/
245 VOID
246 BmmCreateEmptyLine (
247 IN EFI_HII_HANDLE HiiHandle,
248 IN VOID *StartOpCodeHandle
249 )
250 {
251 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_NULL_STRING), 0, 0, 0);
252 }
253
254 /**
255 Extract device path for given HII handle and class guid.
256
257 @param Handle The HII handle.
258
259 @retval NULL Fail to get the device path string.
260 @return PathString Get the device path string.
261
262 **/
263 CHAR16 *
264 ExtractDevicePathFromHandle (
265 IN EFI_HII_HANDLE Handle
266 )
267 {
268 EFI_STATUS Status;
269 EFI_HANDLE DriverHandle;
270
271 ASSERT (Handle != NULL);
272
273 if (Handle == NULL) {
274 return NULL;
275 }
276
277 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
278 if (EFI_ERROR (Status)) {
279 return NULL;
280 }
281
282 return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);
283 }
284
285 /**
286 Check whether this driver need to be shown in the front page.
287
288 @param HiiHandle The hii handle for the driver.
289 @param Guid The special guid for the driver which is the target.
290 @param PromptId Return the prompt string id.
291 @param HelpId Return the help string id.
292 @param FormsetGuid Return the formset guid info.
293
294 @retval EFI_SUCCESS Search the driver success
295
296 **/
297 BOOLEAN
298 IsRequiredDriver (
299 IN EFI_HII_HANDLE HiiHandle,
300 IN EFI_GUID *Guid,
301 OUT EFI_STRING_ID *PromptId,
302 OUT EFI_STRING_ID *HelpId,
303 OUT VOID *FormsetGuid
304 )
305 {
306 EFI_STATUS Status;
307 UINT8 ClassGuidNum;
308 EFI_GUID *ClassGuid;
309 EFI_IFR_FORM_SET *Buffer;
310 UINTN BufferSize;
311 UINT8 *Ptr;
312 UINTN TempSize;
313 BOOLEAN RetVal;
314
315 Status = HiiGetFormSetFromHiiHandle(HiiHandle, &Buffer,&BufferSize);
316 if (EFI_ERROR (Status)) {
317 return FALSE;
318 }
319
320 RetVal = FALSE;
321 TempSize = 0;
322 Ptr = (UINT8 *) Buffer;
323 while(TempSize < BufferSize) {
324 TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
325
326 if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){
327 Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
328 continue;
329 }
330
331 ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);
332 ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));
333 while (ClassGuidNum-- > 0) {
334 if (!CompareGuid (Guid, ClassGuid)){
335 ClassGuid ++;
336 continue;
337 }
338
339 *PromptId = ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle;
340 *HelpId = ((EFI_IFR_FORM_SET *)Ptr)->Help;
341 CopyMem (FormsetGuid, &((EFI_IFR_FORM_SET *) Ptr)->Guid, sizeof (EFI_GUID));
342 RetVal = TRUE;
343 }
344 }
345
346 FreePool (Buffer);
347
348 return RetVal;
349 }
350
351 /**
352 Search the drivers in the system which need to show in the front page
353 and insert the menu to the front page.
354
355 @param HiiHandle The hii handle for the Uiapp driver.
356 @param ClassGuid The class guid for the driver which is the target.
357 @param StartOpCodeHandle The opcode handle to save the new opcode.
358 @param SpecialHandler The pointer to the specail handler function, if any.
359
360 @retval EFI_SUCCESS Search the driver success
361
362 **/
363 EFI_STATUS
364 BmmListThirdPartyDrivers (
365 IN EFI_HII_HANDLE HiiHandle,
366 IN EFI_GUID *ClassGuid,
367 IN DRIVER_SPECIAL_HANDLER SpecialHandlerFn,
368 IN VOID *StartOpCodeHandle
369 )
370 {
371 UINTN Index;
372 EFI_STRING String;
373 EFI_STRING_ID Token;
374 EFI_STRING_ID TokenHelp;
375 EFI_HII_HANDLE *HiiHandles;
376 CHAR16 *DevicePathStr;
377 UINTN Count;
378 UINTN CurrentSize;
379 UI_HII_DRIVER_INSTANCE *DriverListPtr;
380 EFI_STRING NewName;
381 BOOLEAN EmptyLineAfter;
382
383 if (gHiiDriverList != NULL) {
384 FreePool (gHiiDriverList);
385 }
386
387 HiiHandles = HiiGetHiiHandles (NULL);
388 ASSERT (HiiHandles != NULL);
389
390 gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE));
391 ASSERT (gHiiDriverList != NULL);
392 DriverListPtr = gHiiDriverList;
393 CurrentSize = UI_HII_DRIVER_LIST_SIZE;
394
395 for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) {
396 if (!IsRequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) {
397 continue;
398 }
399
400 String = HiiGetString (HiiHandles[Index], Token, NULL);
401 if (String == NULL) {
402 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
403 ASSERT (String != NULL);
404 } else if (SpecialHandlerFn != NULL) {
405 //
406 // Check whether need to rename the driver name.
407 //
408 EmptyLineAfter = FALSE;
409 if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) {
410 FreePool (String);
411 String = NewName;
412 DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter;
413 }
414 }
415 DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL);
416 FreePool (String);
417
418 String = HiiGetString (HiiHandles[Index], TokenHelp, NULL);
419 if (String == NULL) {
420 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
421 ASSERT (String != NULL);
422 }
423 DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL);
424 FreePool (String);
425
426 DevicePathStr = ExtractDevicePathFromHandle(HiiHandles[Index]);
427 if (DevicePathStr != NULL){
428 DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
429 FreePool (DevicePathStr);
430 } else {
431 DriverListPtr[Count].DevicePathId = 0;
432 }
433
434 Count++;
435 if (Count >= CurrentSize) {
436 DriverListPtr = AllocateCopyPool ((Count + UI_HII_DRIVER_LIST_SIZE) * sizeof (UI_HII_DRIVER_INSTANCE), gHiiDriverList);
437 ASSERT (DriverListPtr != NULL);
438 FreePool (gHiiDriverList);
439 gHiiDriverList = DriverListPtr;
440 CurrentSize += UI_HII_DRIVER_LIST_SIZE;
441 }
442 }
443
444 FreePool (HiiHandles);
445
446 Index = 0;
447 while (gHiiDriverList[Index].PromptId != 0) {
448 HiiCreateGotoExOpCode (
449 StartOpCodeHandle,
450 0,
451 gHiiDriverList[Index].PromptId,
452 gHiiDriverList[Index].HelpId,
453 0,
454 0,
455 0,
456 &gHiiDriverList[Index].FormSetGuid,
457 gHiiDriverList[Index].DevicePathId
458 );
459
460 if (gHiiDriverList[Index].EmptyLineAfter) {
461 BmmCreateEmptyLine (HiiHandle, StartOpCodeHandle);
462 }
463
464 Index ++;
465 }
466
467 return EFI_SUCCESS;
468 }
469