]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
MdeModulePkg: Use IsZeroGuid API for zero GUID checking
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
index 43cfc87eeb3d2ce39d936257241522666fb9056c..3f368b54ec7d6b67d1fe546aaa575d198fc5edde 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Entry and initialization module for the browser.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -181,7 +181,7 @@ UiFindMenuList (
     // Find the same FromSet.\r
     //\r
     if (MenuList->HiiHandle == HiiHandle) {\r
-      if (CompareGuid (&MenuList->FormSetGuid, &gZeroGuid)) {\r
+      if (IsZeroGuid (&MenuList->FormSetGuid)) {\r
         //\r
         // FormSetGuid is not specified.\r
         //\r
@@ -1429,40 +1429,44 @@ BufferToValue (
   *StringPtr = L'\0';\r
 \r
   LengthStr = StrLen (Value);\r
+\r
+  //\r
+  // Value points to a Unicode hexadecimal string, we need to convert the string to the value with CHAR16/UINT8...type.\r
+  // When generating the Value string, we follow this rule: 1 byte -> 2 Unicode characters (for string: 2 byte(CHAR16) ->4 Unicode characters).\r
+  // So the maximum value string length of a question is : Question->StorageWidth * 2.\r
+  // If the value string length > Question->StorageWidth * 2, only set the string length as Question->StorageWidth * 2, then convert.\r
+  //\r
+  if (LengthStr > (UINTN) Question->StorageWidth * 2) {\r
+    Length = (UINTN) Question->StorageWidth * 2;\r
+  } else {\r
+    Length = LengthStr;\r
+  }\r
+\r
   Status    = EFI_SUCCESS;\r
   if (!IsBufferStorage && IsString) {\r
     //\r
     // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"\r
     // Add string tail char L'\0' into Length\r
     //\r
-    Length    = Question->StorageWidth + sizeof (CHAR16);\r
-    if (Length < ((LengthStr / 4 + 1) * 2)) {\r
-      Status = EFI_BUFFER_TOO_SMALL;\r
-    } else {\r
-      DstBuf = (CHAR16 *) Dst;\r
-      ZeroMem (TemStr, sizeof (TemStr));\r
-      for (Index = 0; Index < LengthStr; Index += 4) {\r
-        StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4);\r
-        DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
-      }\r
-      //\r
-      // Add tailing L'\0' character\r
-      //\r
-      DstBuf[Index/4] = L'\0';\r
+    DstBuf = (CHAR16 *) Dst;\r
+    ZeroMem (TemStr, sizeof (TemStr));\r
+    for (Index = 0; Index < Length; Index += 4) {\r
+      StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4);\r
+      DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
     }\r
+    //\r
+    // Add tailing L'\0' character\r
+    //\r
+    DstBuf[Index/4] = L'\0';\r
   } else {\r
-    if (Question->StorageWidth < ((LengthStr + 1) / 2)) {\r
-      Status = EFI_BUFFER_TOO_SMALL;\r
-    } else {\r
-      ZeroMem (TemStr, sizeof (TemStr));\r
-      for (Index = 0; Index < LengthStr; Index ++) {\r
-        TemStr[0] = Value[LengthStr - Index - 1];\r
-        DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
-        if ((Index & 1) == 0) {\r
-          Dst [Index/2] = DigitUint8;\r
-        } else {\r
-          Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
-        }\r
+    ZeroMem (TemStr, sizeof (TemStr));\r
+    for (Index = 0; Index < Length; Index ++) {\r
+      TemStr[0] = Value[LengthStr - Index - 1];\r
+      DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+      if ((Index & 1) == 0) {\r
+        Dst [Index/2] = DigitUint8;\r
+      } else {\r
+        Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
       }\r
     }\r
   }\r
@@ -2426,6 +2430,10 @@ SendDiscardInfoToDriver (
     //\r
     GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer);\r
 \r
+    if (Question->Operand == EFI_IFR_STRING_OP){\r
+      HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
+    }\r
+\r
     if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
       TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
     } else {\r
@@ -2444,6 +2452,94 @@ SendDiscardInfoToDriver (
   }\r
 }\r
 \r
+/**\r
+  When submit the question value, call the callback function with Submitted type\r
+  to inform the hii driver.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
+\r
+**/\r
+VOID\r
+SubmitCallbackForForm (\r
+  IN FORM_BROWSER_FORMSET             *FormSet,\r
+  IN FORM_BROWSER_FORM                *Form\r
+  )\r
+{\r
+  LIST_ENTRY                  *Link;\r
+  FORM_BROWSER_STATEMENT      *Question;\r
+  EFI_IFR_TYPE_VALUE          *TypeValue;\r
+  EFI_BROWSER_ACTION_REQUEST  ActionRequest;\r
+\r
+  if (FormSet->ConfigAccess == NULL) {\r
+    return;\r
+  }\r
+\r
+  Link = GetFirstNode (&Form->StatementListHead);\r
+  while (!IsNull (&Form->StatementListHead, Link)) {\r
+    Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
+    Link = GetNextNode (&Form->StatementListHead, Link);\r
+\r
+    if (Question->Storage == NULL || Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+      continue;\r
+    }\r
+\r
+    if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {\r
+       continue;\r
+    }\r
+\r
+    if (Question->Operand == EFI_IFR_PASSWORD_OP) {\r
+       continue;\r
+    }\r
+\r
+    if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
+      TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
+    } else {\r
+      TypeValue = &Question->HiiValue.Value;\r
+    }\r
+\r
+    ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
+    FormSet->ConfigAccess->Callback (\r
+                             FormSet->ConfigAccess,\r
+                             EFI_BROWSER_ACTION_SUBMITTED,\r
+                             Question->QuestionId,\r
+                             Question->HiiValue.Type,\r
+                             TypeValue,\r
+                             &ActionRequest\r
+                             );\r
+  }\r
+}\r
+\r
+/**\r
+  When value set Success, call the submit callback function.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
+\r
+**/\r
+VOID\r
+SubmitCallback (\r
+  IN FORM_BROWSER_FORMSET             *FormSet,\r
+  IN FORM_BROWSER_FORM                *Form\r
+  )\r
+{\r
+  FORM_BROWSER_FORM       *CurrentForm;\r
+  LIST_ENTRY              *Link;\r
+\r
+  if (Form != NULL) {\r
+    SubmitCallbackForForm(FormSet, Form);\r
+    return;\r
+  }\r
+\r
+  Link = GetFirstNode (&FormSet->FormListHead);\r
+  while (!IsNull (&FormSet->FormListHead, Link)) {\r
+    CurrentForm = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+    Link = GetNextNode (&FormSet->FormListHead, Link);\r
+\r
+    SubmitCallbackForForm(FormSet, CurrentForm);\r
+  }\r
+}\r
+\r
 /**\r
   Validate the HiiHandle.\r
 \r
@@ -2755,6 +2851,108 @@ FindQuestionFromProgress (
   return (BOOLEAN) (*RetForm != NULL);\r
 }\r
 \r
+/**\r
+  Base on the return Progress string to get the SyncConfigRequest and RestoreConfigRequest\r
+  for form and formset.\r
+\r
+  @param  Storage                 Storage which has this Progress string.\r
+  @param  ConfigRequest           The ConfigRequest string.\r
+  @param  Progress                The Progress string which has the first fail string.\r
+  @param  RestoreConfigRequest    Return the RestoreConfigRequest string.\r
+  @param  SyncConfigRequest       Return the SyncConfigRequest string.\r
+\r
+**/\r
+VOID\r
+GetSyncRestoreConfigRequest(\r
+  IN  BROWSER_STORAGE   *Storage,\r
+  IN  EFI_STRING        ConfigRequest,\r
+  IN  EFI_STRING        Progress,\r
+  OUT EFI_STRING        *RestoreConfigRequest,\r
+  OUT EFI_STRING        *SyncConfigRequest\r
+  )\r
+{\r
+  EFI_STRING    EndStr;\r
+  EFI_STRING    ConfigHdrEndStr;\r
+  EFI_STRING    ElementStr;\r
+  UINTN         TotalSize;\r
+  UINTN         RestoreEleSize;\r
+  UINTN         SyncSize;\r
+\r
+  ASSERT ((*Progress == L'&') || (*Progress == L'G'));\r
+  //\r
+  // If the Progress starts with ConfigHdr, means the failure is in the first name / value pair.\r
+  // Need to restore all the fields in the ConfigRequest.\r
+  //\r
+  if (*Progress == L'G') {\r
+    *RestoreConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest);\r
+    ASSERT (*RestoreConfigRequest != NULL);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Find the first fail "NAME" or "OFFSET=0x####&WIDTH=0x####" string.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    //\r
+    // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,\r
+    // here, just keep the "Fred" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"PATH=");\r
+    ASSERT (ConfigHdrEndStr != NULL);\r
+    while (*ConfigHdrEndStr != L'&') {\r
+      ConfigHdrEndStr++;\r
+    }\r
+  } else {\r
+    //\r
+    // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",\r
+    // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"&VALUE=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"&OFFSET=");\r
+  }\r
+  //\r
+  // Find the first fail pair in the ConfigRequest.\r
+  //\r
+  ElementStr = StrStr (ConfigRequest, Progress);\r
+  ASSERT (ElementStr != NULL);\r
+  //\r
+  // To get the RestoreConfigRequest.\r
+  //\r
+  RestoreEleSize = StrSize (ElementStr);\r
+  TotalSize = (ConfigHdrEndStr - ConfigRequest) * sizeof (CHAR16) + RestoreEleSize + sizeof (CHAR16);\r
+  *RestoreConfigRequest = AllocateZeroPool (TotalSize);\r
+  ASSERT (*RestoreConfigRequest != NULL);\r
+  StrnCpyS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ConfigRequest, ConfigHdrEndStr - ConfigRequest);\r
+  StrCatS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ElementStr);\r
+  //\r
+  // To get the SyncConfigRequest.\r
+  //\r
+  SyncSize = StrSize (ConfigRequest) - RestoreEleSize + sizeof (CHAR16);\r
+  *SyncConfigRequest = AllocateZeroPool (SyncSize);\r
+  ASSERT (*SyncConfigRequest != NULL);\r
+  StrnCpyS (*SyncConfigRequest, SyncSize / sizeof (CHAR16), ConfigRequest, SyncSize / sizeof (CHAR16) - 1);\r
+\r
+  //\r
+  // restore the Progress string to the original format.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    *EndStr = L'=';\r
+  } else {\r
+    *EndStr = L'&';\r
+  }\r
+}\r
+\r
 /**\r
   Popup an save error info and get user input.\r
 \r
@@ -2988,6 +3186,9 @@ SubmitForForm (
   EFI_STRING              Progress;\r
   BROWSER_STORAGE         *Storage;\r
   FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;\r
+  BOOLEAN                 SubmitFormFail;\r
+\r
+  SubmitFormFail = FALSE;\r
 \r
   if (!IsNvUpdateRequiredForForm (Form)) {\r
     return EFI_SUCCESS;\r
@@ -3031,13 +3232,19 @@ SubmitForForm (
                                       ConfigResp,\r
                                       &Progress\r
                                       );\r
-    FreePool (ConfigResp);\r
 \r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      SubmitFormFail = TRUE;\r
+      GetSyncRestoreConfigRequest (ConfigInfo->Storage, ConfigInfo->ConfigRequest, Progress, &ConfigInfo->RestoreConfigRequest, &ConfigInfo->SyncConfigRequest);\r
       InsertTailList (&gBrowserSaveFailFormSetList, &ConfigInfo->SaveFailLink);\r
+      FreePool (ConfigResp);\r
       continue;\r
     }\r
 \r
+    FreePool (ConfigResp);\r
     //\r
     // 3. Config success, update storage shadow Buffer, only update the data belong to this form.\r
     //\r
@@ -3053,8 +3260,18 @@ SubmitForForm (
       while (!IsNull (&gBrowserSaveFailFormSetList, Link)) {\r
         ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link);\r
         Link = GetNextNode (&gBrowserSaveFailFormSetList, Link);\r
-\r
-        SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE);\r
+        //\r
+        // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+        // base on the SyncConfigRequest to Sync the buffer.\r
+        //\r
+        SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->RestoreConfigRequest, FALSE);\r
+        FreePool (ConfigInfo->RestoreConfigRequest);\r
+        ConfigInfo->RestoreConfigRequest = NULL;\r
+        if (ConfigInfo->SyncConfigRequest != NULL) {\r
+          SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->SyncConfigRequest, TRUE);\r
+          FreePool (ConfigInfo->SyncConfigRequest);\r
+          ConfigInfo->SyncConfigRequest = NULL;\r
+        }\r
 \r
         Status = EFI_SUCCESS;\r
       }\r
@@ -3077,6 +3294,13 @@ SubmitForForm (
   //\r
   ValueChangeResetFlagUpdate(TRUE, FormSet, Form);\r
 \r
+  //\r
+  // 6 Call callback with Submitted type to inform the driver.\r
+  //\r
+  if (!SubmitFormFail) {\r
+    SubmitCallback (FormSet, Form);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -3111,8 +3335,10 @@ SubmitForFormSet (
   FORM_BROWSER_FORM       *Form;\r
   BOOLEAN                 HasInserted;\r
   FORM_BROWSER_STATEMENT  *Question;\r
+  BOOLEAN                 SubmitFormSetFail;\r
 \r
   HasInserted = FALSE;\r
+  SubmitFormSetFail = FALSE;\r
 \r
   if (!IsNvUpdateRequiredForFormSet (FormSet)) {\r
     return EFI_SUCCESS;\r
@@ -3172,6 +3398,11 @@ SubmitForFormSet (
                                       &Progress\r
                                       );\r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      SubmitFormSetFail = TRUE;\r
+      GetSyncRestoreConfigRequest (FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, Progress, &FormSetStorage->RestoreConfigRequest, &FormSetStorage->SyncConfigRequest);\r
       InsertTailList (&FormSet->SaveFailStorageListHead, &FormSetStorage->SaveFailLink);\r
       if (!HasInserted) {\r
         //\r
@@ -3213,8 +3444,18 @@ SubmitForFormSet (
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link);\r
           Storage        = FormSetStorage->BrowserStorage;\r
           Link = GetNextNode (&FormSet->SaveFailStorageListHead, Link);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if (FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
 \r
           Status = EFI_SUCCESS;\r
         }\r
@@ -3251,6 +3492,13 @@ SubmitForFormSet (
   // \r
   ValueChangeResetFlagUpdate(TRUE, FormSet, NULL);\r
 \r
+  //\r
+  // 6. Call callback with Submitted type to inform the driver.\r
+  //\r
+  if (!SubmitFormSetFail) {\r
+    SubmitCallback (FormSet, NULL);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -3343,8 +3591,18 @@ SubmitForSystem (
         while (!IsNull (&LocalFormSet->SaveFailStorageListHead, StorageLink)) {\r
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink);\r
           StorageLink = GetNextNode (&LocalFormSet->SaveFailStorageListHead, StorageLink);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if ( FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
         }\r
       }\r
 \r
@@ -3502,6 +3760,11 @@ GetOffsetFromConfigResp (
   // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER\r
   //\r
 \r
+  //\r
+  // Convert all hex digits in ConfigResp to lower case before searching.\r
+  //\r
+  HiiToLower (ConfigResp);\r
+\r
   //\r
   // 1. Directly use Question->BlockName to find.\r
   //\r
@@ -3795,9 +4058,15 @@ GetQuestionDefault (
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
   INTN                            Action;\r
   CHAR16                          *NewString;\r
+  EFI_IFR_TYPE_VALUE              *TypeValue;\r
+  UINT16                          OriginalDefaultId;\r
+  FORMSET_DEFAULTSTORE            *DefaultStore;\r
+  LIST_ENTRY                      *DefaultLink;\r
 \r
   Status   = EFI_NOT_FOUND;\r
   StrValue = NULL;\r
+  OriginalDefaultId  = DefaultId;\r
+  DefaultLink        = GetFirstNode (&FormSet->DefaultStoreListHead);\r
 \r
   //\r
   // Statement don't have storage, skip them\r
@@ -3814,7 +4083,15 @@ GetQuestionDefault (
   //  4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)\r
   //  5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)\r
   //\r
+ReGetDefault:\r
   HiiValue = &Question->HiiValue;\r
+  TypeValue = &HiiValue->Value;\r
+  if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {\r
+    //\r
+    // For orderedlist, need to pass the BufferValue to Callback function.\r
+    //\r
+    TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
+  }\r
 \r
   //\r
   // Get Question defaut value from call back function.\r
@@ -3828,7 +4105,7 @@ GetQuestionDefault (
                              Action,\r
                              Question->QuestionId,\r
                              HiiValue->Type,\r
-                             &HiiValue->Value,\r
+                             TypeValue,\r
                              &ActionRequest\r
                              );\r
     if (!EFI_ERROR (Status)) {\r
@@ -3838,6 +4115,7 @@ GetQuestionDefault (
 \r
         ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth);\r
         if (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth) {\r
+          ZeroMem (Question->BufferValue, Question->StorageWidth);\r
           CopyMem (Question->BufferValue, NewString, StrSize (NewString));\r
         } else {\r
           CopyMem (Question->BufferValue, NewString, Question->StorageWidth);\r
@@ -3908,6 +4186,7 @@ GetQuestionDefault (
             return EFI_NOT_FOUND;\r
           }\r
           if (Question->StorageWidth > StrSize (StrValue)) {\r
+            ZeroMem (Question->BufferValue, Question->StorageWidth);\r
             CopyMem (Question->BufferValue, StrValue, StrSize (StrValue));\r
           } else {\r
             CopyMem (Question->BufferValue, StrValue, Question->StorageWidth);\r
@@ -3962,8 +4241,6 @@ GetQuestionDefault (
           ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0))\r
          ) {\r
         HiiValue->Value.b = TRUE;\r
-      } else {\r
-        HiiValue->Value.b = FALSE;\r
       }\r
 \r
       return EFI_SUCCESS;\r
@@ -3971,10 +4248,30 @@ GetQuestionDefault (
   }\r
 \r
   //\r
-  // For Questions without default\r
+  // For question without default value for current default Id, we try to re-get the default value form other default id in the DefaultStoreList.\r
+  // If get, will exit the function, if not, will choose next default id in the DefaultStoreList.\r
+  // The default id in DefaultStoreList are in ascending order to make sure choose the smallest default id every time.\r
+  //\r
+  while (!IsNull(&FormSet->DefaultStoreListHead, DefaultLink)) {\r
+    DefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink);\r
+    DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead,DefaultLink);\r
+    DefaultId = DefaultStore->DefaultId;\r
+    if (DefaultId == OriginalDefaultId) {\r
+      continue;\r
+    }\r
+    goto ReGetDefault;\r
+  }\r
+\r
+  //\r
+  // For Questions without default value for all the default id in the DefaultStoreList.\r
   //\r
   Status = EFI_NOT_FOUND;\r
   switch (Question->Operand) {\r
+  case EFI_IFR_CHECKBOX_OP:\r
+    HiiValue->Value.b = FALSE;\r
+    Status = EFI_SUCCESS;\r
+    break;\r
+\r
   case EFI_IFR_NUMERIC_OP:\r
     //\r
     // Take minimum value as numeric default value\r
@@ -5392,7 +5689,7 @@ GetIfrBinaryData (
           //\r
           // Try to compare against formset GUID\r
           //\r
-          if (CompareGuid (FormSetGuid, &gZeroGuid) || \r
+          if (IsZeroGuid (FormSetGuid) ||\r
               CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {\r
             break;\r
           }\r
@@ -5541,8 +5838,9 @@ SaveBrowserContext (
   VOID\r
   )\r
 {\r
-  BROWSER_CONTEXT  *Context;\r
-  FORM_ENTRY_INFO     *MenuList;\r
+  BROWSER_CONTEXT      *Context;\r
+  FORM_ENTRY_INFO      *MenuList;\r
+  FORM_BROWSER_FORMSET *FormSet;\r
 \r
   gBrowserContextCount++;\r
   if (gBrowserContextCount == 1) {\r
@@ -5568,6 +5866,10 @@ SaveBrowserContext (
   Context->HiiHandle            = mCurrentHiiHandle;\r
   Context->FormId               = mCurrentFormId;\r
   CopyGuid (&Context->FormSetGuid, &mCurrentFormSetGuid);\r
+  Context->SystemLevelFormSet   = mSystemLevelFormSet;\r
+  Context->CurFakeQestId        = mCurFakeQestId;\r
+  Context->HiiPackageListUpdated = mHiiPackageListUpdated;\r
+  Context->FinishRetrieveCall   = mFinishRetrieveCall;\r
 \r
   //\r
   // Save the menu history data.\r
@@ -5580,6 +5882,17 @@ SaveBrowserContext (
     InsertTailList(&Context->FormHistoryList, &MenuList->Link);\r
   }\r
 \r
+  //\r
+  // Save formset list.\r
+  //\r
+  InitializeListHead(&Context->FormSetList);\r
+  while (!IsListEmpty (&gBrowserFormSetList)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (gBrowserFormSetList.ForwardLink);\r
+    RemoveEntryList (&FormSet->Link);\r
+\r
+    InsertTailList(&Context->FormSetList, &FormSet->Link);\r
+  }\r
+\r
   //\r
   // Insert to FormBrowser context list\r
   //\r
@@ -5598,7 +5911,8 @@ RestoreBrowserContext (
 {\r
   LIST_ENTRY       *Link;\r
   BROWSER_CONTEXT  *Context;\r
-  FORM_ENTRY_INFO     *MenuList;\r
+  FORM_ENTRY_INFO      *MenuList;\r
+  FORM_BROWSER_FORMSET *FormSet;\r
 \r
   ASSERT (gBrowserContextCount != 0);\r
   gBrowserContextCount--;\r
@@ -5625,6 +5939,10 @@ RestoreBrowserContext (
   mCurrentHiiHandle     = Context->HiiHandle;\r
   mCurrentFormId        = Context->FormId;\r
   CopyGuid (&mCurrentFormSetGuid, &Context->FormSetGuid);\r
+  mSystemLevelFormSet   = Context->SystemLevelFormSet;\r
+  mCurFakeQestId        = Context->CurFakeQestId;\r
+  mHiiPackageListUpdated = Context->HiiPackageListUpdated;\r
+  mFinishRetrieveCall   = Context->FinishRetrieveCall;\r
 \r
   //\r
   // Restore the menu history data.\r
@@ -5636,6 +5954,16 @@ RestoreBrowserContext (
     InsertTailList(&mPrivateData.FormBrowserEx2.FormViewHistoryHead, &MenuList->Link);\r
   }\r
 \r
+  //\r
+  // Restore the Formset data.\r
+  //\r
+  while (!IsListEmpty (&Context->FormSetList)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Context->FormSetList.ForwardLink);\r
+    RemoveEntryList (&FormSet->Link);\r
+\r
+    InsertTailList(&gBrowserFormSetList, &FormSet->Link);\r
+  }\r
+\r
   //\r
   // Remove from FormBrowser context list\r
   //\r