]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1) Add in code to sync Browser Data with the NvMapOverride that may be updated by...
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Aug 2008 10:44:50 +0000 (10:44 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Aug 2008 10:44:50 +0000 (10:44 +0000)
2) Convert lang code to RFC3066 format in Framework HII's GetSring and NewString
3) Make sure the default ThunkExtractConfig is able to save the data even if it is not present initially.
4) Enable Framework HII's HiiGetGlyph and HiiGlyphToBlt.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5689 6f19259b-4bc3-4df7-8a09-765794883524

EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/FrameworkHiiToUefiHiiThunk.inf
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.h
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/OpcodeCreation.c
EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c

index 88565d128ca8eac685379062e191ec6bd6b6e891..c537a47b1ce9c5c43277a6f9bfcb701191d91b17 100644 (file)
@@ -433,7 +433,7 @@ ThunkExtractConfig (
   EFI_STATUS                                  Status;\r
   CONFIG_ACCESS_PRIVATE                       *ConfigAccess;\r
   LIST_ENTRY                                  *Link;\r
-  BUFFER_STORAGE_ENTRY               *BufferStorage;\r
+  BUFFER_STORAGE_ENTRY                        *BufferStorage;\r
   VOID                                        *Data;\r
   UINTN                                       DataSize;\r
 \r
@@ -451,20 +451,31 @@ ThunkExtractConfig (
   \r
   BufferStorage = BUFFER_STORAGE_ENTRY_FROM_LINK (Link);\r
 \r
-  if (ConfigAccess->FormCallbackProtocol == NULL ||\r
-      ConfigAccess->FormCallbackProtocol->NvRead == NULL) {\r
-    Status = GetUefiVariable (\r
-               BufferStorage,\r
-               &Data,\r
-               &DataSize\r
-               );\r
+  if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r
+    if (ConfigAccess->FormCallbackProtocol == NULL ||\r
+        ConfigAccess->FormCallbackProtocol->NvRead == NULL) {\r
+      Status = GetUefiVariable (\r
+                 BufferStorage,\r
+                 &Data,\r
+                 &DataSize\r
+                 );\r
+    } else {\r
+      Status = CallFormCallBack (\r
+                 BufferStorage,\r
+                 ConfigAccess->FormCallbackProtocol,\r
+                  &Data,\r
+                  &DataSize\r
+                 );\r
+    }\r
   } else {\r
-    Status = CallFormCallBack (\r
-               BufferStorage,\r
-               ConfigAccess->FormCallbackProtocol,\r
-                &Data,\r
-                &DataSize\r
-               );\r
+    DataSize = BufferStorage->Size;\r
+    Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride);\r
+    \r
+    if (Data != NULL) {\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
   }\r
   \r
   if (!EFI_ERROR (Status)) {\r
@@ -518,7 +529,6 @@ ThunkRouteConfig (
   BOOLEAN                                     DataAllocated;\r
 \r
   Data = NULL;\r
-  DataAllocated = TRUE;\r
   ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);\r
 \r
   //\r
@@ -533,6 +543,7 @@ ThunkRouteConfig (
   BufferStorage = BUFFER_STORAGE_ENTRY_FROM_LINK (Link);\r
   DataSize2     = BufferStorage->Size;\r
   if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r
+    DataAllocated = TRUE;\r
     if (ConfigAccess->FormCallbackProtocol == NULL ||\r
         ConfigAccess->FormCallbackProtocol->NvRead == NULL) {\r
       Status = GetUefiVariable (\r
@@ -540,8 +551,6 @@ ThunkRouteConfig (
                  &Data,\r
                  &DataSize\r
                  );\r
-      ASSERT (DataSize == DataSize2);\r
-      \r
     } else {\r
       Status = CallFormCallBack (\r
                  BufferStorage,\r
@@ -549,17 +558,20 @@ ThunkRouteConfig (
                   &Data,\r
                   &DataSize\r
                  );\r
-      ASSERT (DataSize == DataSize2);\r
-      \r
     }\r
   } else {\r
+    //\r
+    // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.\r
+    //\r
     Status = EFI_SUCCESS;\r
     Data = ConfigAccess->ThunkContext->NvMapOverride;\r
     DataSize      = DataSize2;\r
     DataAllocated = FALSE;\r
   }  \r
-  if (EFI_ERROR (Status)) {\r
-    goto Done;\r
+  if (EFI_ERROR (Status) || (DataSize2 != DataSize)) {\r
+    if (Data == NULL) {\r
+      Data = AllocateZeroPool (DataSize2);\r
+    }\r
   }\r
 \r
   Status = mHiiConfigRoutingProtocol->ConfigToBlock (\r
@@ -573,26 +585,28 @@ ThunkRouteConfig (
     goto Done;\r
   }\r
 \r
-  if (ConfigAccess->FormCallbackProtocol == NULL ||\r
-      ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {\r
-    Status = gRT->SetVariable (\r
-                  BufferStorage->Name,\r
-                  &BufferStorage->Guid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  DataSize,\r
-                  Data\r
-                  );\r
-  } else {\r
-    Status = ConfigAccess->FormCallbackProtocol->NvWrite (\r
-                  ConfigAccess->FormCallbackProtocol,  \r
-                  BufferStorage->Name,\r
-                  &BufferStorage->Guid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  DataSize,\r
-                  Data,\r
-                  &ResetRequired\r
-                  );\r
-    \r
+  if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r
+    if (ConfigAccess->FormCallbackProtocol == NULL ||\r
+        ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {\r
+      Status = gRT->SetVariable (\r
+                    BufferStorage->Name,\r
+                    &BufferStorage->Guid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    DataSize2,\r
+                    Data\r
+                    );\r
+    } else {\r
+      Status = ConfigAccess->FormCallbackProtocol->NvWrite (\r
+                    ConfigAccess->FormCallbackProtocol,  \r
+                    BufferStorage->Name,\r
+                    &BufferStorage->Guid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    DataSize2,\r
+                    Data,\r
+                    &ResetRequired\r
+                    );\r
+      \r
+    }\r
   }\r
 \r
 Done: \r
@@ -617,25 +631,27 @@ CreateIfrDataArray (
   UINTN                             BrowserDataSize;\r
   BUFFER_STORAGE_ENTRY              *BufferStorageEntry;\r
   LIST_ENTRY                        *Link;\r
+  EFI_STATUS                        Status;\r
 \r
   IfrDataArray = AllocateZeroPool (0x100);\r
   ASSERT (IfrDataArray != NULL);\r
 \r
-  if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r
-    Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);\r
-\r
-    ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));\r
-\r
-    BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);\r
+  Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);\r
+  ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));\r
+  \r
+  BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);\r
+  BrowserDataSize = BufferStorageEntry->Size;\r
 \r
-    BrowserDataSize = BufferStorageEntry->Size;\r
+  if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r
     *NvMapAllocated = TRUE;\r
     IfrDataArray->NvRamMap = AllocateZeroPool (BrowserDataSize);\r
-    GetBrowserData (NULL, NULL, &BrowserDataSize, IfrDataArray->NvRamMap);\r
   } else {\r
     *NvMapAllocated = FALSE;\r
     IfrDataArray->NvRamMap = ConfigAccess->ThunkContext->NvMapOverride;\r
   }\r
+  \r
+  Status = GetBrowserData (NULL, NULL, &BrowserDataSize, IfrDataArray->NvRamMap);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   IfrDataEntry = (FRAMEWORK_EFI_IFR_DATA_ENTRY *) (IfrDataArray + 1);\r
 \r
@@ -656,6 +672,30 @@ CreateIfrDataArray (
   return IfrDataArray;\r
 }\r
 \r
+VOID\r
+SyncBrowserDataForNvMapOverride (\r
+  IN    CONFIG_ACCESS_PRIVATE         *ConfigAccess\r
+  )\r
+{\r
+  BUFFER_STORAGE_ENTRY              *BufferStorageEntry;\r
+  LIST_ENTRY                        *Link;\r
+  EFI_STATUS                        Status;\r
+  UINTN                             BrowserDataSize;\r
+\r
+  if (ConfigAccess->ThunkContext->NvMapOverride != NULL) {\r
+    \r
+    Link = GetFirstNode (&ConfigAccess->BufferStorageListHead);\r
+    ASSERT (!IsNull (&ConfigAccess->BufferStorageListHead, Link));\r
+    \r
+    BufferStorageEntry = BUFFER_STORAGE_ENTRY_FROM_LINK(Link);\r
+    BrowserDataSize = BufferStorageEntry->Size;\r
+\r
+    Status = SetBrowserData (NULL, NULL, BrowserDataSize, ConfigAccess->ThunkContext->NvMapOverride, NULL);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+}\r
+\r
 VOID\r
 DestroyIfrDataArray (\r
   IN  FRAMEWORK_EFI_IFR_DATA_ARRAY *Array,\r
@@ -850,6 +890,7 @@ ThunkCallback (
               Data,\r
               &Packet\r
               );\r
+  SyncBrowserDataForNvMapOverride (ConfigAccess);\r
 \r
   //\r
   // Callback require browser to perform action\r
index 1d58dcd90849193c2cff1dd0e02ce2425d40e068..34a89b1b0879d14d9bf8e125f45d538c42c90813 100644 (file)
@@ -16,8 +16,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
+EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};\r
+\r
+BOOLEAN                         mSysFontColorCached = FALSE;\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL   mSysFGColor = {0};\r
 \r
-UINT8 mGlyphBuffer[EFI_GLYPH_WIDTH * 2 * EFI_GLYPH_HEIGHT];\r
 \r
 /**\r
   This function is only called by Graphics Console module and GraphicsLib. \r
@@ -47,8 +50,76 @@ HiiGetGlyph (
   IN OUT UINT32             *InternalStatus\r
   )\r
 {\r
-  ASSERT (FALSE);\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                Status;\r
+  EFI_IMAGE_OUTPUT          *Blt;\r
+  EFI_FONT_DISPLAY_INFO     *FontInfo;\r
+  UINTN                     Xpos;\r
+  UINTN                     Ypos;\r
+  UINTN                     BaseLine;\r
+\r
+  if (!mSysFontColorCached) {\r
+    //\r
+    // Cache the system font's foreground color.\r
+    //\r
+    Status = mHiiFontProtocol->GetFontInfo (\r
+                                 mHiiFontProtocol,\r
+                                 NULL,\r
+                                 NULL,\r
+                                 &FontInfo,\r
+                                 NULL\r
+                                 );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);\r
+      mSysFGColor = FontInfo->ForegroundColor;\r
+      FreePool (FontInfo);\r
+\r
+      mSysFontColorCached = TRUE;\r
+    }\r
+    \r
+  }\r
+\r
+  Blt = NULL;\r
+  Status = mHiiFontProtocol->GetGlyph (\r
+                               mHiiFontProtocol,\r
+                               Source[*Index],\r
+                               NULL,\r
+                               &Blt,\r
+                               &BaseLine\r
+                               );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // For simplicity, we only handle Narrow Glyph.\r
+    //\r
+    ASSERT (Blt->Height == EFI_GLYPH_HEIGHT);\r
+    ASSERT (Blt->Width == EFI_GLYPH_WIDTH);\r
+\r
+    if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {\r
+\r
+      ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));\r
+      mNarrowGlyphBuffer.UnicodeWeight = *Source;\r
+      for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {\r
+        for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {\r
+          if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {\r
+            mNarrowGlyphBuffer.GlyphCol1[Ypos] |= 1 << (EFI_GLYPH_WIDTH - 1 - Xpos);\r
+          }\r
+        }\r
+      }\r
+\r
+      *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;\r
+      *BitWidth    = EFI_GLYPH_WIDTH;\r
+      *Index += 1;\r
+    } else {\r
+      Status = EFI_NOT_FOUND;\r
+    }\r
+\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    *GlyphBuffer = NULL;\r
+  }\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -83,6 +154,21 @@ HiiGlyphToBlt (
   IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer\r
   )\r
 {\r
-  ASSERT (FALSE);\r
-  return EFI_UNSUPPORTED;\r
+  UINTN X;\r
+  UINTN Y;\r
+\r
+  //\r
+  // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
+  //\r
+  for (Y = 0; Y < Height; Y++) {\r
+    for (X = 0; X < Width; X++) {\r
+      if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {\r
+        BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;\r
+      } else {\r
+        BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
index 88f05ad3a1522541a2784fafea67aaa7e2c6835d..ea83bdf66e5c2bc3b4edd0ea3233b6abe6c30be5 100644 (file)
@@ -97,6 +97,7 @@
 [Depex]\r
   gEfiHiiDatabaseProtocolGuid AND\r
   gEfiHiiStringProtocolGuid AND\r
-  gEfiHiiConfigRoutingProtocolGuid\r
+  gEfiHiiConfigRoutingProtocolGuid AND\r
+  gEfiHiiFontProtocolGuid\r
 \r
 \r
index 50b902a952cd08b01b8cb3eb79c2a36b06df983b..c9428a23281489255f6afbf81ea28d6cc55faf69 100644 (file)
@@ -76,6 +76,7 @@ EFI_FORMBROWSER_THUNK_PRIVATE_DATA mBrowserThunkPrivateDataTemplate = {
 CONST EFI_HII_DATABASE_PROTOCOL            *mHiiDatabase;\r
 CONST EFI_HII_IMAGE_PROTOCOL               *mHiiImageProtocol;\r
 CONST EFI_HII_STRING_PROTOCOL              *mHiiStringProtocol;\r
+CONST EFI_HII_FONT_PROTOCOL                *mHiiFontProtocol;\r
 CONST EFI_HII_CONFIG_ROUTING_PROTOCOL      *mHiiConfigRoutingProtocol;\r
 CONST EFI_FORM_BROWSER2_PROTOCOL           *mFormBrowser2Protocol;\r
 \r
@@ -134,6 +135,13 @@ Returns:
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiHiiFontProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &mHiiFontProtocol\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   Status = gBS->LocateProtocol (\r
                   &gEfiHiiConfigRoutingProtocolGuid,\r
                   NULL,\r
index 3a0f09f0c81528cc04a567f15cce3263aa86c0f4..55362ea7bf39b8cc28c7413c91dabf71fe2a425d 100644 (file)
@@ -211,6 +211,7 @@ typedef struct {
 extern CONST EFI_HII_DATABASE_PROTOCOL            *mHiiDatabase;\r
 extern CONST EFI_HII_IMAGE_PROTOCOL               *mHiiImageProtocol;\r
 extern CONST EFI_HII_STRING_PROTOCOL              *mHiiStringProtocol;\r
+extern CONST EFI_HII_FONT_PROTOCOL                *mHiiFontProtocol;\r
 extern CONST EFI_HII_CONFIG_ROUTING_PROTOCOL      *mHiiConfigRoutingProtocol;\r
 extern CONST EFI_FORM_BROWSER2_PROTOCOL           *mFormBrowser2Protocol;\r
 \r
index 87763853759a9aad049e126625d531914be54dcc..cf43572ab716a820d8d15f529e49de6aeb983626 100644 (file)
@@ -351,7 +351,9 @@ F2UCreateOneOfOpCode (
 \r
   UOpcode.Question.Header.Prompt = FwOpcode->Prompt;\r
   UOpcode.Question.Header.Help = FwOpcode->Help;\r
\r
+  UOpcode.Question.VarStoreId  = VarStoreId;\r
+  UOpcode.Question.VarStoreInfo.VarOffset = FwOpcode->QuestionId;\r
+  \r
   //\r
   // Go over the Framework IFR binary to get the QuestionId for generated UEFI One Of Option opcode\r
   //\r
@@ -386,18 +388,18 @@ F2UCreateOneOfOpCode (
         }\r
 \r
         InsertTailList (&ThunkContext->OneOfOptionMapListHead, &OneOfOptionMap->Link);\r
-      } else {      \r
-        OneOfOptionMapEntry = AllocateZeroPool (sizeof (ONE_OF_OPTION_MAP_ENTRY));\r
-        ASSERT (OneOfOptionMapEntry != NULL);\r
+      }\r
+      \r
+      OneOfOptionMapEntry = AllocateZeroPool (sizeof (ONE_OF_OPTION_MAP_ENTRY));\r
+      ASSERT (OneOfOptionMapEntry != NULL);\r
 \r
-        OneOfOptionMapEntry->FwKey = FwOneOfOp->Key;\r
-        OneOfOptionMapEntry->Signature = ONE_OF_OPTION_MAP_ENTRY_SIGNATURE;\r
-        \r
-        CopyMem (&OneOfOptionMapEntry->Value, &FwOneOfOp->Value, FwOpcode->Width);\r
+      OneOfOptionMapEntry->FwKey = FwOneOfOp->Key;\r
+      OneOfOptionMapEntry->Signature = ONE_OF_OPTION_MAP_ENTRY_SIGNATURE;\r
+      \r
+      CopyMem (&OneOfOptionMapEntry->Value, &FwOneOfOp->Value, FwOpcode->Width);\r
 \r
-        ASSERT (OneOfOptionMap != NULL);\r
-        InsertTailList (&OneOfOptionMap->OneOfOptionMapEntryListHead, &OneOfOptionMapEntry->Link);\r
-      }\r
+      ASSERT (OneOfOptionMap != NULL);\r
+      InsertTailList (&OneOfOptionMap->OneOfOptionMapEntryListHead, &OneOfOptionMapEntry->Link);\r
     }\r
 \r
     if (FwOneOfOp->Flags & FRAMEWORK_EFI_IFR_FLAG_RESET_REQUIRED) {\r
@@ -499,6 +501,7 @@ F2UCreateOrderedListOpCode (
   UOpcode.Question.Header.Prompt = FwOpcode->Prompt;\r
   UOpcode.Question.Header.Help = FwOpcode->Help;\r
   UOpcode.Question.VarStoreId  = VarStoreId;\r
+  UOpcode.Question.VarStoreInfo.VarOffset = FwOpcode->QuestionId;\r
 \r
   UOpcode.MaxContainers = FwOpcode->MaxEntries;\r
 \r
index 318f9ee1be4a006636b83a35b46fdfc76a216c1b..9a380605227ad840da21feac846d31a66d04e97b 100644 (file)
@@ -15,6 +15,33 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
+typedef struct {\r
+  CHAR8 *Iso639;\r
+  CHAR8 *Rfc3066;\r
+} ISO639TORFC3066MAP;\r
+\r
+ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
+    {"eng", "en-US"},\r
+    {"fra", "fr-FR"},\r
+};\r
+\r
+CHAR8 *\r
+ConvertIso639ToRfc3066 (\r
+  CHAR8 *Iso638Lang\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
+    if (AsciiStrnCmp (Iso638Lang, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (Iso638Lang)) == 0) {\r
+      return Iso639ToRfc3066Map[Index].Rfc3066;\r
+    }\r
+  }\r
+\r
+  return (CHAR8 *) NULL;\r
+}\r
+\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 HiiTestString (\r
@@ -38,6 +65,8 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+\r
 EFI_STATUS\r
 GetTagGuidByFwHiiHandle (\r
   IN  CONST HII_THUNK_PRIVATE_DATA      *Private,\r
@@ -99,8 +128,9 @@ Returns:
   HII_THUNK_CONTEXT                          *ThunkContext;\r
   EFI_STRING_ID                             StringId;\r
   EFI_STRING_ID                             LastStringId;\r
-  CHAR8                                     *AsciiLanguage;\r
+  CHAR8                                     AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
   BOOLEAN                                   Found;\r
+  CHAR8                                     *Rfc3066AsciiLanguage;\r
 \r
   //\r
   // BugBug: Conver the language to 3066.\r
@@ -109,7 +139,7 @@ Returns:
   LastStringId      = (EFI_STRING_ID) 0;\r
   StringId          = (EFI_STRING_ID) 0;\r
   Found             = FALSE;\r
-  AsciiLanguage     = NULL;\r
+  Rfc3066AsciiLanguage = NULL;\r
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
 \r
@@ -117,8 +147,11 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   if (Language != NULL) {\r
-    AsciiLanguage = AllocateZeroPool (StrLen (Language) + 1);\r
+    ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
+    \r
     UnicodeStrToAsciiStr (Language, AsciiLanguage);\r
+    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
+    ASSERT (Rfc3066AsciiLanguage != NULL);\r
   }\r
 \r
   Link = GetFirstNode (&Private->ThunkContextListHead);\r
@@ -131,7 +164,7 @@ Returns:
         //\r
         // Create a new string token.\r
         //\r
-        if (AsciiLanguage == NULL) {\r
+        if (Rfc3066AsciiLanguage == NULL) {\r
           //\r
           // For all languages in the package list.\r
           //\r
@@ -144,7 +177,7 @@ Returns:
                                          mHiiStringProtocol,\r
                                          ThunkContext->UefiHiiHandle,\r
                                          &StringId,\r
-                                         AsciiLanguage,\r
+                                         Rfc3066AsciiLanguage,\r
                                          NULL,\r
                                          NewString,\r
                                          NULL\r
@@ -154,7 +187,7 @@ Returns:
         //\r
         // Update the existing string token.\r
         //\r
-        if (AsciiLanguage == NULL) {\r
+        if (Rfc3066AsciiLanguage == NULL) {\r
           //\r
           // For all languages in the package list.\r
           //\r
@@ -167,7 +200,7 @@ Returns:
                                        mHiiStringProtocol,\r
                                        ThunkContext->UefiHiiHandle,\r
                                        *Reference,\r
-                                       AsciiLanguage,\r
+                                       Rfc3066AsciiLanguage,\r
                                        NewString,\r
                                        NULL\r
                                        );\r
@@ -245,42 +278,16 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-typedef struct {\r
-  CHAR8 *Iso639;\r
-  CHAR8 *Rfc3066;\r
-} ISO639TORFC3066MAP;\r
-\r
-ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
-    {"eng", "en-US"},\r
-    {"fra", "fr-FR"},\r
-};\r
-\r
-CHAR8 *\r
-ConvertIso639ToRfc3066 (\r
-  CHAR8 *Iso638Lang\r
-  )\r
-{\r
-  UINTN Index;\r
-\r
-  for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
-    if (AsciiStrnCmp (Iso638Lang, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (Iso638Lang)) == 0) {\r
-      return Iso639ToRfc3066Map[Index].Rfc3066;\r
-    }\r
-  }\r
-\r
-  return (CHAR8 *) NULL;\r
-}\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 HiiGetString (\r
-  IN     EFI_HII_PROTOCOL    *This,\r
-  IN     FRAMEWORK_EFI_HII_HANDLE       Handle,\r
-  IN     STRING_REF          Token,\r
-  IN     BOOLEAN             Raw,\r
-  IN     CHAR16              *LanguageString,\r
-  IN OUT UINTN               *BufferLengthTemp,\r
-  OUT    EFI_STRING          StringBuffer\r
+  IN     EFI_HII_PROTOCOL           *This,\r
+  IN     FRAMEWORK_EFI_HII_HANDLE   Handle,\r
+  IN     STRING_REF                 Token,\r
+  IN     BOOLEAN                    Raw,\r
+  IN     CHAR16                     *LanguageString,\r
+  IN OUT UINTN                      *BufferLengthTemp,\r
+  OUT    EFI_STRING                 StringBuffer\r
   )\r
 /*++\r
 \r
@@ -310,68 +317,62 @@ Returns:
 \r
 --*/\r
 {\r
-  LIST_ENTRY                                *Link;\r
-  HII_THUNK_CONTEXT  *ThunkContext;\r
-  CHAR8                                     *AsciiLanguage;\r
+  CHAR8                                 *Iso639AsciiLanguage;\r
   HII_THUNK_PRIVATE_DATA                *Private;\r
-  CHAR8                                     *Rfc3066AsciiLanguage;\r
+  CHAR8                                 *Rfc3066AsciiLanguage;\r
+  EFI_HII_HANDLE                        UefiHiiHandle;\r
+  EFI_STATUS                            Status;\r
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
 \r
-  if (LanguageString == NULL) {\r
-    AsciiLanguage = NULL;\r
-  } else {\r
-    AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
-    if (AsciiLanguage == NULL) {\r
+  Iso639AsciiLanguage = NULL;\r
+  Rfc3066AsciiLanguage = NULL;\r
+\r
+  if (LanguageString != NULL) {\r
+    Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
+    if (Iso639AsciiLanguage == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    UnicodeStrToAsciiStr  (LanguageString, AsciiLanguage);\r
+    UnicodeStrToAsciiStr  (LanguageString, Iso639AsciiLanguage);\r
 \r
-    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
+    //\r
+    // Caller of Framework HII Interface uses the Language Identification String defined \r
+    // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
+    //\r
+    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
 \r
     //\r
     // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
     // Iso639ToRfc3066Map.\r
     //\r
     ASSERT (Rfc3066AsciiLanguage != NULL);\r
-    //\r
-    // Caller of Framework HII Interface uses the Language Identification String defined \r
-    // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
-    //\r
-    if (Rfc3066AsciiLanguage != NULL) {\r
-      FreePool (AsciiLanguage);\r
-      AsciiLanguage = AllocateCopyPool (AsciiStrSize (Rfc3066AsciiLanguage), Rfc3066AsciiLanguage);\r
-    }\r
     \r
   }\r
 \r
-  Link = GetFirstNode (&Private->ThunkContextListHead);\r
-\r
-  while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
-\r
-    ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
+  UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
+  if (UefiHiiHandle == NULL) {\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
+  }\r
 \r
-    if (Handle == ThunkContext->FwHiiHandle) {\r
-      if (AsciiLanguage == NULL) {\r
-        return HiiLibGetString (ThunkContext->UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);\r
-      } else {\r
-        return mHiiStringProtocol->GetString (\r
-                                     mHiiStringProtocol,\r
-                                     AsciiLanguage,\r
-                                     ThunkContext->UefiHiiHandle,\r
-                                     Token,\r
-                                     StringBuffer,\r
-                                     BufferLengthTemp,\r
-                                     NULL\r
-                                     );\r
-      }\r
-    }\r
-    \r
-    \r
-    Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
+  if (Rfc3066AsciiLanguage == NULL) {\r
+    Status =  HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);\r
+  } else {\r
+    Status = mHiiStringProtocol->GetString (\r
+                                 mHiiStringProtocol,\r
+                                 Rfc3066AsciiLanguage,\r
+                                 UefiHiiHandle,\r
+                                 Token,\r
+                                 StringBuffer,\r
+                                 BufferLengthTemp,\r
+                                 NULL\r
+                                 );\r
   }\r
 \r
-  return EFI_NOT_FOUND;\r
+Done:\r
+  SafeFreePool (Iso639AsciiLanguage);\r
+  \r
+  return Status;\r
 }\r
 \r
 EFI_STATUS\r