|
From: <yd...@us...> - 2011-07-12 06:55:46
|
Revision: 2209
http://edk2-buildtools.svn.sourceforge.net/edk2-buildtools/?rev=2209&view=rev
Author: ydong10
Date: 2011-07-12 06:55:40 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Enable new efi varstore storage format.
Signed-off-by: ydong10
Reviewed-by: lgao4
Modified Paths:
--------------
trunk/BaseTools/Conf/build_rule.template
trunk/BaseTools/Source/C/Include/Common/UefiInternalFormRepresentation.h
trunk/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
trunk/BaseTools/Source/C/VfrCompile/VfrFormPkg.h
trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g
trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
trunk/BaseTools/Source/Python/AutoGen/AutoGen.py
Modified: trunk/BaseTools/Conf/build_rule.template
===================================================================
--- trunk/BaseTools/Conf/build_rule.template 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Conf/build_rule.template 2011-07-12 06:55:40 UTC (rev 2209)
@@ -198,7 +198,7 @@
-$(MD) $(OUTPUT_DIR)(+)${s_dir} > NUL 2>&1
"$(VFRPP)" $(VFRPP_FLAGS) $(INC) ${src} > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
-$(MD) ${d_path} > NUL 2>&1
- "$(VFR)" $(VFR_FLAGS) --output-directory ${d_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
+ "$(VFR)" $(VFR_FLAGS) --string-db $(OUTPUT_DIR)(+)$(MODULE_NAME)StrDefs.hpk --output-directory ${d_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
[Object-File]
<InputFile>
@@ -474,6 +474,7 @@
<OutputFile>
$(DEBUG_DIR)(+)AutoGen.c
$(DEBUG_DIR)(+)$(MODULE_NAME)StrDefs.h
+ $(OUTPUT_DIR)(+)$(MODULE_NAME)StrDefs.hpk
<Command>
@@ -513,7 +514,7 @@
-$(MD) $(OUTPUT_DIR)(+)${s_dir} > NUL 2>&1
"$(VFRPP)" $(VFRPP_FLAGS) $(INC) ${src} > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
-$(MD) $(OUTPUT_DIR)(+)${s_dir} > NUL 2>&1
- "$(VFR)" $(VFR_FLAGS) --create-ifr-package --output-directory $(OUTPUT_DIR)(+)${s_dir} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
+ "$(VFR)" $(VFR_FLAGS) --create-ifr-package --string-db $(OUTPUT_DIR)(+)$(MODULE_NAME)StrDefs.hpk --output-directory $(OUTPUT_DIR)(+)${s_dir} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i
[Hii-Binary-Package.UEFI_HII]
<InputFile>
Modified: trunk/BaseTools/Source/C/Include/Common/UefiInternalFormRepresentation.h
===================================================================
--- trunk/BaseTools/Source/C/Include/Common/UefiInternalFormRepresentation.h 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/Include/Common/UefiInternalFormRepresentation.h 2011-07-12 06:55:40 UTC (rev 2209)
@@ -749,6 +749,8 @@
EFI_VARSTORE_ID VarStoreId;
EFI_GUID Guid;
UINT32 Attributes;
+ UINT16 Size;
+ UINT8 Name[1];
} EFI_IFR_VARSTORE_EFI;
typedef struct _EFI_IFR_VARSTORE_NAME_VALUE {
Modified: trunk/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
===================================================================
--- trunk/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp 2011-07-12 06:55:40 UTC (rev 2209)
@@ -22,6 +22,7 @@
PACKAGE_DATA gCBuffer;
PACKAGE_DATA gRBuffer;
+CVfrStringDB gCVfrStringDB;
VOID
CVfrCompiler::DebugError (
@@ -132,6 +133,14 @@
AppendCPreprocessorOptions (Argv[Index]);
} else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {
mOptions.CompatibleMode = TRUE;
+ } else if (stricmp(Argv[Index], "-s") == 0|| stricmp(Argv[Index], "--string-db") == 0) {
+ Index++;
+ if ((Index >= Argc) || (Argv[Index][0] == '-')) {
+ DebugError (NULL, 0, 1001, "Missing option", "-s missing input string file name");
+ goto Fail;
+ }
+ gCVfrStringDB.SetStringFileName(Argv[Index]);
+ DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", Argv[Index]);
} else {
DebugError (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);
goto Fail;
@@ -399,6 +408,8 @@
" do not preprocessing input file",
" -c, --compatible-framework",
" compatible framework vfr file",
+ " -s, --string-db",
+ " input uni string package file",
NULL
};
for (Index = 0; Help[Index] != NULL; Index++) {
Modified: trunk/BaseTools/Source/C/VfrCompile/VfrFormPkg.h
===================================================================
--- trunk/BaseTools/Source/C/VfrCompile/VfrFormPkg.h 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/VfrCompile/VfrFormPkg.h 2011-07-12 06:55:40 UTC (rev 2209)
@@ -144,7 +144,8 @@
);
};
-extern CFormPkg gCFormPkg;
+extern CFormPkg gCFormPkg;
+extern CVfrStringDB gCVfrStringDB;
struct SIfrRecord {
UINT32 mLineNo;
@@ -233,6 +234,15 @@
return FALSE;
}
}
+
+ inline bool ShrinkObjBin (IN UINT8 Size) {
+ if ((mDelayEmit == TRUE) && (mObjBinLen > Size)) {
+ mObjBinLen -= Size;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
};
/*
@@ -254,7 +264,7 @@
VOID DecLength (UINT8 Size) {
if (mHeader->Length >= Size) {
- mHeader -= Size;
+ mHeader->Length -= Size;
}
}
@@ -755,10 +765,12 @@
EFI_IFR_VARSTORE_EFI *mVarStoreEfi;
public:
- CIfrVarStoreEfi () : CIfrObj (EFI_IFR_VARSTORE_EFI_OP, (CHAR8 **)&mVarStoreEfi),
+ CIfrVarStoreEfi () : CIfrObj (EFI_IFR_VARSTORE_EFI_OP, (CHAR8 **)&mVarStoreEfi, sizeof (EFI_IFR_VARSTORE_EFI), TRUE),
CIfrOpHeader (EFI_IFR_VARSTORE_EFI_OP, &mVarStoreEfi->Header) {
mVarStoreEfi->VarStoreId = EFI_VAROFFSET_INVALID;
+ mVarStoreEfi->Size = 0;
memset (&mVarStoreEfi->Guid, 0, sizeof (EFI_GUID));
+ mVarStoreEfi->Name[0] = '\0';
}
VOID SetGuid (IN EFI_GUID *Guid) {
@@ -772,6 +784,36 @@
VOID SetAttributes (IN UINT32 Attributes) {
mVarStoreEfi->Attributes = Attributes;
}
+ VOID SetSize (IN UINT16 Size) {
+ mVarStoreEfi->Size = Size;
+ }
+
+ VOID SetName (IN CHAR8 *Name) {
+ UINT8 Len;
+
+ if (Name != NULL) {
+ Len = (UINT8) strlen (Name);
+ if (Len != 0) {
+ if (ExpendObjBin (Len) == TRUE) {
+ IncLength (Len);
+ strcpy ((CHAR8 *)(mVarStoreEfi->Name), Name);
+ }
+ }
+ }
+ }
+
+ VOID SetBinaryLength (IN UINT16 Size) {
+ UINT16 Len;
+
+ Len = sizeof (EFI_IFR_VARSTORE_EFI);
+ if (Size > Len) {
+ ExpendObjBin(Size - Len);
+ IncLength(Size - Len);
+ } else {
+ ShrinkObjBin(Len - Size);
+ DecLength(Len - Size);
+ }
+ }
};
class CIfrVarStoreNameValue : public CIfrObj, public CIfrOpHeader {
Modified: trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g
===================================================================
--- trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g 2011-07-12 06:55:40 UTC (rev 2209)
@@ -853,22 +853,102 @@
vfrStatementVarStoreEfi :
<<
+ BOOLEAN IsUEFI23EfiVarstore = TRUE;
EFI_GUID Guid;
CIfrVarStoreEfi VSEObj;
- EFI_VARSTORE_ID VarStoreId;
+ EFI_VARSTORE_ID VarStoreId = EFI_VARSTORE_ID_INVALID;
UINT32 Attr = 0;
+ UINT32 Size;
+ CHAR8 *TypeName;
+ UINT32 LineNum;
+ CHAR8 *StoreName = NULL;
>>
E:Efivarstore << VSEObj.SetLineNo(E->getLine()); >>
- SN:StringIdentifier ","
+ (
+ TN:StringIdentifier "," << TypeName = TN->getText(); LineNum = TN->getLine(); >>
+ | U8:"UINT8" "," << TypeName = U8->getText(); LineNum = U8->getLine(); >>
+ | U16:"UINT16" "," << TypeName = U16->getText(); LineNum = U16->getLine(); >>
+ | C16:"CHAR16" "," << TypeName = (CHAR8 *) "UINT16"; LineNum = C16->getLine(); >>
+ | U32:"UINT32" "," << TypeName = U32->getText(); LineNum = U32->getLine(); >>
+ | U64:"UINT64" "," << TypeName = U64->getText(); LineNum = U64->getLine(); >>
+ | D:"EFI_HII_DATE" "," << TypeName = D->getText(); LineNum = D->getLine(); >>
+ | T:"EFI_HII_TIME" "," << TypeName = T->getText(); LineNum = T->getLine(); >>
+ | R:"EFI_HII_REF" "," << TypeName = R->getText(); LineNum = R->getLine(); >>
+ )
+ {
+ VarId "=" ID:Number "," <<
+ _PCATCH(
+ (INTN)(VarStoreId = _STOU16(ID->getText())) != 0,
+ (INTN)TRUE,
+ ID,
+ "varid 0 is not allowed."
+ );
+ >>
+ }
Attribute "=" vfrVarStoreEfiAttr[Attr] ( "\|" vfrVarStoreEfiAttr[Attr] )* ","
<< VSEObj.SetAttributes (Attr); >>
- Name "=" "STRING_TOKEN" "\(" VN:Number "\)" ","
- VarSize "=" N:Number ","
- Uuid "=" guidDefinition[Guid] << mCVfrDataStorage.DeclareEfiVarStore (SN->getText(), &Guid, _STOSID(VN->getText()), _STOU32(N->getText())); >>
- <<
- VSEObj.SetGuid (&Guid);
- _PCATCH(mCVfrDataStorage.GetVarStoreId(SN->getText(), &VarStoreId), SN);
+
+ (
+ Name "=" SN:StringIdentifier "," << StoreName = SN->getText(); >>
+ |
+ Name "=" "STRING_TOKEN" "\(" VN:Number "\)" ","
+ VarSize "=" N:Number "," <<
+ IsUEFI23EfiVarstore = FALSE;
+ gCVfrStringDB.GetVarStoreNameFormStringId(_STOSID(VN->getText()), &StoreName);
+ if (StoreName == NULL) {
+ _PCATCH (VFR_RETURN_UNSUPPORTED, VN->getLine(), "Can't get varstore name for this StringId!");
+ }
+ Size = _STOU32(N->getText());
+ switch (Size) {
+ case 1:
+ TypeName = (CHAR8 *) "UINT8";
+ break;
+ case 2:
+ TypeName = (CHAR8 *) "UINT16";
+ break;
+ case 4:
+ TypeName = (CHAR8 *) "UINT32";
+ break;
+ case 8:
+ TypeName = (CHAR8 *) "UINT64";
+ break;
+ default:
+ _PCATCH (VFR_RETURN_UNSUPPORTED, N);
+ break;
+ }
+ >>
+ )
+
+ Uuid "=" guidDefinition[Guid] <<
+ if (IsUEFI23EfiVarstore) {
+ _PCATCH(mCVfrDataStorage.DeclareBufferVarStore (
+ StoreName,
+ &Guid,
+ &gCVfrVarDataTypeDB,
+ TypeName,
+ VarStoreId
+ ), LineNum);
+ _PCATCH(mCVfrDataStorage.GetVarStoreId(StoreName, &VarStoreId), SN);
+ _PCATCH(gCVfrVarDataTypeDB.GetDataTypeSize(TypeName, &Size), LineNum);
+ } else {
+ _PCATCH(mCVfrDataStorage.DeclareBufferVarStore (
+ TN->getText(),
+ &Guid,
+ &gCVfrVarDataTypeDB,
+ TypeName,
+ VarStoreId
+ ), LineNum);
+ _PCATCH(mCVfrDataStorage.GetVarStoreId(TN->getText(), &VarStoreId), VN);
+ _PCATCH(gCVfrVarDataTypeDB.GetDataTypeSize(TypeName, &Size), N->getLine());
+ }
+ VSEObj.SetGuid (&Guid);
VSEObj.SetVarStoreId (VarStoreId);
+
+ VSEObj.SetSize ((UINT16) Size);
+ VSEObj.SetName (StoreName);
+ if (IsUEFI23EfiVarstore == FALSE && StoreName != NULL) {
+ delete StoreName;
+ }
>>
";"
;
@@ -1547,7 +1627,7 @@
CIfrRef5 *R5Obj = NULL;
>>
G:Goto
- (
+ {
(
DevicePath "=" "STRING_TOKEN" "\(" P:Number "\)" ","
FormSetGuid "=" guidDefinition[FSId] ","
@@ -1587,10 +1667,7 @@
FId = _STOFID(F4->getText());
>>
)
- |
- (
- )
- )
+ }
<<
switch (RefType) {
case 5:
@@ -4294,6 +4371,9 @@
VSEObj.SetAttributes (0x00000002); //hardcode EFI_VARIABLE_BOOTSERVICE_ACCESS attribute
VSEObj.SetGuid (&pNode->mGuid);
VSEObj.SetVarStoreId (pNode->mVarStoreId);
+ // Generate old efi varstore storage structure for compatiable with old "VarEqVal" opcode,
+ // which is 3 bytes less than new structure define in UEFI Spec 2.3.1.
+ VSEObj.SetBinaryLength (sizeof (EFI_IFR_VARSTORE_EFI) - 3);
#ifdef VFREXP_DEBUG
printf ("undefined Efi VarStoreName is %s and Id is 0x%x\n", pNode->mVarStoreName, pNode->mVarStoreId);
#endif
Modified: trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
===================================================================
--- trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp 2011-07-12 06:55:40 UTC (rev 2209)
@@ -3034,6 +3034,406 @@
return VFR_RETURN_UNDEFINED;
}
+CVfrStringDB::CVfrStringDB ()
+{
+ mStringFileName = NULL;
+}
+
+CVfrStringDB::~CVfrStringDB ()
+{
+ if (mStringFileName != NULL) {
+ delete mStringFileName;
+ }
+ mStringFileName = NULL;
+}
+
+
+VOID
+CVfrStringDB::SetStringFileName(IN CHAR8 *StringFileName)
+{
+ UINT32 FileLen = 0;
+
+ if (StringFileName == NULL) {
+ return;
+ }
+
+ FileLen = strlen (StringFileName) + 1;
+ mStringFileName = new CHAR8[FileLen];
+ if (mStringFileName == NULL) {
+ return;
+ }
+
+ strcpy (mStringFileName, StringFileName);
+ mStringFileName[FileLen - 1] = '\0';
+}
+
+VOID
+CVfrStringDB::GetVarStoreNameFormStringId (
+ IN EFI_STRING_ID StringId,
+ OUT CHAR8 **VarStoreName
+ )
+{
+ FILE *pInFile = NULL;
+ UINT32 NameOffset;
+ UINT32 Length;
+ CHAR8 *StringPtr;
+ CHAR8 *StringName;
+ CHAR16 *UnicodeString;
+ CHAR8 *DestTmp;
+ EFI_STATUS Status;
+ CHAR8 LineBuf[EFI_IFR_MAX_LENGTH];
+ UINT8 BlockType;
+ EFI_HII_STRING_PACKAGE_HDR PkgHeader;
+
+ if (VarStoreName == NULL) {
+ return;
+ }
+
+ *VarStoreName = NULL;
+
+ if (mStringFileName == '\0' ) {
+ return;
+ }
+
+ if ((pInFile = fopen (mStringFileName, "r")) == NULL) {
+ return;
+ }
+
+ //
+ // fgets will add "\0" at the end of the string, so need to add one byte extra buffer.
+ //
+ while (fgets ((char *)(&PkgHeader), sizeof (EFI_HII_STRING_PACKAGE_HDR), pInFile) != NULL) {
+
+ if (PkgHeader.Header.Type != EFI_HII_PACKAGE_STRINGS) {
+ fclose (pInFile);
+ return;
+ }
+
+ Length = PkgHeader.HdrSize - sizeof (EFI_HII_STRING_PACKAGE_HDR) + 1 + 1;
+ if (fgets (LineBuf, Length, pInFile) == NULL) {
+ fclose (pInFile);
+ return;
+ }
+
+ Length = PkgHeader.Header.Length - PkgHeader.HdrSize + 1;
+ StringPtr = new CHAR8[Length];
+ if (StringPtr == NULL) {
+ fclose (pInFile);
+ }
+
+ if (fgets (StringPtr, Length, pInFile) == NULL ) {
+ fclose (pInFile);
+ return;
+ }
+
+ if (strcmp (LineBuf, "en-US") == 0) {
+ //
+ // Skip the data that the language is not english.
+ //
+ break;
+ }
+ delete StringPtr;
+ }
+
+ //
+ // Find the string block according the stringId.
+ //
+ Status = FindStringBlock(StringPtr, StringId, &NameOffset, &BlockType);
+ if (Status != EFI_SUCCESS) {
+ delete StringPtr;
+ fclose (pInFile);
+ return;
+ }
+
+ //
+ // Get varstore name according the string type.
+ //
+ switch (BlockType) {
+ case EFI_HII_SIBT_STRING_SCSU:
+ case EFI_HII_SIBT_STRING_SCSU_FONT:
+ case EFI_HII_SIBT_STRINGS_SCSU:
+ case EFI_HII_SIBT_STRINGS_SCSU_FONT:
+ StringName = StringPtr + NameOffset;
+ *VarStoreName = new CHAR8[strlen(StringName) + 1];
+ strcpy (*VarStoreName, StringName);
+ break;
+ case EFI_HII_SIBT_STRING_UCS2:
+ case EFI_HII_SIBT_STRING_UCS2_FONT:
+ case EFI_HII_SIBT_STRINGS_UCS2:
+ case EFI_HII_SIBT_STRINGS_UCS2_FONT:
+ UnicodeString = (CHAR16*)(StringPtr + NameOffset);
+ Status = GetUnicodeStringTextOrSize (NULL, (CHAR8*)UnicodeString, &Length) ;
+ DestTmp = new CHAR8[Length / 2 + 1];
+ *VarStoreName = DestTmp;
+ while (*UnicodeString != '\0') {
+ *(DestTmp++) = (CHAR8) *(UnicodeString++);
+ }
+ *DestTmp = '\0';
+ break;
+ default:
+ break;
+ }
+
+ delete StringPtr;
+ fclose (pInFile);
+}
+
+EFI_STATUS
+CVfrStringDB::FindStringBlock (
+ IN CHAR8 *StringData,
+ IN EFI_STRING_ID StringId,
+ OUT UINTN *StringTextOffset,
+ OUT UINT8 *BlockType
+ )
+{
+ CHAR8 *BlockHdr;
+ EFI_STRING_ID CurrentStringId;
+ UINTN BlockSize;
+ UINTN Index;
+ CHAR8 *StringTextPtr;
+ UINTN Offset;
+ UINT16 StringCount;
+ UINT16 SkipCount;
+ UINT8 Length8;
+ EFI_HII_SIBT_EXT2_BLOCK Ext2;
+ UINT32 Length32;
+ UINTN StringSize;
+
+ CurrentStringId = 1;
+
+ //
+ // Parse the string blocks to get the string text and font.
+ //
+ BlockHdr = StringData;
+ BlockSize = 0;
+ Offset = 0;
+ while (*BlockHdr != EFI_HII_SIBT_END) {
+ switch (*BlockHdr) {
+ case EFI_HII_SIBT_STRING_SCSU:
+ Offset = sizeof (EFI_HII_STRING_BLOCK);
+ StringTextPtr = BlockHdr + Offset;
+ BlockSize += Offset + strlen ((CHAR8 *) StringTextPtr) + 1;
+ CurrentStringId++;
+ break;
+
+ case EFI_HII_SIBT_STRING_SCSU_FONT:
+ Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);
+ StringTextPtr = BlockHdr + Offset;
+ BlockSize += Offset + strlen ((CHAR8 *) StringTextPtr) + 1;
+ CurrentStringId++;
+ break;
+
+ case EFI_HII_SIBT_STRINGS_SCSU:
+ memcpy (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
+ StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8);
+ BlockSize += StringTextPtr - BlockHdr;
+
+ for (Index = 0; Index < StringCount; Index++) {
+ BlockSize += strlen ((CHAR8 *) StringTextPtr) + 1;
+ if (CurrentStringId == StringId) {
+ *BlockType = *BlockHdr;
+ *StringTextOffset = StringTextPtr - StringData;
+ return EFI_SUCCESS;
+ }
+ StringTextPtr = StringTextPtr + strlen ((CHAR8 *) StringTextPtr) + 1;
+ CurrentStringId++;
+ }
+ break;
+
+ case EFI_HII_SIBT_STRINGS_SCSU_FONT:
+ memcpy (
+ &StringCount,
+ BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
+ sizeof (UINT16)
+ );
+ StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8);
+ BlockSize += StringTextPtr - BlockHdr;
+
+ for (Index = 0; Index < StringCount; Index++) {
+ BlockSize += strlen ((CHAR8 *) StringTextPtr) + 1;
+ if (CurrentStringId == StringId) {
+ *BlockType = *BlockHdr;
+ *StringTextOffset = StringTextPtr - StringData;
+ return EFI_SUCCESS;
+ }
+ StringTextPtr = StringTextPtr + strlen ((CHAR8 *) StringTextPtr) + 1;
+ CurrentStringId++;
+ }
+ break;
+
+ case EFI_HII_SIBT_STRING_UCS2:
+ Offset = sizeof (EFI_HII_STRING_BLOCK);
+ StringTextPtr = BlockHdr + Offset;
+ //
+ // Use StringSize to store the size of the specified string, including the NULL
+ // terminator.
+ //
+ GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
+ BlockSize += Offset + StringSize;
+ CurrentStringId++;
+ break;
+
+ case EFI_HII_SIBT_STRING_UCS2_FONT:
+ Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);
+ StringTextPtr = BlockHdr + Offset;
+ //
+ // Use StrSize to store the size of the specified string, including the NULL
+ // terminator.
+ //
+ GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
+ BlockSize += Offset + StringSize;
+ CurrentStringId++;
+ break;
+
+ case EFI_HII_SIBT_STRINGS_UCS2:
+ Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);
+ StringTextPtr = BlockHdr + Offset;
+ BlockSize += Offset;
+ memcpy (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
+ for (Index = 0; Index < StringCount; Index++) {
+ GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
+ BlockSize += StringSize;
+ if (CurrentStringId == StringId) {
+ *BlockType = *BlockHdr;
+ *StringTextOffset = StringTextPtr - StringData;
+ return EFI_SUCCESS;
+ }
+ StringTextPtr = StringTextPtr + StringSize;
+ CurrentStringId++;
+ }
+ break;
+
+ case EFI_HII_SIBT_STRINGS_UCS2_FONT:
+ Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);
+ StringTextPtr = BlockHdr + Offset;
+ BlockSize += Offset;
+ memcpy (
+ &StringCount,
+ BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
+ sizeof (UINT16)
+ );
+ for (Index = 0; Index < StringCount; Index++) {
+ GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
+ BlockSize += StringSize;
+ if (CurrentStringId == StringId) {
+ *BlockType = *BlockHdr;
+ *StringTextOffset = StringTextPtr - StringData;
+ return EFI_SUCCESS;
+ }
+ StringTextPtr = StringTextPtr + StringSize;
+ CurrentStringId++;
+ }
+ break;
+
+ case EFI_HII_SIBT_DUPLICATE:
+ if (CurrentStringId == StringId) {
+ //
+ // Incoming StringId is an id of a duplicate string block.
+ // Update the StringId to be the previous string block.
+ // Go back to the header of string block to search.
+ //
+ memcpy (
+ &StringId,
+ BlockHdr + sizeof (EFI_HII_STRING_BLOCK),
+ sizeof (EFI_STRING_ID)
+ );
+ CurrentStringId = 1;
+ BlockSize = 0;
+ } else {
+ BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);
+ CurrentStringId++;
+ }
+ break;
+
+ case EFI_HII_SIBT_SKIP1:
+ SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));
+ CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
+ BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
+ break;
+
+ case EFI_HII_SIBT_SKIP2:
+ memcpy (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
+ CurrentStringId = (UINT16) (CurrentStringId + SkipCount);
+ BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
+ break;
+
+ case EFI_HII_SIBT_EXT1:
+ memcpy (
+ &Length8,
+ BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
+ sizeof (UINT8)
+ );
+ BlockSize += Length8;
+ break;
+
+ case EFI_HII_SIBT_EXT2:
+ memcpy (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
+ BlockSize += Ext2.Length;
+ break;
+
+ case EFI_HII_SIBT_EXT4:
+ memcpy (
+ &Length32,
+ BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),
+ sizeof (UINT32)
+ );
+
+ BlockSize += Length32;
+ break;
+
+ default:
+ break;
+ }
+
+ if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) {
+ *StringTextOffset = BlockHdr - StringData + Offset;
+ *BlockType = *BlockHdr;
+
+ if (StringId == CurrentStringId - 1) {
+ //
+ // if only one skip item, return EFI_NOT_FOUND.
+ //
+ if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) {
+ return EFI_NOT_FOUND;
+ } else {
+ return EFI_SUCCESS;
+ }
+ }
+
+ if (StringId < CurrentStringId - 1) {
+ return EFI_NOT_FOUND;
+ }
+ }
+ BlockHdr = StringData + BlockSize;
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+EFI_STATUS
+CVfrStringDB::GetUnicodeStringTextOrSize (
+ OUT EFI_STRING StringDest, OPTIONAL
+ IN CHAR8 *StringSrc,
+ IN OUT UINTN *BufferSize
+ )
+{
+ UINTN StringSize;
+ CHAR16 *StringPtr;
+
+ StringSize = (wcslen ((wchar_t*)StringSrc) + 1 ) * sizeof (CHAR16);
+ if (*BufferSize < StringSize) {
+ *BufferSize = StringSize;
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ if (StringDest != NULL) {
+ wcscpy ((wchar_t*)StringDest, (wchar_t*)StringSrc);
+ }
+
+ *BufferSize = StringSize;
+ return EFI_SUCCESS;
+}
+
BOOLEAN VfrCompatibleMode = FALSE;
CVfrVarDataTypeDB gCVfrVarDataTypeDB;
Modified: trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
===================================================================
--- trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h 2011-07-12 06:55:40 UTC (rev 2209)
@@ -424,4 +424,36 @@
UINT8 GetRuleId (IN CHAR8 *);
};
+class CVfrStringDB {
+private:
+ CHAR8 *mStringFileName;
+
+ EFI_STATUS FindStringBlock (
+ IN CHAR8 *StringData,
+ IN EFI_STRING_ID StringId,
+ OUT UINTN *StringTextOffset,
+ OUT UINT8 *BlockType
+ );
+
+ EFI_STATUS GetUnicodeStringTextOrSize (
+ OUT EFI_STRING StringDest, OPTIONAL
+ IN CHAR8 *StringSrc,
+ IN OUT UINTN *BufferSize
+ );
+
+public:
+ CVfrStringDB ();
+ ~CVfrStringDB ();
+
+ VOID SetStringFileName (
+ IN CHAR8 *StringFileName
+ );
+
+ VOID GetVarStoreNameFormStringId (
+ IN EFI_STRING_ID StringId,
+ OUT CHAR8 **VarStoreName
+ );
+
+};
+
#endif
Modified: trunk/BaseTools/Source/Python/AutoGen/AutoGen.py
===================================================================
--- trunk/BaseTools/Source/Python/AutoGen/AutoGen.py 2011-07-12 06:51:36 UTC (rev 2208)
+++ trunk/BaseTools/Source/Python/AutoGen/AutoGen.py 2011-07-12 06:55:40 UTC (rev 2209)
@@ -2166,9 +2166,8 @@
#
def _GetAutoGenFileList(self):
UniStringAutoGenC = True
- UniStringBinBuffer = None
+ UniStringBinBuffer = StringIO()
if self.BuildType == 'UEFI_HII':
- UniStringBinBuffer = StringIO()
UniStringAutoGenC = False
if self._AutoGenFileList == None:
self._AutoGenFileList = {}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|