diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 5887e0f3be..a437674bdc 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -2847,6 +2847,108 @@ FindQuestionFromProgress ( return (BOOLEAN) (*RetForm != NULL); } +/** + Base on the return Progress string to get the SyncConfigRequest and RestoreConfigRequest + for form and formset. + + @param Storage Storage which has this Progress string. + @param ConfigRequest The ConfigRequest string. + @param Progress The Progress string which has the first fail string. + @param RestoreConfigRequest Return the RestoreConfigRequest string. + @param SyncConfigRequest Return the SyncConfigRequest string. + +**/ +VOID +GetSyncRestoreConfigRequest( + IN BROWSER_STORAGE *Storage, + IN EFI_STRING ConfigRequest, + IN EFI_STRING Progress, + OUT EFI_STRING *RestoreConfigRequest, + OUT EFI_STRING *SyncConfigRequest + ) +{ + EFI_STRING EndStr; + EFI_STRING ConfigHdrEndStr; + EFI_STRING ElementStr; + UINTN TotalSize; + UINTN RestoreEleSize; + UINTN SyncSize; + + ASSERT ((*Progress == L'&') || (*Progress == L'G')); + // + // If the Progress starts with ConfigHdr, means the failure is in the first name / value pair. + // Need to restore all the fields in the ConfigRequest. + // + if (*Progress == L'G') { + *RestoreConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest); + ASSERT (*RestoreConfigRequest != NULL); + return; + } + + // + // Find the first fail "NAME" or "OFFSET=0x####&WIDTH=0x####" string. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + // + // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset, + // here, just keep the "Fred" string. + // + EndStr = StrStr (Progress, L"="); + ASSERT (EndStr != NULL); + *EndStr = L'\0'; + // + // Find the ConfigHdr in ConfigRequest. + // + ConfigHdrEndStr = StrStr (ConfigRequest, L"PATH="); + ASSERT (ConfigHdrEndStr != NULL); + while (*ConfigHdrEndStr != L'&') { + ConfigHdrEndStr++; + } + } else { + // + // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####", + // here, just keep the "OFFSET=0x####&WIDTH=0x####" string. + // + EndStr = StrStr (Progress, L"&VALUE="); + ASSERT (EndStr != NULL); + *EndStr = L'\0'; + // + // Find the ConfigHdr in ConfigRequest. + // + ConfigHdrEndStr = StrStr (ConfigRequest, L"&OFFSET="); + } + // + // Find the first fail pair in the ConfigRequest. + // + ElementStr = StrStr (ConfigRequest, Progress); + ASSERT (ElementStr != NULL); + // + // To get the RestoreConfigRequest. + // + RestoreEleSize = StrSize (ElementStr); + TotalSize = (ConfigHdrEndStr - ConfigRequest) * sizeof (CHAR16) + RestoreEleSize + sizeof (CHAR16); + *RestoreConfigRequest = AllocateZeroPool (TotalSize); + ASSERT (*RestoreConfigRequest != NULL); + StrnCpyS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ConfigRequest, ConfigHdrEndStr - ConfigRequest); + StrCatS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ElementStr); + // + // To get the SyncConfigRequest. + // + SyncSize = StrSize (ConfigRequest) - RestoreEleSize + sizeof (CHAR16); + *SyncConfigRequest = AllocateZeroPool (SyncSize); + ASSERT (*SyncConfigRequest != NULL); + StrnCpyS (*SyncConfigRequest, SyncSize / sizeof (CHAR16), ConfigRequest, SyncSize / sizeof (CHAR16) - 1); + + // + // restore the Progress string to the original format. + // + if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) { + *EndStr = L'='; + } else { + *EndStr = L'&'; + } +} + /** Popup an save error info and get user input. @@ -3126,6 +3228,10 @@ SubmitForForm ( FreePool (ConfigResp); if (EFI_ERROR (Status)) { + // + // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest. + // + GetSyncRestoreConfigRequest (ConfigInfo->Storage, ConfigInfo->ConfigRequest, Progress, &ConfigInfo->RestoreConfigRequest, &ConfigInfo->SyncConfigRequest); InsertTailList (&gBrowserSaveFailFormSetList, &ConfigInfo->SaveFailLink); continue; } @@ -3145,8 +3251,18 @@ SubmitForForm ( while (!IsNull (&gBrowserSaveFailFormSetList, Link)) { ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link); Link = GetNextNode (&gBrowserSaveFailFormSetList, Link); - - SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->RestoreConfigRequest, FALSE); + FreePool (ConfigInfo->RestoreConfigRequest); + ConfigInfo->RestoreConfigRequest = NULL; + if (ConfigInfo->SyncConfigRequest != NULL) { + SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->SyncConfigRequest, TRUE); + FreePool (ConfigInfo->SyncConfigRequest); + ConfigInfo->SyncConfigRequest = NULL; + } Status = EFI_SUCCESS; } @@ -3269,6 +3385,10 @@ SubmitForFormSet ( &Progress ); if (EFI_ERROR (Status)) { + // + // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest. + // + GetSyncRestoreConfigRequest (FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, Progress, &FormSetStorage->RestoreConfigRequest, &FormSetStorage->SyncConfigRequest); InsertTailList (&FormSet->SaveFailStorageListHead, &FormSetStorage->SaveFailLink); if (!HasInserted) { // @@ -3310,8 +3430,18 @@ SubmitForFormSet ( FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link); Storage = FormSetStorage->BrowserStorage; Link = GetNextNode (&FormSet->SaveFailStorageListHead, Link); - - SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE); + FreePool (FormSetStorage->RestoreConfigRequest); + FormSetStorage->RestoreConfigRequest = NULL; + if (FormSetStorage->SyncConfigRequest != NULL) { + SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE); + FreePool (FormSetStorage->SyncConfigRequest); + FormSetStorage->SyncConfigRequest = NULL; + } Status = EFI_SUCCESS; } @@ -3445,8 +3575,18 @@ SubmitForSystem ( while (!IsNull (&LocalFormSet->SaveFailStorageListHead, StorageLink)) { FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink); StorageLink = GetNextNode (&LocalFormSet->SaveFailStorageListHead, StorageLink); - - SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE); + // + // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer + // base on the SyncConfigRequest to Sync the buffer. + // + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE); + FreePool (FormSetStorage->RestoreConfigRequest); + FormSetStorage->RestoreConfigRequest = NULL; + if ( FormSetStorage->SyncConfigRequest != NULL) { + SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE); + FreePool (FormSetStorage->SyncConfigRequest); + FormSetStorage->SyncConfigRequest = NULL; + } } } diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h index 0abb09cf87..cbc5401323 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h @@ -1,7 +1,7 @@ /** @file Private MACRO, structure and function definitions for Setup Browser module. -Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, 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 @@ -178,6 +178,8 @@ typedef struct { BOOLEAN HasCallAltCfg; // Flag to show whether browser has call ExtractConfig to get Altcfg string. UINTN ElementCount; // Number of in the UINTN SpareStrLen; // Spare length of ConfigRequest string buffer + CHAR16 *RestoreConfigRequest; // When submit formset fail, the element need to be restored + CHAR16 *SyncConfigRequest; // When submit formset fail, the element need to be synced } FORMSET_STORAGE; #define FORMSET_STORAGE_FROM_LINK(a) CR (a, FORMSET_STORAGE, Link, FORMSET_STORAGE_SIGNATURE) @@ -387,6 +389,8 @@ typedef struct { CHAR16 *ConfigAltResp; // Alt config response string for this ConfigRequest. UINTN ElementCount; // Number of in the UINTN SpareStrLen; + CHAR16 *RestoreConfigRequest; // When submit form fail, the element need to be restored + CHAR16 *SyncConfigRequest; // When submit form fail, the element need to be synced BROWSER_STORAGE *Storage; } FORM_BROWSER_CONFIG_REQUEST;