]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
remove the unused msa files in MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 3f35ed9005e27405399beb58e09ae6da29bdc13e..73c4e0f362aafaece78cad2caf5fac4a8e7e5928 100644 (file)
@@ -25,202 +25,18 @@ Revision History
 \r
 #include "HiiDatabase.h"\r
 \r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
-\r
-STATIC\r
-CHAR16\r
-NibbleToHexCharPrivate (\r
-  IN UINT8                         Nibble\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Converts the low nibble of a byte to hex unicode character.\r
-\r
-  Arguments:\r
-    Nibble - lower nibble of a byte.\r
-\r
-  Returns:\r
-    Hex unicode character between L'0' to L'f'.\r
-\r
---*/\r
-{\r
-  Nibble &= 0x0F;\r
-\r
-  if (Nibble <= 0x9) {\r
-    return (CHAR16)(Nibble + L'0');\r
-  }\r
-\r
-  return (CHAR16)(Nibble - 0xA + L'a');\r
-}\r
-\r
-\r
-/**\r
-  Converts Unicode string to binary buffer.\r
-  The conversion may be partial.\r
-  The first character in the string that is not hex digit stops the conversion.\r
-  At a minimum, any blob of data could be represented as a hex string.\r
-\r
-  @param  Buf                    Pointer to buffer that receives the data.\r
-  @param  Len                    Length in bytes of the buffer to hold converted\r
-                                 data. If routine return with EFI_SUCCESS,\r
-                                 containing length of converted data. If routine\r
-                                 return with EFI_BUFFER_TOO_SMALL, containg length\r
-                                 of buffer desired.\r
-  @param  Str                    String to be converted from.\r
-  @param  ConvertedStrLen        Length of the Hex String consumed.\r
-\r
-  @retval EFI_SUCCESS            Routine Success.\r
-  @retval EFI_BUFFER_TOO_SMALL   The buffer is too small to hold converted data.\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-HexStringToBufPrivate (\r
-  IN OUT UINT8                     *Buf,\r
-  IN OUT UINTN                     *Len,\r
-  IN     CHAR16                    *Str,\r
-  OUT    UINTN                     *ConvertedStrLen  OPTIONAL\r
-  )\r
-{\r
-  UINTN       HexCnt;\r
-  UINTN       Idx;\r
-  UINTN       BufferLength;\r
-  UINT8       Digit;\r
-  UINT8       Byte;\r
-\r
-  //\r
-  // Find out how many hex characters the string has.\r
-  //\r
-  for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);\r
-\r
-  if (HexCnt == 0) {\r
-    *Len = 0;\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Two Unicode characters make up 1 buffer byte. Round up.\r
-  //\r
-  BufferLength = (HexCnt + 1) / 2;\r
-\r
-  //\r
-  // Test if  buffer is passed enough.\r
-  //\r
-  if (BufferLength > (*Len)) {\r
-    *Len = BufferLength;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *Len = BufferLength;\r
-\r
-  for (Idx = 0; Idx < HexCnt; Idx++) {\r
-\r
-    IsHexDigit (&Digit, Str[Idx]);\r
-\r
-    //\r
-    // For odd charaters, write the lower nibble for each buffer byte,\r
-    // and for even characters, the upper nibble.\r
-    //\r
-    if ((Idx & 1) == 0) {\r
-      Byte = (UINT8) (Digit << 4);\r
-    } else {\r
-      Byte = Buf[Idx / 2];\r
-      Byte &= 0xF0;\r
-      Byte = (UINT8) (Byte | Digit);\r
-    }\r
-\r
-    Buf[Idx / 2] = Byte;\r
-  }\r
-\r
-  if (ConvertedStrLen != NULL) {\r
-    *ConvertedStrLen = HexCnt;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Converts binary buffer to Unicode string.\r
-  At a minimum, any blob of data could be represented as a hex string.\r
-\r
-  @param  Str                    Pointer to the string.\r
-  @param  HexStringBufferLength  Length in bytes of buffer to hold the hex string.\r
-                                 Includes tailing '\0' character. If routine return\r
-                                 with EFI_SUCCESS, containing length of hex string\r
-                                 buffer. If routine return with\r
-                                 EFI_BUFFER_TOO_SMALL, containg length of hex\r
-                                 string buffer desired.\r
-  @param  Buf                    Buffer to be converted from.\r
-  @param  Len                    Length in bytes of the buffer to be converted.\r
-  @param  Flag                   If TRUE, encode the data in the same order as the\r
-                                 it  resides in the Buf. Else encode it in the\r
-                                 reverse direction.\r
-\r
-  @retval EFI_SUCCESS            Routine  success.\r
-  @retval EFI_BUFFER_TOO_SMALL   The hex string buffer is too small.\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-BufToHexStringPrivate (\r
-  IN OUT CHAR16                    *Str,\r
-  IN OUT UINTN                     *HexStringBufferLength,\r
-  IN     UINT8                     *Buf,\r
-  IN     UINTN                     Len,\r
-  IN     BOOLEAN                   Flag\r
-  )\r
-{\r
-  UINTN       Idx;\r
-  UINT8       Byte;\r
-  UINTN       StrLen;\r
-\r
-  //\r
-  // Make sure string is either passed or allocate enough.\r
-  // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.\r
-  // Plus the Unicode termination character.\r
-  //\r
-  StrLen = Len * 2;\r
-  if ((*HexStringBufferLength) < (StrLen + 1) * sizeof (CHAR16)) {\r
-    *HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);\r
-\r
-  //\r
-  // Ends the string.\r
-  //\r
-  Str[StrLen] = 0;\r
-\r
-  for (Idx = 0; Idx < Len; Idx++) {\r
-\r
-    Byte = Buf[Idx];\r
-    if (Flag) {\r
-      Str[Idx * 2]     = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));\r
-      Str[Idx * 2 + 1] = NibbleToHexCharPrivate (Byte);\r
-    } else {\r
-      Str[StrLen - 1 - Idx * 2] = NibbleToHexCharPrivate (Byte);\r
-      Str[StrLen - 2 - Idx * 2] = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
 /**\r
   Calculate the number of Unicode characters of the incoming Configuration string,\r
   not including NULL terminator.\r
 \r
+  This is a internal function.\r
+\r
   @param  String                 String in <MultiConfigRequest> or\r
                                  <MultiConfigResp> format.\r
 \r
   @return The number of Unicode characters.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 CalculateConfigStringLen (\r
   IN EFI_STRING                    String\r
@@ -254,6 +70,8 @@ CalculateConfigStringLen (
   Convert the hex UNICODE %02x encoding of a UEFI device path to binary\r
   from <PathHdr> of <ConfigHdr>.\r
 \r
+  This is a internal function.\r
+\r
   @param  String                 UEFI configuration string\r
   @param  DevicePath             binary of a UEFI device path.\r
 \r
@@ -263,7 +81,6 @@ CalculateConfigStringLen (
                                  binary format.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 GetDevicePath (\r
   IN  EFI_STRING                   String,\r
@@ -306,7 +123,6 @@ GetDevicePath (
   // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order\r
   // as the device path resides in RAM memory.\r
   // Translate the data into binary.\r
-  // Two Unicode characters make up 1 buffer byte.\r
   //\r
   Length /= 2;\r
   *DevicePath = (UINT8 *) AllocateZeroPool (Length);\r
@@ -315,7 +131,7 @@ GetDevicePath (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  HexStringToBufPrivate (*DevicePath, &Length, DevicePathString, NULL);\r
+  HexStringToBuffer (*DevicePath, &Length, DevicePathString);\r
 \r
   SafeFreePool (DevicePathString);\r
 \r
@@ -327,6 +143,8 @@ GetDevicePath (
 /**\r
   Extract Storage from all Form Packages in current hii database.\r
 \r
+  This is a internal function.\r
+\r
   @param  HiiDatabase            EFI_HII_DATABASE_PROTOCOL instance.\r
   @param  StorageListHead        Storage link List head.\r
 \r
@@ -335,7 +153,6 @@ GetDevicePath (
   @retval EFI_SUCCESS            All existing storage is exported.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExportAllStorage (\r
   IN EFI_HII_DATABASE_PROTOCOL     *HiiDatabase,\r
@@ -500,33 +317,34 @@ ExportAllStorage (
 /**\r
   Generate a sub string then output it.\r
 \r
+  This is a internal function.\r
+\r
   @param  String                 A constant string which is the prefix of the to be\r
                                  generated string, e.g. GUID=\r
   @param  BufferLen              The length of the Buffer in bytes.\r
-  @param  Buffer                 Points to a buffer which will be converted to hex\r
-                                 string and to be the content of the generated\r
-                                 string.\r
-  @param  Flag                   If TRUE, convert the buffer data in the same order\r
-                                 as the it  resides in the Buffer. Else convert it\r
-                                 in the reverse direction.\r
+  @param  Buffer                 Points to a buffer which will be converted to be the \r
+                                          content of the generated string.\r
+  @param  Flag           If 1, the buffer contains data for the value of GUID or PATH stored in \r
+                                UINT8 *; if 2, the buffer contains unicode string for the value of NAME;\r
+                                if 3, the buffer contains other data.\r
   @param  SubStr                 Points to the output string. It's caller's\r
                                  responsibility to free this buffer.\r
 \r
 \r
 **/\r
-STATIC\r
 VOID\r
 GenerateSubStr (\r
   IN CONST EFI_STRING              String,\r
   IN  UINTN                        BufferLen,\r
-  IN  UINT8                        *Buffer,\r
-  IN  BOOLEAN                      Flag,\r
+  IN  VOID                         *Buffer,\r
+  IN  UINT8                        Flag,\r
   OUT EFI_STRING                   *SubStr\r
   )\r
 {\r
   UINTN       Length;\r
   EFI_STRING  Str;\r
   EFI_STATUS  Status;\r
+  EFI_STRING  StringHeader;\r
 \r
   ASSERT (String != NULL && SubStr != NULL);\r
 \r
@@ -536,20 +354,33 @@ GenerateSubStr (
     return ;\r
   }\r
 \r
-  Length = BufferLen * 2 + 1 + StrLen (String) + 1;\r
+  Length = StrLen (String) + BufferLen * 2 + 1 + 1;\r
   Str = AllocateZeroPool (Length * sizeof (CHAR16));\r
   ASSERT (Str != NULL);\r
 \r
   StrCpy (Str, String);\r
   Length = (BufferLen * 2 + 1) * sizeof (CHAR16);\r
 \r
-  Status = BufToHexStringPrivate (\r
-             Str + StrLen (String),\r
-             &Length,\r
-             Buffer,\r
-             BufferLen,\r
-             Flag\r
-             );\r
+  Status       = EFI_SUCCESS;\r
+  StringHeader = Str + StrLen (String);\r
+\r
+  switch (Flag) {\r
+  case 1:\r
+    Status = BufferToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);\r
+    break;\r
+  case 2:\r
+    Status = UnicodeToConfigString (StringHeader, &Length, (CHAR16 *) Buffer);\r
+    break;\r
+  case 3:\r
+    Status = BufToHexString (StringHeader, &Length, (UINT8 *) Buffer, BufferLen);\r
+    //\r
+    // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
+    //\r
+    ToLower (StringHeader);\r
+    break;\r
+  default:\r
+    break;\r
+  }\r
 \r
   ASSERT_EFI_ERROR (Status);\r
   StrCat (Str, L"&");\r
@@ -561,6 +392,8 @@ GenerateSubStr (
 /**\r
   Retrieve the <ConfigBody> from String then output it.\r
 \r
+  This is a internal function.\r
+\r
   @param  String                 A sub string of a configuration string in\r
                                  <MultiConfigAltResp> format.\r
   @param  ConfigBody             Points to the output string. It's caller's\r
@@ -571,7 +404,6 @@ GenerateSubStr (
   @retval EFI_SUCCESS            All existing storage is exported.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 OutputConfigBody (\r
   IN  EFI_STRING                   String,\r
@@ -613,38 +445,33 @@ OutputConfigBody (
 }\r
 \r
 \r
-#endif\r
+/**\r
+  Adjusts the size of a previously allocated buffer.\r
+\r
+\r
+  @param OldPool         A pointer to the buffer whose size is being adjusted.\r
+  @param OldSize         The size of the current buffer.\r
+  @param NewSize         The size of the new buffer.\r
+\r
+  @return The new buffer allocated.\r
 \r
+**/\r
 VOID *\r
 ReallocatePool (\r
   IN VOID                          *OldPool,\r
   IN UINTN                         OldSize,\r
   IN UINTN                         NewSize\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Adjusts the size of a previously allocated buffer.\r
-\r
-Arguments:\r
-  OldPool               - A pointer to the buffer whose size is being adjusted.\r
-  OldSize               - The size of the current buffer.\r
-  NewSize               - The size of the new buffer.\r
-\r
-Returns:\r
-  Points to the new buffer\r
-\r
---*/\r
 {\r
   VOID  *NewPool;\r
 \r
   NewPool = NULL;\r
-  if (NewSize) {\r
+  if (NewSize != 0) {\r
     NewPool = AllocateZeroPool (NewSize);\r
   }\r
 \r
-  if (OldPool) {\r
-    if (NewPool) {\r
+  if (OldPool != NULL) {\r
+    if (NewPool != NULL) {\r
       CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
     }\r
 \r
@@ -658,6 +485,8 @@ Returns:
 /**\r
   Append a string to a multi-string format.\r
 \r
+  This is a internal function.\r
+\r
   @param  MultiString            String in <MultiConfigRequest>,\r
                                  <MultiConfigAltResp>, or <MultiConfigResp>. On\r
                                  input, the buffer length of  this string is\r
@@ -669,7 +498,6 @@ Returns:
   @retval EFI_SUCCESS            AppendString is append to the end of MultiString\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 AppendToMultiString (\r
   IN OUT EFI_STRING                *MultiString,\r
@@ -712,6 +540,8 @@ AppendToMultiString (
   or WIDTH or VALUE.\r
   <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r
 \r
+  This is a internal function.\r
+\r
   @param  StringPtr              String in <BlockConfig> format and points to the\r
                                  first character of <Number>.\r
   @param  Number                 The output value. Caller takes the responsibility\r
@@ -724,7 +554,6 @@ AppendToMultiString (
                                  successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 GetValueOfNumber (\r
   IN EFI_STRING                    StringPtr,\r
@@ -827,8 +656,6 @@ HiiConfigRoutingExtractConfig (
   OUT EFI_STRING                             *Results\r
   )\r
 {\r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
-\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   EFI_STRING                          StringPtr;\r
   EFI_STRING                          ConfigRequest;\r
@@ -845,6 +672,15 @@ HiiConfigRoutingExtractConfig (
   UINTN                               RemainSize;\r
   EFI_STRING                          TmpPtr;\r
 \r
+  //\r
+  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
+  // as FALSE. But this renders the system to not 100% compliant with\r
+  // UEFI 2.1. Use this with caution.\r
+  //\r
+  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if (This == NULL || Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -993,9 +829,6 @@ HiiConfigRoutingExtractConfig (
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 \r
 }\r
 \r
@@ -1029,8 +862,6 @@ HiiConfigRoutingExportConfig (
   OUT EFI_STRING                             *Results\r
   )\r
 {\r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
-\r
   EFI_STATUS                          Status;\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   LIST_ENTRY                          StorageListHdr;\r
@@ -1048,6 +879,15 @@ HiiConfigRoutingExportConfig (
   EFI_STRING                          AccessResults;\r
   UINTN                               TmpSize;\r
 \r
+  //\r
+  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
+  // as FALSE. But this renders the system to not 100% compliant with\r
+  // UEFI 2.1. Use this with caution.\r
+  //\r
+  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if (This == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1096,7 +936,7 @@ HiiConfigRoutingExportConfig (
     if (PathHdr == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    Status = BufToHexStringPrivate (PathHdr, &PathHdrSize, (UINT8 *) DevicePath, Length, TRUE);\r
+    Status = BufferToHexString (PathHdr, (UINT8 *) DevicePath, Length);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
@@ -1104,7 +944,7 @@ HiiConfigRoutingExportConfig (
     // It means extract all possible configurations from this specific driver.\r
     //\r
     TmpSize = StrLen (L"GUID=&NAME=&PATH=");\r
-    RequestSize   = (TmpSize + sizeof (EFI_GUID) * 2 +  StrLen (Storage->Name))\r
+    RequestSize   = (TmpSize + 32 +  StrLen (Storage->Name) * 4)\r
                      * sizeof (CHAR16) + PathHdrSize;\r
     ConfigRequest = (EFI_STRING) AllocateZeroPool (RequestSize);\r
     if (ConfigRequest == NULL) {\r
@@ -1115,20 +955,16 @@ HiiConfigRoutingExportConfig (
     //\r
     // Add <GuidHdr>\r
     // <GuidHdr> ::= 'GUID='<Guid>\r
+    // Convert <Guid> in the same order as it resides in RAM memory.\r
     //\r
     StringPtr = ConfigRequest;\r
     StrnCpy (StringPtr, L"GUID=", StrLen (L"GUID="));\r
     StringPtr += StrLen (L"GUID=");\r
 \r
-    Status = BufToHexStringPrivate (\r
-               StringPtr,\r
-               &RequestSize,\r
-               (UINT8 *) (&Storage->Guid),\r
-               sizeof (EFI_GUID),\r
-               FALSE\r
-               );\r
+    Status = BufferToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));\r
     ASSERT_EFI_ERROR (Status);\r
-    StringPtr += RequestSize / 2 - 1;\r
+    \r
+    StringPtr += 32;\r
     ASSERT (*StringPtr == 0);\r
     *StringPtr = L'&';\r
     StringPtr++;\r
@@ -1139,8 +975,12 @@ HiiConfigRoutingExportConfig (
     //\r
     StrnCpy (StringPtr, L"NAME=", StrLen (L"NAME="));\r
     StringPtr += StrLen (L"NAME=");\r
-    StrnCpy (StringPtr, Storage->Name, StrLen (Storage->Name));\r
-    StringPtr += StrLen (Storage->Name);\r
+\r
+    Length = (StrLen (Storage->Name) * 4 + 1) * sizeof (CHAR16);\r
+    Status = UnicodeToConfigString (StringPtr, &Length, Storage->Name);\r
+    ASSERT_EFI_ERROR (Status);\r
+    StringPtr += StrLen (Storage->Name) * 4;\r
+    \r
     *StringPtr = L'&';\r
     StringPtr++;\r
 \r
@@ -1217,9 +1057,6 @@ HiiConfigRoutingExportConfig (
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 }\r
 \r
 \r
@@ -1250,14 +1087,12 @@ HiiConfigRoutingExportConfig (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HiiConfigRoutingRoutConfig (\r
+HiiConfigRoutingRouteConfig (\r
   IN  CONST EFI_HII_CONFIG_ROUTING_PROTOCOL  *This,\r
   IN  CONST EFI_STRING                       Configuration,\r
   OUT EFI_STRING                             *Progress\r
   )\r
 {\r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
-\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   EFI_STRING                          StringPtr;\r
   EFI_STRING                          ConfigResp;\r
@@ -1273,6 +1108,15 @@ HiiConfigRoutingRoutConfig (
   UINTN                               RemainSize;\r
   EFI_STRING                          TmpPtr;\r
 \r
+  //\r
+  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
+  // as FALSE. But this renders the system to not 100% compliant with\r
+  // UEFI 2.1. Use this with caution.\r
+  //\r
+  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if (This == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1407,9 +1251,6 @@ HiiConfigRoutingRoutConfig (
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 }\r
 \r
 \r
@@ -1609,6 +1450,8 @@ HiiBlockToConfig (
 \r
     Status = BufToHexString (ValueStr, &Length, Value, Width);\r
     ASSERT_EFI_ERROR (Status);\r
+    ToLower (ValueStr);\r
+\r
     SafeFreePool (Value);\r
     Value = NULL;\r
 \r
@@ -1926,22 +1769,40 @@ HiiGetAltCfg (
   OUT EFI_STRING                               *AltCfgResp\r
   )\r
 {\r
-#ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
-\r
   EFI_STATUS                          Status;\r
   EFI_STRING                          StringPtr;\r
-  EFI_STRING                          HdrStart = NULL;\r
-  EFI_STRING                          HdrEnd   = NULL;\r
+  EFI_STRING                          HdrStart;\r
+  EFI_STRING                          HdrEnd;\r
   EFI_STRING                          TmpPtr;\r
   UINTN                               Length;\r
-  EFI_STRING                          GuidStr  = NULL;\r
-  EFI_STRING                          NameStr  = NULL;\r
-  EFI_STRING                          PathStr  = NULL;\r
-  EFI_STRING                          AltIdStr = NULL;\r
-  EFI_STRING                          Result   = NULL;\r
-  BOOLEAN                             GuidFlag = FALSE;\r
-  BOOLEAN                             NameFlag = FALSE;\r
-  BOOLEAN                             PathFlag = FALSE;\r
+  EFI_STRING                          GuidStr;\r
+  EFI_STRING                          NameStr;\r
+  EFI_STRING                          PathStr;\r
+  EFI_STRING                          AltIdStr;\r
+  EFI_STRING                          Result;\r
+  BOOLEAN                             GuidFlag;\r
+  BOOLEAN                             NameFlag;\r
+  BOOLEAN                             PathFlag;\r
+\r
+  //\r
+  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
+  // as FALSE. But this renders the system to not 100% compliant with\r
+  // UEFI 2.1. Use this with caution.\r
+  //\r
+  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HdrStart = NULL;\r
+  HdrEnd   = NULL;\r
+  GuidStr  = NULL;\r
+  NameStr  = NULL;\r
+  PathStr  = NULL;\r
+  AltIdStr = NULL;\r
+  Result   = NULL;\r
+  GuidFlag = FALSE;\r
+  NameFlag = FALSE;\r
+  PathFlag = FALSE;\r
 \r
   if (This == NULL || Configuration == NULL || AltCfgResp == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1955,30 +1816,21 @@ HiiGetAltCfg (
   //\r
   // Generate the sub string for later matching.\r
   //\r
-  GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (UINT8 *) Guid, FALSE, &GuidStr);\r
+  GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) Guid, 1, &GuidStr);\r
   GenerateSubStr (\r
     L"PATH=",\r
     GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r
-    (UINT8 *) DevicePath,\r
-    TRUE,\r
+    (VOID *) DevicePath,\r
+    1,\r
     &PathStr\r
     );\r
   if (AltCfgId != NULL) {\r
-    GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (UINT8 *) AltCfgId, FALSE, &AltIdStr);\r
+    GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (VOID *) AltCfgId, 3, &AltIdStr);  \r
   }\r
   if (Name != NULL) {\r
-    Length  = StrLen (Name);\r
-    Length  += StrLen (L"NAME=&") + 1;\r
-    NameStr = AllocateZeroPool (Length * sizeof (CHAR16));\r
-    if (NameStr == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
-      goto Exit;\r
-    }\r
-    StrCpy (NameStr, L"NAME=");\r
-    StrCat (NameStr, Name);\r
-    StrCat (NameStr, L"&");\r
+    GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr);    \r
   } else {\r
-    GenerateSubStr (L"NAME=", 0, NULL, FALSE, &NameStr);\r
+    GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r
   }\r
 \r
   while (*StringPtr != 0) {\r
@@ -2108,10 +1960,6 @@ Exit:
 \r
   return Status;\r
 \r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
-\r
 }\r
 \r
 \r