]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/VpdInfoFile.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / Common / VpdInfoFile.py
index b98c021b57770a45cb9cd78f224ad54542c92883..0485bf482ec0509f1af450e1b394137b80241282 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
-# \r
+#\r
 # This package manage the VPD PCD information file which will be generated\r
 # by build tool's autogen.\r
 # The VPD PCD information file will be input for third-party BPDG tool which\r
-# is pointed by *_*_*_VPD_TOOL_GUID in conf/tools_def.txt \r
+# is pointed by *_*_*_VPD_TOOL_GUID in conf/tools_def.txt\r
 #\r
 #\r
 # Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
@@ -33,8 +33,8 @@ FILE_COMMENT_TEMPLATE = \
 #  THIS IS AUTO-GENERATED FILE BY BUILD TOOLS AND PLEASE DO NOT MAKE MODIFICATION.\r
 #\r
 #  This file lists all VPD informations for a platform collected by build.exe.\r
-# \r
-# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -70,17 +70,17 @@ FILE_COMMENT_TEMPLATE = \
 #\r
 class VpdInfoFile:\r
 \r
-    _rVpdPcdLine = None \r
+    _rVpdPcdLine = None\r
     ## Constructor\r
     def __init__(self):\r
         ## Dictionary for VPD in following format\r
         #\r
-        #  Key    : PcdClassObject instance. \r
+        #  Key    : PcdClassObject instance.\r
         #           @see BuildClassObject.PcdClassObject\r
         #  Value  : offset in different SKU such as [sku1_offset, sku2_offset]\r
         self._VpdArray = {}\r
         self._VpdInfo = {}\r
-    \r
+\r
     ## Add a VPD PCD collected from platform's autogen when building.\r
     #\r
     #  @param vpds  The list of VPD PCD collected for a platform.\r
@@ -91,40 +91,40 @@ class VpdInfoFile:
     def Add(self, Vpd, skuname, Offset):\r
         if (Vpd is None):\r
             EdkLogger.error("VpdInfoFile", BuildToolError.ATTRIBUTE_UNKNOWN_ERROR, "Invalid VPD PCD entry.")\r
-        \r
+\r
         if not (Offset >= 0 or Offset == "*"):\r
             EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, "Invalid offset parameter: %s." % Offset)\r
-        \r
+\r
         if Vpd.DatumType == TAB_VOID:\r
             if Vpd.MaxDatumSize <= 0:\r
-                EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, \r
+                EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,\r
                                 "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))\r
-        elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES: \r
+        elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:\r
             if not Vpd.MaxDatumSize:\r
                 Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]\r
         else:\r
             if Vpd.MaxDatumSize <= 0:\r
                 EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,\r
                                 "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))\r
-            \r
+\r
         if Vpd not in self._VpdArray:\r
             #\r
-            # If there is no Vpd instance in dict, that imply this offset for a given SKU is a new one \r
+            # If there is no Vpd instance in dict, that imply this offset for a given SKU is a new one\r
             #\r
             self._VpdArray[Vpd] = {}\r
 \r
         self._VpdArray[Vpd].update({skuname:Offset})\r
-            \r
-        \r
+\r
+\r
     ## Generate VPD PCD information into a text file\r
-    #  \r
+    #\r
     #  If parameter FilePath is invalid, then assert.\r
-    #  If \r
+    #  If\r
     #  @param FilePath        The given file path which would hold VPD information\r
     def Write(self, FilePath):\r
         if not (FilePath is not None or len(FilePath) != 0):\r
-            EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,  \r
-                            "Invalid parameter FilePath: %s." % FilePath)        \r
+            EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,\r
+                            "Invalid parameter FilePath: %s." % FilePath)\r
 \r
         Content = FILE_COMMENT_TEMPLATE\r
         Pcds = sorted(self._VpdArray.keys())\r
@@ -155,15 +155,15 @@ class VpdInfoFile:
         try:\r
             fd = open(FilePath, "r")\r
         except:\r
