]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/BPDG/GenVpd.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / GenVpd.py
index 3bae803467a882d3fe6a9890425b44644960b847..2eefcc24905fcddc34165678a907149340af368d 100644 (file)
@@ -31,10 +31,10 @@ _FORMAT_CHAR = {1: 'B',
 \r
 ## The VPD PCD data structure for store and process each VPD PCD entry.\r
 #\r
-#  This class contain method to format and pack pcd's value.          \r
+#  This class contain method to format and pack pcd's value.\r
 #\r
 class PcdEntry:\r
-    def __init__(self, PcdCName, SkuId,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, Alignment=None):\r
         self.PcdCName       = PcdCName.strip()\r
         self.SkuId          = SkuId.strip()\r
@@ -47,7 +47,7 @@ class PcdEntry:
         self.PcdBinOffset   = PcdBinOffset\r
         self.PcdBinSize     = PcdBinSize\r
         self.Alignment       = Alignment\r
-        \r
+\r
         if self.PcdValue == '' :\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
                             "Invalid PCD format(Name: %s File: %s line: %s) , no Value specified!" % (self.PcdCName, self.FileName, self.Lineno))\r
@@ -63,13 +63,13 @@ class PcdEntry:
         self._GenOffsetValue ()\r
 \r
     ## Analyze the string value to judge the PCD's datum type equal to Boolean or not.\r
-    # \r
+    #\r
     #  @param   ValueString      PCD's value\r
     #  @param   Size             PCD's size\r
-    #  \r
+    #\r
     #  @retval  True   PCD's datum type is Boolean\r
-    #  @retval  False  PCD's datum type is not Boolean.              \r
-    #    \r
+    #  @retval  False  PCD's datum type is not Boolean.\r
+    #\r
     def _IsBoolean(self, ValueString, Size):\r
         if (Size == "1"):\r
             if ValueString.upper() in ["TRUE", "FALSE"]:\r
@@ -80,10 +80,10 @@ class PcdEntry:
         return False\r
 \r
     ## Convert the PCD's value from string to integer.\r
-    #              \r
+    #\r
     #  This function will try to convert the Offset value form string to integer\r
     #  for both hexadecimal and decimal.\r
-    #    \r
+    #\r
     def _GenOffsetValue(self):\r
         if self.PcdOffset != "*" :\r
             try:\r
@@ -96,10 +96,10 @@ class PcdEntry:
                                     "Invalid offset value %s for PCD %s (File: %s Line: %s)" % (self.PcdOffset, self.PcdCName, self.FileName, self.Lineno))\r
 \r
     ## Pack Boolean type VPD PCD's value form string to binary type.\r
-    # \r
+    #\r
     #  @param ValueString     The boolean type string for pack.\r
-    # \r
-    # \r
+    #\r
+    #\r
     def _PackBooleanValue(self, ValueString):\r
         if ValueString.upper() == "TRUE" or ValueString in ["1", "0x1", "0x01"]:\r
             try:\r
@@ -115,10 +115,10 @@ class PcdEntry:
                                 "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))\r
 \r
     ## Pack Integer type VPD PCD's value form string to binary type.\r
-    # \r
+    #\r
     #  @param ValueString     The Integer type string for pack.\r
-    # \r
-    #                                \r
+    #\r
+    #\r
     def _PackIntValue(self, IntValue, Size):\r
         if Size not in _FORMAT_CHAR:\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
@@ -170,7 +170,7 @@ class PcdEntry:
     #    3:    {bytearray}, only support byte-array.\r
     #\r
     #  @param ValueString     The Integer type string for pack.\r
-    #       \r
+    #\r
     def _PackPtrValue(self, ValueString, Size):\r
         if ValueString.startswith('L"') or ValueString.startswith("L'"):\r
             self._PackUnicode(ValueString, Size)\r
