X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FBootMaintenanceManagerUiLib%2FBootMaintenance.c;h=fdcb56a9df2b5d7012767eef22c980f12d6d31dc;hp=8189bd10842a45a9180b21672be0ee69ee73216d;hb=14923c1a6bf9940b48feeaf47cb5d6c662b6528c;hpb=13c4e86462f2a4cdf80d10696b33e7836c6bf377 diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c index 8189bd1084..fdcb56a9df 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c @@ -1,7 +1,7 @@ /** @file The functions for Boot Maintainence Main menu. -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -30,6 +30,8 @@ UINT32 mBmmSetupTextModeRow = 0; UINT32 mBmmSetupHorizontalResolution = 0; UINT32 mBmmSetupVerticalResolution = 0; +BOOLEAN mBmmModeInitialized = FALSE; + EFI_DEVICE_PATH_PROTOCOL EndDevicePath[] = { { END_DEVICE_PATH_TYPE, @@ -82,6 +84,7 @@ BMM_CALLBACK_DATA gBootMaintenancePrivate = { BMM_CALLBACK_DATA *mBmmCallbackInfo = &gBootMaintenancePrivate; BOOLEAN mAllMenuInit = FALSE; +BOOLEAN mFirstEnterBMMForm = FALSE; /** Init all memu. @@ -103,6 +106,16 @@ FreeAllMenu ( VOID ); +/** + + Update the menus in the BMM page. + +**/ +VOID +CustomizeMenus ( + VOID + ); + /** This function will change video resolution and text mode according to defined setup mode or defined boot mode @@ -114,8 +127,7 @@ FreeAllMenu ( **/ EFI_STATUS -EFIAPI -BmmBdsSetConsoleMode ( +BmmSetConsoleMode ( BOOLEAN IsSetupMode ) { @@ -167,7 +179,7 @@ BmmBdsSetConsoleMode ( if (IsSetupMode) { // - // The requried resolution and text mode is setup mode. + // The required resolution and text mode is setup mode. // NewHorizontalResolution = mBmmSetupHorizontalResolution; NewVerticalResolution = mBmmSetupVerticalResolution; @@ -223,7 +235,7 @@ BmmBdsSetConsoleMode ( return EFI_SUCCESS; } else { // - // If current text mode is different from requried text mode. Set new video mode + // If current text mode is different from required text mode. Set new video mode // for (Index = 0; Index < MaxTextMode; Index++) { Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow); @@ -248,7 +260,7 @@ BmmBdsSetConsoleMode ( } if (Index == MaxTextMode) { // - // If requried text mode is not supported, return error. + // If required text mode is not supported, return error. // FreePool (Info); return EFI_UNSUPPORTED; @@ -378,6 +390,7 @@ ExtractFileNameFromDevicePath ( String = UiDevicePathToStr(DevicePath); MatchString = String; LastMatch = String; + FileName = NULL; while(MatchString != NULL){ LastMatch = MatchString + 1; @@ -386,7 +399,9 @@ ExtractFileNameFromDevicePath ( Length = StrLen(LastMatch); FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch); - *(FileName + Length) = 0; + if (FileName != NULL) { + *(FileName + Length) = 0; + } FreePool(String); @@ -428,6 +443,194 @@ BmmExtractDevicePathFromHiiHandle ( } +/** + Converts the unicode character of the string from uppercase to lowercase. + This is a internal function. + + @param ConfigString String to be converted + +**/ +VOID +HiiToLower ( + IN EFI_STRING ConfigString + ) +{ + EFI_STRING String; + BOOLEAN Lower; + + ASSERT (ConfigString != NULL); + + // + // Convert all hex digits in range [A-F] in the configuration header to [a-f] + // + for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) { + if (*String == L'=') { + Lower = TRUE; + } else if (*String == L'&') { + Lower = FALSE; + } else if (Lower && *String >= L'A' && *String <= L'F') { + *String = (CHAR16) (*String - L'A' + L'a'); + } + } +} + +/** + Update the progress string through the offset value. + + @param Offset The offset value + @param Configuration Point to the configuration string. + +**/ +EFI_STRING +UpdateProgress( + IN UINTN Offset, + IN EFI_STRING Configuration +) +{ + UINTN Length; + EFI_STRING StringPtr; + EFI_STRING ReturnString; + + StringPtr = NULL; + ReturnString = NULL; + + // + // &OFFSET=XXXX followed by a Null-terminator. + // Length = StrLen (L"&OFFSET=") + 4 + 1 + // + Length = StrLen (L"&OFFSET=") + 4 + 1; + + StringPtr = AllocateZeroPool (Length * sizeof (CHAR16)); + + if (StringPtr == NULL) { + return NULL; + } + + UnicodeSPrint ( + StringPtr, + (8 + 4 + 1) * sizeof (CHAR16), + L"&OFFSET=%04x", + Offset + ); + + ReturnString = StrStr (Configuration, StringPtr); + + if (ReturnString == NULL) { + // + // If doesn't find the string in Configuration, convert the string to lower case then search again. + // + HiiToLower (StringPtr); + ReturnString = StrStr (Configuration, StringPtr); + } + + FreePool (StringPtr); + + return ReturnString; +} + +/** + Update the terminal content in TerminalMenu. + + @param BmmData The BMM fake NV data. + +**/ +VOID +UpdateTerminalContent ( + IN BMM_FAKE_NV_DATA *BmmData + ) +{ + UINT16 Index; + BM_TERMINAL_CONTEXT *NewTerminalContext; + BM_MENU_ENTRY *NewMenuEntry; + + for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { + NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); + ASSERT (NewMenuEntry != NULL); + NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; + NewTerminalContext->BaudRateIndex = BmmData->COMBaudRate[Index]; + ASSERT (BmmData->COMBaudRate[Index] < (ARRAY_SIZE (BaudRateList))); + NewTerminalContext->BaudRate = BaudRateList[BmmData->COMBaudRate[Index]].Value; + NewTerminalContext->DataBitsIndex = BmmData->COMDataRate[Index]; + ASSERT (BmmData->COMDataRate[Index] < (ARRAY_SIZE (DataBitsList))); + NewTerminalContext->DataBits = (UINT8) DataBitsList[BmmData->COMDataRate[Index]].Value; + NewTerminalContext->StopBitsIndex = BmmData->COMStopBits[Index]; + ASSERT (BmmData->COMStopBits[Index] < (ARRAY_SIZE (StopBitsList))); + NewTerminalContext->StopBits = (UINT8) StopBitsList[BmmData->COMStopBits[Index]].Value; + NewTerminalContext->ParityIndex = BmmData->COMParity[Index]; + ASSERT (BmmData->COMParity[Index] < (ARRAY_SIZE (ParityList))); + NewTerminalContext->Parity = (UINT8) ParityList[BmmData->COMParity[Index]].Value; + NewTerminalContext->TerminalType = BmmData->COMTerminalType[Index]; + NewTerminalContext->FlowControl = BmmData->COMFlowControl[Index]; + ChangeTerminalDevicePath ( + NewTerminalContext->DevicePath, + FALSE + ); + } +} + +/** + Update the console content in ConsoleMenu. + + @param ConsoleName The name for the console device type. + @param BmmData The BMM fake NV data. + +**/ +VOID +UpdateConsoleContent( + IN CHAR16 *ConsoleName, + IN BMM_FAKE_NV_DATA *BmmData + ) +{ + UINT16 Index; + BM_CONSOLE_CONTEXT *NewConsoleContext; + BM_TERMINAL_CONTEXT *NewTerminalContext; + BM_MENU_ENTRY *NewMenuEntry; + + if (StrCmp (ConsoleName, L"ConIn") == 0) { + for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++){ + NewMenuEntry = BOpt_GetMenuEntry(&ConsoleInpMenu, Index); + NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; + ASSERT (Index < MAX_MENU_NUMBER); + NewConsoleContext->IsActive = BmmData->ConsoleInCheck[Index]; + } + for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { + NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); + NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; + ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER); + NewTerminalContext->IsConIn = BmmData->ConsoleInCheck[Index + ConsoleInpMenu.MenuNumber]; + } + } + + if (StrCmp (ConsoleName, L"ConOut") == 0) { + for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++){ + NewMenuEntry = BOpt_GetMenuEntry(&ConsoleOutMenu, Index); + NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; + ASSERT (Index < MAX_MENU_NUMBER); + NewConsoleContext->IsActive = BmmData->ConsoleOutCheck[Index]; + } + for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { + NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); + NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; + ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER); + NewTerminalContext->IsConOut = BmmData->ConsoleOutCheck[Index + ConsoleOutMenu.MenuNumber]; + } + } + if (StrCmp (ConsoleName, L"ErrOut") == 0) { + for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++){ + NewMenuEntry = BOpt_GetMenuEntry(&ConsoleErrMenu, Index); + NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; + ASSERT (Index < MAX_MENU_NUMBER); + NewConsoleContext->IsActive = BmmData->ConsoleErrCheck[Index]; + } + for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { + NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); + NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; + ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER); + NewTerminalContext->IsStdErr = BmmData->ConsoleErrCheck[Index + ConsoleErrMenu.MenuNumber]; + } + } +} + /** This function allows a caller to extract the current configuration for one or more named elements from the target driver. @@ -574,13 +777,12 @@ BootMaintRouteConfig ( EFI_HII_CONFIG_ROUTING_PROTOCOL *ConfigRouting; BMM_FAKE_NV_DATA *NewBmmData; BMM_FAKE_NV_DATA *OldBmmData; - BM_CONSOLE_CONTEXT *NewConsoleContext; - BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; UINT16 Index; BOOLEAN TerminalAttChange; - BMM_CALLBACK_DATA *Private; + BMM_CALLBACK_DATA *Private; + UINTN Offset; if (Progress == NULL) { return EFI_INVALID_PARAMETER; @@ -615,6 +817,7 @@ BootMaintRouteConfig ( BufferSize = sizeof (BMM_FAKE_NV_DATA); OldBmmData = &Private->BmmOldFakeNVData; NewBmmData = &Private->BmmFakeNvData; + Offset = 0; // // Convert to buffer data by helper function ConfigToBlock() // @@ -636,6 +839,10 @@ BootMaintRouteConfig ( // if (CompareMem (&NewBmmData->BootNext, &OldBmmData->BootNext, sizeof (NewBmmData->BootNext)) != 0) { Status = Var_UpdateBootNext (Private); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootNext); + goto Exit; + } } // @@ -652,11 +859,19 @@ BootMaintRouteConfig ( NewBmmData->BootOptionDelMark[Index] = FALSE; } - Var_DelBootOption (); + Status = Var_DelBootOption (); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootOptionDel); + goto Exit; + } } if (CompareMem (NewBmmData->BootOptionOrder, OldBmmData->BootOptionOrder, sizeof (NewBmmData->BootOptionOrder)) != 0) { Status = Var_UpdateBootOrder (Private); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootOptionOrder); + goto Exit; + } } if (CompareMem (&NewBmmData->BootTimeOut, &OldBmmData->BootTimeOut, sizeof (NewBmmData->BootTimeOut)) != 0){ @@ -667,8 +882,10 @@ BootMaintRouteConfig ( sizeof(UINT16), &(NewBmmData->BootTimeOut) ); - ASSERT_EFI_ERROR(Status); - + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootTimeOut); + goto Exit; + } Private->BmmOldFakeNVData.BootTimeOut = NewBmmData->BootTimeOut; } @@ -685,15 +902,27 @@ BootMaintRouteConfig ( NewBmmData->DriverOptionDel[Index] = FALSE; NewBmmData->DriverOptionDelMark[Index] = FALSE; } - Var_DelDriverOption (); + Status = Var_DelDriverOption (); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, DriverOptionDel); + goto Exit; + } } if (CompareMem (NewBmmData->DriverOptionOrder, OldBmmData->DriverOptionOrder, sizeof (NewBmmData->DriverOptionOrder)) != 0) { Status = Var_UpdateDriverOrder (Private); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, DriverOptionOrder); + goto Exit; + } } if (CompareMem (&NewBmmData->ConsoleOutMode, &OldBmmData->ConsoleOutMode, sizeof (NewBmmData->ConsoleOutMode)) != 0){ - Var_UpdateConMode(Private); + Status = Var_UpdateConMode(Private); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, ConsoleOutMode); + goto Exit; + } } TerminalAttChange = FALSE; @@ -711,83 +940,60 @@ BootMaintRouteConfig ( continue; } - NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); - ASSERT (NewMenuEntry != NULL); - NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; - NewTerminalContext->BaudRateIndex = NewBmmData->COMBaudRate[Index]; - ASSERT (NewBmmData->COMBaudRate[Index] < (sizeof (BaudRateList) / sizeof (BaudRateList[0]))); - NewTerminalContext->BaudRate = BaudRateList[NewBmmData->COMBaudRate[Index]].Value; - NewTerminalContext->DataBitsIndex = NewBmmData->COMDataRate[Index]; - ASSERT (NewBmmData->COMDataRate[Index] < (sizeof (DataBitsList) / sizeof (DataBitsList[0]))); - NewTerminalContext->DataBits = (UINT8) DataBitsList[NewBmmData->COMDataRate[Index]].Value; - NewTerminalContext->StopBitsIndex = NewBmmData->COMStopBits[Index]; - ASSERT (NewBmmData->COMStopBits[Index] < (sizeof (StopBitsList) / sizeof (StopBitsList[0]))); - NewTerminalContext->StopBits = (UINT8) StopBitsList[NewBmmData->COMStopBits[Index]].Value; - NewTerminalContext->ParityIndex = NewBmmData->COMParity[Index]; - ASSERT (NewBmmData->COMParity[Index] < (sizeof (ParityList) / sizeof (ParityList[0]))); - NewTerminalContext->Parity = (UINT8) ParityList[NewBmmData->COMParity[Index]].Value; - NewTerminalContext->TerminalType = NewBmmData->COMTerminalType[Index]; - NewTerminalContext->FlowControl = NewBmmData->COMFlowControl[Index]; - ChangeTerminalDevicePath ( - NewTerminalContext->DevicePath, - FALSE - ); TerminalAttChange = TRUE; } if (TerminalAttChange) { - Var_UpdateConsoleInpOption (); - Var_UpdateConsoleOutOption (); - Var_UpdateErrorOutOption (); + if (CompareMem (&NewBmmData->COMBaudRate[Index], &OldBmmData->COMBaudRate[Index], sizeof (NewBmmData->COMBaudRate[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMBaudRate); + } else if (CompareMem (&NewBmmData->COMDataRate[Index], &OldBmmData->COMDataRate[Index], sizeof (NewBmmData->COMDataRate[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMDataRate); + } else if (CompareMem (&NewBmmData->COMStopBits[Index], &OldBmmData->COMStopBits[Index], sizeof (NewBmmData->COMStopBits[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMStopBits); + } else if (CompareMem (&NewBmmData->COMParity[Index], &OldBmmData->COMParity[Index], sizeof (NewBmmData->COMParity[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMParity); + } else if (CompareMem (&NewBmmData->COMTerminalType[Index], &OldBmmData->COMTerminalType[Index], sizeof (NewBmmData->COMTerminalType[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMTerminalType); + } else if (CompareMem (&NewBmmData->COMFlowControl[Index], &OldBmmData->COMFlowControl[Index], sizeof (NewBmmData->COMFlowControl[Index])) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, COMFlowControl); + } + Status = Var_UpdateConsoleInpOption (); + if (EFI_ERROR (Status)) { + goto Exit; + } + Status = Var_UpdateConsoleOutOption (); + if (EFI_ERROR (Status)) { + goto Exit; + } + Status = Var_UpdateErrorOutOption (); + if (EFI_ERROR (Status)) { + goto Exit; + } } // // Check data which located in Console Options Menu and save the settings if need // if (CompareMem (NewBmmData->ConsoleInCheck, OldBmmData->ConsoleInCheck, sizeof (NewBmmData->ConsoleInCheck)) != 0){ - for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++){ - NewMenuEntry = BOpt_GetMenuEntry(&ConsoleInpMenu, Index); - NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; - ASSERT (Index < MAX_MENU_NUMBER); - NewConsoleContext->IsActive = NewBmmData->ConsoleInCheck[Index]; - } - for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { - NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); - NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; - ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER); - NewTerminalContext->IsConIn = NewBmmData->ConsoleInCheck[Index + ConsoleInpMenu.MenuNumber]; + Status = Var_UpdateConsoleInpOption(); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, ConsoleInCheck); + goto Exit; } - Var_UpdateConsoleInpOption(); } if (CompareMem (NewBmmData->ConsoleOutCheck, OldBmmData->ConsoleOutCheck, sizeof (NewBmmData->ConsoleOutCheck)) != 0){ - for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++){ - NewMenuEntry = BOpt_GetMenuEntry(&ConsoleOutMenu, Index); - NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; - ASSERT (Index < MAX_MENU_NUMBER); - NewConsoleContext->IsActive = NewBmmData->ConsoleOutCheck[Index]; - } - for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { - NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); - NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; - ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER); - NewTerminalContext->IsConOut = NewBmmData->ConsoleOutCheck[Index + ConsoleOutMenu.MenuNumber]; + Status = Var_UpdateConsoleOutOption(); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, ConsoleOutCheck); + goto Exit; } - Var_UpdateConsoleOutOption(); } if (CompareMem (NewBmmData->ConsoleErrCheck, OldBmmData->ConsoleErrCheck, sizeof (NewBmmData->ConsoleErrCheck)) != 0){ - for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++){ - NewMenuEntry = BOpt_GetMenuEntry(&ConsoleErrMenu, Index); - NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; - ASSERT (Index < MAX_MENU_NUMBER); - NewConsoleContext->IsActive = NewBmmData->ConsoleErrCheck[Index]; - } - for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { - NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); - NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; - ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER); - NewTerminalContext->IsStdErr = NewBmmData->ConsoleErrCheck[Index + ConsoleErrMenu.MenuNumber]; + Status = Var_UpdateErrorOutOption(); + if (EFI_ERROR (Status)) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, ConsoleErrCheck); + goto Exit; } - Var_UpdateErrorOutOption(); } if (CompareMem (NewBmmData->BootDescriptionData, OldBmmData->BootDescriptionData, sizeof (NewBmmData->BootDescriptionData)) != 0 || @@ -795,7 +1001,12 @@ BootMaintRouteConfig ( Status = Var_UpdateBootOption (Private); NewBmmData->BootOptionChanged = FALSE; if (EFI_ERROR (Status)) { - return Status; + if (CompareMem (NewBmmData->BootDescriptionData, OldBmmData->BootDescriptionData, sizeof (NewBmmData->BootDescriptionData)) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootDescriptionData); + } else { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, BootOptionalData); + } + goto Exit; } BOpt_GetBootOptions (Private); } @@ -812,7 +1023,12 @@ BootMaintRouteConfig ( NewBmmData->DriverOptionChanged = FALSE; NewBmmData->ForceReconnect = TRUE; if (EFI_ERROR (Status)) { - return Status; + if (CompareMem (NewBmmData->DriverDescriptionData, OldBmmData->DriverDescriptionData, sizeof (NewBmmData->DriverDescriptionData)) != 0) { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, DriverDescriptionData); + } else { + Offset = OFFSET_OF (BMM_FAKE_NV_DATA, DriverOptionalData); + } + goto Exit; } BOpt_GetDriverOptions (Private); @@ -824,6 +1040,17 @@ BootMaintRouteConfig ( CopyMem (OldBmmData, NewBmmData, sizeof (BMM_FAKE_NV_DATA)); return EFI_SUCCESS; + +Exit: + // + // Fail to save the data, update the progress string. + // + *Progress = UpdateProgress (Offset, Configuration); + if (Status == EFI_OUT_OF_RESOURCES) { + return Status; + } else { + return EFI_NOT_FOUND; + } } /** @@ -858,27 +1085,43 @@ BootMaintCallback ( BMM_CALLBACK_DATA *Private; BM_MENU_ENTRY *NewMenuEntry; BMM_FAKE_NV_DATA *CurrentFakeNVMap; - UINTN OldValue; - UINTN NewValue; - UINTN Number; + BMM_FAKE_NV_DATA *OldFakeNVMap; UINTN Index; EFI_DEVICE_PATH_PROTOCOL * File; - if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) { + if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED && Action != EFI_BROWSER_ACTION_FORM_OPEN) { // - // Do nothing for other UEFI Action. Only do call back when data is changed. + // Do nothing for other UEFI Action. Only do call back when data is changed or the form is open. // return EFI_UNSUPPORTED; } - OldValue = 0; - NewValue = 0; - Number = 0; Private = BMM_CALLBACK_DATA_FROM_THIS (This); + + if (Action == EFI_BROWSER_ACTION_FORM_OPEN) { + if (QuestionId == KEY_VALUE_TRIGGER_FORM_OPEN_ACTION) { + if (!mFirstEnterBMMForm) { + // + // BMMUiLib depends on LegacyUi library to show legacy menus. + // If we want to show Legacy menus correctly in BMM page, + // we must do it after the LegacyUi library has already been initialized. + // Opening the BMM form is the appropriate time that the LegacyUi library has already been initialized. + // So we do the tasks which are related to legacy menus here. + // 1. Update the menus (including legacy munu) show in BootMiantenanceManager page. + // 2. Re-scan the BootOption menus (including the legacy boot option). + // + CustomizeMenus (); + EfiBootManagerRefreshAllBootOption (); + BOpt_GetBootOptions (Private); + mFirstEnterBMMForm = TRUE; + } + } + } // - // Retrive uncommitted data from Form Browser + // Retrieve uncommitted data from Form Browser // CurrentFakeNVMap = &Private->BmmFakeNvData; + OldFakeNVMap = &Private->BmmOldFakeNVData; HiiGetBrowserData (&mBootMaintGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap); if (Action == EFI_BROWSER_ACTION_CHANGING) { @@ -893,12 +1136,12 @@ BootMaintCallback ( switch (QuestionId) { case FORM_BOOT_ADD_ID: // Leave BMM and enter FileExplorer. - ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) CreateBootOptionFromFile, &File); + ChooseFile (NULL, L".efi", CreateBootOptionFromFile, &File); break; case FORM_DRV_ADD_FILE_ID: // Leave BMM and enter FileExplorer. - ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) CreateDriverOptionFromFile, &File); + ChooseFile (NULL, L".efi", CreateDriverOptionFromFile, &File); break; case FORM_DRV_ADD_HANDLE_ID: @@ -921,16 +1164,6 @@ BootMaintCallback ( UpdateDrvDelPage (Private); break; - case FORM_BOOT_NEXT_ID: - CleanUpPage (FORM_BOOT_NEXT_ID, Private); - UpdateBootNextPage (Private); - break; - - case FORM_TIME_OUT_ID: - CleanUpPage (FORM_TIME_OUT_ID, Private); - UpdateTimeOutPage (Private); - break; - case FORM_CON_IN_ID: case FORM_CON_OUT_ID: case FORM_CON_ERR_ID: @@ -974,7 +1207,7 @@ BootMaintCallback ( } if (QuestionId == KEY_VALUE_BOOT_FROM_FILE){ // Leave BMM and enter FileExplorer. - ChooseFile( NULL, L".efi", (CHOOSE_HANDLER) BootFromFile, &File); + ChooseFile (NULL, L".efi", BootFromFile, &File); } } else if (Action == EFI_BROWSER_ACTION_CHANGED) { if ((Value == NULL) || (ActionRequest == NULL)) { @@ -982,17 +1215,21 @@ BootMaintCallback ( } if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT) { + CleanUselessBeforeSubmit (Private); CurrentFakeNVMap->BootOptionChanged = FALSE; *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; } else if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) { + CleanUselessBeforeSubmit (Private); CurrentFakeNVMap->DriverOptionChanged = FALSE; *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) { // // Discard changes and exit formset // - CurrentFakeNVMap->DriverOptionalData[0] = 0x0000; - CurrentFakeNVMap->DriverDescriptionData[0] = 0x0000; + ZeroMem (CurrentFakeNVMap->DriverOptionalData, sizeof (CurrentFakeNVMap->DriverOptionalData)); + ZeroMem (CurrentFakeNVMap->BootDescriptionData, sizeof (CurrentFakeNVMap->BootDescriptionData)); + ZeroMem (OldFakeNVMap->DriverOptionalData, sizeof (OldFakeNVMap->DriverOptionalData)); + ZeroMem (OldFakeNVMap->DriverDescriptionData, sizeof (OldFakeNVMap->DriverDescriptionData)); CurrentFakeNVMap->DriverOptionChanged = FALSE; CurrentFakeNVMap->ForceReconnect = TRUE; *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT; @@ -1000,8 +1237,10 @@ BootMaintCallback ( // // Discard changes and exit formset // - CurrentFakeNVMap->BootOptionalData[0] = 0x0000; - CurrentFakeNVMap->BootDescriptionData[0] = 0x0000; + ZeroMem (CurrentFakeNVMap->BootOptionalData, sizeof (CurrentFakeNVMap->BootOptionalData)); + ZeroMem (CurrentFakeNVMap->BootDescriptionData, sizeof (CurrentFakeNVMap->BootDescriptionData)); + ZeroMem (OldFakeNVMap->BootOptionalData, sizeof (OldFakeNVMap->BootOptionalData)); + ZeroMem (OldFakeNVMap->BootDescriptionData, sizeof (OldFakeNVMap->BootDescriptionData)); CurrentFakeNVMap->BootOptionChanged = FALSE; *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT; } else if (QuestionId == KEY_VALUE_BOOT_DESCRIPTION || QuestionId == KEY_VALUE_BOOT_OPTION) { @@ -1033,6 +1272,7 @@ BootMaintCallback ( case KEY_VALUE_SAVE_AND_EXIT: case KEY_VALUE_NO_SAVE_AND_EXIT: if (QuestionId == KEY_VALUE_SAVE_AND_EXIT) { + CleanUselessBeforeSubmit (Private); *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT) { DiscardChangeHandler (Private, CurrentFakeNVMap); @@ -1049,6 +1289,22 @@ BootMaintCallback ( break; } } + // + // Update the content in Terminal menu and Console menu here. + // + if (QuestionId == COM_BAUD_RATE_QUESTION_ID + Private->CurrentTerminal || QuestionId == COM_DATA_RATE_QUESTION_ID + Private->CurrentTerminal || + QuestionId == COM_PARITY_QUESTION_ID + Private->CurrentTerminal || QuestionId == COM_STOP_BITS_QUESTION_ID + Private->CurrentTerminal || + QuestionId == COM_TERMINAL_QUESTION_ID + Private->CurrentTerminal || QuestionId == COM_FLOWCONTROL_QUESTION_ID + Private->CurrentTerminal + ) { + UpdateTerminalContent(CurrentFakeNVMap); + } + if ((QuestionId >= CON_IN_DEVICE_QUESTION_ID) && (QuestionId < CON_IN_DEVICE_QUESTION_ID + MAX_MENU_NUMBER)) { + UpdateConsoleContent (L"ConIn",CurrentFakeNVMap); + } else if ((QuestionId >= CON_OUT_DEVICE_QUESTION_ID) && (QuestionId < CON_OUT_DEVICE_QUESTION_ID + MAX_MENU_NUMBER)) { + UpdateConsoleContent (L"ConOut", CurrentFakeNVMap); + } else if ((QuestionId >= CON_ERR_DEVICE_QUESTION_ID) && (QuestionId < CON_ERR_DEVICE_QUESTION_ID + MAX_MENU_NUMBER)) { + UpdateConsoleContent (L"ErrOut", CurrentFakeNVMap); + } } // @@ -1119,42 +1375,50 @@ DiscardChangeHandler ( } /** - Create dynamic code for BMM. + This function is to clean some useless data before submit changes. - @param BmmCallbackInfo The BMM context data. + @param Private The BMM context data. **/ VOID -InitializeDrivers( - IN BMM_CALLBACK_DATA *BmmCallbackInfo +CleanUselessBeforeSubmit ( + IN BMM_CALLBACK_DATA *Private + ) +{ + UINT16 Index; + if (Private->BmmPreviousPageId != FORM_BOOT_DEL_ID) { + for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { + if (Private->BmmFakeNvData.BootOptionDel[Index] && !Private->BmmFakeNvData.BootOptionDelMark[Index]) { + Private->BmmFakeNvData.BootOptionDel[Index] = FALSE; + Private->BmmOldFakeNVData.BootOptionDel[Index] = FALSE; + } + } + } + if (Private->BmmPreviousPageId != FORM_DRV_DEL_ID) { + for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { + if (Private->BmmFakeNvData.DriverOptionDel[Index] && !Private->BmmFakeNvData.DriverOptionDelMark[Index]) { + Private->BmmFakeNvData.DriverOptionDel[Index] = FALSE; + Private->BmmOldFakeNVData.DriverOptionDel[Index] = FALSE; + } + } + } +} + +/** + + Update the menus in the BMM page. + +**/ +VOID +CustomizeMenus ( + VOID ) { - EFI_HII_HANDLE HiiHandle; VOID *StartOpCodeHandle; VOID *EndOpCodeHandle; - EFI_IFR_GUID_LABEL *StartLabel; - EFI_IFR_GUID_LABEL *EndLabel; - UINTN Index; - EFI_STRING String; - EFI_STRING_ID Token; - EFI_STRING_ID TokenHelp; - EFI_HII_HANDLE *HiiHandles; - EFI_GUID FormSetGuid; - CHAR16 *DevicePathStr; - EFI_STRING_ID DevicePathId; - EFI_IFR_FORM_SET *Buffer; - UINTN BufferSize; - UINT8 ClassGuidNum; - EFI_GUID *ClassGuid; - UINTN TempSize; - UINT8 *Ptr; - EFI_STATUS Status; - - TempSize =0; - BufferSize = 0; - Buffer = NULL; - - HiiHandle = BmmCallbackInfo->BmmHiiHandle; + EFI_IFR_GUID_LABEL *StartGuidLabel; + EFI_IFR_GUID_LABEL *EndGuidLabel; + // // Allocate space for creation of UpdateData Buffer // @@ -1163,104 +1427,29 @@ InitializeDrivers( EndOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (EndOpCodeHandle != NULL); - // // Create Hii Extend Label OpCode as the start opcode // - StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartLabel->Number = LABEL_BMM_PLATFORM_INFORMATION; - + StartGuidLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartGuidLabel->Number = LABEL_FORM_MAIN_START; // // Create Hii Extend Label OpCode as the end opcode // - EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndLabel->Number = LABEL_END; - - // - // Get all the Hii handles - // - HiiHandles = HiiGetHiiHandles (NULL); - ASSERT (HiiHandles != NULL); + EndGuidLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndGuidLabel->Number = LABEL_FORM_MAIN_END; // - // Search for formset of each class type + //Updata Front Page form // - for (Index = 0; HiiHandles[Index] != NULL; Index++) { - Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize); - if (EFI_ERROR (Status)) { - continue; - } - - Ptr = (UINT8 *)Buffer; - while(TempSize < BufferSize) { - TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length; - - if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){ - Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length; - continue; - } - - // - // Find FormSet OpCode - // - ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3); - ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET)); - while (ClassGuidNum-- > 0) { - if (CompareGuid (&gEfiIfrBootMaintenanceGuid, ClassGuid) == 0){ - ClassGuid ++; - continue; - } - - String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } - Token = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); - - String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } - TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); - - FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid; - - DevicePathStr = BmmExtractDevicePathFromHiiHandle(HiiHandles[Index]); - DevicePathId = 0; - if (DevicePathStr != NULL){ - DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); - FreePool (DevicePathStr); - } - HiiCreateGotoExOpCode ( - StartOpCodeHandle, - 0, - Token, - TokenHelp, - 0, - (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_OFFSET), - 0, - &FormSetGuid, - DevicePathId - ); - break; - } - Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length; - } + UiCustomizeBMMPage ( + mBmmCallbackInfo->BmmHiiHandle, + StartOpCodeHandle + ); - FreePool(Buffer); - Buffer = NULL; - TempSize = 0; - BufferSize = 0; - } - HiiUpdateForm ( - HiiHandle, + mBmmCallbackInfo->BmmHiiHandle, &mBootMaintGuid, FORM_MAIN_ID, StartOpCodeHandle, @@ -1268,8 +1457,7 @@ InitializeDrivers( ); HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); - FreePool (HiiHandles); + HiiFreeOpCodeHandle (EndOpCodeHandle); } /** @@ -1290,8 +1478,6 @@ InitializeBmmConfig ( ASSERT (CallbackData != NULL); - InitializeDrivers (CallbackData); - // // Initialize data which located in BMM main page // @@ -1379,6 +1565,77 @@ FreeAllMenu ( mAllMenuInit = FALSE; } +/** + Initial the boot mode related parameters. + +**/ +VOID +BmmInitialBootModeInfo ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; + UINTN BootTextColumn; + UINTN BootTextRow; + + if (mBmmModeInitialized) { + return; + } + + // + // After the console is ready, get current video resolution + // and text mode before launching setup at first time. + // + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID**)&GraphicsOutput + ); + if (EFI_ERROR (Status)) { + GraphicsOutput = NULL; + } + + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiSimpleTextOutProtocolGuid, + (VOID**)&SimpleTextOut + ); + if (EFI_ERROR (Status)) { + SimpleTextOut = NULL; + } + + if (GraphicsOutput != NULL) { + // + // Get current video resolution and text mode. + // + mBmmBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution; + mBmmBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution; + } + + if (SimpleTextOut != NULL) { + Status = SimpleTextOut->QueryMode ( + SimpleTextOut, + SimpleTextOut->Mode->Mode, + &BootTextColumn, + &BootTextRow + ); + mBmmBootTextModeColumn = (UINT32)BootTextColumn; + mBmmBootTextModeRow = (UINT32)BootTextRow; + } + + // + // Get user defined text mode for setup. + // + mBmmSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution); + mBmmSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution); + mBmmSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn); + mBmmSetupTextModeRow = PcdGet32 (PcdSetupConOutRow); + + mBmmModeInitialized = TRUE; +} + /** Install Boot Maintenance Manager Menu driver. @@ -1434,8 +1691,6 @@ BootMaintenanceManagerUiLibConstructor ( Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mBmmCallbackInfo->FormBrowser2); ASSERT_EFI_ERROR (Status); - EfiBootManagerRefreshAllBootOption (); - // // Create LoadOption in BmmCallbackInfo for Driver Callback // @@ -1467,6 +1722,8 @@ BootMaintenanceManagerUiLibConstructor ( // InitializeBmmConfig(mBmmCallbackInfo); + BmmInitialBootModeInfo(); + return EFI_SUCCESS; }