]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BootMaintenanceManagerLib/BootMaintenance.c
MdeModulePkg:Create Boot Maintenance Manager Library
[mirror_edk2.git] / MdeModulePkg / Library / BootMaintenanceManagerLib / BootMaintenance.c
1 /** @file
2 The functions for Boot Maintainence Main menu.
3
4 Copyright (c) 2004 - 2015, 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 #include "BootMaintenanceManager.h"
16
17 #define FRONT_PAGE_KEY_OFFSET 0x4000
18 //
19 // Boot video resolution and text mode.
20 //
21 UINT32 mBmmBootHorizontalResolution = 0;
22 UINT32 mBmmBootVerticalResolution = 0;
23 UINT32 mBmmBootTextModeColumn = 0;
24 UINT32 mBmmBootTextModeRow = 0;
25 //
26 // BIOS setup video resolution and text mode.
27 //
28 UINT32 mBmmSetupTextModeColumn = 0;
29 UINT32 mBmmSetupTextModeRow = 0;
30 UINT32 mBmmSetupHorizontalResolution = 0;
31 UINT32 mBmmSetupVerticalResolution = 0;
32
33 EFI_DEVICE_PATH_PROTOCOL EndDevicePath[] = {
34 {
35 END_DEVICE_PATH_TYPE,
36 END_ENTIRE_DEVICE_PATH_SUBTYPE,
37 {
38 END_DEVICE_PATH_LENGTH,
39 0
40 }
41 }
42 };
43
44 HII_VENDOR_DEVICE_PATH mBmmHiiVendorDevicePath = {
45 {
46 {
47 HARDWARE_DEVICE_PATH,
48 HW_VENDOR_DP,
49 {
50 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
51 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
52 }
53 },
54 //
55 // {165A028F-0BB2-4b5f-8747-77592E3F6499}
56 //
57 { 0x165a028f, 0xbb2, 0x4b5f, { 0x87, 0x47, 0x77, 0x59, 0x2e, 0x3f, 0x64, 0x99 } }
58 },
59 {
60 END_DEVICE_PATH_TYPE,
61 END_ENTIRE_DEVICE_PATH_SUBTYPE,
62 {
63 (UINT8) (END_DEVICE_PATH_LENGTH),
64 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
65 }
66 }
67 };
68
69 EFI_GUID mBootMaintGuid = BOOT_MAINT_FORMSET_GUID;
70
71 CHAR16 mBootMaintStorageName[] = L"BmmData";
72 BMM_CALLBACK_DATA gBootMaintenancePrivate = {
73 BMM_CALLBACK_DATA_SIGNATURE,
74 NULL,
75 NULL,
76 {
77 BootMaintExtractConfig,
78 BootMaintRouteConfig,
79 BootMaintCallback
80 }
81 };
82
83 BMM_CALLBACK_DATA *mBmmCallbackInfo = &gBootMaintenancePrivate;
84 BOOLEAN mAllMenuInit = FALSE;
85
86 /**
87 Init all memu.
88
89 @param CallbackData The BMM context data.
90
91 **/
92 VOID
93 InitAllMenu (
94 IN BMM_CALLBACK_DATA *CallbackData
95 );
96
97 /**
98 Free up all Menu Option list.
99
100 **/
101 VOID
102 FreeAllMenu (
103 VOID
104 );
105
106 /**
107 This function will change video resolution and text mode
108 according to defined setup mode or defined boot mode
109
110 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
111
112 @retval EFI_SUCCESS Mode is changed successfully.
113 @retval Others Mode failed to be changed.
114
115 **/
116 EFI_STATUS
117 EFIAPI
118 BmmBdsSetConsoleMode (
119 BOOLEAN IsSetupMode
120 )
121 {
122 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
123 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
124 UINTN SizeOfInfo;
125 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
126 UINT32 MaxGopMode;
127 UINT32 MaxTextMode;
128 UINT32 ModeNumber;
129 UINT32 NewHorizontalResolution;
130 UINT32 NewVerticalResolution;
131 UINT32 NewColumns;
132 UINT32 NewRows;
133 UINTN HandleCount;
134 EFI_HANDLE *HandleBuffer;
135 EFI_STATUS Status;
136 UINTN Index;
137 UINTN CurrentColumn;
138 UINTN CurrentRow;
139
140 MaxGopMode = 0;
141 MaxTextMode = 0;
142
143 //
144 // Get current video resolution and text mode
145 //
146 Status = gBS->HandleProtocol (
147 gST->ConsoleOutHandle,
148 &gEfiGraphicsOutputProtocolGuid,
149 (VOID**)&GraphicsOutput
150 );
151 if (EFI_ERROR (Status)) {
152 GraphicsOutput = NULL;
153 }
154
155 Status = gBS->HandleProtocol (
156 gST->ConsoleOutHandle,
157 &gEfiSimpleTextOutProtocolGuid,
158 (VOID**)&SimpleTextOut
159 );
160 if (EFI_ERROR (Status)) {
161 SimpleTextOut = NULL;
162 }
163
164 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
165 return EFI_UNSUPPORTED;
166 }
167
168 if (IsSetupMode) {
169 //
170 // The requried resolution and text mode is setup mode.
171 //
172 NewHorizontalResolution = mBmmSetupHorizontalResolution;
173 NewVerticalResolution = mBmmSetupVerticalResolution;
174 NewColumns = mBmmSetupTextModeColumn;
175 NewRows = mBmmSetupTextModeRow;
176 } else {
177 //
178 // The required resolution and text mode is boot mode.
179 //
180 NewHorizontalResolution = mBmmBootHorizontalResolution;
181 NewVerticalResolution = mBmmBootVerticalResolution;
182 NewColumns = mBmmBootTextModeColumn;
183 NewRows = mBmmBootTextModeRow;
184 }
185
186 if (GraphicsOutput != NULL) {
187 MaxGopMode = GraphicsOutput->Mode->MaxMode;
188 }
189
190 if (SimpleTextOut != NULL) {
191 MaxTextMode = SimpleTextOut->Mode->MaxMode;
192 }
193
194 //
195 // 1. If current video resolution is same with required video resolution,
196 // video resolution need not be changed.
197 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
198 // 1.2. If current text mode is different from required text mode, text mode need be changed.
199 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
200 //
201 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
202 Status = GraphicsOutput->QueryMode (
203 GraphicsOutput,
204 ModeNumber,
205 &SizeOfInfo,
206 &Info
207 );
208 if (!EFI_ERROR (Status)) {
209 if ((Info->HorizontalResolution == NewHorizontalResolution) &&
210 (Info->VerticalResolution == NewVerticalResolution)) {
211 if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
212 (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {
213 //
214 // Current resolution is same with required resolution, check if text mode need be set
215 //
216 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
217 ASSERT_EFI_ERROR (Status);
218 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {
219 //
220 // If current text mode is same with required text mode. Do nothing
221 //
222 FreePool (Info);
223 return EFI_SUCCESS;
224 } else {
225 //
226 // If current text mode is different from requried text mode. Set new video mode
227 //
228 for (Index = 0; Index < MaxTextMode; Index++) {
229 Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
230 if (!EFI_ERROR(Status)) {
231 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
232 //
233 // Required text mode is supported, set it.
234 //
235 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
236 ASSERT_EFI_ERROR (Status);
237 //
238 // Update text mode PCD.
239 //
240 PcdSet32 (PcdConOutColumn, mBmmSetupTextModeColumn);
241 PcdSet32 (PcdConOutRow, mBmmSetupTextModeRow);
242 FreePool (Info);
243 return EFI_SUCCESS;
244 }
245 }
246 }
247 if (Index == MaxTextMode) {
248 //
249 // If requried text mode is not supported, return error.
250 //
251 FreePool (Info);
252 return EFI_UNSUPPORTED;
253 }
254 }
255 } else {
256 //
257 // If current video resolution is not same with the new one, set new video resolution.
258 // In this case, the driver which produces simple text out need be restarted.
259 //
260 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
261 if (!EFI_ERROR (Status)) {
262 FreePool (Info);
263 break;
264 }
265 }
266 }
267 FreePool (Info);
268 }
269 }
270
271 if (ModeNumber == MaxGopMode) {
272 //
273 // If the resolution is not supported, return error.
274 //
275 return EFI_UNSUPPORTED;
276 }
277
278 //
279 // Set PCD to Inform GraphicsConsole to change video resolution.
280 // Set PCD to Inform Consplitter to change text mode.
281 //
282 PcdSet32 (PcdVideoHorizontalResolution, NewHorizontalResolution);
283 PcdSet32 (PcdVideoVerticalResolution, NewVerticalResolution);
284 PcdSet32 (PcdConOutColumn, NewColumns);
285 PcdSet32 (PcdConOutRow, NewRows);
286
287 //
288 // Video mode is changed, so restart graphics console driver and higher level driver.
289 // Reconnect graphics console driver and higher level driver.
290 // Locate all the handles with GOP protocol and reconnect it.
291 //
292 Status = gBS->LocateHandleBuffer (
293 ByProtocol,
294 &gEfiSimpleTextOutProtocolGuid,
295 NULL,
296 &HandleCount,
297 &HandleBuffer
298 );
299 if (!EFI_ERROR (Status)) {
300 for (Index = 0; Index < HandleCount; Index++) {
301 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
302 }
303 for (Index = 0; Index < HandleCount; Index++) {
304 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
305 }
306 if (HandleBuffer != NULL) {
307 FreePool (HandleBuffer);
308 }
309 }
310
311 return EFI_SUCCESS;
312 }
313
314 /**
315 This function converts an input device structure to a Unicode string.
316
317 @param DevPath A pointer to the device path structure.
318
319 @return A new allocated Unicode string that represents the device path.
320
321 **/
322 CHAR16 *
323 UiDevicePathToStr (
324 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
325 )
326 {
327 EFI_STATUS Status;
328 CHAR16 *ToText;
329 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
330
331 if (DevPath == NULL) {
332 return NULL;
333 }
334
335 Status = gBS->LocateProtocol (
336 &gEfiDevicePathToTextProtocolGuid,
337 NULL,
338 (VOID **) &DevPathToText
339 );
340 ASSERT_EFI_ERROR (Status);
341 ToText = DevPathToText->ConvertDevicePathToText (
342 DevPath,
343 FALSE,
344 TRUE
345 );
346 ASSERT (ToText != NULL);
347 return ToText;
348 }
349
350 /**
351 Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.
352 The caller is responsible for freeing the allocated buffer using FreePool().
353
354 @param DevicePath Device path.
355
356 @return A new allocated string that represents the file name.
357
358 **/
359 CHAR16 *
360 ExtractFileNameFromDevicePath (
361 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
362 )
363 {
364 CHAR16 *String;
365 CHAR16 *MatchString;
366 CHAR16 *LastMatch;
367 CHAR16 *FileName;
368 UINTN Length;
369
370 ASSERT(DevicePath != NULL);
371
372 String = UiDevicePathToStr(DevicePath);
373 MatchString = String;
374 LastMatch = String;
375
376 while(MatchString != NULL){
377 LastMatch = MatchString + 1;
378 MatchString = StrStr(LastMatch,L"\\");
379 }
380
381 Length = StrLen(LastMatch);
382 FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);
383 *(FileName + Length) = 0;
384
385 FreePool(String);
386
387 return FileName;
388 }
389
390 /**
391 Extract device path for given HII handle and class guid.
392
393 @param Handle The HII handle.
394
395 @retval NULL Fail to get the device path string.
396 @return PathString Get the device path string.
397
398 **/
399 CHAR16 *
400 BmmExtractDevicePathFromHiiHandle (
401 IN EFI_HII_HANDLE Handle
402 )
403 {
404 EFI_STATUS Status;
405 EFI_HANDLE DriverHandle;
406
407 ASSERT (Handle != NULL);
408
409 if (Handle == NULL) {
410 return NULL;
411 }
412
413 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
414 if (EFI_ERROR (Status)) {
415 return NULL;
416 }
417
418 //
419 // Get device path string.
420 //
421 return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);
422
423 }
424
425 /**
426 This function allows a caller to extract the current configuration for one
427 or more named elements from the target driver.
428
429 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
430 @param Request A null-terminated Unicode string in <ConfigRequest> format.
431 @param Progress On return, points to a character in the Request string.
432 Points to the string's null terminator if request was successful.
433 Points to the most recent '&' before the first failing name/value
434 pair (or the beginning of the string if the failure is in the
435 first name/value pair) if the request was not successful.
436 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
437 has all values filled in for the names in the Request string.
438 String to be allocated by the called function.
439
440 @retval EFI_SUCCESS The Results is filled with the requested values.
441 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
442 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
443 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
444
445 **/
446 EFI_STATUS
447 EFIAPI
448 BootMaintExtractConfig (
449 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
450 IN CONST EFI_STRING Request,
451 OUT EFI_STRING *Progress,
452 OUT EFI_STRING *Results
453 )
454 {
455 EFI_STATUS Status;
456 UINTN BufferSize;
457 BMM_CALLBACK_DATA *Private;
458 EFI_STRING ConfigRequestHdr;
459 EFI_STRING ConfigRequest;
460 BOOLEAN AllocatedRequest;
461 UINTN Size;
462
463 if (Progress == NULL || Results == NULL) {
464 return EFI_INVALID_PARAMETER;
465 }
466
467 *Progress = Request;
468 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mBootMaintGuid, mBootMaintStorageName)) {
469 return EFI_NOT_FOUND;
470 }
471
472 ConfigRequestHdr = NULL;
473 ConfigRequest = NULL;
474 AllocatedRequest = FALSE;
475 Size = 0;
476
477 Private = BMM_CALLBACK_DATA_FROM_THIS (This);
478 //
479 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
480 //
481 BufferSize = sizeof (BMM_FAKE_NV_DATA);
482 ConfigRequest = Request;
483 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
484 //
485 // Request has no request element, construct full request string.
486 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
487 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
488 //
489 ConfigRequestHdr = HiiConstructConfigHdr (&mBootMaintGuid, mBootMaintStorageName, Private->BmmDriverHandle);
490 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
491 ConfigRequest = AllocateZeroPool (Size);
492 ASSERT (ConfigRequest != NULL);
493 AllocatedRequest = TRUE;
494 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
495 FreePool (ConfigRequestHdr);
496 }
497
498 Status = gHiiConfigRouting->BlockToConfig (
499 gHiiConfigRouting,
500 ConfigRequest,
501 (UINT8 *) &Private->BmmFakeNvData,
502 BufferSize,
503 Results,
504 Progress
505 );
506 //
507 // Free the allocated config request string.
508 //
509 if (AllocatedRequest) {
510 FreePool (ConfigRequest);
511 ConfigRequest = NULL;
512 }
513 //
514 // Set Progress string to the original request string.
515 //
516 if (Request == NULL) {
517 *Progress = NULL;
518 } else if (StrStr (Request, L"OFFSET") == NULL) {
519 *Progress = Request + StrLen (Request);
520 }
521
522 return Status;
523 }
524
525 /**
526 This function applies changes in a driver's configuration.
527 Input is a Configuration, which has the routing data for this
528 driver followed by name / value configuration pairs. The driver
529 must apply those pairs to its configurable storage. If the
530 driver's configuration is stored in a linear block of data
531 and the driver's name / value pairs are in <BlockConfig>
532 format, it may use the ConfigToBlock helper function (above) to
533 simplify the job. Currently not implemented.
534
535 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
536 @param[in] Configuration A null-terminated Unicode string in
537 <ConfigString> format.
538 @param[out] Progress A pointer to a string filled in with the
539 offset of the most recent '&' before the
540 first failing name / value pair (or the
541 beginn ing of the string if the failure
542 is in the first name / value pair) or
543 the terminating NULL if all was
544 successful.
545
546 @retval EFI_SUCCESS The results have been distributed or are
547 awaiting distribution.
548 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
549 parts of the results that must be
550 stored awaiting possible future
551 protocols.
552 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
553 Results parameter would result
554 in this type of error.
555 @retval EFI_NOT_FOUND Target for the specified routing data
556 was not found.
557 **/
558 EFI_STATUS
559 EFIAPI
560 BootMaintRouteConfig (
561 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
562 IN CONST EFI_STRING Configuration,
563 OUT EFI_STRING *Progress
564 )
565 {
566 EFI_STATUS Status;
567 UINTN BufferSize;
568 EFI_HII_CONFIG_ROUTING_PROTOCOL *ConfigRouting;
569 BMM_FAKE_NV_DATA *NewBmmData;
570 BMM_FAKE_NV_DATA *OldBmmData;
571 BM_CONSOLE_CONTEXT *NewConsoleContext;
572 BM_TERMINAL_CONTEXT *NewTerminalContext;
573 BM_MENU_ENTRY *NewMenuEntry;
574 BM_LOAD_CONTEXT *NewLoadContext;
575 UINT16 Index;
576 BOOLEAN TerminalAttChange;
577 BMM_CALLBACK_DATA *Private;
578
579 if (Progress == NULL) {
580 return EFI_INVALID_PARAMETER;
581 }
582 *Progress = Configuration;
583
584 if (Configuration == NULL) {
585 return EFI_INVALID_PARAMETER;
586 }
587
588 //
589 // Check routing data in <ConfigHdr>.
590 // Note: there is no name for Name/Value storage, only GUID will be checked
591 //
592 if (!HiiIsConfigHdrMatch (Configuration, &mBootMaintGuid, mBootMaintStorageName)) {
593 return EFI_NOT_FOUND;
594 }
595
596 Status = gBS->LocateProtocol (
597 &gEfiHiiConfigRoutingProtocolGuid,
598 NULL,
599 (VOID **)&ConfigRouting
600 );
601 if (EFI_ERROR (Status)) {
602 return Status;
603 }
604
605 Private = BMM_CALLBACK_DATA_FROM_THIS (This);
606 //
607 // Get Buffer Storage data from EFI variable
608 //
609 BufferSize = sizeof (BMM_FAKE_NV_DATA);
610 OldBmmData = &Private->BmmOldFakeNVData;
611 NewBmmData = &Private->BmmFakeNvData;
612 //
613 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
614 //
615 Status = ConfigRouting->ConfigToBlock (
616 ConfigRouting,
617 Configuration,
618 (UINT8 *) NewBmmData,
619 &BufferSize,
620 Progress
621 );
622 ASSERT_EFI_ERROR (Status);
623 //
624 // Compare new and old BMM configuration data and only do action for modified item to
625 // avoid setting unnecessary non-volatile variable
626 //
627
628 //
629 // Check data which located in BMM main page and save the settings if need
630 //
631 if (CompareMem (&NewBmmData->BootNext, &OldBmmData->BootNext, sizeof (NewBmmData->BootNext)) != 0) {
632 Status = Var_UpdateBootNext (Private);
633 }
634
635 //
636 // Check data which located in Boot Options Menu and save the settings if need
637 //
638 if (CompareMem (NewBmmData->BootOptionDel, OldBmmData->BootOptionDel, sizeof (NewBmmData->BootOptionDel)) != 0) {
639 for (Index = 0;
640 ((Index < BootOptionMenu.MenuNumber) && (Index < (sizeof (NewBmmData->BootOptionDel) / sizeof (NewBmmData->BootOptionDel[0]))));
641 Index ++) {
642 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
643 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
644 NewLoadContext->Deleted = NewBmmData->BootOptionDel[Index];
645 NewBmmData->BootOptionDel[Index] = FALSE;
646 NewBmmData->BootOptionDelMark[Index] = FALSE;
647 }
648
649 Var_DelBootOption ();
650 }
651
652 if (CompareMem (NewBmmData->BootOptionOrder, OldBmmData->BootOptionOrder, sizeof (NewBmmData->BootOptionOrder)) != 0) {
653 Status = Var_UpdateBootOrder (Private);
654 }
655
656 if (CompareMem (&NewBmmData->BootTimeOut, &OldBmmData->BootTimeOut, sizeof (NewBmmData->BootTimeOut)) != 0){
657 Status = gRT->SetVariable(
658 L"Timeout",
659 &gEfiGlobalVariableGuid,
660 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
661 sizeof(UINT16),
662 &(NewBmmData->BootTimeOut)
663 );
664 ASSERT_EFI_ERROR(Status);
665
666 Private->BmmOldFakeNVData.BootTimeOut = NewBmmData->BootTimeOut;
667 }
668
669 //
670 // Check data which located in Driver Options Menu and save the settings if need
671 //
672 if (CompareMem (NewBmmData->DriverOptionDel, OldBmmData->DriverOptionDel, sizeof (NewBmmData->DriverOptionDel)) != 0) {
673 for (Index = 0;
674 ((Index < DriverOptionMenu.MenuNumber) && (Index < (sizeof (NewBmmData->DriverOptionDel) / sizeof (NewBmmData->DriverOptionDel[0]))));
675 Index++) {
676 NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);
677 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
678 NewLoadContext->Deleted = NewBmmData->DriverOptionDel[Index];
679 NewBmmData->DriverOptionDel[Index] = FALSE;
680 NewBmmData->DriverOptionDelMark[Index] = FALSE;
681 }
682 Var_DelDriverOption ();
683 }
684
685 if (CompareMem (NewBmmData->DriverOptionOrder, OldBmmData->DriverOptionOrder, sizeof (NewBmmData->DriverOptionOrder)) != 0) {
686 Status = Var_UpdateDriverOrder (Private);
687 }
688
689 if (CompareMem (&NewBmmData->ConsoleOutMode, &OldBmmData->ConsoleOutMode, sizeof (NewBmmData->ConsoleOutMode)) != 0){
690 Var_UpdateConMode(Private);
691 }
692
693 TerminalAttChange = FALSE;
694 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
695
696 //
697 // only need update modified items
698 //
699 if (CompareMem (&NewBmmData->COMBaudRate[Index], &OldBmmData->COMBaudRate[Index], sizeof (NewBmmData->COMBaudRate[Index])) == 0 &&
700 CompareMem (&NewBmmData->COMDataRate[Index], &OldBmmData->COMDataRate[Index], sizeof (NewBmmData->COMDataRate[Index])) == 0 &&
701 CompareMem (&NewBmmData->COMStopBits[Index], &OldBmmData->COMStopBits[Index], sizeof (NewBmmData->COMStopBits[Index])) == 0 &&
702 CompareMem (&NewBmmData->COMParity[Index], &OldBmmData->COMParity[Index], sizeof (NewBmmData->COMParity[Index])) == 0 &&
703 CompareMem (&NewBmmData->COMTerminalType[Index], &OldBmmData->COMTerminalType[Index], sizeof (NewBmmData->COMTerminalType[Index])) == 0 &&
704 CompareMem (&NewBmmData->COMFlowControl[Index], &OldBmmData->COMFlowControl[Index], sizeof (NewBmmData->COMFlowControl[Index])) == 0) {
705 continue;
706 }
707
708 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
709 ASSERT (NewMenuEntry != NULL);
710 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
711 NewTerminalContext->BaudRateIndex = NewBmmData->COMBaudRate[Index];
712 ASSERT (NewBmmData->COMBaudRate[Index] < (sizeof (BaudRateList) / sizeof (BaudRateList[0])));
713 NewTerminalContext->BaudRate = BaudRateList[NewBmmData->COMBaudRate[Index]].Value;
714 NewTerminalContext->DataBitsIndex = NewBmmData->COMDataRate[Index];
715 ASSERT (NewBmmData->COMDataRate[Index] < (sizeof (DataBitsList) / sizeof (DataBitsList[0])));
716 NewTerminalContext->DataBits = (UINT8) DataBitsList[NewBmmData->COMDataRate[Index]].Value;
717 NewTerminalContext->StopBitsIndex = NewBmmData->COMStopBits[Index];
718 ASSERT (NewBmmData->COMStopBits[Index] < (sizeof (StopBitsList) / sizeof (StopBitsList[0])));
719 NewTerminalContext->StopBits = (UINT8) StopBitsList[NewBmmData->COMStopBits[Index]].Value;
720 NewTerminalContext->ParityIndex = NewBmmData->COMParity[Index];
721 ASSERT (NewBmmData->COMParity[Index] < (sizeof (ParityList) / sizeof (ParityList[0])));
722 NewTerminalContext->Parity = (UINT8) ParityList[NewBmmData->COMParity[Index]].Value;
723 NewTerminalContext->TerminalType = NewBmmData->COMTerminalType[Index];
724 NewTerminalContext->FlowControl = NewBmmData->COMFlowControl[Index];
725 ChangeTerminalDevicePath (
726 NewTerminalContext->DevicePath,
727 FALSE
728 );
729 TerminalAttChange = TRUE;
730 }
731 if (TerminalAttChange) {
732 Var_UpdateConsoleInpOption ();
733 Var_UpdateConsoleOutOption ();
734 Var_UpdateErrorOutOption ();
735 }
736 //
737 // Check data which located in Console Options Menu and save the settings if need
738 //
739 if (CompareMem (NewBmmData->ConsoleInCheck, OldBmmData->ConsoleInCheck, sizeof (NewBmmData->ConsoleInCheck)) != 0){
740 for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++){
741 NewMenuEntry = BOpt_GetMenuEntry(&ConsoleInpMenu, Index);
742 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
743 ASSERT (Index < MAX_MENU_NUMBER);
744 NewConsoleContext->IsActive = NewBmmData->ConsoleInCheck[Index];
745 }
746 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
747 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
748 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
749 ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER);
750 NewTerminalContext->IsConIn = NewBmmData->ConsoleInCheck[Index + ConsoleInpMenu.MenuNumber];
751 }
752 Var_UpdateConsoleInpOption();
753 }
754
755 if (CompareMem (NewBmmData->ConsoleOutCheck, OldBmmData->ConsoleOutCheck, sizeof (NewBmmData->ConsoleOutCheck)) != 0){
756 for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++){
757 NewMenuEntry = BOpt_GetMenuEntry(&ConsoleOutMenu, Index);
758 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
759 ASSERT (Index < MAX_MENU_NUMBER);
760 NewConsoleContext->IsActive = NewBmmData->ConsoleOutCheck[Index];
761 }
762 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
763 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
764 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
765 ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER);
766 NewTerminalContext->IsConOut = NewBmmData->ConsoleOutCheck[Index + ConsoleOutMenu.MenuNumber];
767 }
768 Var_UpdateConsoleOutOption();
769 }
770
771 if (CompareMem (NewBmmData->ConsoleErrCheck, OldBmmData->ConsoleErrCheck, sizeof (NewBmmData->ConsoleErrCheck)) != 0){
772 for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++){
773 NewMenuEntry = BOpt_GetMenuEntry(&ConsoleErrMenu, Index);
774 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
775 ASSERT (Index < MAX_MENU_NUMBER);
776 NewConsoleContext->IsActive = NewBmmData->ConsoleErrCheck[Index];
777 }
778 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
779 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
780 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
781 ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER);
782 NewTerminalContext->IsStdErr = NewBmmData->ConsoleErrCheck[Index + ConsoleErrMenu.MenuNumber];
783 }
784 Var_UpdateErrorOutOption();
785 }
786
787 if (CompareMem (NewBmmData->BootDescriptionData, OldBmmData->BootDescriptionData, sizeof (NewBmmData->BootDescriptionData)) != 0 ||
788 CompareMem (NewBmmData->BootOptionalData, OldBmmData->BootOptionalData, sizeof (NewBmmData->BootOptionalData)) != 0) {
789 Status = Var_UpdateBootOption (Private);
790 NewBmmData->BootOptionChanged = FALSE;
791 if (EFI_ERROR (Status)) {
792 return Status;
793 }
794 BOpt_GetBootOptions (Private);
795 }
796
797 if (CompareMem (NewBmmData->DriverDescriptionData, OldBmmData->DriverDescriptionData, sizeof (NewBmmData->DriverDescriptionData)) != 0 ||
798 CompareMem (NewBmmData->DriverOptionalData, OldBmmData->DriverOptionalData, sizeof (NewBmmData->DriverOptionalData)) != 0) {
799 Status = Var_UpdateDriverOption (
800 Private,
801 Private->BmmHiiHandle,
802 NewBmmData->DriverDescriptionData,
803 NewBmmData->DriverOptionalData,
804 NewBmmData->ForceReconnect
805 );
806 NewBmmData->DriverOptionChanged = FALSE;
807 NewBmmData->ForceReconnect = TRUE;
808 if (EFI_ERROR (Status)) {
809 return Status;
810 }
811
812 BOpt_GetDriverOptions (Private);
813 }
814
815 //
816 // After user do the save action, need to update OldBmmData.
817 //
818 CopyMem (OldBmmData, NewBmmData, sizeof (BMM_FAKE_NV_DATA));
819
820 return EFI_SUCCESS;
821 }
822
823 /**
824 This function processes the results of changes in configuration.
825
826
827 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
828 @param Action Specifies the type of action taken by the browser.
829 @param QuestionId A unique value which is sent to the original exporting driver
830 so that it can identify the type of data to expect.
831 @param Type The type of value for the question.
832 @param Value A pointer to the data being sent to the original exporting driver.
833 @param ActionRequest On return, points to the action requested by the callback function.
834
835 @retval EFI_SUCCESS The callback successfully handled the action.
836 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
837 @retval EFI_DEVICE_ERROR The variable could not be saved.
838 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
839 @retval EFI_INVALID_PARAMETER The parameter of Value or ActionRequest is invalid.
840 **/
841 EFI_STATUS
842 EFIAPI
843 BootMaintCallback (
844 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
845 IN EFI_BROWSER_ACTION Action,
846 IN EFI_QUESTION_ID QuestionId,
847 IN UINT8 Type,
848 IN EFI_IFR_TYPE_VALUE *Value,
849 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
850 )
851 {
852 BMM_CALLBACK_DATA *Private;
853 BM_MENU_ENTRY *NewMenuEntry;
854 BMM_FAKE_NV_DATA *CurrentFakeNVMap;
855 UINTN OldValue;
856 UINTN NewValue;
857 UINTN Number;
858 UINTN Index;
859 EFI_DEVICE_PATH_PROTOCOL * File;
860
861 if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) {
862 //
863 // Do nothing for other UEFI Action. Only do call back when data is changed.
864 //
865 return EFI_UNSUPPORTED;
866 }
867 OldValue = 0;
868 NewValue = 0;
869 Number = 0;
870
871 Private = BMM_CALLBACK_DATA_FROM_THIS (This);
872 //
873 // Retrive uncommitted data from Form Browser
874 //
875 CurrentFakeNVMap = &Private->BmmFakeNvData;
876 HiiGetBrowserData (&mBootMaintGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap);
877
878 if (Action == EFI_BROWSER_ACTION_CHANGING) {
879 if (Value == NULL) {
880 return EFI_INVALID_PARAMETER;
881 }
882
883 UpdatePageId (Private, QuestionId);
884
885 if (QuestionId < FILE_OPTION_OFFSET) {
886 if (QuestionId < CONFIG_OPTION_OFFSET) {
887 switch (QuestionId) {
888 case FORM_BOOT_ADD_ID:
889 // Leave BMM and enter FileExplorer.
890 ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) CreateBootOptionFromFile, &File);
891 break;
892
893 case FORM_DRV_ADD_FILE_ID:
894 // Leave BMM and enter FileExplorer.
895 ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) CreateDriverOptionFromFile, &File);
896 break;
897
898 case FORM_DRV_ADD_HANDLE_ID:
899 CleanUpPage (FORM_DRV_ADD_HANDLE_ID, Private);
900 UpdateDrvAddHandlePage (Private);
901 break;
902
903 case FORM_BOOT_DEL_ID:
904 CleanUpPage (FORM_BOOT_DEL_ID, Private);
905 UpdateBootDelPage (Private);
906 break;
907
908 case FORM_BOOT_CHG_ID:
909 case FORM_DRV_CHG_ID:
910 UpdatePageBody (QuestionId, Private);
911 break;
912
913 case FORM_DRV_DEL_ID:
914 CleanUpPage (FORM_DRV_DEL_ID, Private);
915 UpdateDrvDelPage (Private);
916 break;
917
918 case FORM_BOOT_NEXT_ID:
919 CleanUpPage (FORM_BOOT_NEXT_ID, Private);
920 UpdateBootNextPage (Private);
921 break;
922
923 case FORM_TIME_OUT_ID:
924 CleanUpPage (FORM_TIME_OUT_ID, Private);
925 UpdateTimeOutPage (Private);
926 break;
927
928 case FORM_CON_IN_ID:
929 case FORM_CON_OUT_ID:
930 case FORM_CON_ERR_ID:
931 UpdatePageBody (QuestionId, Private);
932 break;
933
934 case FORM_CON_MODE_ID:
935 CleanUpPage (FORM_CON_MODE_ID, Private);
936 UpdateConModePage (Private);
937 break;
938
939 case FORM_CON_COM_ID:
940 CleanUpPage (FORM_CON_COM_ID, Private);
941 UpdateConCOMPage (Private);
942 break;
943
944 default:
945 break;
946 }
947 } else if ((QuestionId >= TERMINAL_OPTION_OFFSET) && (QuestionId < CONSOLE_OPTION_OFFSET)) {
948 Index = (UINT16) (QuestionId - TERMINAL_OPTION_OFFSET);
949 Private->CurrentTerminal = Index;
950
951 CleanUpPage (FORM_CON_COM_SETUP_ID, Private);
952 UpdateTerminalPage (Private);
953
954 } else if (QuestionId >= HANDLE_OPTION_OFFSET) {
955 Index = (UINT16) (QuestionId - HANDLE_OPTION_OFFSET);
956
957 NewMenuEntry = BOpt_GetMenuEntry (&DriverMenu, Index);
958 ASSERT (NewMenuEntry != NULL);
959 Private->HandleContext = (BM_HANDLE_CONTEXT *) NewMenuEntry->VariableContext;
960
961 CleanUpPage (FORM_DRV_ADD_HANDLE_DESC_ID, Private);
962
963 Private->MenuEntry = NewMenuEntry;
964 Private->LoadContext->FilePathList = Private->HandleContext->DevicePath;
965
966 UpdateDriverAddHandleDescPage (Private);
967 }
968 }
969 if (QuestionId == KEY_VALUE_BOOT_FROM_FILE){
970 // Leave BMM and enter FileExplorer.
971 ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) BootFromFile, &File);
972 }
973 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
974 if ((Value == NULL) || (ActionRequest == NULL)) {
975 return EFI_INVALID_PARAMETER;
976 }
977
978 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT) {
979 CurrentFakeNVMap->BootOptionChanged = FALSE;
980 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
981 } else if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) {
982 CurrentFakeNVMap->DriverOptionChanged = FALSE;
983 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
984 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) {
985 //
986 // Discard changes and exit formset
987 //
988 CurrentFakeNVMap->DriverOptionalData[0] = 0x0000;
989 CurrentFakeNVMap->DriverDescriptionData[0] = 0x0000;
990 CurrentFakeNVMap->DriverOptionChanged = FALSE;
991 CurrentFakeNVMap->ForceReconnect = TRUE;
992 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
993 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_BOOT) {
994 //
995 // Discard changes and exit formset
996 //
997 CurrentFakeNVMap->BootOptionalData[0] = 0x0000;
998 CurrentFakeNVMap->BootDescriptionData[0] = 0x0000;
999 CurrentFakeNVMap->BootOptionChanged = FALSE;
1000 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
1001 } else if (QuestionId == KEY_VALUE_BOOT_DESCRIPTION || QuestionId == KEY_VALUE_BOOT_OPTION) {
1002 CurrentFakeNVMap->BootOptionChanged = TRUE;
1003 } else if (QuestionId == KEY_VALUE_DRIVER_DESCRIPTION || QuestionId == KEY_VALUE_DRIVER_OPTION) {
1004 CurrentFakeNVMap->DriverOptionChanged = TRUE;
1005 }
1006
1007 if ((QuestionId >= BOOT_OPTION_DEL_QUESTION_ID) && (QuestionId < BOOT_OPTION_DEL_QUESTION_ID + MAX_MENU_NUMBER)) {
1008 if (Value->b){
1009 //
1010 // Means user try to delete this boot option but not press F10 or "Commit Changes and Exit" menu.
1011 //
1012 CurrentFakeNVMap->BootOptionDelMark[QuestionId - BOOT_OPTION_DEL_QUESTION_ID] = TRUE;
1013 } else {
1014 //
1015 // Means user remove the old check status.
1016 //
1017 CurrentFakeNVMap->BootOptionDelMark[QuestionId - BOOT_OPTION_DEL_QUESTION_ID] = FALSE;
1018 }
1019 } else if ((QuestionId >= DRIVER_OPTION_DEL_QUESTION_ID) && (QuestionId < DRIVER_OPTION_DEL_QUESTION_ID + MAX_MENU_NUMBER)) {
1020 if (Value->b){
1021 CurrentFakeNVMap->DriverOptionDelMark[QuestionId - DRIVER_OPTION_DEL_QUESTION_ID] = TRUE;
1022 } else {
1023 CurrentFakeNVMap->DriverOptionDelMark[QuestionId - DRIVER_OPTION_DEL_QUESTION_ID] = FALSE;
1024 }
1025 } else {
1026 switch (QuestionId) {
1027 case KEY_VALUE_SAVE_AND_EXIT:
1028 case KEY_VALUE_NO_SAVE_AND_EXIT:
1029 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT) {
1030 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
1031 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT) {
1032 DiscardChangeHandler (Private, CurrentFakeNVMap);
1033 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
1034 }
1035
1036 break;
1037
1038 case FORM_RESET:
1039 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1040 return EFI_UNSUPPORTED;
1041
1042 default:
1043 break;
1044 }
1045 }
1046 }
1047
1048 //
1049 // Pass changed uncommitted data back to Form Browser
1050 //
1051 HiiSetBrowserData (&mBootMaintGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap, NULL);
1052
1053 return EFI_SUCCESS;
1054 }
1055
1056 /**
1057 Discard all changes done to the BMM pages such as Boot Order change,
1058 Driver order change.
1059
1060 @param Private The BMM context data.
1061 @param CurrentFakeNVMap The current Fack NV Map.
1062
1063 **/
1064 VOID
1065 DiscardChangeHandler (
1066 IN BMM_CALLBACK_DATA *Private,
1067 IN BMM_FAKE_NV_DATA *CurrentFakeNVMap
1068 )
1069 {
1070 UINT16 Index;
1071
1072 switch (Private->BmmPreviousPageId) {
1073 case FORM_BOOT_CHG_ID:
1074 CopyMem (CurrentFakeNVMap->BootOptionOrder, Private->BmmOldFakeNVData.BootOptionOrder, sizeof (CurrentFakeNVMap->BootOptionOrder));
1075 break;
1076
1077 case FORM_DRV_CHG_ID:
1078 CopyMem (CurrentFakeNVMap->DriverOptionOrder, Private->BmmOldFakeNVData.DriverOptionOrder, sizeof (CurrentFakeNVMap->DriverOptionOrder));
1079 break;
1080
1081 case FORM_BOOT_DEL_ID:
1082 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->BootOptionDel) / sizeof (CurrentFakeNVMap->BootOptionDel[0])));
1083 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
1084 CurrentFakeNVMap->BootOptionDel[Index] = FALSE;
1085 }
1086 break;
1087
1088 case FORM_DRV_DEL_ID:
1089 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->DriverOptionDel) / sizeof (CurrentFakeNVMap->DriverOptionDel[0])));
1090 for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {
1091 CurrentFakeNVMap->DriverOptionDel[Index] = FALSE;
1092 }
1093 break;
1094
1095 case FORM_BOOT_NEXT_ID:
1096 CurrentFakeNVMap->BootNext = Private->BmmOldFakeNVData.BootNext;
1097 break;
1098
1099 case FORM_TIME_OUT_ID:
1100 CurrentFakeNVMap->BootTimeOut = Private->BmmOldFakeNVData.BootTimeOut;
1101 break;
1102
1103 case FORM_DRV_ADD_HANDLE_DESC_ID:
1104 case FORM_DRV_ADD_FILE_ID:
1105 case FORM_DRV_ADD_HANDLE_ID:
1106 CurrentFakeNVMap->DriverAddHandleDesc[0] = 0x0000;
1107 CurrentFakeNVMap->DriverAddHandleOptionalData[0] = 0x0000;
1108 break;
1109
1110 default:
1111 break;
1112 }
1113 }
1114
1115 /**
1116 Create dynamic code for BMM.
1117
1118 @param BmmCallbackInfo The BMM context data.
1119
1120 **/
1121 VOID
1122 InitializeDrivers(
1123 IN BMM_CALLBACK_DATA *BmmCallbackInfo
1124 )
1125 {
1126 EFI_HII_HANDLE HiiHandle;
1127 VOID *StartOpCodeHandle;
1128 VOID *EndOpCodeHandle;
1129 EFI_IFR_GUID_LABEL *StartLabel;
1130 EFI_IFR_GUID_LABEL *EndLabel;
1131 UINTN Index;
1132 EFI_STRING String;
1133 EFI_STRING_ID Token;
1134 EFI_STRING_ID TokenHelp;
1135 EFI_HII_HANDLE *HiiHandles;
1136 EFI_GUID FormSetGuid;
1137 CHAR16 *DevicePathStr;
1138 EFI_STRING_ID DevicePathId;
1139 EFI_IFR_FORM_SET *Buffer;
1140 UINTN BufferSize;
1141 UINT8 ClassGuidNum;
1142 EFI_GUID *ClassGuid;
1143 UINTN TempSize;
1144 UINT8 *Ptr;
1145 EFI_STATUS Status;
1146
1147 TempSize =0;
1148 BufferSize = 0;
1149 Buffer = NULL;
1150
1151 HiiHandle = BmmCallbackInfo->BmmHiiHandle;
1152 //
1153 // Allocate space for creation of UpdateData Buffer
1154 //
1155 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
1156 ASSERT (StartOpCodeHandle != NULL);
1157
1158 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
1159 ASSERT (EndOpCodeHandle != NULL);
1160
1161 //
1162 // Create Hii Extend Label OpCode as the start opcode
1163 //
1164 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1165 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
1166 StartLabel->Number = LABEL_BMM_PLATFORM_INFORMATION;
1167
1168 //
1169 // Create Hii Extend Label OpCode as the end opcode
1170 //
1171 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1172 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
1173 EndLabel->Number = LABEL_END;
1174
1175 //
1176 // Get all the Hii handles
1177 //
1178 HiiHandles = HiiGetHiiHandles (NULL);
1179 ASSERT (HiiHandles != NULL);
1180
1181 //
1182 // Search for formset of each class type
1183 //
1184 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
1185 Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize);
1186 if (EFI_ERROR (Status)) {
1187 continue;
1188 }
1189
1190 Ptr = (UINT8 *)Buffer;
1191 while(TempSize < BufferSize) {
1192 TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
1193
1194 if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){
1195 Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
1196 continue;
1197 }
1198
1199 //
1200 // Find FormSet OpCode
1201 //
1202 ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);
1203 ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));
1204 while (ClassGuidNum-- > 0) {
1205 if (CompareGuid (&gEfiIfrBootMaintenanceGuid, ClassGuid) == 0){
1206 ClassGuid ++;
1207 continue;
1208 }
1209
1210 String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL);
1211 if (String == NULL) {
1212 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
1213 ASSERT (String != NULL);
1214 }
1215 Token = HiiSetString (HiiHandle, 0, String, NULL);
1216 FreePool (String);
1217
1218 String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL);
1219 if (String == NULL) {
1220 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
1221 ASSERT (String != NULL);
1222 }
1223 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
1224 FreePool (String);
1225
1226 FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid;
1227
1228 DevicePathStr = BmmExtractDevicePathFromHiiHandle(HiiHandles[Index]);
1229 DevicePathId = 0;
1230 if (DevicePathStr != NULL){
1231 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
1232 FreePool (DevicePathStr);
1233 }
1234 HiiCreateGotoExOpCode (
1235 StartOpCodeHandle,
1236 0,
1237 Token,
1238 TokenHelp,
1239 0,
1240 (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_OFFSET),
1241 0,
1242 &FormSetGuid,
1243 DevicePathId
1244 );
1245 break;
1246 }
1247 Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
1248 }
1249
1250 FreePool(Buffer);
1251 Buffer = NULL;
1252 TempSize = 0;
1253 BufferSize = 0;
1254 }
1255
1256 HiiUpdateForm (
1257 HiiHandle,
1258 &mBootMaintGuid,
1259 FORM_MAIN_ID,
1260 StartOpCodeHandle,
1261 EndOpCodeHandle
1262 );
1263
1264 HiiFreeOpCodeHandle (StartOpCodeHandle);
1265 HiiFreeOpCodeHandle (EndOpCodeHandle);
1266 FreePool (HiiHandles);
1267 }
1268
1269 /**
1270 Create dynamic code for BMM and initialize all of BMM configuration data in BmmFakeNvData and
1271 BmmOldFakeNVData member in BMM context data.
1272
1273 @param CallbackData The BMM context data.
1274
1275 **/
1276 VOID
1277 InitializeBmmConfig (
1278 IN BMM_CALLBACK_DATA *CallbackData
1279 )
1280 {
1281 BM_MENU_ENTRY *NewMenuEntry;
1282 BM_LOAD_CONTEXT *NewLoadContext;
1283 UINT16 Index;
1284
1285 ASSERT (CallbackData != NULL);
1286
1287 InitializeDrivers (CallbackData);
1288
1289 //
1290 // Initialize data which located in BMM main page
1291 //
1292 CallbackData->BmmFakeNvData.BootNext = (UINT16) (BootOptionMenu.MenuNumber);
1293 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
1294 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
1295 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
1296
1297 if (NewLoadContext->IsBootNext) {
1298 CallbackData->BmmFakeNvData.BootNext = Index;
1299 break;
1300 }
1301 }
1302
1303 CallbackData->BmmFakeNvData.BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);
1304
1305 //
1306 // Initialize data which located in Boot Options Menu
1307 //
1308 GetBootOrder (CallbackData);
1309
1310 //
1311 // Initialize data which located in Driver Options Menu
1312 //
1313 GetDriverOrder (CallbackData);
1314
1315 //
1316 // Initialize data which located in Console Options Menu
1317 //
1318 GetConsoleOutMode (CallbackData);
1319 GetConsoleInCheck (CallbackData);
1320 GetConsoleOutCheck (CallbackData);
1321 GetConsoleErrCheck (CallbackData);
1322 GetTerminalAttribute (CallbackData);
1323
1324 CallbackData->BmmFakeNvData.ForceReconnect = TRUE;
1325
1326 //
1327 // Backup Initialize BMM configuartion data to BmmOldFakeNVData
1328 //
1329 CopyMem (&CallbackData->BmmOldFakeNVData, &CallbackData->BmmFakeNvData, sizeof (BMM_FAKE_NV_DATA));
1330 }
1331
1332 /**
1333 Initialized all Menu Option List.
1334
1335 @param CallbackData The BMM context data.
1336
1337 **/
1338 VOID
1339 InitAllMenu (
1340 IN BMM_CALLBACK_DATA *CallbackData
1341 )
1342 {
1343 InitializeListHead (&BootOptionMenu.Head);
1344 InitializeListHead (&DriverOptionMenu.Head);
1345 BOpt_GetBootOptions (CallbackData);
1346 BOpt_GetDriverOptions (CallbackData);
1347 BOpt_FindDrivers ();
1348 InitializeListHead (&ConsoleInpMenu.Head);
1349 InitializeListHead (&ConsoleOutMenu.Head);
1350 InitializeListHead (&ConsoleErrMenu.Head);
1351 InitializeListHead (&TerminalMenu.Head);
1352 LocateSerialIo ();
1353 GetAllConsoles ();
1354 mAllMenuInit = TRUE;
1355 }
1356
1357 /**
1358 Free up all Menu Option list.
1359
1360 **/
1361 VOID
1362 FreeAllMenu (
1363 VOID
1364 )
1365 {
1366 if (!mAllMenuInit){
1367 return;
1368 }
1369 BOpt_FreeMenu (&BootOptionMenu);
1370 BOpt_FreeMenu (&DriverOptionMenu);
1371 BOpt_FreeMenu (&DriverMenu);
1372 FreeAllConsoles ();
1373 mAllMenuInit = FALSE;
1374 }
1375
1376 /**
1377
1378 Install Boot Maintenance Manager Menu driver.
1379
1380 @param ImageHandle The image handle.
1381 @param SystemTable The system table.
1382
1383 @retval EFI_SUCEESS Install Boot manager menu success.
1384 @retval Other Return error status.
1385
1386 **/
1387 EFI_STATUS
1388 EFIAPI
1389 BootMaintenanceManagerLibConstructor (
1390 IN EFI_HANDLE ImageHandle,
1391 IN EFI_SYSTEM_TABLE *SystemTable
1392 )
1393
1394 {
1395 EFI_STATUS Status;
1396 UINT8 *Ptr;
1397
1398 Status = EFI_SUCCESS;
1399
1400 //
1401 // Install Device Path Protocol and Config Access protocol to driver handle
1402 //
1403 Status = gBS->InstallMultipleProtocolInterfaces (
1404 &mBmmCallbackInfo->BmmDriverHandle,
1405 &gEfiDevicePathProtocolGuid,
1406 &mBmmHiiVendorDevicePath,
1407 &gEfiHiiConfigAccessProtocolGuid,
1408 &mBmmCallbackInfo->BmmConfigAccess,
1409 NULL
1410 );
1411 ASSERT_EFI_ERROR (Status);
1412
1413 //
1414 // Post our Boot Maint VFR binary to the HII database.
1415 //
1416 mBmmCallbackInfo->BmmHiiHandle = HiiAddPackages (
1417 &mBootMaintGuid,
1418 mBmmCallbackInfo->BmmDriverHandle,
1419 BootMaintenanceManagerBin,
1420 BootMaintenanceManagerLibStrings,
1421 NULL
1422 );
1423 ASSERT (mBmmCallbackInfo->BmmHiiHandle != NULL);
1424
1425 //
1426 // Locate Formbrowser2 protocol
1427 //
1428 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mBmmCallbackInfo->FormBrowser2);
1429 ASSERT_EFI_ERROR (Status);
1430
1431 EfiBootManagerRefreshAllBootOption ();
1432
1433 //
1434 // Create LoadOption in BmmCallbackInfo for Driver Callback
1435 //
1436 Ptr = AllocateZeroPool (sizeof (BM_LOAD_CONTEXT) + sizeof (BM_FILE_CONTEXT) + sizeof (BM_HANDLE_CONTEXT) + sizeof (BM_MENU_ENTRY));
1437 ASSERT (Ptr != NULL);
1438
1439 //
1440 // Initialize Bmm callback data.
1441 //
1442 mBmmCallbackInfo->LoadContext = (BM_LOAD_CONTEXT *) Ptr;
1443 Ptr += sizeof (BM_LOAD_CONTEXT);
1444
1445 mBmmCallbackInfo->FileContext = (BM_FILE_CONTEXT *) Ptr;
1446 Ptr += sizeof (BM_FILE_CONTEXT);
1447
1448 mBmmCallbackInfo->HandleContext = (BM_HANDLE_CONTEXT *) Ptr;
1449 Ptr += sizeof (BM_HANDLE_CONTEXT);
1450
1451 mBmmCallbackInfo->MenuEntry = (BM_MENU_ENTRY *) Ptr;
1452
1453 mBmmCallbackInfo->BmmPreviousPageId = FORM_MAIN_ID;
1454 mBmmCallbackInfo->BmmCurrentPageId = FORM_MAIN_ID;
1455
1456 InitAllMenu (mBmmCallbackInfo);
1457
1458 CreateUpdateData();
1459 //
1460 // Update boot maintenance manager page
1461 //
1462 InitializeBmmConfig(mBmmCallbackInfo);
1463
1464 return EFI_SUCCESS;
1465 }
1466
1467 /**
1468 Unloads the application and its installed protocol.
1469
1470 @param ImageHandle Handle that identifies the image to be unloaded.
1471 @param SystemTable The system table.
1472
1473 @retval EFI_SUCCESS The image has been unloaded.
1474
1475 **/
1476 EFI_STATUS
1477 EFIAPI
1478 BootMaintenanceManagerLibDestructor (
1479 IN EFI_HANDLE ImageHandle,
1480 IN EFI_SYSTEM_TABLE *SystemTable
1481 )
1482
1483 {
1484 if (mStartOpCodeHandle != NULL) {
1485 HiiFreeOpCodeHandle (mStartOpCodeHandle);
1486 }
1487
1488 if (mEndOpCodeHandle != NULL) {
1489 HiiFreeOpCodeHandle (mEndOpCodeHandle);
1490 }
1491
1492 FreeAllMenu ();
1493
1494 //
1495 // Remove our IFR data from HII database
1496 //
1497 HiiRemovePackages (mBmmCallbackInfo->BmmHiiHandle);
1498
1499 gBS->UninstallMultipleProtocolInterfaces (
1500 mBmmCallbackInfo->BmmDriverHandle,
1501 &gEfiDevicePathProtocolGuid,
1502 &mBmmHiiVendorDevicePath,
1503 &gEfiHiiConfigAccessProtocolGuid,
1504 &mBmmCallbackInfo->BmmConfigAccess,
1505 NULL
1506 );
1507
1508 FreePool (mBmmCallbackInfo->LoadContext);
1509
1510 return EFI_SUCCESS;
1511 }
1512