+def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):\r
+ VfrNameList = []\r
+ if os.path.isdir(DebugDir):\r
+ for CurrentDir, Dirs, Files in os.walk(DebugDir):\r
+ for FileName in Files:\r
+ Name, Ext = os.path.splitext(FileName)\r
+ if Ext == '.lst':\r
+ VfrNameList.append (Name + 'Bin')\r
+\r
+ VfrNameList.append (ModuleName + 'Strings')\r
+\r
+ EfiFileName = os.path.join(DebugDir, ModuleName + '.efi')\r
+ MapFileName = os.path.join(DebugDir, ModuleName + '.map')\r
+ VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrNameList)\r
+\r
+ if not VfrUniOffsetList:\r
+ return\r
+\r
+ try:\r
+ fInputfile = open(OutputFile, "wb+", 0)\r
+ except:\r
+ EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None)\r
+\r
+ # Use a instance of StringIO to cache data\r
+ fStringIO = StringIO.StringIO('')\r
+\r
+ for Item in VfrUniOffsetList:\r
+ if (Item[0].find("Strings") != -1):\r
+ #\r
+ # UNI offset in image.\r
+ # GUID + Offset\r
+ # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
+ #\r
+ UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
+ UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
+ fStringIO.write(''.join(UniGuid))\r
+ UniValue = pack ('Q', int (Item[1], 16))\r
+ fStringIO.write (UniValue)\r
+ else:\r
+ #\r
+ # VFR binary offset in image.\r
+ # GUID + Offset\r
+ # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
+ #\r
+ VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
+ VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
+ fStringIO.write(''.join(VfrGuid))\r
+ type (Item[1])\r
+ VfrValue = pack ('Q', int (Item[1], 16))\r
+ fStringIO.write (VfrValue)\r
+\r
+ #\r
+ # write data into file.\r
+ #\r
+ try :\r
+ fInputfile.write (fStringIO.getvalue())\r
+ except:\r
+ EdkLogger.error("Trim", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %OutputFile, None)\r
+\r
+ fStringIO.close ()\r
+ fInputfile.close ()\r
+\r