@@ -183,9 +183,9 @@ class PcdEntry:
                             "Invalid VOID* type PCD %s value %s (File: %s Line: %s)" % (self.PcdCName, ValueString, self.FileName, self.Lineno))\r
 \r
     ## Pack an Ascii PCD value.\r
-    #  \r
+    #\r
     #  An Ascii string for a PCD should be in format as  ""/''.\r
-    #                   \r
+    #\r
     def _PackString(self, ValueString, Size):\r
         if (Size < 0):\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
@@ -198,7 +198,7 @@ class PcdEntry:
             QuotedFlag = False\r
 \r
         ValueString = ValueString[1:-1]\r
-        # No null-terminator in 'string' \r
+        # No null-terminator in 'string'\r
         if (QuotedFlag and len(ValueString) + 1 > Size) or (not QuotedFlag and len(ValueString) > Size):\r
             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,\r
                             "PCD value string %s is exceed to size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))\r
@@ -209,9 +209,9 @@ class PcdEntry:
                             "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))\r
 \r
     ## Pack a byte-array PCD value.\r
-    #  \r
+    #\r
     #  A byte-array for a PCD should be in format as  {0x01, 0x02, ...}.\r
-    #         \r
+    #\r
     def _PackByteArray(self, ValueString, Size):\r
         if (Size < 0):\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))\r
@@ -261,7 +261,7 @@ class PcdEntry:
         self.PcdValue = ReturnArray.tolist()\r
 \r
     ## Pack a unicode PCD value into byte array.\r
-    #  \r
+    #\r
     #  A unicode string for a PCD should be in format as  L""/L''.\r
     #\r
     def _PackUnicode(self, UnicodeString, Size):\r
@@ -271,7 +271,7 @@ class PcdEntry:
 \r
         QuotedFlag = True\r
         if UnicodeString.startswith("L'"):\r
-            QuotedFlag = False \r
+            QuotedFlag = False\r
         UnicodeString = UnicodeString[2:-1]\r
 \r
         # No null-terminator in L'string'\r
@@ -304,7 +304,7 @@ class PcdEntry:
 #       2. Format the input file data to remove unused lines;\r
 #       3. Fixed offset if needed;\r
 #       4. Generate output file, including guided.map and guided.bin file;\r
-#        \r
+#\r
 class GenVPD :\r
     ## Constructor of DscBuildData\r
     #\r
@@ -334,9 +334,9 @@ class GenVPD :
             EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % InputFileName, None)\r
 \r
     ##\r
-    # Parser the input file which is generated by the build tool. Convert the value of each pcd's \r
+    # Parser the input file which is generated by the build tool. Convert the value of each pcd's\r
     # from string to it's real format. Also remove the useless line in the input file.\r
-    # \r
+    #\r
     def ParserInputFile (self):\r
         count = 0\r
         for line in self.FileLinesList:\r
@@ -390,7 +390,7 @@ class GenVPD :
         #\r
         # After remove the useless line, if there are no data remain in the file line list,\r
         # Report warning messages to user's.\r
-        # \r
+        #\r
         if len(self.FileLinesList) == 0 :\r
             EdkLogger.warn('BPDG', BuildToolError.RESOURCE_NOT_AVAILABLE,\r
                            "There are no VPD type pcds defined in DSC file, Please check it.")\r
@@ -480,14 +480,14 @@ class GenVPD :
                 continue\r
 \r
     ##\r
-    # This function used to create a clean list only contain useful information and reorganized to make it \r
+    # This function used to create a clean list only contain useful information and reorganized to make it\r
     # easy to be sorted\r
     #\r
     def FormatFileLine (self) :\r
 \r
         for eachPcd in self.FileLinesList :\r
             if eachPcd.PcdOffset != '*' :\r
-                # Use pcd's Offset value as key, and pcd's Value as value \r
+                # Use pcd's Offset value as key, and pcd's Value as value\r
                 self.PcdFixedOffsetSizeList.append(eachPcd)\r
             else :\r
                 # Use pcd's CName as key, and pcd's Size as value\r
