X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FSetup.c;h=ed904161b619dd538b8ce296c83764791da2f225;hb=0a6f8af50ddc87a47e3fa38d7449fcae26ab1f5d;hp=381cefeae5937690e40442d22a4175b9486fefcb;hpb=826120239506ccaf7a8603560b79cf341f2d3bd5;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 381cefeae5..ed904161b6 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -1,7 +1,7 @@ /** @file Entry and initialization module for the browser. -Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2013, 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 @@ -32,11 +32,13 @@ SETUP_DRIVER_PRIVATE_DATA mPrivateData = { EFI_HII_DATABASE_PROTOCOL *mHiiDatabase; EFI_HII_STRING_PROTOCOL *mHiiString; EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting; +EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mPathFromText; UINTN gBrowserContextCount = 0; LIST_ENTRY gBrowserContextList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList); LIST_ENTRY gBrowserFormSetList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserFormSetList); LIST_ENTRY gBrowserHotKeyList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserHotKeyList); +LIST_ENTRY gBrowserStorageList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserStorageList); BANNER_DATA *gBannerData; EFI_HII_HANDLE gFrontPageHandle; @@ -84,6 +86,7 @@ CHAR16 *gAdjustNumber; CHAR16 *gSaveChanges; CHAR16 *gOptionMismatch; CHAR16 *gFormSuppress; +CHAR16 *gProtocolNotFound; CHAR16 *mUnknownString = L"!"; @@ -242,6 +245,11 @@ SendForm ( // gFooterHeight = FOOTER_HEIGHT + (Index / 3); + // + // Clean the history menu list. + // + InitializeListHead (&gMenuList); + // // Save globals used by SendForm() // @@ -303,8 +311,6 @@ SendForm ( // InitializeBrowserStrings (); - gFunctionKeySetting = ENABLE_FUNCTION_KEY_SETTING; - // // Ensure we are in Text mode // @@ -361,6 +367,7 @@ SendForm ( // If no data is changed, don't need to save current FormSet into the maintain list. // if (!IsNvUpdateRequired (gOldFormSet)) { + CleanBrowserStorage(gOldFormSet); RemoveEntryList (&gOldFormSet->Link); DestroyFormSet (gOldFormSet); } @@ -378,6 +385,7 @@ SendForm ( } FreeBrowserStrings (); + UiFreeMenuList(&gMenuList); gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK)); gST->ConOut->ClearScreen (gST->ConOut); @@ -469,9 +477,9 @@ BrowserCallback ( Storage = FORMSET_STORAGE_FROM_LINK (Link); Link = GetNextNode (&FormSet->StorageListHead, Link); - if (CompareGuid (&Storage->Guid, (EFI_GUID *) VariableGuid)) { - if (Storage->Type == EFI_HII_VARSTORE_BUFFER || - Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { + if (CompareGuid (&Storage->BrowserStorage->Guid, (EFI_GUID *) VariableGuid)) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_BUFFER || + Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { // // Buffer storage require both GUID and Name // @@ -479,7 +487,7 @@ BrowserCallback ( return EFI_NOT_FOUND; } - if (StrCmp (Storage->Name, (CHAR16 *) VariableName) != 0) { + if (StrCmp (Storage->BrowserStorage->Name, (CHAR16 *) VariableName) != 0) { continue; } } @@ -509,7 +517,7 @@ BrowserCallback ( // // Generate // - Status = StorageToConfigResp (Storage, &ConfigResp, FALSE); + Status = StorageToConfigResp (Storage->BrowserStorage, &ConfigResp, Storage->ConfigRequest); if (EFI_ERROR (Status)) { return Status; } @@ -517,7 +525,7 @@ BrowserCallback ( // // Skip and '&' to point to // - StrPtr = ConfigResp + StrLen (Storage->ConfigHdr) + 1; + StrPtr = ConfigResp + StrLen (Storage->BrowserStorage->ConfigHdr) + 1; BufferSize = StrSize (StrPtr); if (*ResultsDataSize < BufferSize) { @@ -536,18 +544,18 @@ BrowserCallback ( // Prepare // TmpSize = StrLen (ResultsData); - BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16); + BufferSize = (TmpSize + StrLen (Storage->BrowserStorage->ConfigHdr) + 2) * sizeof (CHAR16); ConfigResp = AllocateZeroPool (BufferSize); ASSERT (ConfigResp != NULL); - StrCpy (ConfigResp, Storage->ConfigHdr); + StrCpy (ConfigResp, Storage->BrowserStorage->ConfigHdr); StrCat (ConfigResp, L"&"); StrCat (ConfigResp, ResultsData); // // Update Browser uncommited data // - Status = ConfigRespToStorage (Storage, ConfigResp); + Status = ConfigRespToStorage (Storage->BrowserStorage, ConfigResp); if (EFI_ERROR (Status)) { return Status; } @@ -556,66 +564,6 @@ BrowserCallback ( return EFI_SUCCESS; } -/** - Notify function will remove the formset in the maintain list - once this formset is removed. - - Functions which are registered to receive notification of - database events have this prototype. The actual event is encoded - in NotifyType. The following table describes how PackageType, - PackageGuid, Handle, and Package are used for each of the - notification types. - - @param PackageType Package type of the notification. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID from the Guid - field of EFI_HII_PACKAGE_GUID_HEADER. - Otherwise, it must be NULL. - - @param Package Points to the package referred to by the - notification Handle The handle of the package - list which contains the specified package. - - @param Handle The HII handle. - - @param NotifyType The type of change concerning the - database. See - EFI_HII_DATABASE_NOTIFY_TYPE. - -**/ -EFI_STATUS -EFIAPI -FormsetRemoveNotify ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN CONST EFI_HII_PACKAGE_HEADER *Package, - IN EFI_HII_HANDLE Handle, - IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType - ) -{ - FORM_BROWSER_FORMSET *FormSet; - - // - // Ignore the update for current using formset, which is handled by another notify function. - // - if (IsHiiHandleInBrowserContext (Handle)) { - return EFI_SUCCESS; - } - - // - // Remove the backup FormSet data when the Form Package is removed. - // - FormSet = GetFormSetFromHiiHandle (Handle); - if (FormSet != NULL) { - RemoveEntryList (&FormSet->Link); - DestroyFormSet (FormSet); - } - - return EFI_SUCCESS; -} - /** Initialize Setup Browser driver. @@ -634,7 +582,6 @@ InitializeSetup ( ) { EFI_STATUS Status; - EFI_HANDLE NotifyHandle; EFI_INPUT_KEY DefaultHotKey; EFI_STRING HelpString; @@ -662,6 +609,12 @@ InitializeSetup ( ); ASSERT_EFI_ERROR (Status); + Status = gBS->LocateProtocol ( + &gEfiDevicePathFromTextProtocolGuid, + NULL, + (VOID **) &mPathFromText + ); + // // Publish our HII data // @@ -726,19 +679,6 @@ InitializeSetup ( ); ASSERT_EFI_ERROR (Status); - // - // Register notify for Form package remove - // - Status = mHiiDatabase->RegisterPackageNotify ( - mHiiDatabase, - EFI_HII_PACKAGE_FORMS, - NULL, - FormsetRemoveNotify, - EFI_HII_DATABASE_NOTIFY_REMOVE_PACK, - &NotifyHandle - ); - ASSERT_EFI_ERROR (Status); - return Status; } @@ -888,7 +828,7 @@ NewStringCat ( **/ VOID SynchronizeStorage ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN BOOLEAN SyncOrRestore ) { @@ -941,7 +881,7 @@ SynchronizeStorage ( **/ EFI_STATUS GetValueByName ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN CHAR16 *Name, IN OUT CHAR16 **Value, IN GET_SET_QUESTION_VALUE_WITH GetValueFrom @@ -990,7 +930,7 @@ GetValueByName ( **/ EFI_STATUS SetValueByName ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN CHAR16 *Name, IN CHAR16 *Value, IN GET_SET_QUESTION_VALUE_WITH SetValueTo @@ -1037,9 +977,9 @@ SetValueByName ( /** Convert setting of Buffer Storage or NameValue Storage to . - @param Buffer The Storage to be conveted. + @param Storage The Storage to be conveted. @param ConfigResp The returned . - @param SingleForm Whether update data for single form or formset level. + @param ConfigRequest The ConfigRequest string. @retval EFI_SUCCESS Convert success. @retval EFI_INVALID_PARAMETER Incorrect storage type. @@ -1047,28 +987,17 @@ SetValueByName ( **/ EFI_STATUS StorageToConfigResp ( - IN VOID *Buffer, + IN BROWSER_STORAGE *Storage, IN CHAR16 **ConfigResp, - IN BOOLEAN SingleForm + IN CHAR16 *ConfigRequest ) { - EFI_STATUS Status; - EFI_STRING Progress; + EFI_STATUS Status; + EFI_STRING Progress; LIST_ENTRY *Link; NAME_VALUE_NODE *Node; - CHAR16 *ConfigRequest; - FORMSET_STORAGE *Storage; - FORM_BROWSER_CONFIG_REQUEST *ConfigInfo; Status = EFI_SUCCESS; - if (SingleForm) { - ConfigInfo = (FORM_BROWSER_CONFIG_REQUEST *) Buffer; - Storage = ConfigInfo->Storage; - ConfigRequest = ConfigInfo->ConfigRequest; - } else { - Storage = (FORMSET_STORAGE *) Buffer; - ConfigRequest = Storage->ConfigRequest; - } switch (Storage->Type) { case EFI_HII_VARSTORE_BUFFER: @@ -1123,7 +1052,7 @@ StorageToConfigResp ( **/ EFI_STATUS ConfigRespToStorage ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN CHAR16 *ConfigResp ) { @@ -1215,7 +1144,7 @@ GetQuestionValue ( UINT8 *Dst; UINTN StorageWidth; EFI_TIME EfiTime; - FORMSET_STORAGE *Storage; + BROWSER_STORAGE *Storage; EFI_IFR_TYPE_VALUE *QuestionValue; CHAR16 *ConfigRequest; CHAR16 *Progress; @@ -1640,7 +1569,7 @@ SetQuestionValue ( EFI_TIME EfiTime; UINTN BufferLen; UINTN StorageWidth; - FORMSET_STORAGE *Storage; + BROWSER_STORAGE *Storage; EFI_IFR_TYPE_VALUE *QuestionValue; CHAR16 *ConfigResp; CHAR16 *Progress; @@ -2250,6 +2179,53 @@ SendDiscardInfoToDriver ( } } +/** + Validate the FormSet. If the formset is not validate, remove it from the list. + + @param FormSet The input FormSet which need to validate. + + @retval TRUE The handle is validate. + @retval FALSE The handle is invalidate. + +**/ +BOOLEAN +ValidateFormSet ( + FORM_BROWSER_FORMSET *FormSet + ) +{ + EFI_HII_HANDLE *HiiHandles; + UINTN Index; + BOOLEAN Find; + + ASSERT (FormSet != NULL); + Find = FALSE; + // + // Get all the Hii handles + // + HiiHandles = HiiGetHiiHandles (NULL); + ASSERT (HiiHandles != NULL); + + // + // Search for formset of each class type + // + for (Index = 0; HiiHandles[Index] != NULL; Index++) { + if (HiiHandles[Index] == FormSet->HiiHandle) { + Find = TRUE; + break; + } + } + + if (!Find) { + CleanBrowserStorage(FormSet); + RemoveEntryList (&FormSet->Link); + DestroyFormSet (FormSet); + } + + FreePool (HiiHandles); + + return Find; +} + /** Discard data based on the input setting scope (Form, FormSet or System). @@ -2320,7 +2296,7 @@ DiscardForm ( Storage = FORMSET_STORAGE_FROM_LINK (Link); Link = GetNextNode (&FormSet->StorageListHead, Link); - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { continue; } @@ -2331,7 +2307,7 @@ DiscardForm ( continue; } - SynchronizeStorage(Storage, FALSE); + SynchronizeStorage(Storage->BrowserStorage, FALSE); } Link = GetFirstNode (&FormSet->FormListHead); @@ -2357,12 +2333,16 @@ DiscardForm ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - DiscardForm (LocalFormSet, NULL, FormSetLevel); Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + DiscardForm (LocalFormSet, NULL, FormSetLevel); if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { // // Remove maintain backup list after discard except for the current using FormSet. // + CleanBrowserStorage(LocalFormSet); RemoveEntryList (&LocalFormSet->Link); DestroyFormSet (LocalFormSet); } @@ -2394,7 +2374,8 @@ SubmitForm ( LIST_ENTRY *Link; EFI_STRING ConfigResp; EFI_STRING Progress; - FORMSET_STORAGE *Storage; + BROWSER_STORAGE *Storage; + FORMSET_STORAGE *FormSetStorage; UINTN BufferSize; UINT8 *TmpBuf; FORM_BROWSER_FORMSET *LocalFormSet; @@ -2442,7 +2423,7 @@ SubmitForm ( // // 1. Prepare // - Status = StorageToConfigResp (ConfigInfo, &ConfigResp, TRUE); + Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest); if (EFI_ERROR (Status)) { return Status; } @@ -2531,7 +2512,8 @@ SubmitForm ( // Link = GetFirstNode (&FormSet->StorageListHead); while (!IsNull (&FormSet->StorageListHead, Link)) { - Storage = FORMSET_STORAGE_FROM_LINK (Link); + FormSetStorage = (FORMSET_STORAGE_FROM_LINK (Link)); + Storage = FormSetStorage->BrowserStorage; Link = GetNextNode (&FormSet->StorageListHead, Link); if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { @@ -2541,14 +2523,14 @@ SubmitForm ( // // Skip if there is no RequestElement // - if (Storage->ElementCount == 0) { + if (FormSetStorage->ElementCount == 0) { continue; } // // 1. Prepare // - Status = StorageToConfigResp (Storage, &ConfigResp, FALSE); + Status = StorageToConfigResp (Storage, &ConfigResp, FormSetStorage->ConfigRequest); if (EFI_ERROR (Status)) { return Status; } @@ -2638,12 +2620,16 @@ SubmitForm ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - SubmitForm (LocalFormSet, NULL, FormSetLevel); Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + SubmitForm (LocalFormSet, NULL, FormSetLevel); if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) { // // Remove maintain backup list after save except for the current using FormSet. // + CleanBrowserStorage(LocalFormSet); RemoveEntryList (&LocalFormSet->Link); DestroyFormSet (LocalFormSet); } @@ -2673,7 +2659,7 @@ GetDefaultValueFromAltCfg ( BOOLEAN IsBufferStorage; BOOLEAN IsString; UINTN Length; - FORMSET_STORAGE *Storage; + BROWSER_STORAGE *Storage; CHAR16 *ConfigRequest; CHAR16 *Progress; CHAR16 *Result; @@ -3161,7 +3147,7 @@ ExtractDefault ( IN UINT16 DefaultId, IN BROWSER_SETTING_SCOPE SettingScope, IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope, - IN FORMSET_STORAGE *Storage OPTIONAL, + IN BROWSER_STORAGE *Storage OPTIONAL, IN BOOLEAN RetrieveValueFirst ) { @@ -3324,8 +3310,11 @@ ExtractDefault ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); } } @@ -3452,200 +3441,405 @@ LoadFormSetConfig ( } /** - Fill storage's edit copy with settings requested from Configuration Driver. + Remove the Request element from the Config Request. - @param FormSet FormSet data structure. - @param Storage Buffer Storage. - - @retval EFI_SUCCESS The function completed successfully. + @param Storage Pointer to the browser storage. + @param RequestElement The pointer to the Request element. **/ -EFI_STATUS -LoadStorage ( - IN FORM_BROWSER_FORMSET *FormSet, - IN FORMSET_STORAGE *Storage +VOID +RemoveElement ( + IN OUT BROWSER_STORAGE *Storage, + IN CHAR16 *RequestElement ) { - EFI_STATUS Status; - EFI_STRING Progress; - EFI_STRING Result; - CHAR16 *StrPtr; + CHAR16 *NewStr; + CHAR16 *DestStr; - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { - return EFI_SUCCESS; - } + ASSERT (Storage->ConfigRequest != NULL && RequestElement != NULL); - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - (UINTN*)&Storage->Size, - Storage->EditBuffer - ); - return Status; - } + NewStr = StrStr (Storage->ConfigRequest, RequestElement); - if (FormSet->ConfigAccess == NULL) { - return EFI_NOT_FOUND; + if (NewStr == NULL) { + return; } - if (Storage->ElementCount == 0) { + // + // Remove this element from this ConfigRequest. + // + DestStr = NewStr; + NewStr += StrLen (RequestElement); + CopyMem (DestStr, NewStr, StrSize (NewStr)); + + Storage->SpareStrLen += StrLen (RequestElement); +} + +/** + Adjust config request in storage, remove the request elements existed in the input ConfigRequest. + + @param Storage Pointer to the browser storage. + @param ConfigRequest The pointer to the Request element. + +**/ +VOID +RemoveConfigRequest ( + BROWSER_STORAGE *Storage, + CHAR16 *ConfigRequest + ) +{ + CHAR16 *RequestElement; + CHAR16 *NextRequestElement; + CHAR16 *SearchKey; + + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // - // Skip if there is no RequestElement + // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage // - return EFI_SUCCESS; + SearchKey = L"&"; + } else { + // + // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage + // + SearchKey = L"&OFFSET"; } // - // Request current settings from Configuration Driver + // Find SearchKey storage // - Status = FormSet->ConfigAccess->ExtractConfig ( - FormSet->ConfigAccess, - Storage->ConfigRequest, - &Progress, - &Result - ); - if (EFI_ERROR (Status)) { - return Status; + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + RequestElement = StrStr (ConfigRequest, L"PATH"); + ASSERT (RequestElement != NULL); + RequestElement = StrStr (RequestElement, SearchKey); + } else { + RequestElement = StrStr (ConfigRequest, SearchKey); + } + + while (RequestElement != NULL) { + // + // +1 to avoid find header itself. + // + NextRequestElement = StrStr (RequestElement + 1, SearchKey); + + // + // The last Request element in configRequest string. + // + if (NextRequestElement != NULL) { + // + // Replace "&" with '\0'. + // + *NextRequestElement = L'\0'; + } + + RemoveElement (Storage, RequestElement); + + if (NextRequestElement != NULL) { + // + // Restore '&' with '\0' for later used. + // + *NextRequestElement = L'&'; + } + + RequestElement = NextRequestElement; } // - // Convert Result from to + // If no request element remain, just remove the ConfigRequest string. // - StrPtr = StrStr (Result, L"ALTCFG"); - if (StrPtr != NULL) { - *StrPtr = L'\0'; + if (StrCmp (Storage->ConfigRequest, Storage->ConfigHdr) == 0) { + FreePool (Storage->ConfigRequest); + Storage->ConfigRequest = NULL; + Storage->SpareStrLen = 0; } - - Status = ConfigRespToStorage (Storage, Result); - FreePool (Result); - return Status; } +/** + Base on the current formset info, clean the ConfigRequest string in browser storage. + + @param FormSet Pointer of the FormSet + +**/ +VOID +CleanBrowserStorage ( + IN OUT FORM_BROWSER_FORMSET *FormSet + ) +{ + LIST_ENTRY *Link; + FORMSET_STORAGE *Storage; + + Link = GetFirstNode (&FormSet->StorageListHead); + while (!IsNull (&FormSet->StorageListHead, Link)) { + Storage = FORMSET_STORAGE_FROM_LINK (Link); + Link = GetNextNode (&FormSet->StorageListHead, Link); + + if ((Storage->BrowserStorage->Type != EFI_HII_VARSTORE_BUFFER) && + (Storage->BrowserStorage->Type != EFI_HII_VARSTORE_NAME_VALUE)) { + continue; + } + + if (Storage->ConfigRequest == NULL || Storage->BrowserStorage->ConfigRequest == NULL) { + continue; + } + + RemoveConfigRequest (Storage->BrowserStorage, Storage->ConfigRequest); + } +} /** - Copy uncommitted data from source Storage to destination Storage. + Check whether current element in the ConfigReqeust string. - @param Dst Target Storage for uncommitted data. - @param Src Source Storage for uncommitted data. + @param BrowserStorage Storage which includes ConfigReqeust. + @param RequestElement New element need to check. - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type. + @retval TRUE The Element is in the ConfigReqeust string. + @retval FALSE The Element not in the configReqeust String. **/ -EFI_STATUS -CopyStorage ( - IN OUT FORMSET_STORAGE *Dst, - IN FORMSET_STORAGE *Src +BOOLEAN +ElementValidation ( + BROWSER_STORAGE *BrowserStorage, + CHAR16 *RequestElement ) { - LIST_ENTRY *Link; - NAME_VALUE_NODE *Node; + return StrStr (BrowserStorage->ConfigRequest, RequestElement) != NULL ? TRUE : FALSE; +} - if ((Dst->Type != Src->Type) || (Dst->Size != Src->Size)) { - return EFI_INVALID_PARAMETER; - } +/** + Append the Request element to the Config Request. - switch (Src->Type) { - case EFI_HII_VARSTORE_BUFFER: - case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER: - CopyMem (Dst->EditBuffer, Src->EditBuffer, Src->Size); - CopyMem (Dst->Buffer, Src->Buffer, Src->Size); - break; + @param ConfigRequest Current ConfigRequest info. + @param SpareStrLen Current remain free buffer for config reqeust. + @param RequestElement New Request element. - case EFI_HII_VARSTORE_NAME_VALUE: - Link = GetFirstNode (&Src->NameValueListHead); - while (!IsNull (&Src->NameValueListHead, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); +**/ +VOID +AppendConfigRequest ( + IN OUT CHAR16 **ConfigRequest, + IN OUT UINTN *SpareStrLen, + IN CHAR16 *RequestElement + ) +{ + CHAR16 *NewStr; + UINTN StringSize; + UINTN StrLength; - SetValueByName (Dst, Node->Name, Node->EditValue, GetSetValueWithEditBuffer); - SetValueByName (Dst, Node->Name, Node->Value, GetSetValueWithBuffer); + StrLength = StrLen (RequestElement); - Link = GetNextNode (&Src->NameValueListHead, Link); - } - break; + // + // Append to + // + if (StrLength > *SpareStrLen) { + // + // Old String buffer is not sufficient for RequestElement, allocate a new one + // + StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof (CHAR16); + NewStr = AllocateZeroPool (StringSize + CONFIG_REQUEST_STRING_INCREMENTAL * sizeof (CHAR16)); + ASSERT (NewStr != NULL); - case EFI_HII_VARSTORE_EFI_VARIABLE: - default: - break; + if (*ConfigRequest != NULL) { + CopyMem (NewStr, *ConfigRequest, StringSize); + FreePool (*ConfigRequest); + } + *ConfigRequest = NewStr; + *SpareStrLen = CONFIG_REQUEST_STRING_INCREMENTAL; } - return EFI_SUCCESS; + StrCat (*ConfigRequest, RequestElement); + *SpareStrLen -= StrLength; } /** - Get old question value from the saved formset. + Adjust the config request info, remove the request elements which already in AllConfigRequest string. - @param Statement The question which need to get old question value. - @param OldFormSet FormSet data structure saved in the list. + @param Storage Form set Storage. + @param ConfigRequest Return the ConfigRequest info. + + @retval TRUE Has element not covered by current used elements, need to continue to call ExtractConfig + @retval FALSE All elements covered by current used elements. **/ -VOID -GetOldQuestionValue ( - IN OUT FORM_BROWSER_STATEMENT *Statement, - IN FORM_BROWSER_FORMSET *OldFormSet +BOOLEAN +ConfigRequestAdjust ( + IN FORMSET_STORAGE *Storage, + OUT CHAR16 **ConfigRequest ) { - LIST_ENTRY *FormLink; - LIST_ENTRY *Link; - FORM_BROWSER_STATEMENT *Question; - FORM_BROWSER_FORM *Form; + CHAR16 *RequestElement; + CHAR16 *NextRequestElement; + CHAR16 *RetBuf; + UINTN SpareBufLen; + CHAR16 *SearchKey; + BOOLEAN RetVal; + + SpareBufLen = 0; + RetBuf = NULL; + RetVal = FALSE; + + if (Storage->BrowserStorage->ConfigRequest == NULL) { + Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); + *ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest); + return TRUE; + } - FormLink = GetFirstNode (&OldFormSet->FormListHead); - while (!IsNull (&OldFormSet->FormListHead, FormLink)) { - Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); - FormLink = GetNextNode (&OldFormSet->FormListHead, FormLink); + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + // + // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage + // + SearchKey = L"&"; + } else { + // + // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage + // + SearchKey = L"&OFFSET"; + } - Link = GetFirstNode (&Form->StatementListHead); - while (!IsNull (&Form->StatementListHead, Link)) { - Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); - Link = GetNextNode (&Form->StatementListHead, Link); + // + // Prepare the config header. + // + RetBuf = AllocateCopyPool(StrSize (Storage->BrowserStorage->ConfigHdr), Storage->BrowserStorage->ConfigHdr); + ASSERT (RetBuf != NULL); - if (Question->QuestionId != Statement->QuestionId) { - continue; - } + // + // Find SearchKey storage + // + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + RequestElement = StrStr (Storage->ConfigRequest, L"PATH"); + ASSERT (RequestElement != NULL); + RequestElement = StrStr (RequestElement, SearchKey); + } else { + RequestElement = StrStr (Storage->ConfigRequest, SearchKey); + } + + while (RequestElement != NULL) { + // + // +1 to avoid find header itself. + // + NextRequestElement = StrStr (RequestElement + 1, SearchKey); + + // + // The last Request element in configRequest string. + // + if (NextRequestElement != NULL) { + // + // Replace "&" with '\0'. + // + *NextRequestElement = L'\0'; + } + + if (!ElementValidation (Storage->BrowserStorage, RequestElement)) { + // + // Add this element to the Storage->BrowserStorage->AllRequestElement. + // + AppendConfigRequest(&Storage->BrowserStorage->ConfigRequest, &Storage->BrowserStorage->SpareStrLen, RequestElement); + AppendConfigRequest (&RetBuf, &SpareBufLen, RequestElement); + RetVal = TRUE; + } - CopyMem (&Statement->HiiValue, &Question->HiiValue, sizeof (EFI_HII_VALUE)); - return; + if (NextRequestElement != NULL) { + // + // Restore '&' with '\0' for later used. + // + *NextRequestElement = L'&'; } + + RequestElement = NextRequestElement; } + + if (RetVal) { + *ConfigRequest = RetBuf; + } else { + FreePool (RetBuf); + } + + return RetVal; } /** - Get old question value from the saved formset, all these questions not have - storage. + Fill storage's edit copy with settings requested from Configuration Driver. + + @param FormSet FormSet data structure. + @param Storage Buffer Storage. - @param FormSet FormSet data structure which is used now. - @param OldFormSet FormSet data structure saved in the list. + @retval EFI_SUCCESS The function completed successfully. **/ -VOID -CopyOldValueForNoStorageQst ( - IN OUT FORM_BROWSER_FORMSET *FormSet, - IN FORM_BROWSER_FORMSET *OldFormSet +EFI_STATUS +LoadStorage ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORMSET_STORAGE *Storage ) { - LIST_ENTRY *FormLink; - LIST_ENTRY *Link; - FORM_BROWSER_STATEMENT *Question; - FORM_BROWSER_FORM *Form; - - FormLink = GetFirstNode (&FormSet->FormListHead); - while (!IsNull (&FormSet->FormListHead, FormLink)) { - Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); - FormLink = GetNextNode (&FormSet->FormListHead, FormLink); + EFI_STATUS Status; + EFI_STRING Progress; + EFI_STRING Result; + CHAR16 *StrPtr; + CHAR16 *ConfigRequest; - Link = GetFirstNode (&Form->StatementListHead); - while (!IsNull (&Form->StatementListHead, Link)) { - Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); - Link = GetNextNode (&Form->StatementListHead, Link); + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + return EFI_SUCCESS; + } - if (Question->Storage == NULL) { - GetOldQuestionValue (Question, OldFormSet); - } + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { + Status = EFI_SUCCESS; + // + // EFI varstore data all get from variable, so no need to get again. + // + if (Storage->BrowserStorage->ReferenceCount == 1) { + Status = gRT->GetVariable ( + Storage->BrowserStorage->Name, + &Storage->BrowserStorage->Guid, + NULL, + (UINTN*)&Storage->BrowserStorage->Size, + Storage->BrowserStorage->EditBuffer + ); } + return Status; + } + + if (FormSet->ConfigAccess == NULL) { + return EFI_NOT_FOUND; + } + + if (Storage->ElementCount == 0) { + // + // Skip if there is no RequestElement + // + return EFI_SUCCESS; + } + + // + // Adjust the ConfigRequest string, only the field not saved in BrowserStorage->AllConfig + // will used to call ExtractConfig. + // + if (!ConfigRequestAdjust(Storage, &ConfigRequest)) { + return EFI_SUCCESS; + } + + // + // Request current settings from Configuration Driver + // + Status = FormSet->ConfigAccess->ExtractConfig ( + FormSet->ConfigAccess, + ConfigRequest, + &Progress, + &Result + ); + FreePool (ConfigRequest); + + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Convert Result from to + // + StrPtr = StrStr (Result, L"&GUID="); + if (StrPtr != NULL) { + *StrPtr = L'\0'; } + + Status = ConfigRespToStorage (Storage->BrowserStorage, Result); + FreePool (Result); + return Status; } /** @@ -3700,17 +3894,18 @@ InitializeCurrentSetting ( } } + // + // Storage is not found in backup formset and current global storage not has other driver used, + // request it from ConfigDriver + // if (OldStorage == NULL) { - // - // Storage is not found in backup formset, request it from ConfigDriver - // Status = LoadStorage (FormSet, Storage); if (EFI_ERROR (Status)) { // // If get last time changed value failed, extract default from IFR binary // - ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage, TRUE); + ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE); // // ExtractDefault will set the NV flag to TRUE, so need this function to clean the flag // in current situation. @@ -3722,12 +3917,7 @@ InitializeCurrentSetting ( // Now Edit Buffer is filled with default values(lower priority) or current // settings(higher priority), sychronize it to shadow Buffer // - SynchronizeStorage (Storage, TRUE); - } else { - // - // Storage found in backup formset, use it - // - Status = CopyStorage (Storage, OldStorage); + SynchronizeStorage (Storage->BrowserStorage, TRUE); } Link = GetNextNode (&FormSet->StorageListHead, Link); @@ -4020,6 +4210,8 @@ InitializeFormSet ( } } + gFunctionKeySetting = ENABLE_FUNCTION_KEY_SETTING; + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) { gFrontPageHandle = FormSet->HiiHandle; gFunctionKeySetting = NONE_FUNCTION_KEY_SETTING; @@ -4107,6 +4299,7 @@ SaveBrowserContext ( Context->HelpBlockWidth = gHelpBlockWidth; Context->OldFormSet = gOldFormSet; Context->MenuRefreshHead = gMenuRefreshHead; + Context->ProtocolNotFound = gProtocolNotFound; CopyMem (&Context->ScreenDimensions, &gScreenDimensions, sizeof (gScreenDimensions)); CopyMem (&Context->MenuOption, &gMenuOption, sizeof (gMenuOption)); @@ -4184,6 +4377,7 @@ RestoreBrowserContext ( gHelpBlockWidth = Context->HelpBlockWidth; gOldFormSet = Context->OldFormSet; gMenuRefreshHead = Context->MenuRefreshHead; + gProtocolNotFound = Context->ProtocolNotFound; CopyMem (&gScreenDimensions, &Context->ScreenDimensions, sizeof (gScreenDimensions)); CopyMem (&gMenuOption, &Context->MenuOption, sizeof (gMenuOption)); @@ -4214,10 +4408,13 @@ GetFormSetFromHiiHandle ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); + Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(FormSet)) { + continue; + } if (FormSet->HiiHandle == Handle) { return FormSet; } - Link = GetNextNode (&gBrowserFormSetList, Link); } return NULL; @@ -4470,11 +4667,14 @@ SaveReminder ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); + Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(FormSet)) { + continue; + } if (IsNvUpdateRequired (FormSet)) { IsDataChanged = TRUE; break; } - Link = GetNextNode (&gBrowserFormSetList, Link); } //