]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
MdeModulePkg/SetupBrowser: Call submit callback function when no failure
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 4caf361bd22272cc51c0a3de82e9305cd0ef5ee4..cc155ccc61c9780b8c8605101401406240f99a3c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2014, 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
@@ -252,8 +252,7 @@ GenerateSubStr (
   Str    = AllocateZeroPool (Length * sizeof (CHAR16));\r
   ASSERT (Str != NULL);\r
 \r
-  StrCpy (Str, String);\r
-  Length = (BufferLen * 2 + 1) * sizeof (CHAR16);\r
+  StrCpyS (Str, Length, String);\r
 \r
   StringHeader = Str + StrLen (String);\r
   TemString    = (CHAR16 *) StringHeader;\r
@@ -297,7 +296,7 @@ GenerateSubStr (
   //\r
   // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
   //\r
-  StrCat (Str, L"&");  \r
+  StrCatS (Str, Length, L"&");  \r
   HiiToLower (Str);\r
 \r
   *SubStr = Str;\r
@@ -392,6 +391,7 @@ AppendToMultiString (
 {\r
   UINTN AppendStringSize;\r
   UINTN MultiStringSize;\r
+  UINTN MaxLen;\r
 \r
   if (MultiString == NULL || *MultiString == NULL || AppendString == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -399,6 +399,7 @@ AppendToMultiString (
 \r
   AppendStringSize = StrSize (AppendString);\r
   MultiStringSize  = StrSize (*MultiString);\r
+  MaxLen = MAX_STRING_LENGTH / sizeof (CHAR16);\r
 \r
   //\r
   // Enlarge the buffer each time when length exceeds MAX_STRING_LENGTH.\r
@@ -410,12 +411,13 @@ AppendToMultiString (
                                   MultiStringSize + AppendStringSize,\r
                                   (VOID *) (*MultiString)\r
                                   );\r
+    MaxLen = (MultiStringSize + AppendStringSize) / sizeof (CHAR16);\r
     ASSERT (*MultiString != NULL);\r
   }\r
   //\r
   // Append the incoming string\r
   //\r
-  StrCat (*MultiString, AppendString);\r
+  StrCatS (*MultiString, MaxLen, AppendString);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -507,6 +509,479 @@ Exit:
   return Status;\r
 }\r
 \r
+/**\r
+ To find the BlockName in the string with same value.\r
+\r
+  @param  String                 Pointer to a Null-terminated Unicode string.\r
+  @param  BlockName              Pointer to a Null-terminated Unicode string to search for.\r
+  @param  Buffer                 Pointer to the value correspond to the BlockName.\r
+  @param  Found                  The Block whether has been found.\r
+  @param  BufferLen              The length of the buffer.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES   Insufficient resources to store neccessary structures.\r
+  @retval EFI_SUCCESS            The function finishes successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+FindSameBlockElement(\r
+  IN  EFI_STRING   String,\r
+  IN  EFI_STRING   BlockName,\r
+  IN  UINT8        *Buffer,\r
+  OUT BOOLEAN      *Found,\r
+  IN  UINTN        BufferLen\r
+  )\r
+{\r
+  EFI_STRING   BlockPtr;\r
+  UINTN        Length;\r
+  UINT8        *TempBuffer;\r
+  EFI_STATUS   Status;\r
+\r
+  TempBuffer = NULL;\r
+  *Found = FALSE;\r
+  BlockPtr = StrStr (String, BlockName);\r
+\r
+  while (BlockPtr != NULL) {\r
+    BlockPtr += StrLen (BlockName);\r
+    Status = GetValueOfNumber (BlockPtr, &TempBuffer, &Length);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    ASSERT (TempBuffer != NULL);\r
+    if ((BufferLen == Length) && (0 == CompareMem (Buffer, TempBuffer, Length))) {\r
+      *Found = TRUE;\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      FreePool (TempBuffer);\r
+      TempBuffer = NULL;\r
+      BlockPtr = StrStr (BlockPtr + 1, BlockName);\r
+    }\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>\r
+  in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.\r
+\r
+  @param  DefaultAltCfgResp      Pointer to a null-terminated Unicode string in\r
+                                 <MultiConfigAltResp> format. The default value\r
+                                 string may contain more than one ConfigAltResp\r
+                                 string for the different varstore buffer.\r
+  @param  ConfigAltResp          Pointer to a null-terminated Unicode string in\r
+                                 <ConfigAltResp> format.\r
+  @param  AltConfigHdr           Pointer to a Unicode string in <AltConfigHdr> format.\r
+  @param  ConfigAltRespChanged   Whether the ConfigAltResp has been changed.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES   Insufficient resources to store neccessary structures.\r
+  @retval EFI_SUCCESS            The function finishes  successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+CompareBlockElementDefault (\r
+  IN      EFI_STRING  DefaultAltCfgResp,\r
+  IN OUT  EFI_STRING  *ConfigAltResp,\r
+  IN      EFI_STRING  AltConfigHdr,\r
+  IN OUT  BOOLEAN     *ConfigAltRespChanged\r
+)\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_STRING    BlockPtr;\r
+  EFI_STRING    BlockPtrStart;\r
+  EFI_STRING    StringPtr;\r
+  EFI_STRING    AppendString;\r
+  EFI_STRING    AltConfigHdrPtr;\r
+  UINT8         *TempBuffer;\r
+  UINTN         OffsetLength;\r
+  UINTN         AppendSize;\r
+  UINTN         TotalSize;\r
+  BOOLEAN       FoundOffset;\r
+\r
+  AppendString = NULL;\r
+  TempBuffer   = NULL;\r
+  //\r
+  // Make BlockPtr point to the first <BlockConfig> with AltConfigHdr in DefaultAltCfgResp.\r
+  //\r
+  AltConfigHdrPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
+  ASSERT (AltConfigHdrPtr != NULL);\r
+  BlockPtr = StrStr (AltConfigHdrPtr, L"&OFFSET=");\r
+  //\r
+  // Make StringPtr point to the AltConfigHdr in ConfigAltResp.\r
+  //\r
+  StringPtr = StrStr (*ConfigAltResp, AltConfigHdr);\r
+  ASSERT (StringPtr != NULL);\r
+\r
+  while (BlockPtr != NULL) {\r
+    //\r
+    // Find the "&OFFSET=<Number>" block and get the value of the Number with AltConfigHdr in DefaultAltCfgResp.\r
+    //\r
+    BlockPtrStart = BlockPtr;\r
+    BlockPtr += StrLen (L"&OFFSET=");\r
+    Status = GetValueOfNumber (BlockPtr, &TempBuffer, &OffsetLength);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+    //\r
+    // To find the same "&OFFSET=<Number>" block in ConfigAltResp.\r
+    //\r
+    Status = FindSameBlockElement (StringPtr, L"&OFFSET=", TempBuffer, &FoundOffset, OffsetLength);\r
+    if (TempBuffer != NULL) {\r
+      FreePool (TempBuffer);\r
+      TempBuffer = NULL;\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+    if (!FoundOffset) {\r
+      //\r
+      // Don't find the same "&OFFSET=<Number>" block in ConfigAltResp.\r
+      // Calculate the size of <BlockConfig>.\r
+      // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number>.\r
+      //\r
+      BlockPtr = StrStr (BlockPtr + 1, L"&OFFSET=");\r
+      if (BlockPtr != NULL) {\r
+        AppendSize = (BlockPtr - BlockPtrStart) * sizeof (CHAR16);\r
+      } else {\r
+        AppendSize = StrSize (BlockPtrStart);\r
+      }\r
+      //\r
+      // Copy the <BlockConfig> to AppendString.\r
+      //\r
+      if (AppendString == NULL) {\r
+        AppendString = (EFI_STRING) AllocateZeroPool (AppendSize + sizeof (CHAR16));\r
+        StrnCatS (AppendString, AppendSize / sizeof (CHAR16) + 1, BlockPtrStart, AppendSize / sizeof (CHAR16));\r
+      } else {\r
+        TotalSize = StrSize (AppendString) + AppendSize + sizeof (CHAR16);\r
+        AppendString = (EFI_STRING) ReallocatePool (\r
+                                      StrSize (AppendString),\r
+                                      TotalSize,\r
+                                      AppendString\r
+                                      );\r
+        if (AppendString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Exit;\r
+        }\r
+        StrnCatS (AppendString, TotalSize / sizeof (CHAR16), BlockPtrStart, AppendSize / sizeof (CHAR16));\r
+      }\r
+    } else {\r
+      //\r
+      // To find next "&OFFSET=<Number>" block with AltConfigHdr in DefaultAltCfgResp.\r
+      //\r
+      BlockPtr = StrStr (BlockPtr + 1, L"&OFFSET=");\r
+    }\r
+  }\r
+\r
+  if (AppendString != NULL) {\r
+    //\r
+    // Reallocate ConfigAltResp to copy the AppendString.\r
+    //\r
+    TotalSize = StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16);\r
+    *ConfigAltResp = (EFI_STRING) ReallocatePool (\r
+                                    StrSize (*ConfigAltResp),\r
+                                    TotalSize,\r
+                                    *ConfigAltResp\r
+                                    );\r
+    if (*ConfigAltResp == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+    StrCatS (*ConfigAltResp, TotalSize / sizeof (CHAR16), AppendString);\r
+    *ConfigAltRespChanged = TRUE;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+Exit:\r
+  if (AppendString != NULL) {\r
+    FreePool (AppendString);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Compare the <AltResp> in ConfigAltResp and DefaultAltCfgResp, if the <AltResp>\r
+  in DefaultAltCfgResp but not in ConfigAltResp,add it to the ConfigAltResp.\r
+\r
+  @param  DefaultAltCfgResp      Pointer to a null-terminated Unicode string in\r
+                                 <MultiConfigAltResp> format. The default value\r
+                                 string may contain more than one ConfigAltResp\r
+                                 string for the different varstore buffer.\r
+  @param  ConfigAltResp          Pointer to a null-terminated Unicode string in\r
+                                 <ConfigAltResp> format.\r
+  @param  AltConfigHdr           Pointer to a Unicode string in <AltConfigHdr> format.\r
+  @param  ConfigAltRespChanged   Whether the ConfigAltResp has been changed.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES   Insufficient resources to store neccessary structures.\r
+  @retval EFI_SUCCESS            The function finishes  successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+CompareNameElementDefault (\r
+  IN     EFI_STRING  DefaultAltCfgResp,\r
+  IN OUT EFI_STRING  *ConfigAltResp,\r
+  IN     EFI_STRING  AltConfigHdr,\r
+  IN OUT BOOLEAN     *ConfigAltRespChanged\r
+)\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_STRING    NvConfigPtr;\r
+  EFI_STRING    NvConfigStart;\r
+  EFI_STRING    NvConfigValuePtr;\r
+  EFI_STRING    StringPtr;\r
+  EFI_STRING    NvConfigExist;\r
+  EFI_STRING    AppendString;\r
+  CHAR16        TempChar;\r
+  UINTN         AppendSize;\r
+  UINTN         TotalSize;\r
+\r
+  AppendString = NULL;\r
+  NvConfigExist = NULL;\r
+  //\r
+  // Make NvConfigPtr point to the first <NvConfig> with AltConfigHdr in DefaultAltCfgResp.\r
+  //\r
+  NvConfigPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
+  ASSERT (NvConfigPtr != NULL);\r
+  NvConfigPtr = StrStr (NvConfigPtr + StrLen(AltConfigHdr),L"&");\r
+  //\r
+  // Make StringPtr point to the first <NvConfig> with AltConfigHdr in ConfigAltResp.\r
+  //\r
+  StringPtr = StrStr (*ConfigAltResp, AltConfigHdr);\r
+  ASSERT (StringPtr != NULL);\r
+  StringPtr = StrStr (StringPtr + StrLen (AltConfigHdr), L"&");\r
+  ASSERT (StringPtr != NULL);\r
+\r
+  while (NvConfigPtr != NULL) {\r
+    //\r
+    // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number>.\r
+    // Get the <Label> with AltConfigHdr in DefaultAltCfgResp.\r
+    //\r
+    NvConfigStart = NvConfigPtr;\r
+    NvConfigValuePtr = StrStr (NvConfigPtr + 1, L"=");\r
+    ASSERT (NvConfigValuePtr != NULL);\r
+    TempChar = *NvConfigValuePtr;\r
+    *NvConfigValuePtr = L'\0';\r
+    //\r
+    // Get the <Label> with AltConfigHdr in ConfigAltResp.\r
+    //\r
+    NvConfigExist = StrStr (StringPtr, NvConfigPtr);\r
+    if (NvConfigExist == NULL) {\r
+      //\r
+      // Don't find same <Label> in ConfigAltResp.\r
+      // Calculate the size of <NvConfig>.\r
+      //\r
+      *NvConfigValuePtr = TempChar;\r
+      NvConfigPtr = StrStr (NvConfigPtr + 1, L"&");\r
+      if (NvConfigPtr != NULL) {\r
+        AppendSize = (NvConfigPtr - NvConfigStart) * sizeof (CHAR16);\r
+      } else {\r
+        AppendSize = StrSize (NvConfigStart);\r
+      }\r
+      //\r
+      // Copy the <NvConfig> to AppendString.\r
+      //\r
+      if (AppendString == NULL) {\r
+        AppendString = (EFI_STRING) AllocateZeroPool (AppendSize + sizeof (CHAR16));\r
+        StrnCatS (AppendString, AppendSize / sizeof (CHAR16) + 1, NvConfigStart, AppendSize / sizeof (CHAR16));\r
+      } else {\r
+         TotalSize = StrSize (AppendString) + AppendSize + sizeof (CHAR16);\r
+         AppendString = (EFI_STRING) ReallocatePool (\r
+                                       StrSize (AppendString),\r
+                                       TotalSize,\r
+                                       AppendString\r
+                                       );\r
+        if (AppendString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Exit;\r
+        }\r
+        StrnCatS (AppendString, TotalSize / sizeof (CHAR16), NvConfigStart, AppendSize / sizeof (CHAR16));\r
+      }\r
+    } else {\r
+      //\r
+      // To find next <Label> in DefaultAltCfgResp.\r
+      //\r
+      *NvConfigValuePtr = TempChar;\r
+      NvConfigPtr = StrStr (NvConfigPtr + 1, L"&");\r
+    }\r
+  }\r
+  if (AppendString != NULL) {\r
+    //\r
+    // Reallocate ConfigAltResp to copy the AppendString.\r
+    //\r
+    TotalSize = StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16);\r
+    *ConfigAltResp = (EFI_STRING) ReallocatePool (\r
+                                    StrSize (*ConfigAltResp),\r
+                                    StrSize (*ConfigAltResp) + StrSize (AppendString) + sizeof (CHAR16),\r
+                                    *ConfigAltResp\r
+                                    );\r
+    if (*ConfigAltResp == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+    StrCatS (*ConfigAltResp, TotalSize / sizeof (CHAR16), AppendString);\r
+    *ConfigAltRespChanged = TRUE;\r
+  }\r
+  Status = EFI_SUCCESS;\r
+\r
+Exit:\r
+  if (AppendString != NULL) {\r
+    FreePool (AppendString);\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Compare the <AltResp> in AltCfgResp and DefaultAltCfgResp, if the <AltResp>\r
+  in DefaultAltCfgResp but not in AltCfgResp,add it to the AltCfgResp.\r
+\r
+  @param  AltCfgResp             Pointer to a null-terminated Unicode string in\r
+                                 <ConfigAltResp> format.\r
+  @param  DefaultAltCfgResp      Pointer to a null-terminated Unicode string in\r
+                                 <MultiConfigAltResp> format. The default value\r
+                                 string may contain more than one ConfigAltResp\r
+                                 string for the different varstore buffer.\r
+  @param  AltConfigHdr           Pointer to a Unicode string in <AltConfigHdr> format.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES   Insufficient resources to store neccessary\r
+                                 structures.\r
+  @retval EFI_SUCCESS            The function finishes  successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+CompareAndMergeDefaultString (\r
+  IN OUT EFI_STRING  *AltCfgResp,\r
+  IN     EFI_STRING  DefaultAltCfgResp,\r
+  IN     EFI_STRING  AltConfigHdr\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  EFI_STRING     AltCfgRespBackup;\r
+  EFI_STRING     AltConfigHdrPtr;\r
+  EFI_STRING     AltConfigHdrPtrNext;\r
+  EFI_STRING     ConfigAltResp;\r
+  EFI_STRING     StringPtr;\r
+  EFI_STRING     StringPtrNext;\r
+  EFI_STRING     BlockPtr;\r
+  UINTN          ReallocateSize;\r
+  CHAR16         TempChar;\r
+  CHAR16         TempCharA;\r
+  BOOLEAN        ConfigAltRespChanged;\r
+\r
+  Status = EFI_OUT_OF_RESOURCES;\r
+  BlockPtr             = NULL;\r
+  AltConfigHdrPtrNext  = NULL;\r
+  StringPtrNext        = NULL;\r
+  ConfigAltResp        = NULL;\r
+  AltCfgRespBackup     = NULL;\r
+  TempChar             = L'\0';\r
+  TempCharA            = L'\0';\r
+  ConfigAltRespChanged = FALSE;\r
+\r
+  //\r
+  //To find the <AltResp> with AltConfigHdr in DefaultAltCfgResp, ignore other <AltResp> which follow it.\r
+  //\r
+  AltConfigHdrPtr = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
+  ASSERT (AltConfigHdrPtr != NULL);\r
+  AltConfigHdrPtrNext = StrStr (AltConfigHdrPtr + 1, L"&GUID");\r
+  if (AltConfigHdrPtrNext != NULL) {\r
+    TempChar = *AltConfigHdrPtrNext;\r
+    *AltConfigHdrPtrNext = L'\0';\r
+  }\r
+  //\r
+  // To find the <AltResp> with AltConfigHdr in AltCfgResp, ignore other <AltResp> which follow it.\r
+  //\r
+  StringPtr = StrStr (*AltCfgResp, AltConfigHdr);\r
+  StringPtrNext = StrStr (StringPtr + 1, L"&GUID");\r
+  if (StringPtrNext != NULL) {\r
+    TempCharA = *StringPtrNext;\r
+    *StringPtrNext = L'\0';\r
+  }\r
+  //\r
+  // Copy the content of <ConfigAltResp> which contain current AltConfigHdr in AltCfgResp.\r
+  //\r
+  ConfigAltResp = AllocateCopyPool (StrSize (*AltCfgResp), *AltCfgResp);\r
+  if (ConfigAltResp == NULL) {\r
+    goto Exit;\r
+  }\r
+  //\r
+  // To find the <ConfigBody> with AltConfigHdr in DefaultAltCfgResp.\r
+  //\r
+  BlockPtr = StrStr (AltConfigHdrPtr, L"&OFFSET=");\r
+  if (BlockPtr != NULL) {\r
+    //\r
+    // <BlockConfig>::='OFFSET='<Number>'&WIDTH='<Number>'&VALUE='<Number> style.\r
+    // Call function CompareBlockElementDefault to compare the <BlockConfig> in DefaultAltCfgResp and ConfigAltResp.\r
+    // The ConfigAltResp which may contain the new <BlockConfig> get from DefaultAltCfgResp.\r
+    //\r
+    Status = CompareBlockElementDefault (DefaultAltCfgResp, &ConfigAltResp, AltConfigHdr, &ConfigAltRespChanged);\r
+    if (EFI_ERROR(Status)) {\r
+      goto Exit;\r
+    }\r
+  } else {\r
+    //\r
+    // <NvConfig> ::= <Label>'='<String> | <Label>'='<Number> style.\r
+    // Call function CompareNameElementDefault to compare the <NvConfig> in DefaultAltCfgResp and ConfigAltResp.\r
+    // The ConfigAltResp which may contain the new <NvConfig> get from DefaultAltCfgResp.\r
+    //\r
+    Status = CompareNameElementDefault (DefaultAltCfgResp, &ConfigAltResp, AltConfigHdr, &ConfigAltRespChanged);\r
+    if (EFI_ERROR(Status)) {\r
+      goto Exit;\r
+    }\r
+  }\r
+  //\r
+  // Restore the AltCfgResp.\r
+  //\r
+  if (StringPtrNext != NULL) {\r
+    *StringPtrNext = TempCharA;\r
+  }\r
+\r
+  //\r
+  // If the ConfigAltResp has no change,no need to update the content in AltCfgResp.\r
+  //\r
+  if (!ConfigAltRespChanged) {\r
+    Status = EFI_SUCCESS;\r
+    goto Exit;\r
+  }\r
+  //\r
+  // ConfigAltResp has been changed, need to update the content in AltCfgResp.\r
+  //\r
+  if (StringPtrNext != NULL) {\r
+    ReallocateSize = StrSize (ConfigAltResp) + StrSize (StringPtrNext) + sizeof (CHAR16);\r
+  } else {\r
+    ReallocateSize = StrSize (ConfigAltResp) + sizeof (CHAR16);\r
+  }\r
+\r
+  AltCfgRespBackup = (EFI_STRING) AllocateZeroPool (ReallocateSize);\r
+  if (AltCfgRespBackup == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  StrCatS (AltCfgRespBackup, ReallocateSize / sizeof (CHAR16), ConfigAltResp);\r
+  if (StringPtrNext != NULL) {\r
+    StrCatS (AltCfgRespBackup, ReallocateSize / sizeof (CHAR16), StringPtrNext);\r
+  }\r
+\r
+  FreePool (*AltCfgResp);\r
+  *AltCfgResp = AltCfgRespBackup;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+Exit:\r
+  if (ConfigAltResp != NULL) {\r
+    FreePool(ConfigAltResp);\r
+  }\r
+  //\r
+  // Restore the DefaultAltCfgResp.\r
+  //\r
+  if ( AltConfigHdrPtrNext != NULL) {\r
+    *AltConfigHdrPtrNext = TempChar;\r
+    AltConfigHdrPtrNext = NULL;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   This function merges DefaultAltCfgResp string into AltCfgResp string for\r
   the missing AltCfgId in AltCfgResq.\r
@@ -536,6 +1011,8 @@ MergeDefaultString (
   EFI_STRING   AltConfigHdr;\r
   UINTN        HeaderLength;\r
   UINTN        SizeAltCfgResp;\r
+  UINTN        MaxLen;\r
+  UINTN        TotalSize;\r
   \r
   if (*AltCfgResp == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -572,13 +1049,14 @@ MergeDefaultString (
   // Construct AltConfigHdr string  "&<ConfigHdr>&ALTCFG=XXXX\0"\r
   //                                  |1| StrLen (ConfigHdr) | 8 | 4 | 1 |\r
   //\r
-  AltConfigHdr = AllocateZeroPool ((1 + HeaderLength + 8 + 4 + 1) * sizeof (CHAR16));\r
+  MaxLen = 1 + HeaderLength + 8 + 4 + 1;\r
+  AltConfigHdr = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
   if (AltConfigHdr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  StrCpy (AltConfigHdr, L"&");\r
-  StrnCat (AltConfigHdr, *AltCfgResp, HeaderLength);\r
-  StrCat (AltConfigHdr, L"&ALTCFG=");\r
+  StrCpyS (AltConfigHdr, MaxLen, L"&");\r
+  StrnCatS (AltConfigHdr, MaxLen, *AltCfgResp, HeaderLength);\r
+  StrCatS (AltConfigHdr, MaxLen, L"&ALTCFG=");\r
   HeaderLength = StrLen (AltConfigHdr);\r
   \r
   StringPtrDefault = StrStr (DefaultAltCfgResp, AltConfigHdr);\r
@@ -586,7 +1064,7 @@ MergeDefaultString (
     //\r
     // Get AltCfg Name\r
     //\r
-    StrnCat (AltConfigHdr, StringPtrDefault + HeaderLength, 4);\r
+    StrnCatS (AltConfigHdr, MaxLen, StringPtrDefault + HeaderLength, 4);\r
     StringPtr = StrStr (*AltCfgResp, AltConfigHdr); \r
     \r
     //\r
@@ -599,32 +1077,41 @@ MergeDefaultString (
         //\r
         // No more default string is found.\r
         //\r
+        TotalSize = SizeAltCfgResp + StrSize (StringPtrDefault);\r
         *AltCfgResp    = (EFI_STRING) ReallocatePool (\r
                                      SizeAltCfgResp,\r
-                                     SizeAltCfgResp + StrSize (StringPtrDefault),\r
+                                     TotalSize,\r
                                      (VOID *) (*AltCfgResp)\r
                                      );\r
         if (*AltCfgResp == NULL) {\r
           FreePool (AltConfigHdr);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
-        StrCat (*AltCfgResp, StringPtrDefault);\r
+        StrCatS (*AltCfgResp, TotalSize / sizeof (CHAR16), StringPtrDefault);\r
         break;\r
       } else {\r
         TempChar = *StringPtrEnd;\r
         *StringPtrEnd = L'\0';\r
+        TotalSize = SizeAltCfgResp + StrSize (StringPtrDefault);\r
         *AltCfgResp = (EFI_STRING) ReallocatePool (\r
                                      SizeAltCfgResp,\r
-                                     SizeAltCfgResp + StrSize (StringPtrDefault),\r
+                                     TotalSize,\r
                                      (VOID *) (*AltCfgResp)\r
                                      );\r
         if (*AltCfgResp == NULL) {\r
           FreePool (AltConfigHdr);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
-        StrCat (*AltCfgResp, StringPtrDefault);\r
+        StrCatS (*AltCfgResp, TotalSize / sizeof (CHAR16), StringPtrDefault);\r
         *StringPtrEnd = TempChar;\r
       }\r
+    } else {\r
+      //\r
+      // The AltCfgResp contains <AltCfgResp>.\r
+      // If the <ConfigElement> in <AltCfgResp> in the DefaultAltCfgResp but not in the\r
+      // related <AltCfgResp> in AltCfgResp, merge it to AltCfgResp. else no need to merge.\r
+      //\r
+      CompareAndMergeDefaultString (AltCfgResp, DefaultAltCfgResp, AltConfigHdr);\r
     }\r
     \r
     //\r
@@ -1188,8 +1675,8 @@ GetVarStoreType (
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
-      StrCpy (TempStr, GuidStr);\r
-      StrCat (TempStr, NameStr);\r
+      StrCpyS (TempStr, LengthString, GuidStr);\r
+      StrCatS (TempStr, LengthString, NameStr);\r
       if (ConfigHdr == NULL || StrnCmp (ConfigHdr, TempStr, StrLen (TempStr)) == 0) {\r
         *EfiVarStore = (EFI_IFR_VARSTORE_EFI *) AllocateZeroPool (IfrOpHdr->Length);\r
         if (*EfiVarStore == NULL) {\r
@@ -1304,8 +1791,8 @@ IsThisVarstore (
     goto Done;\r
   }\r
 \r
-  StrCpy (TempStr, GuidStr);\r
-  StrCat (TempStr, NameStr);\r
+  StrCpyS (TempStr, LengthString, GuidStr);\r
+  StrCatS (TempStr, LengthString, NameStr);\r
 \r
   if (ConfigHdr == NULL || StrnCmp (ConfigHdr, TempStr, StrLen (TempStr)) == 0) {\r
     RetVal = TRUE;\r
@@ -1460,7 +1947,8 @@ Done:
   @param  ReturnData             The data block added for this opcode.\r
 \r
   @retval  EFI_SUCCESS           This opcode is required.\r
-  @retval  Others                This opcode is not required or error occur.\r
+  @retval  EFI_NOT_FOUND         This opcode is not required.\r
+  @retval  Others                Contain some error.\r
                                  \r
 **/\r
 EFI_STATUS\r
@@ -1492,7 +1980,7 @@ IsThisOpcodeRequired (
       //\r
       // This question is not in the requested string. Skip it.\r
       //\r
-      return EFI_SUCCESS;\r
+      return EFI_NOT_FOUND;\r
     }\r
   } else {\r
     VarOffset = IfrQuestionHdr->VarStoreInfo.VarOffset;\r
@@ -1504,7 +1992,7 @@ IsThisOpcodeRequired (
       //\r
       // This question is not in the requested string. Skip it.\r
       //\r
-      return EFI_SUCCESS;\r
+      return EFI_NOT_FOUND;\r
     }\r
 \r
     //\r
@@ -1593,6 +2081,7 @@ ParseIfrData (
   UINT16                   VarWidth;\r
   UINT16                   VarDefaultId;\r
   BOOLEAN                  FirstOneOfOption;\r
+  BOOLEAN                  FirstOrderedList;\r
   LIST_ENTRY               *LinkData;\r
   LIST_ENTRY               *LinkDefault;\r
   EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueVarStore;\r
@@ -1604,6 +2093,7 @@ ParseIfrData (
   DefaultDataPtr   = NULL;\r
   FirstOneOfOption = FALSE;\r
   VarStoreId       = 0;\r
+  FirstOrderedList = FALSE;\r
   ZeroMem (&DefaultData, sizeof (IFR_DEFAULT_DATA));\r
 \r
   //\r
@@ -1764,8 +2254,21 @@ ParseIfrData (
       }\r
       VarWidth  = (UINT16) (sizeof (EFI_HII_REF));\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -1792,17 +2295,28 @@ ParseIfrData (
       }\r
       VarWidth  = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
-      if (BlockData == NULL) {\r
-        //\r
-        // BlockData == NULL means this opcode is not in the requst array.\r
-        //\r
-        break;\r
-      }\r
+      //\r
+      //when go to there,BlockData can't be NULLL.\r
+      //\r
+      ASSERT (BlockData != NULL);\r
 \r
       if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r
         //\r
@@ -1850,9 +2364,9 @@ ParseIfrData (
       //\r
       // offset by question header\r
       // width by EFI_IFR_ORDERED_LIST MaxContainers * OneofOption Type\r
-      // no default value and default id, how to define its default value?\r
       //\r
 \r
+      FirstOrderedList = TRUE;\r
       //\r
       // OrderedList question is not in IFR Form. This IFR form is not valid. \r
       //\r
@@ -1869,8 +2383,22 @@ ParseIfrData (
         break;\r
       }\r
       VarWidth  = IfrOrderedList->MaxContainers;\r
+\r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -1900,17 +2428,29 @@ ParseIfrData (
         break;\r
       }\r
       VarWidth  = (UINT16) sizeof (BOOLEAN);\r
+\r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
-      if (BlockData == NULL) {\r
-        //\r
-        // BlockData == NULL means this opcode is not in the requst array.\r
-        //\r
-        break;\r
-      }\r
+      //\r
+      //when go to there,BlockData can't be NULLL.\r
+      //\r
+      ASSERT (BlockData != NULL);\r
 \r
       //\r
       // Add default value for standard ID by CheckBox Flag\r
@@ -1987,9 +2527,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) sizeof (EFI_HII_DATE);\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -2016,9 +2569,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) sizeof (EFI_HII_TIME);\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
       break;\r
@@ -2045,16 +2611,24 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
-\r
-      //\r
-      // No default value for string.\r
-      //\r
-      BlockData = NULL;\r
       break;\r
 \r
     case EFI_IFR_PASSWORD_OP:\r
@@ -2079,9 +2653,22 @@ ParseIfrData (
         break;\r
       }\r
 \r
+      //\r
+      // The BlockData may allocate by other opcode,need to clean.\r
+      //\r
+      if (BlockData != NULL){\r
+        BlockData = NULL;\r
+      }\r
+\r
       VarWidth  = (UINT16) (IfrPassword->MaxSize * sizeof (UINT16));\r
       Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData);\r
       if (EFI_ERROR (Status)) {\r
+        if (Status == EFI_NOT_FOUND){\r
+          //\r
+          //The opcode is not required,exit and parse other opcode.\r
+          //\r
+          break;\r
+        }\r
         goto Done;\r
       }\r
 \r
@@ -2101,6 +2688,10 @@ ParseIfrData (
 \r
       IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;\r
       if (BlockData->OpCode == EFI_IFR_ORDERED_LIST_OP) {\r
+\r
+        if (!FirstOrderedList){\r
+          break;\r
+        }\r
         //\r
         // Get ordered list option data type.\r
         //\r
@@ -2157,10 +2748,9 @@ ParseIfrData (
         // Add Block Data into VarStorageData BlockEntry\r
         //\r
         InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
-        //\r
-        // No default data for OrderedList.\r
-        //\r
-        BlockData = NULL;\r
+\r
+        FirstOrderedList = FALSE;\r
+\r
         break;\r
       }\r
 \r
@@ -2221,12 +2811,6 @@ ParseIfrData (
         break;\r
       }\r
 \r
-      if (BlockData->OpCode == EFI_IFR_ORDERED_LIST_OP) {\r
-        //\r
-        // OrderedList Opcode is no default value.\r
-        //\r
-        break;\r
-      }\r
       //\r
       // Get the DefaultId\r
       //\r
@@ -2288,6 +2872,14 @@ ParseIfrData (
     PackageOffset += IfrOpHdr->Length;\r
   }\r
 \r
+  //\r
+  //if Status == EFI_NOT_FOUND, just means the opcode is not required,not contain any error,\r
+  //so set the Status to EFI_SUCCESS.\r
+  //\r
+  if (Status == EFI_NOT_FOUND){\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
 Done:\r
   for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {\r
     BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);\r
@@ -2666,7 +3258,7 @@ GenerateConfigRequest (
   //\r
   // Start with <ConfigHdr>\r
   //\r
-  StrCpy (StringPtr, ConfigHdr);\r
+  StrCpyS (StringPtr, Length, ConfigHdr);\r
   StringPtr += StrLen (StringPtr);\r
 \r
   //\r
@@ -2765,12 +3357,12 @@ GenerateHdr (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
-  StrCpy (*ConfigHdr, GuidStr);\r
-  StrCat (*ConfigHdr, NameStr);\r
+  StrCpyS (*ConfigHdr, Length, GuidStr);\r
+  StrCatS (*ConfigHdr, Length, NameStr);\r
   if (VarStorageData->Name == NULL) {\r
-    StrCat (*ConfigHdr, L"&");\r
+    StrCatS (*ConfigHdr, Length, L"&");\r
   }\r
-  StrCat (*ConfigHdr, PathStr);\r
+  StrCatS (*ConfigHdr, Length, PathStr);\r
 \r
   //\r
   // Remove the last character L'&'\r
@@ -2844,6 +3436,7 @@ GetStorageWidth (
 /**\r
   Generate ConfigAltResp string base on the varstore info.\r
 \r
+  @param      HiiHandle             Hii Handle for this hii package.\r
   @param      ConfigHdr             The config header for this varstore.\r
   @param      VarStorageData        The varstore info.\r
   @param      DefaultIdArray        The Default id array.\r
@@ -2854,6 +3447,7 @@ GetStorageWidth (
 **/\r
 EFI_STATUS\r
 GenerateAltConfigResp (\r
+  IN  EFI_HII_HANDLE               HiiHandle,\r
   IN  CHAR16                       *ConfigHdr,\r
   IN  IFR_VARSTORAGE_DATA          *VarStorageData,\r
   IN  IFR_DEFAULT_DATA             *DefaultIdArray,\r
@@ -2872,10 +3466,11 @@ GenerateAltConfigResp (
   IFR_DEFAULT_DATA      *DefaultValueData;\r
   UINTN                 Width;\r
   UINT8                 *TmpBuffer;\r
+  CHAR16                *DefaultString;\r
 \r
   BlockData     = NULL;\r
   DataExist     = FALSE;\r
-\r
+  DefaultString = NULL;\r
   //\r
   // Add length for <ConfigHdr> + '\0'\r
   //\r
@@ -2934,7 +3529,7 @@ GenerateAltConfigResp (
   //\r
   // Start with <ConfigHdr>\r
   //\r
-  StrCpy (StringPtr, ConfigHdr);\r
+  StrCpyS (StringPtr, Length, ConfigHdr);\r
   StringPtr += StrLen (StringPtr);\r
 \r
   for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) {\r
@@ -2987,10 +3582,19 @@ GenerateAltConfigResp (
         // Convert Value to a hex string in "%x" format\r
         // NOTE: This is in the opposite byte that GUID and PATH use\r
         //\r
-        TmpBuffer = (UINT8 *) &(DefaultValueData->Value);\r
-        for (; Width > 0; Width--) {\r
+        if (BlockData->OpCode == EFI_IFR_STRING_OP){\r
+          DefaultString   = InternalGetString(HiiHandle, DefaultValueData->Value.string);\r
+          TmpBuffer = (UINT8 *) DefaultString;\r
+        } else {\r
+          TmpBuffer = (UINT8 *) &(DefaultValueData->Value);\r
+        }\r
+        for (; Width > 0 && (TmpBuffer != NULL); Width--) {\r
           StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2);\r
         }\r
+        if (DefaultString != NULL){\r
+          FreePool(DefaultString);\r
+          DefaultString = NULL;\r
+        }\r
       }\r
     }\r
   }\r
@@ -3212,7 +3816,7 @@ GetFullStringFromHiiFormPackages (
   // Go through all VarStorageData Entry and get the DefaultId array for each one\r
   // Then construct them all to : ConfigHdr AltConfigHdr ConfigBody AltConfigHdr ConfigBody\r
   //\r
-  Status = GenerateAltConfigResp (ConfigHdr, VarStorageData, DefaultIdArray, &DefaultAltCfgResp);\r
+  Status = GenerateAltConfigResp (DataBaseRecord->Handle,ConfigHdr, VarStorageData, DefaultIdArray, &DefaultAltCfgResp);\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -3678,6 +4282,8 @@ HiiConfigRoutingExtractConfig (
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
   EFI_STRING                          AccessProgress;\r
   EFI_STRING                          AccessResults;\r
+  EFI_STRING                          AccessProgressBackup;\r
+  EFI_STRING                          AccessResultsBackup;\r
   EFI_STRING                          DefaultResults;\r
   BOOLEAN                             FirstElement;\r
   BOOLEAN                             IfrDataParsedFlag;\r
@@ -3685,6 +4291,9 @@ HiiConfigRoutingExtractConfig (
   EFI_IFR_VARSTORE_EFI                *EfiVarStoreInfo;\r
   EFI_STRING                          ErrorPtr;\r
   UINTN                               DevicePathSize;\r
+  UINTN                               ConigStringSize;\r
+  UINTN                               ConigStringSizeNewsize;\r
+  EFI_STRING                          ConfigStringPtr;\r
 \r
   if (This == NULL || Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -3703,6 +4312,8 @@ HiiConfigRoutingExtractConfig (
   Status         = EFI_SUCCESS;\r
   AccessResults  = NULL;\r
   AccessProgress = NULL;\r
+  AccessResultsBackup  = NULL;\r
+  AccessProgressBackup = NULL;\r
   DevicePath     = NULL;\r
   IfrDataParsedFlag = FALSE;\r
   IsEfiVarStore     = FALSE;\r
@@ -3852,6 +4463,62 @@ HiiConfigRoutingExtractConfig (
       //\r
       Status = GetConfigRespFromEfiVarStore(This, EfiVarStoreInfo, ConfigRequest, &AccessResults, &AccessProgress);\r
       FreePool (EfiVarStoreInfo);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // AccessProgress indicates the parsing progress on <ConfigRequest>.\r
+        // Map it to the progress on <MultiConfigRequest> then return it.\r
+        //\r
+        *Progress = StrStr (StringPtr, AccessProgress);\r
+        goto Done;\r
+      }\r
+\r
+      //\r
+      // For EfiVarstore, call corresponding ConfigAccess protocol to get the AltCfgResp from driver.\r
+      //\r
+      Status = gBS->HandleProtocol (\r
+                      DriverHandle,\r
+                      &gEfiHiiConfigAccessProtocolGuid,\r
+                      (VOID **) &ConfigAccess\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // The driver has EfiVarStore, may not install ConfigAccess protocol.\r
+        // So ignore the error status in this case.\r
+        //\r
+        Status = EFI_SUCCESS;\r
+      } else {\r
+        Status = ConfigAccess->ExtractConfig (\r
+                                 ConfigAccess,\r
+                                 ConfigRequest,\r
+                                 &AccessProgressBackup,\r
+                                 &AccessResultsBackup\r
+                                 );\r
+        if (!EFI_ERROR(Status)) {\r
+          //\r
+          //Merge the AltCfgResp in AccessResultsBackup to AccessResults\r
+          //\r
+          if ((AccessResultsBackup != NULL) && (StrStr (AccessResultsBackup, L"&ALTCFG=") != NULL)) {\r
+            ConigStringSize = StrSize (AccessResults);\r
+            ConfigStringPtr = StrStr (AccessResultsBackup, L"&GUID=");\r
+            ConigStringSizeNewsize = StrSize (ConfigStringPtr) + ConigStringSize + sizeof (CHAR16);\r
+            AccessResults = (EFI_STRING) ReallocatePool (\r
+                                         ConigStringSize,\r
+                                         ConigStringSizeNewsize,\r
+                                         AccessResults);\r
+            StrCatS (AccessResults, ConigStringSizeNewsize / sizeof (CHAR16), ConfigStringPtr);\r
+          }\r
+        } else {\r
+          //\r
+          // In the ExtractConfig function of some driver may not support EfiVarStore,\r
+          // may return error status, just ignore the error status in this case.\r
+          //\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        if (AccessResultsBackup != NULL) {\r
+          FreePool (AccessResultsBackup);\r
+          AccessResultsBackup = NULL;\r
+        }\r
+      }\r
     } else {\r
       //\r
       // Call corresponding ConfigAccess protocol to extract settings\r
@@ -3861,7 +4528,9 @@ HiiConfigRoutingExtractConfig (
                       &gEfiHiiConfigAccessProtocolGuid,\r
                       (VOID **) &ConfigAccess\r
                       );\r
-      ASSERT_EFI_ERROR (Status);\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
 \r
       Status = ConfigAccess->ExtractConfig (\r
                                ConfigAccess,\r
@@ -4332,7 +5001,11 @@ HiiConfigRoutingRouteConfig (
                       &gEfiHiiConfigAccessProtocolGuid,\r
                       (VOID **)  &ConfigAccess\r
                       );\r
-      ASSERT_EFI_ERROR (Status);\r
+      if (EFI_ERROR (Status)) {\r
+        *Progress = StringPtr;\r
+        FreePool (ConfigResp);\r
+        return EFI_NOT_FOUND;\r
+      }\r
 \r
       Status = ConfigAccess->RouteConfig (\r
                                ConfigAccess,\r
@@ -4612,8 +5285,8 @@ HiiBlockToConfig (
       *(ConfigElement + (StringPtr - TmpPtr)) = L'&';\r
     }\r
     *(ConfigElement + (StringPtr - TmpPtr) + 1) = 0;\r
-    StrCat (ConfigElement, L"VALUE=");\r
-    StrCat (ConfigElement, ValueStr);\r
+    StrCatS (ConfigElement, Length, L"VALUE=");\r
+    StrCatS (ConfigElement, Length, ValueStr);\r
 \r
     AppendToMultiString (Config, ConfigElement);\r
 \r
@@ -5130,8 +5803,8 @@ Exit:
     if (*AltCfgResp == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
     } else {\r
-      StrnCpy (*AltCfgResp, HdrStart, HdrEnd - HdrStart);\r
-      StrCat (*AltCfgResp, Result);\r
+      StrnCpyS (*AltCfgResp, Length, HdrStart, HdrEnd - HdrStart);\r
+      StrCatS (*AltCfgResp, Length, Result);\r
       Status = EFI_SUCCESS;\r
     }\r
   }\r