@@ -497,11 +497,11 @@ class GenVPD :
     ##\r
     # This function is use to fix the offset value which the not specified in the map file.\r
     # Usually it use the star (meaning any offset) character in the offset field\r
-    #    \r
+    #\r
     def FixVpdOffset (self):\r
         # At first, the offset should start at 0\r
         # Sort fixed offset list in order to find out where has free spaces for the pcd's offset\r
-        # value is "*" to insert into.      \r
+        # value is "*" to insert into.\r
 \r
         self.PcdFixedOffsetSizeList.sort(lambda x, y: cmp(x.PcdBinOffset, y.PcdBinOffset))\r
 \r
@@ -530,57 +530,57 @@ class GenVPD :
                 Pcd.PcdBinOffset = NowOffset\r
                 Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))\r
                 NowOffset       += Pcd.PcdOccupySize\r
-                \r
+\r
             self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList\r
             return\r
 \r
-        # Check the offset of VPD type pcd's offset start from 0.    \r
+        # Check the offset of VPD type pcd's offset start from 0.\r
         if self.PcdFixedOffsetSizeList[0].PcdBinOffset != 0 :\r
             EdkLogger.warn("BPDG", "The offset of VPD type pcd should start with 0, please check it.",\r
                             None)\r
 \r
         # Judge whether the offset in fixed pcd offset list is overlapped or not.\r
         lenOfList = len(self.PcdFixedOffsetSizeList)\r
-        count     = 0                       \r
+        count     = 0\r
         while (count < lenOfList - 1) :\r
             PcdNow  = self.PcdFixedOffsetSizeList[count]\r
             PcdNext = self.PcdFixedOffsetSizeList[count+1]\r
-            # Two pcd's offset is same            \r
+            # Two pcd's offset is same\r
             if PcdNow.PcdBinOffset == PcdNext.PcdBinOffset :\r
                 EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,\r
                                 "The offset of %s at line: %s is same with %s at line: %s in file %s" % \\r
                                 (PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),\r
                                 None)\r
 \r
-            # Overlapped   \r
+            # Overlapped\r
             if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize > PcdNext.PcdBinOffset :\r
                 EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,\r
                                 "The offset of %s at line: %s is overlapped with %s at line: %s in file %s" % \\r
                                 (PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),\r
                                 None)\r
 \r
-            # Has free space, raise a warning message   \r
+            # Has free space, raise a warning message\r
             if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize < PcdNext.PcdBinOffset :\r
                 EdkLogger.warn("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,\r
                                "The offsets have free space of between %s at line: %s and %s at line: %s in file %s" % \\r
                                (PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),\r
                                 None)\r
             count += 1\r
-                             \r
+\r
         LastOffset              = self.PcdFixedOffsetSizeList[0].PcdBinOffset\r
         FixOffsetSizeListCount  = 0\r
         lenOfList               = len(self.PcdFixedOffsetSizeList)\r
         lenOfUnfixedList        = len(self.PcdUnknownOffsetList)\r
-                \r
+\r
         ##\r
-        # Insert the un-fixed offset pcd's list into fixed offset pcd's list if has free space between those pcds. \r
-        # \r
+        # Insert the un-fixed offset pcd's list into fixed offset pcd's list if has free space between those pcds.\r
+        #\r
         while (FixOffsetSizeListCount < lenOfList) :\r
-            \r
-            eachFixedPcd     = self.PcdFixedOffsetSizeList[FixOffsetSizeListCount]                       \r
+\r
+            eachFixedPcd     = self.PcdFixedOffsetSizeList[FixOffsetSizeListCount]\r
             NowOffset        = eachFixedPcd.PcdBinOffset\r
-            \r
-            # Has free space               \r
+\r
+            # Has free space\r
             if LastOffset < NowOffset :\r
                 if lenOfUnfixedList != 0 :\r
                     countOfUnfixedList = 0\r
