X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FSetup.c;h=ed904161b619dd538b8ce296c83764791da2f225;hb=0a6f8af50ddc87a47e3fa38d7449fcae26ab1f5d;hp=88f965059f1dd1c41e9e8433d9be9a94fbe5cb78;hpb=48a9d5f7781e430c54cfc2964243580c56384310;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 88f965059f..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 - 2011, 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 // @@ -322,11 +328,6 @@ SendForm ( CopyMem (&Selection->FormSetGuid, &gEfiHiiPlatformSetupFormsetGuid, sizeof (EFI_GUID)); } - // - // Try to find pre FormSet in the maintain backup list. - // - gOldFormSet = GetFormSetFromHiiHandle (Selection->Handle); - do { FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET)); ASSERT (FormSet != NULL); @@ -334,13 +335,18 @@ SendForm ( // // Initialize internal data structures of FormSet // - Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet); + Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet, TRUE); if (EFI_ERROR (Status) || IsListEmpty (&FormSet->FormListHead)) { DestroyFormSet (FormSet); break; } Selection->FormSet = FormSet; + // + // Try to find pre FormSet in the maintain backup list. + // + gOldFormSet = GetFormSetFromHiiHandle (Selection->Handle); + // // Display this formset // @@ -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; } @@ -815,7 +755,7 @@ GetToken ( String = HiiGetString (HiiHandle, Token, NULL); if (String == NULL) { - String = AllocateCopyPool (sizeof (mUnknownString), mUnknownString); + String = AllocateCopyPool (StrSize (mUnknownString), mUnknownString); ASSERT (String != NULL); } return (CHAR16 *) String; @@ -888,7 +828,7 @@ NewStringCat ( **/ VOID SynchronizeStorage ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN BOOLEAN SyncOrRestore ) { @@ -933,6 +873,7 @@ SynchronizeStorage ( @param Storage The NameValue Storage. @param Name The Name. @param Value The retured Value. + @param GetValueFrom Where to get source value, from EditValue or Value. @retval EFI_SUCCESS Value found for given Name. @retval EFI_NOT_FOUND No such Name found in NameValue storage. @@ -940,14 +881,19 @@ SynchronizeStorage ( **/ EFI_STATUS GetValueByName ( - IN FORMSET_STORAGE *Storage, - IN CHAR16 *Name, - IN OUT CHAR16 **Value + IN BROWSER_STORAGE *Storage, + IN CHAR16 *Name, + IN OUT CHAR16 **Value, + IN GET_SET_QUESTION_VALUE_WITH GetValueFrom ) { LIST_ENTRY *Link; NAME_VALUE_NODE *Node; + if (GetValueFrom != GetSetValueWithEditBuffer && GetValueFrom != GetSetValueWithBuffer) { + return EFI_INVALID_PARAMETER; + } + *Value = NULL; Link = GetFirstNode (&Storage->NameValueListHead); @@ -955,7 +901,11 @@ GetValueByName ( Node = NAME_VALUE_NODE_FROM_LINK (Link); if (StrCmp (Name, Node->Name) == 0) { - NewStringCpy (Value, Node->EditValue); + if (GetValueFrom == GetSetValueWithEditBuffer) { + NewStringCpy (Value, Node->EditValue); + } else { + NewStringCpy (Value, Node->Value); + } return EFI_SUCCESS; } @@ -972,7 +922,7 @@ GetValueByName ( @param Storage The NameValue Storage. @param Name The Name. @param Value The Value to set. - @param Edit Whether update editValue or Value. + @param SetValueTo Whether update editValue or Value. @retval EFI_SUCCESS Value found for given Name. @retval EFI_NOT_FOUND No such Name found in NameValue storage. @@ -980,22 +930,26 @@ GetValueByName ( **/ EFI_STATUS SetValueByName ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN CHAR16 *Name, IN CHAR16 *Value, - IN BOOLEAN Edit + IN GET_SET_QUESTION_VALUE_WITH SetValueTo ) { LIST_ENTRY *Link; NAME_VALUE_NODE *Node; CHAR16 *Buffer; + if (SetValueTo != GetSetValueWithEditBuffer && SetValueTo != GetSetValueWithBuffer) { + return EFI_INVALID_PARAMETER; + } + Link = GetFirstNode (&Storage->NameValueListHead); while (!IsNull (&Storage->NameValueListHead, Link)) { Node = NAME_VALUE_NODE_FROM_LINK (Link); if (StrCmp (Name, Node->Name) == 0) { - if (Edit) { + if (SetValueTo == GetSetValueWithEditBuffer) { Buffer = Node->EditValue; } else { Buffer = Node->Value; @@ -1005,7 +959,7 @@ SetValueByName ( } Buffer = AllocateCopyPool (StrSize (Value), Value); ASSERT (Buffer != NULL); - if (Edit) { + if (SetValueTo == GetSetValueWithEditBuffer) { Node->EditValue = Buffer; } else { Node->Value = Buffer; @@ -1023,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. @@ -1033,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: @@ -1109,7 +1052,7 @@ StorageToConfigResp ( **/ EFI_STATUS ConfigRespToStorage ( - IN FORMSET_STORAGE *Storage, + IN BROWSER_STORAGE *Storage, IN CHAR16 *ConfigResp ) { @@ -1162,7 +1105,7 @@ ConfigRespToStorage ( if (StrPtr != NULL) { *StrPtr = 0; } - SetValueByName (Storage, Name, Value, TRUE); + SetValueByName (Storage, Name, Value, GetSetValueWithEditBuffer); } break; @@ -1182,8 +1125,7 @@ ConfigRespToStorage ( @param FormSet FormSet data structure. @param Form Form data structure. @param Question Question to be initialized. - @param Cached TRUE: get from Edit copy FALSE: get from original - Storage + @param GetValueFrom Where to get value, may from editbuffer, buffer or hii driver. @retval EFI_SUCCESS The function completed successfully. @@ -1193,7 +1135,7 @@ GetQuestionValue ( IN FORM_BROWSER_FORMSET *FormSet, IN FORM_BROWSER_FORM *Form, IN OUT FORM_BROWSER_STATEMENT *Question, - IN BOOLEAN Cached + IN GET_SET_QUESTION_VALUE_WITH GetValueFrom ) { EFI_STATUS Status; @@ -1202,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; @@ -1220,6 +1162,11 @@ GetQuestionValue ( Status = EFI_SUCCESS; Value = NULL; + Result = NULL; + + if (GetValueFrom >= GetSetValueWithMax) { + return EFI_INVALID_PARAMETER; + } // // Statement don't have storage, skip them @@ -1234,7 +1181,19 @@ GetQuestionValue ( if (Question->ValueExpression != NULL) { Status = EvaluateExpression (FormSet, Form, Question->ValueExpression); if (!EFI_ERROR (Status)) { - CopyMem (&Question->HiiValue, &Question->ValueExpression->Result, sizeof (EFI_HII_VALUE)); + if (Question->ValueExpression->Result.Type == EFI_IFR_TYPE_BUFFER) { + ASSERT (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER && Question->HiiValue.Buffer != NULL); + if (Question->StorageWidth > Question->ValueExpression->Result.BufferLen) { + CopyMem (Question->HiiValue.Buffer, Question->ValueExpression->Result.Buffer, Question->ValueExpression->Result.BufferLen); + Question->HiiValue.BufferLen = Question->ValueExpression->Result.BufferLen; + } else { + CopyMem (Question->HiiValue.Buffer, Question->ValueExpression->Result.Buffer, Question->StorageWidth); + Question->HiiValue.BufferLen = Question->StorageWidth; + } + FreePool (Question->ValueExpression->Result.Buffer); + } + Question->HiiValue.Type = Question->ValueExpression->Result.Type; + CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); } return Status; } @@ -1244,11 +1203,24 @@ GetQuestionValue ( // if (Question->ReadExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) { Status = EvaluateExpression (FormSet, Form, Question->ReadExpression); - if (!EFI_ERROR (Status) && (Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER)) { + if (!EFI_ERROR (Status) && + ((Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER) || (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER))) { // // Only update question value to the valid result. // - CopyMem (&Question->HiiValue, &Question->ReadExpression->Result, sizeof (EFI_HII_VALUE)); + if (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER) { + ASSERT (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER && Question->HiiValue.Buffer != NULL); + if (Question->StorageWidth > Question->ReadExpression->Result.BufferLen) { + CopyMem (Question->HiiValue.Buffer, Question->ReadExpression->Result.Buffer, Question->ReadExpression->Result.BufferLen); + Question->HiiValue.BufferLen = Question->ReadExpression->Result.BufferLen; + } else { + CopyMem (Question->HiiValue.Buffer, Question->ReadExpression->Result.Buffer, Question->StorageWidth); + Question->HiiValue.BufferLen = Question->StorageWidth; + } + FreePool (Question->ReadExpression->Result.Buffer); + } + Question->HiiValue.Type = Question->ReadExpression->Result.Type; + CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); return EFI_SUCCESS; } } @@ -1347,15 +1319,22 @@ GetQuestionValue ( IsBufferStorage = FALSE; } IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); - if (Cached) { + if (GetValueFrom == GetSetValueWithEditBuffer || GetValueFrom == GetSetValueWithBuffer ) { if (IsBufferStorage) { - // - // Copy from storage Edit buffer - // - CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth); + if (GetValueFrom == GetSetValueWithEditBuffer) { + // + // Copy from storage Edit buffer + // + CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth); + } else { + // + // Copy from storage Edit buffer + // + CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth); + } } else { Value = NULL; - Status = GetValueByName (Storage, Question->VariableName, &Value); + Status = GetValueByName (Storage, Question->VariableName, &Value, GetValueFrom); if (EFI_ERROR (Status)) { return Status; } @@ -1403,7 +1382,7 @@ GetQuestionValue ( FreePool (Value); } } else { - if (Storage->Type == EFI_HII_VARSTORE_BUFFER) { + if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // // Request current settings from Configuration Driver // @@ -1447,12 +1426,18 @@ GetQuestionValue ( // // Skip // - Value = Result + Length; if (IsBufferStorage) { + Value = StrStr (Result, L"&VALUE"); + if (Value == NULL) { + FreePool (Result); + return EFI_NOT_FOUND; + } // // Skip "&VALUE" // Value = Value + 6; + } else { + Value = Result + Length; } if (*Value != '=') { FreePool (Result); @@ -1510,9 +1495,9 @@ GetQuestionValue ( } } } - FreePool (Result); if (EFI_ERROR (Status)) { + FreePool (Result); return Status; } } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { @@ -1546,7 +1531,11 @@ GetQuestionValue ( if (IsBufferStorage) { CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Dst, StorageWidth); } else { - SetValueByName (Storage, Question->VariableName, Value, TRUE); + SetValueByName (Storage, Question->VariableName, Value, GetSetValueWithEditBuffer); + } + + if (Result != NULL) { + FreePool (Result); } } @@ -1560,8 +1549,7 @@ GetQuestionValue ( @param FormSet FormSet data structure. @param Form Form data structure. @param Question Pointer to the Question. - @param Cached TRUE: set to Edit copy FALSE: set to original - Storage + @param SetValueTo Update the question value to editbuffer , buffer or hii driver. @retval EFI_SUCCESS The function completed successfully. @@ -1571,7 +1559,7 @@ SetQuestionValue ( IN FORM_BROWSER_FORMSET *FormSet, IN FORM_BROWSER_FORM *Form, IN OUT FORM_BROWSER_STATEMENT *Question, - IN BOOLEAN Cached + IN GET_SET_QUESTION_VALUE_WITH SetValueTo ) { EFI_STATUS Status; @@ -1581,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; @@ -1596,6 +1584,10 @@ SetQuestionValue ( Status = EFI_SUCCESS; + if (SetValueTo >= GetSetValueWithMax) { + return EFI_INVALID_PARAMETER; + } + // // Statement don't have storage, skip them // @@ -1711,48 +1703,56 @@ SetQuestionValue ( IsBufferStorage = FALSE; } IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE); - if (IsBufferStorage) { - // - // Copy to storage edit buffer - // - CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); - } else { - if (IsString) { - // - // Allocate enough string buffer. - // - Value = NULL; - BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16); - Value = AllocateZeroPool (BufferLen); - ASSERT (Value != NULL); - // - // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" - // - TemName = (CHAR16 *) Src; - TemString = Value; - for (; *TemName != L'\0'; TemName++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); + + if (SetValueTo == GetSetValueWithEditBuffer || SetValueTo == GetSetValueWithBuffer) { + if (IsBufferStorage) { + if (SetValueTo == GetSetValueWithEditBuffer) { + // + // Copy to storage edit buffer + // + CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); + } else if (SetValueTo == GetSetValueWithBuffer) { + // + // Copy to storage edit buffer + // + CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth); } } else { - BufferLen = StorageWidth * 2 + 1; - Value = AllocateZeroPool (BufferLen * sizeof (CHAR16)); - ASSERT (Value != NULL); - // - // Convert Buffer to Hex String - // - TemBuffer = Src + StorageWidth - 1; - TemString = Value; - for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + if (IsString) { + // + // Allocate enough string buffer. + // + Value = NULL; + BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16); + Value = AllocateZeroPool (BufferLen); + ASSERT (Value != NULL); + // + // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" + // + TemName = (CHAR16 *) Src; + TemString = Value; + for (; *TemName != L'\0'; TemName++) { + TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); + } + } else { + BufferLen = StorageWidth * 2 + 1; + Value = AllocateZeroPool (BufferLen * sizeof (CHAR16)); + ASSERT (Value != NULL); + // + // Convert Buffer to Hex String + // + TemBuffer = Src + StorageWidth - 1; + TemString = Value; + for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) { + TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + } } - } - Status = SetValueByName (Storage, Question->VariableName, Value, TRUE); - FreePool (Value); - } - - if (!Cached) { - if (Storage->Type == EFI_HII_VARSTORE_BUFFER) { + Status = SetValueByName (Storage, Question->VariableName, Value, SetValueTo); + FreePool (Value); + } + } else if (SetValueTo == GetSetValueWithHiiDriver) { + if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { // // ::= + + "&VALUE=" + "StorageWidth * 2" || // + "&" + + "=" + "" @@ -1914,7 +1914,7 @@ ValidateQuestion ( return Status; } - if (Expression->Result.Value.b) { + if ((Expression->Result.Type == EFI_IFR_TYPE_BOOLEAN) && Expression->Result.Value.b) { // // Condition meet, show up error message // @@ -2079,6 +2079,152 @@ SynchronizeStorageForForm ( return Status; } +/** + When discard the question value, call the callback function with Changed type + to inform the hii driver. + + @param FormSet FormSet data structure. + @param Form Form data structure. + +**/ +VOID +SendDiscardInfoToDriver ( + IN FORM_BROWSER_FORMSET *FormSet, + IN FORM_BROWSER_FORM *Form + ) +{ + LIST_ENTRY *Link; + FORM_BROWSER_STATEMENT *Question; + EFI_STATUS Status; + EFI_HII_VALUE HiiValue; + UINT8 *BufferValue; + BOOLEAN ValueChanged; + EFI_IFR_TYPE_VALUE *TypeValue; + EFI_BROWSER_ACTION_REQUEST ActionRequest; + + ValueChanged = FALSE; + BufferValue = NULL; + + if(!Form->NvUpdateRequired) { + return; + } + + Link = GetFirstNode (&Form->StatementListHead); + while (!IsNull (&Form->StatementListHead, Link)) { + Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); + Link = GetNextNode (&Form->StatementListHead, Link); + + if (Question->Storage == NULL || Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + continue; + } + + if (Question->Operand == EFI_IFR_PASSWORD_OP) { + continue; + } + + if (Question->BufferValue != NULL) { + BufferValue = AllocateZeroPool (Question->StorageWidth); + ASSERT (BufferValue != NULL); + CopyMem (BufferValue, Question->BufferValue, Question->StorageWidth); + } else { + HiiValue.Type = Question->HiiValue.Type; + CopyMem (&HiiValue.Value, &Question->HiiValue.Value, sizeof (EFI_IFR_TYPE_VALUE)); + } + + Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithBuffer); + if (EFI_ERROR (Status)) { + if (BufferValue != NULL) { + FreePool (BufferValue); + BufferValue = NULL; + } + continue; + } + + if (Question->BufferValue != NULL) { + if (CompareMem (BufferValue, Question->BufferValue, Question->StorageWidth)) { + ValueChanged = TRUE; + } + } else { + if (CompareMem (&HiiValue.Value, &Question->HiiValue.Value, sizeof (EFI_IFR_TYPE_VALUE))) { + ValueChanged = TRUE; + } + } + + if (BufferValue != NULL) { + FreePool (BufferValue); + BufferValue = NULL; + } + + if (!ValueChanged) { + continue; + } + + ValueChanged = FALSE; + + if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) { + TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue; + } else { + TypeValue = &Question->HiiValue.Value; + } + + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + FormSet->ConfigAccess->Callback ( + FormSet->ConfigAccess, + EFI_BROWSER_ACTION_CHANGED, + Question->QuestionId, + Question->HiiValue.Type, + TypeValue, + &ActionRequest + ); + } +} + +/** + 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). @@ -2132,10 +2278,16 @@ DiscardForm ( // Prepare // SynchronizeStorageForForm(FormSet, ConfigInfo, FALSE); + + // + // Call callback with Changed type to inform the driver. + // + SendDiscardInfoToDriver (FormSet, Form); } Form->NvUpdateRequired = FALSE; } else if (SettingScope == FormSetLevel && IsNvUpdateRequired(FormSet)) { + // // Discard Buffer storage or Name/Value storage // @@ -2144,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; } @@ -2155,7 +2307,18 @@ DiscardForm ( continue; } - SynchronizeStorage(Storage, FALSE); + SynchronizeStorage(Storage->BrowserStorage, FALSE); + } + + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + Link = GetNextNode (&FormSet->FormListHead, Link); + + // + // Call callback with Changed type to inform the driver. + // + SendDiscardInfoToDriver (FormSet, Form); } UpdateNvInfoInForm (FormSet, FALSE); @@ -2170,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); } @@ -2207,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; @@ -2255,7 +2423,7 @@ SubmitForm ( // // 1. Prepare // - Status = StorageToConfigResp (ConfigInfo, &ConfigResp, TRUE); + Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest); if (EFI_ERROR (Status)) { return Status; } @@ -2344,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) { @@ -2354,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; } @@ -2451,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); } @@ -2486,7 +2659,7 @@ GetDefaultValueFromAltCfg ( BOOLEAN IsBufferStorage; BOOLEAN IsString; UINTN Length; - FORMSET_STORAGE *Storage; + BROWSER_STORAGE *Storage; CHAR16 *ConfigRequest; CHAR16 *Progress; CHAR16 *Result; @@ -2789,7 +2962,19 @@ GetQuestionDefault ( return Status; } - CopyMem (HiiValue, &Default->ValueExpression->Result, sizeof (EFI_HII_VALUE)); + if (Default->ValueExpression->Result.Type == EFI_IFR_TYPE_BUFFER) { + ASSERT (HiiValue->Type == EFI_IFR_TYPE_BUFFER && Question->BufferValue != NULL); + if (Question->StorageWidth > Default->ValueExpression->Result.BufferLen) { + CopyMem (Question->HiiValue.Buffer, Default->ValueExpression->Result.Buffer, Default->ValueExpression->Result.BufferLen); + Question->HiiValue.BufferLen = Default->ValueExpression->Result.BufferLen; + } else { + CopyMem (Question->HiiValue.Buffer, Default->ValueExpression->Result.Buffer, Question->StorageWidth); + Question->HiiValue.BufferLen = Question->StorageWidth; + } + FreePool (Default->ValueExpression->Result.Buffer); + } + HiiValue->Type = Default->ValueExpression->Result.Type; + CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE)); } else { // // Default value is embedded in EFI_IFR_DEFAULT @@ -2827,6 +3012,12 @@ GetQuestionDefault ( Link = GetFirstNode (&Question->OptionListHead); while (!IsNull (&Question->OptionListHead, Link)) { Option = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression != NULL) && + EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT) != 0)) || ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0)) @@ -2835,8 +3026,6 @@ GetQuestionDefault ( return EFI_SUCCESS; } - - Link = GetNextNode (&Question->OptionListHead, Link); } } } @@ -2882,10 +3071,18 @@ GetQuestionDefault ( // if (ValueToOption (Question, HiiValue) == NULL) { Link = GetFirstNode (&Question->OptionListHead); - if (!IsNull (&Question->OptionListHead, Link)) { + while (!IsNull (&Question->OptionListHead, Link)) { Option = QUESTION_OPTION_FROM_LINK (Link); - CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); - Status = EFI_SUCCESS; + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression != NULL) && + EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } + + CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE)); + Status = EFI_SUCCESS; + break; } } break; @@ -2899,6 +3096,12 @@ GetQuestionDefault ( while (!IsNull (&Question->OptionListHead, Link)) { Status = EFI_SUCCESS; Option = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((Option->SuppressExpression != NULL) && + EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64); @@ -2906,8 +3109,6 @@ GetQuestionDefault ( if (Index >= Question->MaxContainers) { break; } - - Link = GetNextNode (&Question->OptionListHead, Link); } break; @@ -2920,12 +3121,20 @@ GetQuestionDefault ( /** - Reset Questions to their default value in a Form, Formset or System. + Reset Questions to their initial value or default value in a Form, Formset or System. + + GetDefaultValueScope parameter decides which questions will reset + to its default value. @param FormSet FormSet data structure. @param Form Form data structure. @param DefaultId The Class of the default. @param SettingScope Setting Scope for Default action. + @param GetDefaultValueScope Get default value scope. + @param Storage Get default value only for this storage. + @param RetrieveValueFirst Whether call the retrieve call back to + get the initial value before get default + value. @retval EFI_SUCCESS The function completed successfully. @retval EFI_UNSUPPORTED Unsupport SettingScope. @@ -2936,7 +3145,10 @@ ExtractDefault ( IN FORM_BROWSER_FORMSET *FormSet, IN FORM_BROWSER_FORM *Form, IN UINT16 DefaultId, - IN BROWSER_SETTING_SCOPE SettingScope + IN BROWSER_SETTING_SCOPE SettingScope, + IN BROWSER_GET_DEFAULT_VALUE GetDefaultValueScope, + IN BROWSER_STORAGE *Storage OPTIONAL, + IN BOOLEAN RetrieveValueFirst ) { EFI_STATUS Status; @@ -2948,12 +3160,17 @@ ExtractDefault ( EFI_HII_HANDLE *HiiHandles; UINTN Index; EFI_GUID ZeroGuid; - UINTN BackUpClassOfVfr; + + Status = EFI_SUCCESS; // // Check the supported setting level. // - if (SettingScope >= MaxLevel) { + if (SettingScope >= MaxLevel || GetDefaultValueScope >= GetDefaultForMax) { + return EFI_UNSUPPORTED; + } + + if (GetDefaultValueScope == GetDefaultForStorage && Storage == NULL) { return EFI_UNSUPPORTED; } @@ -2965,31 +3182,53 @@ ExtractDefault ( while (!IsNull (&Form->StatementListHead, Link)) { Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link); Link = GetNextNode (&Form->StatementListHead, Link); - + + // + // If get default value only for this storage, check the storage first. + // + if ((GetDefaultValueScope == GetDefaultForStorage) && (Question->Storage != Storage)) { + continue; + } + + // + // If get default value only for no storage question, just skip the question which has storage. + // + if ((GetDefaultValueScope == GetDefaultForNoStorage) && (Question->Storage != NULL)) { + continue; + } + // // If Question is disabled, don't reset it to default // - if (Question->DisableExpression != NULL) { - Status = EvaluateExpression (FormSet, Form, Question->DisableExpression); - if (!EFI_ERROR (Status) && Question->DisableExpression->Result.Value.b) { + if (Question->Expression != NULL) { + if (EvaluateExpressionList(Question->Expression, TRUE, FormSet, Form) == ExpressDisable) { continue; } } - + + if (RetrieveValueFirst) { + // + // Call the Retrieve call back to get the initial question value. + // + Status = ProcessRetrieveForQuestion(FormSet->ConfigAccess, Question); + } + // - // Reset Question to its default value + // If not request to get the initial value or get initial value fail, then get default value. // - Status = GetQuestionDefault (FormSet, Form, Question, DefaultId); - if (EFI_ERROR (Status)) { - continue; + if (!RetrieveValueFirst || EFI_ERROR (Status)) { + Status = GetQuestionDefault (FormSet, Form, Question, DefaultId); + if (EFI_ERROR (Status)) { + continue; + } } - + // // Synchronize Buffer storage's Edit buffer // if ((Question->Storage != NULL) && (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) { - SetQuestionValue (FormSet, Form, Question, TRUE); + SetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); // // Update Form NV flag. // @@ -3000,7 +3239,7 @@ ExtractDefault ( FormLink = GetFirstNode (&FormSet->FormListHead); while (!IsNull (&FormSet->FormListHead, FormLink)) { Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); - ExtractDefault (FormSet, Form, DefaultId, FormLevel); + ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); FormLink = GetNextNode (&FormSet->FormListHead, FormLink); } } else if (SettingScope == SystemLevel) { @@ -3008,7 +3247,6 @@ ExtractDefault ( // Open all FormSet by locate HII packages. // Initiliaze the maintain FormSet to store default data as back up data. // - BackUpClassOfVfr = gClassOfVfr; BackUpFormSet = gOldFormSet; gOldFormSet = NULL; @@ -3035,7 +3273,7 @@ ExtractDefault ( LocalFormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET)); ASSERT (LocalFormSet != NULL); ZeroMem (&ZeroGuid, sizeof (ZeroGuid)); - Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet); + Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet, FALSE); if (EFI_ERROR (Status) || IsListEmpty (&LocalFormSet->FormListHead)) { DestroyFormSet (LocalFormSet); continue; @@ -3045,7 +3283,15 @@ ExtractDefault ( DestroyFormSet (LocalFormSet); continue; } - + // + // Initilize Questions' Value + // + Status = LoadFormSetConfig (NULL, LocalFormSet); + if (EFI_ERROR (Status)) { + DestroyFormSet (LocalFormSet); + continue; + } + // // Add FormSet into the maintain list. // @@ -3057,7 +3303,6 @@ ExtractDefault ( // FreePool (HiiHandles); gOldFormSet = BackUpFormSet; - gClassOfVfr = BackUpClassOfVfr; // // Set Default Value for each FormSet in the maintain list. @@ -3065,8 +3310,11 @@ ExtractDefault ( Link = GetFirstNode (&gBrowserFormSetList); while (!IsNull (&gBrowserFormSetList, Link)) { LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); - ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel); Link = GetNextNode (&gBrowserFormSetList, Link); + if (!ValidateFormSet(LocalFormSet)) { + continue; + } + ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst); } } @@ -3079,6 +3327,7 @@ ExtractDefault ( @param Selection Selection contains the information about the Selection, form and formset to be displayed. Selection action may be updated in retrieve callback. + If Selection is NULL, only initialize Question value. @param FormSet FormSet data structure. @param Form Form data structure. @@ -3105,7 +3354,7 @@ LoadFormConfig ( // // Initialize local copy of Value for each Question // - Status = GetQuestionValue (FormSet, Form, Question, TRUE); + Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); if (EFI_ERROR (Status)) { return Status; } @@ -3115,25 +3364,10 @@ LoadFormConfig ( } // - // According the spec, ref opcode try to get value from call back with "retrieve" type. - // - if ((Question->Operand == EFI_IFR_REF_OP) && (FormSet->ConfigAccess != NULL)) { - Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // - // Check whether EfiVarstore with CallBack can be got. + // Call the Retrieve call back function for all questions. // - if ((FormSet->ConfigAccess != NULL) && - (Selection->Action != UI_ACTION_REFRESH_FORMSET) && - (Question->QuestionId != 0) && - (Question->Storage != NULL) && - (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) && + if ((FormSet->ConfigAccess != NULL) && (Selection != NULL) && ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK)) { - // // Check QuestionValue does exist. // @@ -3143,17 +3377,21 @@ LoadFormConfig ( } else { BufferValue = (UINT8 *) &Question->HiiValue.Value; } - Status = gRT->GetVariable ( - Question->VariableName, - &Question->Storage->Guid, - NULL, - &StorageWidth, - BufferValue - ); - if (!EFI_ERROR (Status)) { - Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE); + // + // For efivarstore storage, initial question value first. + // + if ((Question->Storage != NULL) && (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) { + Status = gRT->GetVariable ( + Question->VariableName, + &Question->Storage->Guid, + NULL, + &StorageWidth, + BufferValue + ); } + + Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE); } Link = GetNextNode (&Form->StatementListHead, Link); @@ -3168,6 +3406,7 @@ LoadFormConfig ( @param Selection Selection contains the information about the Selection, form and formset to be displayed. Selection action may be updated in retrieve callback. + If Selection is NULL, only initialize Question value. @param FormSet FormSet data structure. @retval EFI_SUCCESS The function completed successfully. @@ -3201,6 +3440,319 @@ LoadFormSetConfig ( return EFI_SUCCESS; } +/** + Remove the Request element from the Config Request. + + @param Storage Pointer to the browser storage. + @param RequestElement The pointer to the Request element. + +**/ +VOID +RemoveElement ( + IN OUT BROWSER_STORAGE *Storage, + IN CHAR16 *RequestElement + ) +{ + CHAR16 *NewStr; + CHAR16 *DestStr; + + ASSERT (Storage->ConfigRequest != NULL && RequestElement != NULL); + + NewStr = StrStr (Storage->ConfigRequest, RequestElement); + + if (NewStr == NULL) { + return; + } + + // + // 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) { + // + // "&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"; + } + + // + // Find SearchKey storage + // + 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; + } + + // + // If no request element remain, just remove the ConfigRequest string. + // + if (StrCmp (Storage->ConfigRequest, Storage->ConfigHdr) == 0) { + FreePool (Storage->ConfigRequest); + Storage->ConfigRequest = NULL; + Storage->SpareStrLen = 0; + } +} + +/** + 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); + } +} + +/** + Check whether current element in the ConfigReqeust string. + + @param BrowserStorage Storage which includes ConfigReqeust. + @param RequestElement New element need to check. + + @retval TRUE The Element is in the ConfigReqeust string. + @retval FALSE The Element not in the configReqeust String. + +**/ +BOOLEAN +ElementValidation ( + BROWSER_STORAGE *BrowserStorage, + CHAR16 *RequestElement + ) +{ + return StrStr (BrowserStorage->ConfigRequest, RequestElement) != NULL ? TRUE : FALSE; +} + +/** + Append the Request element to the Config Request. + + @param ConfigRequest Current ConfigRequest info. + @param SpareStrLen Current remain free buffer for config reqeust. + @param RequestElement New Request element. + +**/ +VOID +AppendConfigRequest ( + IN OUT CHAR16 **ConfigRequest, + IN OUT UINTN *SpareStrLen, + IN CHAR16 *RequestElement + ) +{ + CHAR16 *NewStr; + UINTN StringSize; + UINTN StrLength; + + StrLength = StrLen (RequestElement); + + // + // 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); + + if (*ConfigRequest != NULL) { + CopyMem (NewStr, *ConfigRequest, StringSize); + FreePool (*ConfigRequest); + } + *ConfigRequest = NewStr; + *SpareStrLen = CONFIG_REQUEST_STRING_INCREMENTAL; + } + + StrCat (*ConfigRequest, RequestElement); + *SpareStrLen -= StrLength; +} + +/** + Adjust the config request info, remove the request elements which already in AllConfigRequest string. + + @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. + +**/ +BOOLEAN +ConfigRequestAdjust ( + IN FORMSET_STORAGE *Storage, + OUT CHAR16 **ConfigRequest + ) +{ + 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; + } + + 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"; + } + + // + // Prepare the config header. + // + RetBuf = AllocateCopyPool(StrSize (Storage->BrowserStorage->ConfigHdr), Storage->BrowserStorage->ConfigHdr); + ASSERT (RetBuf != NULL); + + // + // 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; + } + + if (NextRequestElement != NULL) { + // + // Restore '&' with '\0' for later used. + // + *NextRequestElement = L'&'; + } + + RequestElement = NextRequestElement; + } + + if (RetVal) { + *ConfigRequest = RetBuf; + } else { + FreePool (RetBuf); + } + + return RetVal; +} + /** Fill storage's edit copy with settings requested from Configuration Driver. @@ -3220,19 +3772,26 @@ LoadStorage ( EFI_STRING Progress; EFI_STRING Result; CHAR16 *StrPtr; + CHAR16 *ConfigRequest; - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { + if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) { return EFI_SUCCESS; } - if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) { - Status = gRT->GetVariable ( - Storage->Name, - &Storage->Guid, - NULL, - (UINTN*)&Storage->Size, - Storage->EditBuffer - ); + 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; } @@ -3247,15 +3806,25 @@ LoadStorage ( 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, - Storage->ConfigRequest, + ConfigRequest, &Progress, &Result ); + FreePool (ConfigRequest); + if (EFI_ERROR (Status)) { return Status; } @@ -3263,68 +3832,16 @@ LoadStorage ( // // Convert Result from to // - StrPtr = StrStr (Result, L"ALTCFG"); + StrPtr = StrStr (Result, L"&GUID="); if (StrPtr != NULL) { *StrPtr = L'\0'; } - Status = ConfigRespToStorage (Storage, Result); + Status = ConfigRespToStorage (Storage->BrowserStorage, Result); FreePool (Result); return Status; } - -/** - Copy uncommitted data from source Storage to destination Storage. - - @param Dst Target Storage for uncommitted data. - @param Src Source Storage for uncommitted data. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type. - -**/ -EFI_STATUS -CopyStorage ( - IN OUT FORMSET_STORAGE *Dst, - IN FORMSET_STORAGE *Src - ) -{ - LIST_ENTRY *Link; - NAME_VALUE_NODE *Node; - - if ((Dst->Type != Src->Type) || (Dst->Size != Src->Size)) { - return EFI_INVALID_PARAMETER; - } - - 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; - - case EFI_HII_VARSTORE_NAME_VALUE: - Link = GetFirstNode (&Src->NameValueListHead); - while (!IsNull (&Src->NameValueListHead, Link)) { - Node = NAME_VALUE_NODE_FROM_LINK (Link); - - SetValueByName (Dst, Node->Name, Node->EditValue, TRUE); - SetValueByName (Dst, Node->Name, Node->Value, FALSE); - - Link = GetNextNode (&Src->NameValueListHead, Link); - } - break; - - case EFI_HII_VARSTORE_EFI_VARIABLE: - default: - break; - } - - return EFI_SUCCESS; -} - - /** Get current setting of Questions. @@ -3348,10 +3865,9 @@ InitializeCurrentSetting ( EFI_STATUS Status; // - // Extract default from IFR binary - // - ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel); - UpdateNvInfoInForm (FormSet, FALSE); + // Extract default from IFR binary for no storage questions. + // + ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE); // // Request current settings from Configuration Driver @@ -3378,23 +3894,30 @@ 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); - // - // Now Edit Buffer is filled with default values(lower priority) and current - // settings(higher priority), sychronize it to shadow Buffer - // - if (!EFI_ERROR (Status)) { - SynchronizeStorage (Storage, TRUE); + + 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->BrowserStorage, TRUE); + // + // ExtractDefault will set the NV flag to TRUE, so need this function to clean the flag + // in current situation. + // + UpdateNvInfoInForm (FormSet, FALSE); } - } else { + // - // Storage found in backup formset, use it + // Now Edit Buffer is filled with default values(lower priority) or current + // settings(higher priority), sychronize it to shadow Buffer // - Status = CopyStorage (Storage, OldStorage); + SynchronizeStorage (Storage->BrowserStorage, TRUE); } Link = GetNextNode (&FormSet->StorageListHead, Link); @@ -3404,23 +3927,23 @@ InitializeCurrentSetting ( // If has old formset, get the old nv update status. // if (gOldFormSet != NULL) { - Link = GetFirstNode (&FormSet->FormListHead); - while (!IsNull (&FormSet->FormListHead, Link)) { - Form = FORM_BROWSER_FORM_FROM_LINK (Link); - - Link2 = GetFirstNode (&gOldFormSet->FormListHead); - while (!IsNull (&gOldFormSet->FormListHead, Link2)) { - Form2 = FORM_BROWSER_FORM_FROM_LINK (Link2); + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); - if (Form->FormId == Form2->FormId) { - Form->NvUpdateRequired = Form2->NvUpdateRequired; - break; - } + Link2 = GetFirstNode (&gOldFormSet->FormListHead); + while (!IsNull (&gOldFormSet->FormListHead, Link2)) { + Form2 = FORM_BROWSER_FORM_FROM_LINK (Link2); - Link2 = GetNextNode (&gOldFormSet->FormListHead, Link2); + if (Form->FormId == Form2->FormId) { + Form->NvUpdateRequired = Form2->NvUpdateRequired; + break; } - Link = GetNextNode (&FormSet->FormListHead, Link); + + Link2 = GetNextNode (&gOldFormSet->FormListHead, Link2); } + Link = GetNextNode (&FormSet->FormListHead, Link); + } } return EFI_SUCCESS; @@ -3606,6 +4129,7 @@ GetIfrBinaryData ( found in package list. On output, GUID of the formset found(if not NULL). @param FormSet FormSet data structure. + @param UpdateGlobalVar Whether need to update the global variable. @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The specified FormSet could not be found. @@ -3615,7 +4139,8 @@ EFI_STATUS InitializeFormSet ( IN EFI_HII_HANDLE Handle, IN OUT EFI_GUID *FormSetGuid, - OUT FORM_BROWSER_FORMSET *FormSet + OUT FORM_BROWSER_FORMSET *FormSet, + IN BOOLEAN UpdateGlobalVar ) { EFI_STATUS Status; @@ -3660,6 +4185,13 @@ InitializeFormSet ( return Status; } + // + // If not need to update the global variable, just return. + // + if (!UpdateGlobalVar) { + return Status; + } + // // Set VFR type by FormSet SubClass field // @@ -3678,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; @@ -3765,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)); @@ -3842,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)); @@ -3872,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; @@ -4122,18 +4661,20 @@ SaveReminder ( CHAR16 *ChangeReminderString; CHAR16 *SaveConfirmString; EFI_INPUT_KEY Key; - EFI_STATUS Status; DataSavedAction = BROWSER_NO_CHANGES; IsDataChanged = FALSE; 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); } // @@ -4146,7 +4687,7 @@ SaveReminder ( // // If data is changed, prompt user // - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); YesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle); ASSERT (YesResponse != NULL);