-            EdkLogger.error("VpdInfoFile", \r
-                            BuildToolError.FILE_OPEN_FAILURE, \r
+            EdkLogger.error("VpdInfoFile",\r
+                            BuildToolError.FILE_OPEN_FAILURE,\r
                             "Fail to open file %s for written." % FilePath)\r
         Lines = fd.readlines()\r
         for Line in Lines:\r
             Line = Line.strip()\r
             if len(Line) == 0 or Line.startswith("#"):\r
                 continue\r
-            \r
+\r
             #\r
             # the line must follow output format defined in BPDG spec.\r
             #\r
@@ -173,9 +173,9 @@ class VpdInfoFile:
                 TokenSpaceName, PcdTokenName = PcdName.split(".")\r
             except:\r
                 EdkLogger.error("BPDG", BuildToolError.PARSER_ERROR, "Fail to parse VPD information file %s" % FilePath)\r
-            \r
+\r
             Found = False\r
-            \r
+\r
             if (TokenSpaceName, PcdTokenName) not in self._VpdInfo:\r
                 self._VpdInfo[(TokenSpaceName, PcdTokenName)] = []\r
             self._VpdInfo[(TokenSpaceName, PcdTokenName)].append((SkuId, Offset, Value))\r
@@ -188,62 +188,62 @@ class VpdInfoFile:
                     if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObjectTokenCName == PcdTokenName.strip() and sku == SkuId:\r
                         if self._VpdArray[VpdObject][sku] == "*":\r
                             if Offset == "*":\r
-                                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "The offset of %s has not been fixed up by third-party BPDG tool." % PcdName)                              \r
+                                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "The offset of %s has not been fixed up by third-party BPDG tool." % PcdName)\r
                             self._VpdArray[VpdObject][sku] = Offset\r
                         Found = True\r
             if not Found:\r
                 EdkLogger.error("BPDG", BuildToolError.PARSER_ERROR, "Can not find PCD defined in VPD guid file.")\r
-                \r
+\r
     ## Get count of VPD PCD collected from platform's autogen when building.\r
     #\r
-    #  @return The integer count value \r
+    #  @return The integer count value\r
     def GetCount(self):\r
         Count = 0\r
         for OffsetList in self._VpdArray.values():\r
             Count += len(OffsetList)\r
-            \r
+\r
         return Count\r
-    \r
+\r
     ## Get an offset value for a given VPD PCD\r
     #\r
-    #  Because BPDG only support one Sku, so only return offset for SKU default.   \r
+    #  Because BPDG only support one Sku, so only return offset for SKU default.\r
     #\r
-    #  @param vpd    A given VPD PCD \r
+    #  @param vpd    A given VPD PCD\r
     def GetOffset(self, vpd):\r
         if vpd not in self._VpdArray:\r
             return None\r
-        \r
+\r
         if len(self._VpdArray[vpd]) == 0:\r
             return None\r
-        \r
+\r
         return self._VpdArray[vpd]\r
     def GetVpdInfo(self, arg):\r
         (PcdTokenName, TokenSpaceName) = arg\r
         return self._VpdInfo.get((TokenSpaceName, PcdTokenName))\r
-    \r
+\r
 ## Call external BPDG tool to process VPD file\r
-#    \r
+#\r
 #  @param ToolPath      The string path name for BPDG tool\r
 #  @param VpdFileName   The string path name for VPD information guid.txt\r
-# \r
+#\r
 def CallExtenalBPDGTool(ToolPath, VpdFileName):\r
     assert ToolPath is not None, "Invalid parameter ToolPath"\r
     assert VpdFileName is not None and os.path.exists(VpdFileName), "Invalid parameter VpdFileName"\r
-    \r
+\r
     OutputDir = os.path.dirname(VpdFileName)\r
     FileName = os.path.basename(VpdFileName)\r
     BaseName, ext = os.path.splitext(FileName)\r
     OutputMapFileName = os.path.join(OutputDir, "%s.map" % BaseName)\r
     OutputBinFileName = os.path.join(OutputDir, "%s.bin" % BaseName)\r
-          \r
+\r
     try:\r
         PopenObject = subprocess.Popen(' '.join([ToolPath,\r
-                                        '-o', OutputBinFileName, \r
+                                        '-o', OutputBinFileName,\r
                                         '-m', OutputMapFileName,\r
                                         '-q',\r
                                         '-f',\r
                                         VpdFileName]),\r
-                                        stdout=subprocess.PIPE, \r
+                                        stdout=subprocess.PIPE,\r
                                         stderr= subprocess.PIPE,\r
                                         shell=True)\r
     except Exception as X:\r
@@ -252,11 +252,11 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName):
     print(out)\r
     while PopenObject.returncode is None :\r
         PopenObject.wait()\r
-    \r
+\r
     if PopenObject.returncode != 0:\r
         if PopenObject.returncode != 0:\r
             EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(error))\r
             EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, "Fail to execute BPDG tool with exit code: %d, the error message is: \n %s" % \\r
                             (PopenObject.returncode, str(error)))\r
-        \r
+\r
     return PopenObject.returncode\r