]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fixed HiiSetString failed. Tracker NUM:204479
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 20 Jan 2011 02:51:09 +0000 (02:51 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 20 Jan 2011 02:51:09 +0000 (02:51 +0000)
Reason:
    When call function HiiSetString to update the string which has no old string exist for one language, it will failed.
Solution:
    When no old string exist, update with new string.

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

MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
MdeModulePkg/Universal/HiiDatabaseDxe/String.c

index a4640cea4020780b43ced35b3adf61e6fe06b4de..f82842cac1c9dd175c142231e22719f4c5c6ae19 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for EFI_HII_DATABASE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, 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
@@ -856,7 +856,7 @@ InsertStringPackage (
   //\r
   // Collect all font block info\r
   //\r
-  Status = FindStringBlock (Private, StringPackage, (EFI_STRING_ID) (-1), NULL, NULL, NULL, &StringPackage->MaxStringId);\r
+  Status = FindStringBlock (Private, StringPackage, (EFI_STRING_ID) (-1), NULL, NULL, NULL, &StringPackage->MaxStringId, NULL);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
index fd9ec29e8306ffa8b611bf29e9f0c408a1b2086a..554d7c892127686db4e586345e827d89f9a142e6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Private structures definitions in HiiDatabase.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, 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
@@ -436,6 +436,7 @@ GetSystemFont (
   @param  StringTextOffset        Offset, relative to the found block address, of\r
                                   the  string text information.\r
   @param  LastStringId            Output the last string id when StringId = 0 or StringId = -1.\r
+  @param  StartStringId           The first id in the skip block which StringId in the block.\r
 \r
   @retval EFI_SUCCESS             The string text and font is retrieved\r
                                   successfully.\r
@@ -453,7 +454,8 @@ FindStringBlock (
   OUT UINT8                           *BlockType, OPTIONAL\r
   OUT UINT8                           **StringBlockAddr, OPTIONAL\r
   OUT UINTN                           *StringTextOffset, OPTIONAL\r
-  OUT EFI_STRING_ID                   *LastStringId OPTIONAL\r
+  OUT EFI_STRING_ID                   *LastStringId, OPTIONAL\r
+  OUT EFI_STRING_ID                   *StartStringId OPTIONAL\r
   );\r
 \r
 \r
index 9b6a5a3556dc24405c8b13bcea4ddc786aaa5274..3c7b491cc42f5c106843f149dd2eeea80433e1db 100644 (file)
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_STRING_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, 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
@@ -248,6 +248,7 @@ GetStringFontInfo (
   @param  StringTextOffset        Offset, relative to the found block address, of\r
                                   the  string text information.\r
   @param  LastStringId            Output the last string id when StringId = 0 or StringId = -1.\r
+  @param  StartStringId           The first id in the skip block which StringId in the block.\r
 \r
   @retval EFI_SUCCESS             The string text and font is retrieved\r
                                   successfully.\r
@@ -265,7 +266,8 @@ FindStringBlock (
   OUT UINT8                           *BlockType, OPTIONAL\r
   OUT UINT8                           **StringBlockAddr, OPTIONAL\r
   OUT UINTN                           *StringTextOffset, OPTIONAL\r
-  OUT EFI_STRING_ID                   *LastStringId OPTIONAL\r
+  OUT EFI_STRING_ID                   *LastStringId, OPTIONAL\r
+  OUT EFI_STRING_ID                   *StartStringId OPTIONAL\r
   )\r
 {\r
   UINT8                                *BlockHdr;\r
@@ -540,12 +542,21 @@ FindStringBlock (
       break;\r
     }\r
 \r
-    if (StringId > 0) {\r
+    if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) {\r
+      ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r
+      *BlockType        = *BlockHdr;\r
+      *StringBlockAddr  = BlockHdr;\r
+      *StringTextOffset = Offset;\r
+\r
       if (StringId == CurrentStringId - 1) {\r
-        *BlockType        = *BlockHdr;\r
-        *StringBlockAddr  = BlockHdr;\r
-        *StringTextOffset = Offset;\r
-        return EFI_SUCCESS;\r
+        //\r
+        // if only one skip item, return EFI_NOT_FOUND.\r
+        //\r
+        if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) {\r
+          return EFI_NOT_FOUND;\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
       }\r
 \r
       if (StringId < CurrentStringId - 1) {\r
@@ -553,7 +564,9 @@ FindStringBlock (
       }\r
     }\r
     BlockHdr  = StringPackage->StringBlock + BlockSize;\r
-\r
+    if (StartStringId != NULL) {\r
+        *StartStringId  = CurrentStringId;\r
+    }\r
   }\r
   \r
   //\r
@@ -623,6 +636,7 @@ GetStringWorker (
              &BlockType,\r
              &StringBlockAddr,\r
              &StringTextOffset,\r
+             NULL,\r
              NULL\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -684,6 +698,153 @@ GetStringWorker (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  If GetStringBlock find the StringId's string is not saved in the exist string block,\r
+  this function will create the UCS2 string block to save the string; also split the \r
+  skip block into two or one skip block.\r
+\r
+  This is a internal function.\r
+  \r
+  @param  StringPackage           Hii string package instance.\r
+  @param  StartStringId           The first id in the skip block which StringId in the block.\r
+  @param  StringId                The string's id, which is unique within\r
+                                  PackageList.  \r
+  @param  BlockType               Output the block type of found string block.  \r
+  @param  StringBlockAddr         Output the block address of found string block.  \r
+  @param  FontBlock               whether this string block has font info.\r
+\r
+  @retval EFI_SUCCESS            The string font is outputed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES   NO resource for the memory to save the new string block.\r
+\r
+**/\r
+EFI_STATUS\r
+InsertLackStringBlock (\r
+  IN OUT HII_STRING_PACKAGE_INSTANCE         *StringPackage,\r
+  IN EFI_STRING_ID                           StartStringId,\r
+  IN EFI_STRING_ID                           StringId,\r
+  IN OUT UINT8                               *BlockType,\r
+  IN OUT UINT8                               **StringBlockAddr,\r
+  IN BOOLEAN                                 FontBlock\r
+  )\r
+{\r
+  UINT8                                *BlockPtr;\r
+  UINT8                                *StringBlock;\r
+  UINTN                                SkipLen;    \r
+  UINTN                                OldBlockSize;\r
+  UINTN                                NewBlockSize;\r
+  UINTN                                FrontSkipNum;\r
+  UINTN                                NewUCSBlockLen;\r
+  UINT8                                *OldStringAddr;\r
+  UINTN                                IdCount;\r
+\r
+  FrontSkipNum  = 0;\r
+  SkipLen       = 0;\r
+  OldStringAddr = *StringBlockAddr;\r
+  \r
+  ASSERT (*BlockType == EFI_HII_SIBT_SKIP1 || *BlockType == EFI_HII_SIBT_SKIP2);\r
+  //\r
+  // Old skip block size.\r
+  //\r
+  if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+    SkipLen = sizeof (EFI_HII_SIBT_SKIP1_BLOCK);\r
+    IdCount = *(UINT8*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r
+  } else {\r
+    SkipLen = sizeof (EFI_HII_SIBT_SKIP2_BLOCK);\r
+    IdCount = *(UINT16*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r
+  } \r
+\r
+  //\r
+  // New create UCS or UCS2 block size.\r
+  //\r
+  if (FontBlock) {\r
+    NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK);\r
+  } else {\r
+    NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r
+  }\r
+\r
+  OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
+\r
+  if (StartStringId == StringId) {\r
+    //\r
+    // New block + [Skip block]\r
+    //\r
+    if (IdCount > 1) {\r
+      NewBlockSize = OldBlockSize + NewUCSBlockLen;\r
+    } else {\r
+      NewBlockSize = OldBlockSize + NewUCSBlockLen - SkipLen;\r
+    }\r
+  } else if (StartStringId + IdCount - 1 == StringId){\r
+    //\r
+    // Skip block + New block\r
+    //\r
+    NewBlockSize = OldBlockSize + NewUCSBlockLen;\r
+    FrontSkipNum = StringId - StartStringId;\r
+  } else {\r
+    //\r
+    // Skip block + New block + [Skip block]\r
+    //\r
+    NewBlockSize = OldBlockSize + NewUCSBlockLen + SkipLen;\r
+    FrontSkipNum = StringId - StartStringId;\r
+  }\r
+\r
+  StringBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);\r
+  if (StringBlock == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Copy old block in front of skip block.\r
+  //\r
+  CopyMem (StringBlock, StringPackage->StringBlock, OldStringAddr - StringPackage->StringBlock);  \r
+  BlockPtr = StringBlock + (OldStringAddr - StringPackage->StringBlock);\r
+\r
+  if (FrontSkipNum > 0) {\r
+    *BlockPtr = *BlockType;\r
+    if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+      (UINT8) (*(BlockPtr + sizeof (EFI_HII_STRING_BLOCK))) = (UINT8)FrontSkipNum;\r
+    } else {\r
+      (UINT16) (*(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK))) = (UINT16)FrontSkipNum;\r
+    }\r
+    BlockPtr += SkipLen;\r
+  }\r
+\r
+  //\r
+  // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r
+  //\r
+  *StringBlockAddr = BlockPtr;\r
+  if (FontBlock) {\r
+    *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r
+  } else {\r
+    *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r
+  }\r
+  BlockPtr += NewUCSBlockLen;\r
+\r
+  if (IdCount > FrontSkipNum + 1) {\r
+    *BlockPtr = *BlockType;\r
+    if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+      (UINT8) (*(BlockPtr + sizeof (EFI_HII_STRING_BLOCK))) = (UINT8) (IdCount - FrontSkipNum - 1);\r
+    } else {\r
+      (UINT16) (*(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK))) = (UINT16) (IdCount - FrontSkipNum - 1);\r
+    }\r
+    BlockPtr += SkipLen;\r
+  }\r
+\r
+  //\r
+  // Append a EFI_HII_SIBT_END block to the end.\r
+  //\r
+  CopyMem (BlockPtr, OldStringAddr + SkipLen, OldBlockSize - (OldStringAddr - StringPackage->StringBlock) - SkipLen);  \r
+\r
+  if (FontBlock) {\r
+    *BlockType = EFI_HII_SIBT_STRING_UCS2_FONT;\r
+  } else {\r
+    *BlockType = EFI_HII_SIBT_STRING_UCS2;\r
+  }\r
+  FreePool (StringPackage->StringBlock);\r
+  StringPackage->StringBlock = StringBlock;\r
+  StringPackage->StringPkgHdr->Header.Length += NewBlockSize - OldBlockSize;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Parse all string blocks to set a String specified by StringId.\r
@@ -731,8 +892,9 @@ SetStringWorker (
   EFI_HII_SIBT_EXT2_BLOCK              Ext2;\r
   UINTN                                StringSize;\r
   UINTN                                TmpSize;\r
+  EFI_STRING_ID                        StartStringId;\r
 \r
-\r
+  StartStringId = 0;\r
   ASSERT (Private != NULL && StringPackage != NULL && String != NULL);\r
   ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
   //\r
@@ -745,10 +907,25 @@ SetStringWorker (
              &BlockType,\r
              &StringBlockAddr,\r
              &StringTextOffset,\r
-             NULL\r
+             NULL,\r
+             &StartStringId\r
              );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  if (EFI_ERROR (Status) && (BlockType == EFI_HII_SIBT_SKIP1 || BlockType == EFI_HII_SIBT_SKIP2)) {\r
+    Status = InsertLackStringBlock(StringPackage, \r
+                          StartStringId, \r
+                          StringId, \r
+                          &BlockType,\r
+                          &StringBlockAddr,\r
+                          (BOOLEAN)(StringFontInfo != NULL)\r
+                          );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    if (StringFontInfo != NULL) {\r
+      StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r
+    } else {\r
+      StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16);\r
+    }\r
   }\r
 \r
   LocalFont  = NULL;\r
@@ -806,7 +983,7 @@ SetStringWorker (
   case EFI_HII_SIBT_STRINGS_SCSU:\r
   case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
     BlockSize = OldBlockSize + StrLen (String);\r
-    BlockSize -= AsciiStrLen ((CHAR8 *) StringTextPtr);\r
+    BlockSize -= AsciiStrSize ((CHAR8 *) StringTextPtr);\r
     Block = AllocateZeroPool (BlockSize);\r
     if (Block == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -1048,7 +1225,8 @@ HiiNewString (
                NULL,\r
                NULL,\r
                NULL,\r
-               &NextStringId\r
+               &NextStringId,\r
+               NULL\r
                );\r
     if (EFI_ERROR (Status)) {\r
       goto Done;\r