]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/BPDG/GenVpd.py
BaseTools/ECC: Fix some issues of ECC tool
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / GenVpd.py
index f0196e061a64bfad17c3f5d5038688ba302eea80..76d30fa6ff497c165187c3aad98450465489dc21 100644 (file)
@@ -2,7 +2,7 @@
 #  This file include GenVpd class for fix the Vpd type PCD offset, and PcdEntry for describe\r
 #  and process each entry of vpd type PCD.\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
 \r
-import os\r
+import Common.LongFilePathOs as os\r
 import StringIO\r
 import StringTable as st\r
 import array\r
-\r
+import re\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from struct import *\r
 import Common.EdkLogger as EdkLogger\r
 import Common.BuildToolError as BuildToolError\r
@@ -33,9 +34,10 @@ _FORMAT_CHAR = {1: 'B',
 #  This class contain method to format and pack pcd's value.          \r
 #\r
 class PcdEntry:\r
-    def __init__(self, PcdCName, PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None, \r
+    def __init__(self, PcdCName, SkuId,PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None, \r
                  PcdBinOffset=None, PcdBinSize=None):\r
         self.PcdCName       = PcdCName.strip()\r
+        self.SkuId          = SkuId.strip()\r
         self.PcdOffset      = PcdOffset.strip()\r
         self.PcdSize        = PcdSize.strip()\r
         self.PcdValue       = PcdValue.strip()\r
@@ -225,7 +227,7 @@ class PcdEntry:
         \r
         for Index in xrange(len(ValueList)):\r
             Value = None\r
-            if ValueList[Index].startswith('0x'):\r
+            if ValueList[Index].lower().startswith('0x'):\r
                 # translate hex value\r
                 try:\r
                     Value = int(ValueList[Index], 16)\r
@@ -283,7 +285,7 @@ class PcdEntry:
                                 "Invalid unicode character %s in unicode string %s(File: %s Line: %s)" % \\r
                                 (Value, UnicodeString, self.FileName, self.Lineno))\r
                 \r
-        for Index in range(len(UnicodeString) * 2, Size):\r
+        for Index in xrange(len(UnicodeString) * 2, Size):\r
             ReturnArray.append(0)\r
             \r
         self.PcdValue =  ReturnArray.tolist()    \r
@@ -338,8 +340,27 @@ class GenVPD :
             line = line.rstrip(os.linesep)\r
                        \r
             # Skip the comment line\r
-            if (not line.startswith("#")) and len(line) > 1 :              \r
-                self.FileLinesList[count] = line.split('|')\r
+            if (not line.startswith("#")) and len(line) > 1 :\r
+                #\r
+                # Enhanced for support "|" character in the string.\r
+                #\r
+                ValueList = ['', '', '', '','']    \r
+                \r
+                ValueRe  = re.compile(r'\s*L?\".*\|.*\"\s*$')\r
+                PtrValue = ValueRe.findall(line)\r
+                \r
+                ValueUpdateFlag = False\r
+                \r
+                if len(PtrValue) >= 1:\r
+                    line = re.sub(ValueRe, '', line)\r
+                    ValueUpdateFlag = True   \r
+            \r
+                TokenList = line.split('|')\r
+                ValueList[0:len(TokenList)] = TokenList\r
+                \r
+                if ValueUpdateFlag:\r
+                    ValueList[4] = PtrValue[0]                              \r
+                self.FileLinesList[count] = ValueList\r
                 # Store the line number\r
                 self.FileLinesList[count].append(str(count+1))\r
             elif len(line) <= 1 :\r
@@ -373,9 +394,10 @@ class GenVPD :
         count = 0\r
         for line in self.FileLinesList:        \r
             if line != None :\r
-                PCD = PcdEntry(line[0], line[1], line[2], line[3], line[4], self.InputFileName)   \r
+                PCD = PcdEntry(line[0], line[1], line[2], line[3], line[4],line[5], self.InputFileName)   \r
                 # Strip the space char\r
                 PCD.PcdCName     = PCD.PcdCName.strip(' ')\r
+                PCD.SkuId        = PCD.SkuId.strip(' ')\r
                 PCD.PcdOffset    = PCD.PcdOffset.strip(' ')\r
                 PCD.PcdSize      = PCD.PcdSize.strip(' ')\r
                 PCD.PcdValue     = PCD.PcdValue.strip(' ')               \r
@@ -524,10 +546,8 @@ class GenVPD :
                 if lenOfUnfixedList != 0 :\r
                     countOfUnfixedList = 0\r
                     while(countOfUnfixedList < lenOfUnfixedList) :                   \r
-                        #needFixPcdCName, needFixPcdOffset, needFixPcdSize, needFixPcdValue, needFixUnpackValue = self.PcdUnknownOffsetList[countOfUnfixedList][0:6]\r
                         eachUnfixedPcd      = self.PcdUnknownOffsetList[countOfUnfixedList]\r
                         needFixPcdSize      = eachUnfixedPcd.PcdBinSize\r
-                        needFixPcdOffset    = eachUnfixedPcd.PcdOffset\r
                         # Not been fixed\r
                         if eachUnfixedPcd.PcdOffset == '*' :\r
                             # The offset un-fixed pcd can write into this free space\r
@@ -546,18 +566,16 @@ class GenVPD :
                                 FixOffsetSizeListCount  += 1\r
                                 \r
                                 # Decrease the un-fixed pcd offset list's length\r
-                                countOfUnfixedList      += 1\r
                                 lenOfUnfixedList        -= 1\r
                                 \r
                                 # Modify the last offset value \r
-                                LastOffset              += needFixPcdSize\r
-                                continue                            \r
+                                LastOffset              += needFixPcdSize                            \r
                             else :\r
-                                # It can not insert into those two pcds, need to check stiil has other space can store it.\r
+                                # It can not insert into those two pcds, need to check still has other space can store it.\r
+                                LastOffset             = NowOffset + self.PcdFixedOffsetSizeList[FixOffsetSizeListCount].PcdBinSize\r
                                 FixOffsetSizeListCount += 1\r
-                                break                   \r
-                        else :\r
-                            continue\r
+                                break\r
+                                                                                 \r
                 # Set the FixOffsetSizeListCount = lenOfList for quit the loop\r
                 else :\r
                     FixOffsetSizeListCount = lenOfList                    \r
@@ -623,7 +641,7 @@ class GenVPD :
         for eachPcd in self.PcdFixedOffsetSizeList  :\r
             # write map file\r
             try :\r
-                fMapFile.write("%s | %s | %s | %s  \n" % (eachPcd.PcdCName, eachPcd.PcdOffset, eachPcd.PcdSize,eachPcd.PcdUnpackValue))\r
+                fMapFile.write("%s | %s | %s | %s | %s  \n" % (eachPcd.PcdCName, eachPcd.SkuId,eachPcd.PcdOffset, eachPcd.PcdSize,eachPcd.PcdUnpackValue))\r
             except:\r
                 EdkLogger.error("BPDG", BuildToolError.FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %self.MapFileName,None)                                                                      \r
                          \r