]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
index de7cb3f46e0b6b2e7c076480b20c454a93cd1061..6c6561711dbf3e022fd82b0836aa977810b62d28 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   HII Library implementation that uses DXE protocols and services.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2010, 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
   http://opensource.org/licenses/bsd-license.php\r
@@ -105,10 +105,10 @@ InternalHiiExtractGuidFromHiiHandle (
 /**\r
   Registers a list of packages in the HII Database and returns the HII Handle\r
   associated with that registration.  If an HII Handle has already been registered\r
-  with the same PackageListGuid, then NULL is returned.  If there are not enough \r
-  resources to perform the registration, then NULL is returned.  If an empty list \r
-  of packages is passed in, then NULL is returned.  If the size of the list of \r
-  package is 0, then NULL is returned.\r
+  with the same PackageListGuid and DeviceHandle, then NULL is returned.  If there\r
+  are not enough resources to perform the registration, then NULL is returned.\r
+  If an empty list of packages is passed in, then NULL is returned.  If the size of\r
+  the list of package is 0, then NULL is returned.\r
 \r
   The variable arguments are pointers which point to package header that defined \r
   by UEFI VFR compiler and StringGather tool.\r
@@ -145,7 +145,6 @@ HiiAddPackages (
   )\r
 {\r
   EFI_STATUS                   Status;\r
-  EFI_HII_HANDLE               *HiiHandleBuffer;\r
   VA_LIST                      Args;\r
   UINT32                       *Package;\r
   EFI_HII_PACKAGE_LIST_HEADER  *PackageListHeader;\r
@@ -155,16 +154,6 @@ HiiAddPackages (
 \r
   ASSERT (PackageListGuid != NULL);\r
 \r
-  //\r
-  // Check to see if an HII Handle has already been registered with the same \r
-  // PackageListGuid\r
-  //\r
-  HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);\r
-  if (HiiHandleBuffer != NULL) {\r
-    FreePool (HiiHandleBuffer);\r
-    return NULL;\r
-  }\r
-\r
   //\r
   // Calculate the length of all the packages in the variable argument list\r
   //\r
@@ -192,7 +181,7 @@ HiiAddPackages (
   PackageListHeader = AllocateZeroPool (Length);\r
 \r
   //\r
-  // If the Packahge List can not be allocated, then return a NULL HII Handle\r
+  // If the Package List can not be allocated, then return a NULL HII Handle\r
   //\r
   if (PackageListHeader == NULL) {\r
     return NULL;\r
@@ -272,18 +261,19 @@ HiiRemovePackages (
 \r
 \r
 /**\r
-  Retrieves the array of all the HII Handles or the HII handle of a specific\r
-  package list in the HII Database.\r
+  Retrieves the array of all the HII Handles or the HII handles of a specific\r
+  package list GUID in the HII Database.\r
   This array is terminated with a NULL HII Handle.\r
   This function allocates the returned array using AllocatePool().\r
   The caller is responsible for freeing the array with FreePool().\r
 \r
   @param[in]  PackageListGuid  An optional parameter that is used to request \r
-                               an HII Handle that is associatd with a specific\r
-                               Package List GUID.  If this parameter is NULL\r
+                               HII Handles associated with a specific\r
+                               Package List GUID.  If this parameter is NULL,\r
                                then all the HII Handles in the HII Database\r
-                               are returned.  If this parameter is not NULL\r
-                               then at most 1 HII Handle is returned.\r
+                               are returned.  If this parameter is not NULL,\r
+                               then zero or more HII Handles associated with \r
+                               PackageListGuid are returned.\r
 \r
   @retval NULL   No HII handles were found in the HII database\r
   @retval NULL   The array of HII Handles could not be retrieved\r
@@ -301,7 +291,8 @@ HiiGetHiiHandles (
   EFI_HII_HANDLE  TempHiiHandleBuffer;\r
   EFI_HII_HANDLE  *HiiHandleBuffer;\r
   EFI_GUID        Guid;\r
-  UINTN           Index;\r
+  UINTN           Index1;\r
+  UINTN           Index2;\r
 \r
   //\r
   // Retrieve the size required for the buffer of all HII handles.\r
@@ -364,17 +355,20 @@ HiiGetHiiHandles (
     //\r
     return HiiHandleBuffer;\r
   } else {\r
-    for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) {\r
-      Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid);\r
+    for (Index1 = 0, Index2 = 0; HiiHandleBuffer[Index1] != NULL; Index1++) {\r
+      Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index1], &Guid);\r
       ASSERT_EFI_ERROR (Status);\r
       if (CompareGuid (&Guid, PackageListGuid)) {\r
-        HiiHandleBuffer[0] = HiiHandleBuffer[Index];\r
-        HiiHandleBuffer[1] = NULL;\r
-        return HiiHandleBuffer;\r
+        HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1];       \r
       }\r
     }\r
-    FreePool (HiiHandleBuffer);\r
-    return NULL;\r
+    if (Index2 > 0) {\r
+      HiiHandleBuffer[Index2] = NULL;\r
+      return HiiHandleBuffer;\r
+    } else {\r
+      FreePool (HiiHandleBuffer);\r
+      return NULL;\r
+    }\r
   }\r
 }\r
 \r
@@ -382,9 +376,9 @@ HiiGetHiiHandles (
   Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r
   hex digits that appear between a '=' and a '&' in a config string.\r
 \r
-  If String is NULL, then ASSERT().\r
+  If ConfigString is NULL, then ASSERT().\r
 \r
-  @param[in] String  Pointer to a Null-terminated Unicode string.\r
+  @param[in] ConfigString  Pointer to a Null-terminated Unicode string.\r
 \r
   @return  Pointer to the Null-terminated Unicode result string.\r
 \r
@@ -469,10 +463,10 @@ InternalHiiBlockToConfig (
   allocated using AllocatePool().  The caller is then responsible for freeing \r
   the buffer using FreePool().\r
 \r
-  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This \r
-                              is an optional parameter that may be NULL.\r
   @param[in]  VariableGuid    Pointer to an EFI_GUID structure.  This is an optional \r
                               parameter that may be NULL.\r
+  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This \r
+                              is an optional parameter that may be NULL.\r
   @param[in]  SetResultsData  If not NULL, then this parameter specified the buffer\r
                               of uncommited data to set.  If this parameter is NULL,\r
                               then the caller is requesting to get the uncommited data\r
@@ -921,16 +915,17 @@ InternalHiiGetValueOfNumber (
 }\r
 \r
 /**\r
-  This function shares the same logic to parse ConfigAltResp string \r
-  for setting default value and validating current setting.\r
-\r
-  @param ConfigResp         \r
-  @param HiiPackageList     \r
-  @param PackageListLength  \r
-  @param VarGuid\r
-  @param VarName\r
+  This internal function parses IFR data to validate current setting.\r
+\r
+  @param ConfigResp         ConfigResp string contains the current setting.\r
+  @param HiiPackageList     Point to Hii package list.\r
+  @param PackageListLength  The length of the pacakge.\r
+  @param VarGuid            Guid of the buffer storage.\r
+  @param VarName            Name of the buffer storage.\r
   \r
-  @retval EFI_SUCCESS\r
+  @retval EFI_SUCCESS            The current setting is valid.\r
+  @retval EFI_OUT_OF_RESOURCES   The memory is not enough.\r
+  @retval EFI_INVALID_PARAMETER  The config string or the Hii package is invalid.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -981,7 +976,7 @@ InternalHiiValidateCurrentSetting (
   StringPtr = StrStr (ConfigResp, L"&OFFSET");\r
   if (StringPtr == NULL) {\r
     //\r
-    // No ConfigBlock value is requied to be validated.\r
+    // No ConfigBlock value is required to be validated.\r
     // EFI_SUCCESS directly return.\r
     //\r
     return EFI_SUCCESS;\r
@@ -1177,9 +1172,14 @@ InternalHiiValidateCurrentSetting (
     }\r
     Link = Link->ForwardLink;      \r
   }\r
+  \r
+  if (IsListEmpty (&CurrentBlockArray->Entry)) {\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
 \r
   //\r
-  // 2. Check IFR value is in block data, then Validate Vaule\r
+  // 2. Check IFR value is in block data, then Validate Value\r
   //\r
   ZeroMem (&VarBlockData, sizeof (VarBlockData));\r
   VarValue      = 0;\r
@@ -1209,7 +1209,7 @@ InternalHiiValidateCurrentSetting (
           }\r
           //\r
           // Find the matched VarStoreId to the input VarGuid and VarName\r
-          //            \r
+          //\r
           IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r
           if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) {\r
             VarStoreName = (CHAR8 *) IfrVarStore->Name;\r
@@ -1229,20 +1229,28 @@ InternalHiiValidateCurrentSetting (
           }\r
           break;\r
         case EFI_IFR_FORM_OP:\r
+        case EFI_IFR_FORM_MAP_OP:\r
           //\r
           // Check the matched VarStoreId is found.\r
           //\r
           if (IfrVarStore == NULL) {\r
-            Status = EFI_NOT_FOUND;\r
+            Status = EFI_SUCCESS;\r
             goto Done;\r
           }\r
           break;\r
         case EFI_IFR_ONE_OF_OP:\r
           //\r
-          // Check whether current value is the one of option. \r
+          // Check whether current value is the one of option.\r
           //\r
 \r
           //\r
+          // OneOf question is not in IFR Form. This IFR form is not valid. \r
+          //\r
+          if (IfrVarStore == NULL) {\r
+            Status = EFI_INVALID_PARAMETER;\r
+            goto Done;\r
+          }\r
+          // \r
           // Check whether this question is for the requested varstore.\r
           //\r
           IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r
@@ -1293,6 +1301,13 @@ InternalHiiValidateCurrentSetting (
           // Check the current value is in the numeric range.\r
           //\r
 \r
+          //\r
+          // Numeric question is not in IFR Form. This IFR form is not valid. \r
+          //\r
+          if (IfrVarStore == NULL) {\r
+            Status = EFI_INVALID_PARAMETER;\r
+            goto Done;\r
+          }\r
           //\r
           // Check whether this question is for the requested varstore.\r
           //\r
@@ -1376,6 +1391,14 @@ InternalHiiValidateCurrentSetting (
           // Check value is BOOLEAN type, only 0 and 1 is valid.\r
           //\r
 \r
+          //\r
+          // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+          //\r
+          if (IfrVarStore == NULL) {\r
+            Status = EFI_INVALID_PARAMETER;\r
+            goto Done;\r
+          }\r
+\r
           //\r
           // Check whether this question is for the requested varstore.\r
           //\r
@@ -1423,6 +1446,14 @@ InternalHiiValidateCurrentSetting (
           // Check current string length is less than maxsize\r
           //\r
 \r
+          //\r
+          // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+          //\r
+          if (IfrVarStore == NULL) {\r
+            Status = EFI_INVALID_PARAMETER;\r
+            goto Done;\r
+          }\r
+\r
           //\r
           // Check whether this question is for the requested varstore.\r
           //\r
@@ -1501,7 +1532,7 @@ InternalHiiValidateCurrentSetting (
           //\r
           // OneOf value doesn't belong to one of option value. \r
           //\r
-          if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) {\r
+          if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {\r
             Status = EFI_INVALID_PARAMETER;\r
             goto Done;\r
           }\r
@@ -1553,9 +1584,9 @@ Done:
 }\r
 \r
 /**\r
-  This function shares the same logic to parse ConfigAltResp string \r
-  for setting default value and validating current setting.\r
-  \r
+  This function parses the input ConfigRequest string and its matched IFR code\r
+  string for setting default value and validating current setting.\r
+\r
   1. For setting default action, Reset the default value specified by DefaultId \r
   to the driver configuration got by Request string.\r
   2. For validating current setting, Validate the current configuration \r
@@ -1580,7 +1611,7 @@ BOOLEAN
 EFIAPI\r
 InternalHiiIfrValueAction (\r
   IN CONST EFI_STRING Request,  OPTIONAL\r
-  IN UINT16        DefaultId,\r
+  IN UINT16           DefaultId,\r
   IN UINT8            ActionType\r
   )\r
 {\r
@@ -1738,6 +1769,7 @@ InternalHiiIfrValueAction (
       // Its default value and validating can't execute by parsing IFR data.\r
       // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.   \r
       //\r
+           Status = EFI_SUCCESS;\r
       goto NextConfigAltResp;\r
     }\r
     \r
@@ -1819,13 +1851,14 @@ InternalHiiIfrValueAction (
       // Not found the matched default string ID\r
       //\r
       if (EFI_ERROR (Status)) {\r
-        goto Done;\r
+        Status = EFI_SUCCESS;\r
+        goto NextConfigAltResp;\r
       }\r
     }\r
     \r
     //\r
     // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)\r
-    //    Get the default configuration string according to the found defaultname string ID.\r
+    //    Get the default configuration string according to the found default name string ID.\r
     //\r
     Status = gHiiConfigRouting->GetAltConfig (\r
                                   gHiiConfigRouting,\r
@@ -1836,9 +1869,19 @@ InternalHiiIfrValueAction (
                                   (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultName:NULL,  // it can be NULL to get the current setting.\r
                                   &ConfigResp\r
                                 );\r
-\r
+    \r
+    //\r
+    // The required setting can't be found. So, it is not required to be validated and set.\r
+    //\r
     if (EFI_ERROR (Status)) {\r
-      goto Done;\r
+      Status = EFI_SUCCESS;\r
+      goto NextConfigAltResp;\r
+    }\r
+    //\r
+    // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.\r
+    //\r
+    if (StrStr (ConfigResp, L"&OFFSET=") == NULL) {\r
+      goto NextConfigAltResp;\r
     }\r
     \r
     //\r
@@ -1861,6 +1904,7 @@ InternalHiiIfrValueAction (
       goto Done;\r
     }\r
 \r
+NextConfigAltResp:\r
     //\r
     // Free the allocated pacakge buffer and the got ConfigResp string.\r
     //\r
@@ -1868,11 +1912,12 @@ InternalHiiIfrValueAction (
       FreePool (HiiPackageList);\r
       HiiPackageList = NULL;\r
     }\r
+    \r
+       if (ConfigResp != NULL) {\r
+         FreePool (ConfigResp);\r
+         ConfigResp = NULL;\r
+       }\r
 \r
-    FreePool (ConfigResp);\r
-    ConfigResp = NULL;\r
-\r
-NextConfigAltResp:\r
     //\r
     // Free the allocated buffer.\r
     //\r
@@ -1979,7 +2024,7 @@ Done:
 /**\r
   Validate the current configuration by parsing HII form IFR opcode.\r
 \r
-  NULL request string support depends on the ExtractConfig interface of\r
+  NULL request string support depends on the ExportConfig interface of\r
   HiiConfigRouting protocol in UEFI specification.\r
   \r
   @param  Request   A null-terminated Unicode string in \r
@@ -2025,299 +2070,6 @@ HiiSetToDefaults (
   return InternalHiiIfrValueAction (Request, DefaultId, ACTION_SET_DEFAUTL_VALUE);\r
 }\r
 \r
-/**\r
-  Allocates and returns a Null-terminated Unicode <ConfigAltResp> string.\r
-\r
-  If Guid is NULL, then ASSERT().\r
-  If Name is NULL, then ASSERT().\r
-  If BlockNameArray is NULL, then ASSERT().\r
-\r
-  @param[in] Guid               GUID of the buffer storage.\r
-  @param[in] Name               Name of the buffer storage.\r
-  @param[in] DriverHandle       The DriverHandle that support a Device Path\r
-                                Protocol.    \r
-  @param[in] BufferStorage      Content of the buffer storage.\r
-  @param[in] BufferStorageSize  Length in bytes of the buffer storage.\r
-  @param[in] BlockNameArray     Array generated by VFR compiler.  This array\r
-                                contains a UINT32 value that is the length\r
-                                of BlockNameArray in bytes, followed by pairs\r
-                                of 16-bit values that are the offset and length\r
-                                values used to contruct a <ConfigRequest> string.\r
-  @param[in]  ...               A variable argument list that contains pairs of 16-bit\r
-                                ALTCFG identifiers and pointers to DefaultValueArrays.\r
-                                The variable argument list is terminated by a NULL \r
-                                DefaultValueArray pointer.  A DefaultValueArray \r
-                                contains a UINT32 value that is the length, in bytes,\r
-                                of the DefaultValueArray.  The UINT32 length value \r
-                                is followed by a series of records that contain\r
-                                a 16-bit WIDTH value followed by a byte array with \r
-                                WIDTH entries.  The records must be parsed from\r
-                                beginning to end until the UINT32 length limit\r
-                                is reached.  \r
-\r
-  @retval NULL          There are not enough resources to process the request.\r
-  @retval NULL          A <ConfigResp> could not be retrieved from the Config \r
-                        Routing Protocol.\r
-  @retval Other         A pointer to the Null-terminate Unicode <ConfigAltResp>\r
-                        string.\r
-\r
-**/\r
-EFI_STRING\r
-EFIAPI\r
-HiiConstructConfigAltResp (\r
-  IN CONST EFI_GUID  *Guid,\r
-  IN CONST CHAR16    *Name,\r
-  IN EFI_HANDLE      DriverHandle,\r
-  IN CONST VOID      *BufferStorage,\r
-  IN UINTN           BufferStorageSize,\r
-  IN CONST VOID      *BlockNameArray, \r
-  ...\r
-  )\r
-{\r
-  UINTN         Length;\r
-  CHAR16        *String;\r
-  CHAR16        *ConfigHdr;\r
-  UINT8         *Buffer;\r
-  UINT8         *BufferEnd;\r
-  CHAR16        *ConfigRequest;\r
-  EFI_STRING    ConfigResp;\r
-  EFI_STRING    ConfigAltResp;\r
-  VA_LIST       Args;\r
-  UINTN         AltCfgId;\r
-  UINT16        Width;\r
-  UINT16        OffsetValue;\r
-  UINT16        WidthValue;\r
-\r
-  ASSERT (Guid != NULL);\r
-  ASSERT (Name != NULL);\r
-  ASSERT (BlockNameArray != NULL);\r
-\r
-  //\r
-  // Initialize local variables\r
-  //\r
-  ConfigHdr     = NULL;\r
-  ConfigRequest = NULL; \r
-  ConfigResp    = NULL;\r
-\r
-  //\r
-  // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..."\r
-  //\r
-  ConfigHdr = HiiConstructConfigHdr (Guid, Name, DriverHandle);\r
-  if (ConfigHdr == NULL) {\r
-    goto Exit;\r
-  }\r
-\r
-  //\r
-  // Compute the length of the entire request starting with <ConfigHdr> and a \r
-  // Null-terminator\r
-  //\r
-  Length = StrLen (ConfigHdr) + 1;\r
-\r
-  //\r
-  // Determine the size <BlockName> Offset/Width pairs\r
-  //\r
-  Buffer = (UINT8 *)BlockNameArray;\r
-  BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r
-  Buffer += sizeof (UINT32);\r
-\r
-  //\r
-  // Add <BlockName> length that is composed of one or more Offset/Width pairs\r
-  //\r
-  // <BlockName> ::= &OFFSET=1234&WIDTH=1234\r
-  //                 |  8   | 4 |   7  | 4 |\r
-  //\r
-  Length += (((BufferEnd - Buffer) / (sizeof (UINT16) + sizeof (UINT16))) * (8 + 4 + 7 + 4));\r
-\r
-  //\r
-  // Allocate buffer for the entire <ConfigRequest>\r
-  //\r
-  ConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16));\r
-  if (ConfigRequest == NULL) {\r
-    goto Exit;\r
-  }\r
-  String = ConfigRequest;\r
-\r
-  //\r
-  // Start with <ConfigHdr>\r
-  //\r
-  StrCpy (String, ConfigHdr);\r
-  String += StrLen (String);\r
-\r
-  //\r
-  // Loop through all the Offset/Width pairs and append them to ConfigRequest\r
-  //\r
-  while (Buffer < BufferEnd) {\r
-    //\r
-    // Append &OFFSET=XXXX&WIDTH=YYYY\r
-    //\r
-    OffsetValue = ReadUnaligned16 ((UINT16 *)Buffer);\r
-    WidthValue  = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r
-    UnicodeSPrint (\r
-      String, \r
-      (8 + 4 + 7 + 4) * sizeof (CHAR16), \r
-      L"&OFFSET=%04X&WIDTH=%04X", \r
-      OffsetValue, \r
-      WidthValue\r
-    );\r
-\r
-    String += StrLen (String);\r
-    Buffer += (sizeof (UINT16) + sizeof (UINT16));\r
-  }\r
-\r
-  //\r
-  // Get the <ConfigResp>\r
-  //\r
-  ConfigResp = InternalHiiBlockToConfig (ConfigRequest, BufferStorage, BufferStorageSize);\r
-  if (ConfigResp == NULL) {\r
-    goto Exit;\r
-  }\r
-\r
-  //\r
-  // Compute the length of the entire response starting with <ConfigResp> and a \r
-  // Null-terminator\r
-  //\r
-  Length = StrLen (ConfigResp) + 1;\r
-\r
-  //\r
-  // Add the length associated with each pair of variable argument parameters\r
-  //\r
-  VA_START (Args, BlockNameArray);\r
-  while (TRUE) {\r
-    AltCfgId = VA_ARG (Args, UINTN);\r
-    Buffer   = VA_ARG (Args, UINT8 *);\r
-    if (Buffer == NULL) {\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Add length for "&<ConfigHdr>&ALTCFG=XXXX"\r
-    //                |1| StrLen (ConfigHdr) | 8 | 4 |\r
-    //\r
-    Length += (1 + StrLen (ConfigHdr) + 8 + 4);\r
-\r
-    BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r
-    Buffer += sizeof (UINT32);\r
-    while (Buffer < BufferEnd) {\r
-      //\r
-      // Extract Width field\r
-      //\r
-      Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r
-\r
-      //\r
-      // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"\r
-      //                |    8  | 4 |   7  | 4 |   7  | Width * 2 |\r
-      //\r
-      Length += (8 + 4 + 7 + 4 + 7 + Width * 2);\r
-\r
-      //\r
-      // Update Buffer to the next record\r
-      //\r
-      Buffer += (sizeof (UINT16) + sizeof (UINT16) + Width);\r
-    }\r
-  }\r
-  VA_END (Args);\r
-\r
-  //\r
-  // Allocate a buffer for the entire response\r
-  //\r
-  ConfigAltResp = AllocateZeroPool (Length * sizeof (CHAR16));\r
-  if (ConfigAltResp == NULL) {\r
-    goto Exit;\r
-  }\r
-  String = ConfigAltResp;\r
-\r
-  //\r
-  // Add <ConfigResp>\r
-  //\r
-  StrCpy (String, ConfigResp);\r
-  String += StrLen (String);\r
-\r
-  //\r
-  // Add <AltResp> for each pair of variable argument parameters\r
-  //\r
-  VA_START (Args, BlockNameArray);\r
-  while (TRUE) {\r
-    AltCfgId = VA_ARG (Args, UINTN);\r
-    Buffer   = VA_ARG (Args, UINT8 *);\r
-    if (Buffer == NULL) {\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX"\r
-    //                                |1| StrLen (ConfigHdr) | 8 | 4 |\r
-    //\r
-    UnicodeSPrint (\r
-      String, \r
-      (1 + StrLen (ConfigHdr) + 8 + 4) * sizeof (CHAR16), \r
-      L"&%s&ALTCFG=%04X", \r
-      ConfigHdr, \r
-      AltCfgId\r
-      );\r
-    String += StrLen (String);\r
-\r
-    //\r
-    // Add <ConfigBody> ::= <ConfigElement>*\r
-    //\r
-    BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r
-    Buffer += sizeof (UINT32);\r
-    while (Buffer < BufferEnd) {\r
-      //\r
-      // Extract Width field\r
-      //\r
-      Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r
-\r
-      //\r
-      // Add <BlockConfig>\r
-      //\r
-      UnicodeSPrint (\r
-        String, \r
-        (8 + 4 + 7 + 4 + 7 + Width * 2) * sizeof (CHAR16),\r
-        L"&OFFSET=%04X&WIDTH=%04X&VALUE=", \r
-        ReadUnaligned16 ((UINT16 *)Buffer), \r
-        Width\r
-        );\r
-      String += StrLen (String);\r
-\r
-      //\r
-      // Update Buffer to point to the value in the current record\r
-      //\r
-      Buffer += (sizeof (UINT16) + sizeof (UINT16));\r
-\r
-      //\r
-      // Convert Value to a hex string in "%x" format\r
-      //   NOTE: This is in the opposite byte that GUID and PATH use\r
-      //\r
-      for (; Width > 0; Width--) {\r
-        String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, Buffer[Width - 1], 2);\r
-      }\r
-      //\r
-      // Update Buffer to the next record\r
-      //\r
-      Buffer += Width;\r
-    }\r
-  }\r
-  VA_END (Args);\r
-\r
-  //\r
-  // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r
-  //\r
-  return InternalHiiLowerConfigString (ConfigAltResp);\r
-\r
-Exit:\r
-  if (ConfigHdr != NULL) {\r
-    FreePool (ConfigHdr);\r
-  }\r
-  if (ConfigRequest != NULL) {\r
-    FreePool (ConfigRequest);\r
-  }\r
-  if (ConfigResp != NULL) {\r
-    FreePool (ConfigResp);\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
 /**\r
   Determines if two values in config strings match.\r
 \r
@@ -2336,7 +2088,7 @@ Exit:
   @param StartSearchString  Pointer to the Null-terminated Unicode string that \r
                             marks the start of the value string to compare.\r
   @param StopSearchString   Pointer to the Null-terminated Unicode string that \r
-                            marks the end of the vakue string to compare.\r
+                            marks the end of the value string to compare.\r
 \r
   @retval FALSE             StartSearchString is not present in FirstString. \r
   @retval FALSE             StartSearchString is not present in SecondString.\r
@@ -2452,15 +2204,15 @@ HiiIsConfigHdrMatch (
 }\r
 \r
 /**\r
-  Retrieves uncommited data from the Form Browser and converts it to a binary\r
+  Retrieves uncommitted data from the Form Browser and converts it to a binary\r
   buffer.\r
 \r
-  @param[in]  VariableName  Pointer to a Null-terminated Unicode string.  This \r
-                            is an optional parameter that may be NULL.\r
   @param[in]  VariableGuid  Pointer to an EFI_GUID structure.  This is an optional \r
                             parameter that may be NULL.\r
-  @param[in]  BufferSize    Length in bytes of buffer to hold retrived data. \r
-  @param[out] Block         Buffer of data to be updated.\r
+  @param[in]  VariableName  Pointer to a Null-terminated Unicode string.  This \r
+                            is an optional parameter that may be NULL.\r
+  @param[in]  BufferSize    Length in bytes of buffer to hold retrieved data. \r
+  @param[out] Buffer        Buffer of data to be updated.\r
 \r
   @retval FALSE  The uncommitted data could not be retrieved.\r
   @retval TRUE   The uncommitted data was retrieved.\r
@@ -2471,8 +2223,8 @@ EFIAPI
 HiiGetBrowserData (\r
   IN CONST EFI_GUID  *VariableGuid,  OPTIONAL\r
   IN CONST CHAR16    *VariableName,  OPTIONAL\r
-  IN UINTN           BlockSize,\r
-  OUT UINT8          *Block\r
+  IN UINTN           BufferSize,\r
+  OUT UINT8          *Buffer\r
   )\r
 {\r
   EFI_STRING  ResultsData;\r
@@ -2511,8 +2263,8 @@ HiiGetBrowserData (
   Status = gHiiConfigRouting->ConfigToBlock (\r
                                 gHiiConfigRouting,\r
                                 ConfigResp,\r
-                                Block,\r
-                                &BlockSize,\r
+                                Buffer,\r
+                                &BufferSize,\r
                                 &Progress\r
                                 );\r
   //\r
@@ -2532,10 +2284,10 @@ HiiGetBrowserData (
 \r
   If Buffer is NULL, then ASSERT().\r
 \r
-  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This\r
-                              is an optional parameter that may be NULL.\r
   @param[in]  VariableGuid    Pointer to an EFI_GUID structure.  This is an optional\r
                               parameter that may be NULL.\r
+  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This\r
+                              is an optional parameter that may be NULL.\r
   @param[in]  BufferSize      Length, in bytes, of Buffer.\r
   @param[in]  Buffer          Buffer of data to commit.\r
   @param[in]  RequestElement  An optional field to specify which part of the\r
@@ -2667,12 +2419,14 @@ HiiAllocateOpCodeHandle (
 }\r
 \r
 /**\r
-  Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().\r
+  Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().\r
   When an OpCode Handle is freed, all of the opcodes associated with the OpCode\r
   Handle are also freed.\r
 \r
   If OpCodeHandle is NULL, then ASSERT().\r
 \r
+  @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -2691,6 +2445,13 @@ HiiFreeOpCodeHandle (
   FreePool (OpCodeBuffer);\r
 }\r
 \r
+/**\r
+  Internal function gets the current position of opcode buffer.\r
+  \r
+  @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
+\r
+  @return Current position of opcode buffer.\r
+**/\r
 UINTN\r
 EFIAPI\r
 InternalHiiOpCodeHandlePosition (\r
@@ -2700,6 +2461,13 @@ InternalHiiOpCodeHandlePosition (
   return ((HII_LIB_OPCODE_BUFFER  *)OpCodeHandle)->Position;\r
 }\r
 \r
+/**\r
+  Internal function gets the start pointer of opcode buffer.\r
+  \r
+  @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
+\r
+  @return Pointer to the opcode buffer base.\r
+**/\r
 UINT8 *\r
 EFIAPI\r
 InternalHiiOpCodeHandleBuffer (\r
@@ -2709,11 +2477,20 @@ InternalHiiOpCodeHandleBuffer (
   return ((HII_LIB_OPCODE_BUFFER  *)OpCodeHandle)->Buffer;\r
 }\r
 \r
+/**\r
+  Internal function reserves the enough buffer for current opcode.\r
+  When the buffer is not enough, Opcode buffer will be extended.\r
+  \r
+  @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
+  @param[in]  Size           Size of current opcode.\r
+\r
+  @return Pointer to the current opcode.\r
+**/\r
 UINT8 *\r
 EFIAPI\r
 InternalHiiGrowOpCodeHandle (\r
-  VOID   *OpCodeHandle,\r
-  UINTN  Size\r
+  IN VOID   *OpCodeHandle,\r
+  IN UINTN  Size\r
   )\r
 {\r
   HII_LIB_OPCODE_BUFFER  *OpCodeBuffer;\r
@@ -2739,6 +2516,18 @@ InternalHiiGrowOpCodeHandle (
   return Buffer;\r
 }\r
 \r
+/**\r
+  Internal function creates opcode based on the template opcode.\r
+  \r
+  @param[in]  OpCodeHandle    Handle to the buffer of opcodes.\r
+  @param[in]  OpCodeTemplate  Pointer to the template buffer of opcode.\r
+  @param[in]  OpCode          OpCode IFR value.\r
+  @param[in]  OpCodeSize      Size of opcode.\r
+  @param[in]  ExtensionSize   Size of extended opcode.\r
+  @param[in]  Scope           Scope bit of opcode.\r
+\r
+  @return Pointer to the current opcode with opcode data.\r
+**/\r
 UINT8 *\r
 EFIAPI\r
 InternalHiiCreateOpCodeExtended (\r
@@ -2764,6 +2553,16 @@ InternalHiiCreateOpCodeExtended (
   return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize);\r
 }\r
 \r
+/**\r
+  Internal function creates opcode based on the template opcode for the normal opcode.\r
+  \r
+  @param[in]  OpCodeHandle    Handle to the buffer of opcodes.\r
+  @param[in]  OpCodeTemplate  Pointer to the template buffer of opcode.\r
+  @param[in]  OpCode          OpCode IFR value.\r
+  @param[in]  OpCodeSize      Size of opcode.\r
+\r
+  @return Pointer to the current opcode with opcode data.\r
+**/\r
 UINT8 *\r
 EFIAPI\r
 InternalHiiCreateOpCode (\r
@@ -3475,13 +3274,17 @@ HiiCreateOrderedListOpCode (
   This is the internal worker function to update the data in\r
   a form specified by FormSetGuid, FormId and Label.\r
 \r
-  @param FormSetGuid     The optional Formset GUID.\r
-  @param FormId          The Form ID.\r
-  @param Package         The package header.\r
-\r
-  @param TempPacakge     The resultant package.\r
+  @param[in] FormSetGuid       The optional Formset GUID.\r
+  @param[in] FormId            The Form ID.\r
+  @param[in] Package           The package header.\r
+  @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR \r
+                               opcodes to be inserted or replaced in the form.\r
+  @param[in] OpCodeBufferEnd   An OpCcode buffer that contains the IFR opcode\r
+                               that marks the end of a replace operation in the form.\r
+  @param[out] TempPackage      The resultant package.\r
 \r
   @retval EFI_SUCCESS    The function completes successfully.\r
+  @retval EFI_NOT_FOUND  The updated opcode or endopcode is not found.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3531,7 +3334,7 @@ InternalHiiUpdateFormPackageData (
       } else {\r
         GetFormSet = FALSE;\r
       }\r
-    } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP) {\r
+    } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP || IfrOpHdr->OpCode == EFI_IFR_FORM_MAP_OP) {\r
       if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) {\r
         GetForm = TRUE;\r
       } else {\r
@@ -3637,22 +3440,22 @@ InternalHiiUpdateFormPackageData (
   The form to update is specified by Handle, FormSetGuid, and FormId.  Binary \r
   comparisons of IFR opcodes are performed from the beginning of the form being \r
   updated until an IFR opcode is found that exactly matches the first IFR opcode \r
-  specifed by StartOpCodeHandle.  The following rules are used to determine if\r
+  specified by StartOpCodeHandle.  The following rules are used to determine if\r
   an insert, replace, or delete operation is performed.\r
   \r
   1) If no matches are found, then NULL is returned.  \r
   2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes\r
-     from StartOpcodeHandle except the first opcode are inserted immediately after \r
-     the matching IFR opcode in the form beng updated.\r
+     from StartOpCodeHandle except the first opcode are inserted immediately after \r
+     the matching IFR opcode in the form to be updated.\r
   3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made \r
-     from the matching IFR opcode until an IFR opcode exatly matches the first \r
+     from the matching IFR opcode until an IFR opcode exactly matches the first \r
      IFR opcode specified by EndOpCodeHandle.  If no match is found for the first\r
      IFR opcode specified by EndOpCodeHandle, then NULL is returned.  If a match\r
      is found, then all of the IFR opcodes between the start match and the end \r
      match are deleted from the form being updated and all of the IFR opcodes\r
-     from StartOpcodeHandle except the first opcode are inserted immediately after \r
+     from StartOpCodeHandle except the first opcode are inserted immediately after \r
      the matching start IFR opcode.  If StartOpCcodeHandle only contains one\r
-     IFR instruction, then the result of ths operation will delete all of the IFR\r
+     IFR instruction, then the result of this operation will delete all of the IFR\r
      opcodes between the start end matches.\r
 \r
   If HiiHandle is NULL, then ASSERT().\r
@@ -3693,8 +3496,8 @@ HiiUpdateForm (
   IN EFI_HII_HANDLE  HiiHandle,           \r
   IN EFI_GUID        *FormSetGuid,        OPTIONAL\r
   IN EFI_FORM_ID     FormId,\r
-  IN VOID            *StartOpcodeHandle,\r
-  IN VOID            *EndOpcodeHandle     OPTIONAL\r
+  IN VOID            *StartOpCodeHandle,\r
+  IN VOID            *EndOpCodeHandle     OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -3715,19 +3518,19 @@ HiiUpdateForm (
   // Input update data can't be NULL.\r
   //\r
   ASSERT (HiiHandle != NULL);\r
-  ASSERT (StartOpcodeHandle != NULL);\r
+  ASSERT (StartOpCodeHandle != NULL);\r
   UpdatePackageList = NULL;\r
   TempPacakge       = NULL;\r
   HiiPackageList    = NULL;\r
   \r
   //\r
-  // Restrive buffer data from Opcode Handle\r
+  // Retrieve buffer data from Opcode Handle\r
   //\r
-  OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpcodeHandle;\r
-  OpCodeBufferEnd   = (HII_LIB_OPCODE_BUFFER *) EndOpcodeHandle;\r
+  OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle;\r
+  OpCodeBufferEnd   = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle;\r
   \r
   //\r
-  // Get the orginal package list\r
+  // Get the original package list\r
   //\r
   BufferSize = 0;\r
   HiiPackageList   = NULL;\r
@@ -3778,7 +3581,7 @@ HiiUpdateForm (
   UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
   \r
   //\r
-  // Go through each package to find the matched pacakge and update one by one\r
+  // Go through each package to find the matched package and update one by one\r
   //\r
   Updated = FALSE;\r
   Offset  = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
@@ -3794,7 +3597,7 @@ HiiUpdateForm (
       //\r
       Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPacakge);\r
       //\r
-      // The matched package is found. Its pacakge buffer will be updated by the input new data.\r
+      // The matched package is found. Its package buffer will be updated by the input new data.\r
       //\r
       if (!EFI_ERROR(Status)) {\r
         //\r
@@ -3824,7 +3627,7 @@ HiiUpdateForm (
     WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize);\r
     \r
     //\r
-    // Update Pacakge to show form\r
+    // Update Package to show form\r
     //\r
     Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList);\r
   } else {\r
@@ -3849,78 +3652,3 @@ Finish:
 \r
   return Status; \r
 }\r
-\r
-/**\r
-  Configure the buffer accrording to ConfigBody strings in the format of\r
-  <Length:4 bytes>, <Offset: 2 bytes>, <Width:2 bytes>, <Data:n bytes>.\r
-  This ConfigBody strings is generated by UEFI VfrCompiler for the default\r
-  values in a Form Set. The name of the ConfigBody strings is VfrMyIfrNVDataDefault0000\r
-  constructed following this rule: \r
-   "Vfr" + varstore.name + "Default" + defaultstore.attributes.\r
-  Check the generated C file in Output for details.\r
-\r
-  @param  Buffer                 The start address of buffer.\r
-  @param  BufferSize             The size of buffer.\r
-  @param  Number                 The number of the strings.\r
-  @param  ...                    Variable argument list for default value in <AltResp> format \r
-                                 generated by the tool.\r
-\r
-  @retval EFI_BUFFER_TOO_SMALL   the BufferSize is too small to operate.\r
-  @retval EFI_INVALID_PARAMETER  Buffer is NULL or BufferSize is 0.\r
-  @retval EFI_SUCCESS            Operation successful.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-HiiIfrLibExtractDefault(\r
-  IN VOID                         *Buffer,\r
-  IN UINTN                        *BufferSize,\r
-  UINTN                           Number,\r
-  ...\r
-  )\r
-{\r
-  VA_LIST                         Args;\r
-  UINTN                           Index;\r
-  UINT32                          TotalLen;\r
-  UINT8                           *BufCfgArray;\r
-  UINT8                           *BufferPos;\r
-  UINT16                          Offset;\r
-  UINT16                          Width;\r
-  UINT8                           *Value;\r
-\r
-  if ((Buffer == NULL) || (BufferSize == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Offset = 0;\r
-  Width  = 0;\r
-  Value  = NULL;\r
-\r
-  VA_START (Args, Number);\r
-  for (Index = 0; Index < Number; Index++) {\r
-    BufCfgArray = (UINT8 *) VA_ARG (Args, VOID *);\r
-    TotalLen = ReadUnaligned32 ((UINT32 *)BufCfgArray);\r
-    BufferPos = BufCfgArray + sizeof (UINT32);\r
-\r
-    while ((UINT32)(BufferPos - BufCfgArray) < TotalLen) {\r
-      Offset = ReadUnaligned16 ((UINT16 *)BufferPos);\r
-      BufferPos += sizeof (UINT16);\r
-      Width = ReadUnaligned16 ((UINT16 *)BufferPos);\r
-      BufferPos += sizeof (UINT16);\r
-      Value = BufferPos;\r
-      BufferPos += Width;\r
-\r
-      if ((UINTN)(Offset + Width) > *BufferSize) {\r
-        return EFI_BUFFER_TOO_SMALL;\r
-      }\r
-\r
-      CopyMem ((UINT8 *)Buffer + Offset, Value, Width);\r
-    }\r
-  }\r
-  VA_END (Args);\r
-\r
-  *BufferSize = (UINTN)Offset;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r