@@ -598,42 +598,42 @@ class GenVPD :
                                 eachUnfixedPcd.PcdBinOffset = LastOffset\r
                                 # Insert this pcd into fixed offset pcd list.\r
                                 self.PcdFixedOffsetSizeList.insert(FixOffsetSizeListCount, eachUnfixedPcd)\r
-                                \r
+\r
                                 # Delete the item's offset that has been fixed and added into fixed offset list\r
                                 self.PcdUnknownOffsetList.pop(countOfUnfixedList)\r
-                                \r
+\r
                                 # After item added, should enlarge the length of fixed pcd offset list\r
-                                lenOfList               += 1                                \r
+                                lenOfList               += 1\r
                                 FixOffsetSizeListCount  += 1\r
-                                \r
+\r
                                 # Decrease the un-fixed pcd offset list's length\r
                                 lenOfUnfixedList        -= 1\r
-                                \r
-                                # Modify the last offset value \r
-                                LastOffset              += needFixPcdSize                            \r
+\r
+                                # Modify the last offset value\r
+                                LastOffset              += needFixPcdSize\r
                             else :\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].PcdOccupySize\r
                                 FixOffsetSizeListCount += 1\r
                                 break\r
-                                                                                 \r
+\r
                 # Set the FixOffsetSizeListCount = lenOfList for quit the loop\r
                 else :\r
-                    FixOffsetSizeListCount = lenOfList                    \r
-                        \r
-            # No free space, smoothly connect with previous pcd. \r
+                    FixOffsetSizeListCount = lenOfList\r
+\r
+            # No free space, smoothly connect with previous pcd.\r
             elif LastOffset == NowOffset :\r
                 LastOffset = NowOffset + eachFixedPcd.PcdOccupySize\r
                 FixOffsetSizeListCount += 1\r
-            # Usually it will not enter into this thunk, if so, means it overlapped. \r
+            # Usually it will not enter into this thunk, if so, means it overlapped.\r
             else :\r
                 EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_NOT_AVAILABLE,\r
                                 "The offset value definition has overlapped at pcd: %s, it's offset is: %s, in file: %s line: %s" % \\r
                                 (eachFixedPcd.PcdCName, eachFixedPcd.PcdOffset, eachFixedPcd.InputFileName, eachFixedPcd.Lineno),\r
                                 None)\r
                 FixOffsetSizeListCount += 1\r
-        \r
-        # Continue to process the un-fixed offset pcd's list, add this time, just append them behind the fixed pcd's offset list.    \r
+\r
+        # Continue to process the un-fixed offset pcd's list, add this time, just append them behind the fixed pcd's offset list.\r
         lenOfUnfixedList  = len(self.PcdUnknownOffsetList)\r
         lenOfList         = len(self.PcdFixedOffsetSizeList)\r
         while (lenOfUnfixedList > 0) :\r
@@ -641,23 +641,23 @@ class GenVPD :
             # The last pcd instance\r
             LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]\r
             NeedFixPcd = self.PcdUnknownOffsetList[0]\r
-            \r
+\r
             NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize\r
             if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:\r
                 NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment\r
 \r
             NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))\r
-            \r
+\r
             # Insert this pcd into fixed offset pcd list's tail.\r
             self.PcdFixedOffsetSizeList.insert(lenOfList, NeedFixPcd)\r
             # Delete the item's offset that has been fixed and added into fixed offset list\r
             self.PcdUnknownOffsetList.pop(0)\r
-            \r
+\r
             lenOfList          += 1\r
-            lenOfUnfixedList   -= 1                                                                                                                \r
+            lenOfUnfixedList   -= 1\r
     ##\r
     # Write the final data into output files.\r
-    #   \r
+    #\r
     def GenerateVpdFile (self, MapFileName, BinFileName):\r
         #Open an VPD file to process\r
 \r
@@ -705,4 +705,4 @@ class GenVPD :
         fStringIO.close ()\r
         fVpdFile.close ()\r
         fMapFile.close ()\r
-        \r
+\r