import Common.EdkLogger as EdkLogger\r
from Common.BuildToolError import *\r
from UniClassObject import *\r
+from StringIO import StringIO\r
+from struct import pack\r
\r
##\r
# Static definitions\r
STRING = 'string'\r
TO = 'to'\r
STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r
+COMPATIBLE_STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Za-z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r
\r
EFI_HII_ARRAY_SIZE_LENGTH = 4\r
EFI_HII_PACKAGE_HEADER_LENGTH = 4\r
#\r
# Create content of .h file\r
#\r
-# @param BaseName: The basename of strings\r
-# @param UniObjectClass: A UniObjectClass instance\r
+# @param BaseName: The basename of strings\r
+# @param UniObjectClass A UniObjectClass instance\r
+# @param IsCompatibleMode Compatible mode\r
+# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
#\r
# @retval Str: A string of .h file content\r
#\r
-def CreateHFileContent(BaseName, UniObjectClass):\r
+def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):\r
Str = ''\r
ValueStartPtr = 60\r
Line = COMMENT_DEFINE_STR + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(0, 4) + COMMENT_NOT_REFERENCED\r
Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED\r
Str = WriteLine(Str, Line)\r
\r
- Str = WriteLine(Str, '')\r
- Str = WriteLine(Str, 'extern unsigned char ' + BaseName + 'Strings[];')\r
+ Str = WriteLine(Str, '')\r
+ if IsCompatibleMode or UniGenCFlag:\r
+ Str = WriteLine(Str, 'extern unsigned char ' + BaseName + 'Strings[];')\r
return Str\r
\r
## Create a complete .h file\r
#\r
# Create a complet .h file with file header and file content\r
#\r
-# @param BaseName: The basename of strings\r
-# @param UniObjectClass: A UniObjectClass instance\r
+# @param BaseName: The basename of strings\r
+# @param UniObjectClass A UniObjectClass instance\r
+# @param IsCompatibleMode Compatible mode\r
+# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
#\r
# @retval Str: A string of complete .h file\r
#\r
-def CreateHFile(BaseName, UniObjectClass):\r
- HFile = WriteLine('', CreateHFileContent(BaseName, UniObjectClass))\r
+def CreateHFile(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):\r
+ HFile = WriteLine('', CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag))\r
\r
return HFile\r
\r
\r
return Str\r
\r
+## Create a buffer to store all items in an array\r
+#\r
+# @param BinBuffer Buffer to contain Binary data.\r
+# @param Array: The array need to be formatted\r
+#\r
+def CreateBinBuffer(BinBuffer, Array):\r
+ for Item in Array:\r
+ BinBuffer.write(pack("B", int(Item,16)))\r
+\r
## Create a formatted string all items in an array\r
#\r
# Use ',' to join each item in an array, and break an new line when reaching the width (default is 16)\r
#\r
# Create content of .c file\r
#\r
-# @param BaseName: The basename of strings\r
-# @param UniObjectClass: A UniObjectClass instance\r
+# @param BaseName: The basename of strings\r
+# @param UniObjectClass A UniObjectClass instance\r
+# @param IsCompatibleMode Compatible mode\r
+# @param UniBinBuffer UniBinBuffer to contain UniBinary data.\r
#\r
# @retval Str: A string of .c file content\r
#\r
-def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode):\r
+def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer=None):\r
#\r
# Init array length\r
#\r
Language = UniObjectClass.LanguageDef[IndexI][0]\r
LangPrintName = UniObjectClass.LanguageDef[IndexI][1]\r
\r
+ StringBuffer = StringIO()\r
StrStringValue = ''\r
ArrayLength = 0\r
- NumberOfUseOhterLangDef = 0\r
+ NumberOfUseOtherLangDef = 0\r
Index = 0\r
for IndexJ in range(1, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[IndexI][0]])):\r
Item = UniObjectClass.FindByToken(IndexJ, Language)\r
UseOtherLangDef = Item.UseOtherLangDef\r
\r
if UseOtherLangDef != '' and Referenced:\r
- NumberOfUseOhterLangDef = NumberOfUseOhterLangDef + 1\r
+ NumberOfUseOtherLangDef = NumberOfUseOtherLangDef + 1\r
Index = Index + 1\r
else:\r
- if NumberOfUseOhterLangDef > 0:\r
- StrStringValue = WriteLine(StrStringValue, CreateArrayItem([StringSkipType] + DecToHexList(NumberOfUseOhterLangDef, 4)))\r
- NumberOfUseOhterLangDef = 0\r
+ if NumberOfUseOtherLangDef > 0:\r
+ StrStringValue = WriteLine(StrStringValue, CreateArrayItem([StringSkipType] + DecToHexList(NumberOfUseOtherLangDef, 4)))\r
+ CreateBinBuffer (StringBuffer, ([StringSkipType] + DecToHexList(NumberOfUseOtherLangDef, 4)))\r
+ NumberOfUseOtherLangDef = 0\r
ArrayLength = ArrayLength + 3\r
if Referenced and Item.Token > 0:\r
Index = Index + 1\r
StrStringValue = WriteLine(StrStringValue, "// %s: %s:%s" % (DecToHexStr(Index, 4), Name, DecToHexStr(Token, 4)))\r
StrStringValue = Write(StrStringValue, CreateCFileStringValue(Value))\r
- Offset = Offset + Length\r
+ CreateBinBuffer (StringBuffer, [StringBlockType] + Value)\r
ArrayLength = ArrayLength + Item.Length + 1 # 1 is for the length of string type\r
\r
#\r
# Add an EFI_HII_SIBT_END at last\r
#\r
Str = WriteLine(Str, ' ' + EFI_HII_SIBT_END + ",")\r
+ \r
+ #\r
+ # Create binary UNI string\r
+ #\r
+ if UniBinBuffer:\r
+ CreateBinBuffer (UniBinBuffer, List)\r
+ UniBinBuffer.write (StringBuffer.getvalue())\r
+ UniBinBuffer.write (pack("B", int(EFI_HII_SIBT_END,16)))\r
+ StringBuffer.close()\r
\r
#\r
# Create line for string variable name\r
#\r
AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + BaseName + COMMON_FILE_NAME + '[] = {\n' )\r
\r
- #\r
- # Create FRAMEWORK_EFI_HII_PACK_HEADER in compatible mode\r
- #\r
if IsCompatibleMode:\r
+ #\r
+ # Create FRAMEWORK_EFI_HII_PACK_HEADER in compatible mode\r
+ #\r
AllStr = WriteLine(AllStr, '// FRAMEWORK PACKAGE HEADER Length')\r
AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength + 2)) + '\n')\r
AllStr = WriteLine(AllStr, '// FRAMEWORK PACKAGE HEADER Type')\r
AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(2, 4)) + '\n')\r
-\r
- #\r
- # Create whole array length in UEFI mode\r
- #\r
- if not IsCompatibleMode:\r
+ else:\r
+ #\r
+ # Create whole array length in UEFI mode\r
+ #\r
AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')\r
AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')\r
\r
#\r
# Create a complete .c file\r
#\r
-# @param BaseName: The basename of strings\r
-# @param UniObjectClass: A UniObjectClass instance\r
+# @param BaseName: The basename of strings\r
+# @param UniObjectClass A UniObjectClass instance\r
+# @param IsCompatibleMode Compatible Mode\r
#\r
# @retval CFile: A string of complete .c file\r
#\r
#\r
# @param UniObjectClass: Input UniObjectClass\r
# @param FileList: Search path list\r
+# @param IsCompatibleMode Compatible Mode\r
#\r
# @retval UniObjectClass: UniObjectClass after searched\r
#\r
-def SearchString(UniObjectClass, FileList):\r
+def SearchString(UniObjectClass, FileList, IsCompatibleMode):\r
if FileList == []:\r
return UniObjectClass\r
\r
if os.path.isfile(File):\r
Lines = open(File, 'r')\r
for Line in Lines:\r
- StringTokenList = STRING_TOKEN.findall(Line)\r
+ if not IsCompatibleMode:\r
+ StringTokenList = STRING_TOKEN.findall(Line)\r
+ else:\r
+ StringTokenList = COMPATIBLE_STRING_TOKEN.findall(Line)\r
for StrName in StringTokenList:\r
EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName)\r
UniObjectClass.SetStringReferenced(StrName)\r
# This function is used for UEFI2.1 spec\r
#\r
#\r
-def GetStringFiles(UniFilList, SourceFileList, IncludeList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False):\r
+def GetStringFiles(UniFilList, SourceFileList, IncludeList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None):\r
Status = True\r
ErrorMessage = ''\r
\r
\r
FileList = GetFileList(SourceFileList, IncludeList, SkipList)\r
\r
- Uni = SearchString(Uni, FileList)\r
+ Uni = SearchString(Uni, FileList, IsCompatibleMode)\r
\r
- HFile = CreateHFile(BaseName, Uni)\r
- CFile = CreateCFile(BaseName, Uni, IsCompatibleMode)\r
+ HFile = CreateHFile(BaseName, Uni, IsCompatibleMode, UniGenCFlag)\r
+ CFile = None\r
+ if IsCompatibleMode or UniGenCFlag:\r
+ CFile = CreateCFile(BaseName, Uni, IsCompatibleMode)\r
+ if UniGenBinBuffer:\r
+ CreateCFileContent(BaseName, Uni, IsCompatibleMode, UniGenBinBuffer)\r
\r
return HFile, CFile\r
\r