]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add missing BPDG tool sources when sync to BaseTools r2042
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 6 Sep 2010 02:01:57 +0000 (02:01 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 6 Sep 2010 02:01:57 +0000 (02:01 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10851 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/Python/BPDG/BPDG.py [new file with mode: 0644]
BaseTools/Source/Python/BPDG/GenVpd.py [new file with mode: 0644]
BaseTools/Source/Python/BPDG/StringTable.py [new file with mode: 0644]
BaseTools/Source/Python/BPDG/__init__.py [new file with mode: 0644]

diff --git a/BaseTools/Source/Python/BPDG/BPDG.py b/BaseTools/Source/Python/BPDG/BPDG.py
new file mode 100644 (file)
index 0000000..10692c4
--- /dev/null
@@ -0,0 +1,141 @@
+## @file\r
+#  Intel Binary Product Data Generation Tool (Intel BPDG).\r
+#  This tool provide a simple process for the creation of a binary file containing read-only \r
+#  configuration data for EDK II platforms that contain Dynamic and DynamicEx PCDs described \r
+#  in VPD sections. It also provide an option for specifying an alternate name for a mapping \r
+#  file of PCD layout for use during the build when the platform integrator selects to use \r
+#  automatic offset calculation.\r
+#\r
+#  Copyright (c) 2010, 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
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import os\r
+import sys\r
+import encodings.ascii\r
+\r
+from optparse import OptionParser\r
+from encodings import gbk\r
+from Common import EdkLogger\r
+from Common.BuildToolError import *\r
+\r
+import StringTable as st\r
+import GenVpd\r
+\r
+PROJECT_NAME       = st.LBL_BPDG_LONG_UNI\r
+VERSION            = st.LBL_BPDG_VERSION\r
+\r
+## Tool entrance method\r
+#\r
+# This method mainly dispatch specific methods per the command line options.\r
+# If no error found, return zero value so the caller of this tool can know\r
+# if it's executed successfully or not.\r
+#\r
+#   @retval 0     Tool was successful\r
+#   @retval 1     Tool failed\r
+#\r
+def main():\r
+    global Options, Args\r
+    \r
+    # Initialize log system\r
+    EdkLogger.Initialize()          \r
+    Options, Args = myOptionParser()\r
+    \r
+    ReturnCode = 0\r
+    \r
+    if Options.opt_slient:\r
+        EdkLogger.SetLevel(EdkLogger.ERROR)\r
+    elif Options.opt_verbose:\r
+        EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
+    elif Options.opt_quiet:\r
+        EdkLogger.SetLevel(EdkLogger.QUIET)\r
+    elif Options.debug_level != None:\r
+        EdkLogger.SetLevel(Options.debug_level + 1) \r
+    else:\r
+        EdkLogger.SetLevel(EdkLogger.INFO)\r
+                  \r
+    if Options.vpd_filename == None:\r
+        EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")  \r
+    if Options.filename == None:\r
+        EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")  \r
+\r
+    Force = False\r
+    if Options.opt_force != None:\r
+        Force = True\r
+\r
+    if (Args[0] != None) :\r
+        startBPDG(Args[0], Options.filename, Options.vpd_filename, Force)\r
+    else :\r
+        EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",\r
+                        None)         \r
+    \r
+    return ReturnCode\r
+            \r
+def myOptionParser():   \r
+    #\r
+    # Process command line firstly.\r
+    #\r
+    parser = OptionParser(version="%s - Version %s\n" % (PROJECT_NAME, VERSION),\r
+                          description='',\r
+                          prog='BPDG',\r
+                          usage=st.LBL_BPDG_USAGE\r
+                          )\r
+    parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',\r
+                      help=st.MSG_OPTION_DEBUG_LEVEL)\r
+    parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',\r
+                      help=st.MSG_OPTION_VERBOSE)\r
+    parser.add_option('-s', '--silent', action='store_true', dest='opt_slient', default=False,\r
+                      help=st.MSG_OPTION_SILENT)\r
+    parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,\r
+                      help=st.MSG_OPTION_QUIET)\r
+    parser.add_option('-o', '--vpd-filename', action='store', dest='vpd_filename',\r
+                      help=st.MSG_OPTION_VPD_FILENAME)\r
+    parser.add_option('-m', '--map-filename', action='store', dest='filename',\r
+                      help=st.MSG_OPTION_MAP_FILENAME)   \r
+    parser.add_option('-f', '--force', action='store_true', dest='opt_force',\r
+                      help=st.MSG_OPTION_FORCE)     \r
+    \r
+    (options, args) = parser.parse_args()\r
+    if len(args) == 0:\r
+        EdkLogger.info("Please specify the filename.txt file which contain the VPD pcd info!")\r
+        EdkLogger.info(parser.usage)\r
+        sys.exit(1)\r
+    return options, args\r
+    \r
+def startBPDG(InputFileName, MapFileName, VpdFileName, Force):\r
+    if os.path.exists(VpdFileName) and not Force:\r
+        print "\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName\r
+        choice = sys.stdin.readline()\r
+        if choice.strip().lower() not in ['y', 'yes', '']:\r
+            return\r
+        \r
+    GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)\r
+    \r
+    EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))  \r
+    EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))\r
+    EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))  \r
+          \r
+    GenVPD.ParserInputFile()\r
+    GenVPD.FormatFileLine()\r
+    GenVPD.FixVpdOffset()\r
+    GenVPD.GenerateVpdFile(MapFileName, VpdFileName)\r
+    \r
+    EdkLogger.info("- Vpd pcd fixed done! -")    \r
+\r
+if __name__ == '__main__':\r
+    r = main()\r
+    ## 0-127 is a safe return range, and 1 is a standard default error\r
+    if r < 0 or r > 127: r = 1\r
+    sys.exit(r)\r
+\r
+    \r
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
new file mode 100644 (file)
index 0000000..05f5b6c
--- /dev/null
@@ -0,0 +1,556 @@
+## @file\r
+#  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
+#\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
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+import os\r
+import StringIO\r
+import StringTable as st\r
+import array\r
+\r
+from struct import *\r
+import Common.EdkLogger as EdkLogger\r
+import Common.BuildToolError as BuildToolError\r
+\r
+_FORMAT_CHAR = {1: 'B',\r
+                2: 'H',\r
+                4: 'I',\r
+                8: 'Q'\r
+                }\r
+\r
+class PcdEntry:\r
+    def __init__(self, PcdCName, PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None, \r
+                 PcdBinOffset=None, PcdBinSize=None):\r
+        self.PcdCName       = PcdCName.strip()\r
+        self.PcdOffset      = PcdOffset.strip()\r
+        self.PcdSize        = PcdSize.strip()\r
+        self.PcdValue       = PcdValue.strip()\r
+        self.Lineno         = Lineno.strip()\r
+        self.FileName       = FileName.strip()\r
+        self.PcdUnpackValue = PcdUnpackValue\r
+        self.PcdBinOffset   = PcdBinOffset\r
+        self.PcdBinSize     = PcdBinSize\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
+                         \r
+        if self.PcdOffset == '' :\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid PCD format(Name: %s File: %s Line: %s) , no Offset specified!" %(self.PcdCName, self.FileName, self.Lineno))\r
+            \r
+        if self.PcdSize == '' :\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid PCD format(Name: %s File: %s Line: %s), no PcdSize specified!" %(self.PcdCName, self.FileName, self.Lineno))  \r
+                   \r
+        self._GenOffsetValue ()\r
+        \r
+    def _IsBoolean(self, ValueString):\r
+        if ValueString.upper() in ["TRUE", "FALSE"]:\r
+            return True\r
+        return False\r
+    \r
+    def _GenOffsetValue(self):\r
+        if self.PcdOffset != "*" :\r
+            try:\r
+                self.PcdBinOffset = int (self.PcdOffset)\r
+            except:\r
+                try:\r
+                    self.PcdBinOffset = int(self.PcdOffset, 16)\r
+                except:\r
+                    EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                    "Invalid offset value %s for PCD %s (File: %s Line: %s)" % (self.PcdOffset, self.PcdCName, self.FileName, self.Lineno))                                  \r
+        \r
+    def _PackBooleanValue(self, ValueString):\r
+        if ValueString.upper() == "TRUE":\r
+            try:    \r
+                self.PcdValue =  pack(_FORMAT_CHAR[1], 1)\r
+            except:\r
+                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))                 \r
+        else:\r
+            try:\r
+                self.PcdValue =  pack(_FORMAT_CHAR[1], 0)\r
+            except:\r
+                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))      \r
+                               \r
+    def _PackIntValue(self, IntValue, Size):\r
+        if Size not in _FORMAT_CHAR.keys():\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno))        \r
+        try:\r
+            self.PcdValue =  pack(_FORMAT_CHAR[Size], IntValue)\r
+        except:\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))                \r
+        \r
+    def _PackPtrValue(self, ValueString, Size):\r
+        if ValueString.startswith('L"'):\r
+            self._PackUnicode(ValueString, Size)\r
+        elif ValueString.startswith('{') and ValueString.endswith('}'):\r
+            self._PackByteArray(ValueString, Size)\r
+        elif ValueString.startswith('"') and ValueString.endswith('"'):\r
+            self._PackString(ValueString, Size)\r
+        else:\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid VOID* type PCD %s value %s (File: %s Line: %s)" % (self.PcdCName, ValueString, self.FileName, self.Lineno)) \r
+                   \r
+    def _PackString(self, ValueString, Size):\r
+        if (Size < 0):\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))\r
+        if (ValueString == ""):\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter ValueString %s of PCD %s!(File: %s Line: %s)" % (self.PcdUnpackValue, self.PcdCName, self.FileName, self.Lineno))        \r
+        if (len(ValueString) < 2):\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "For PCD: %s ,ASCII string %s at least contains two!(File: %s Line: %s)" % (self.PcdCName, self.PcdUnpackValue, self.FileName, self.Lineno))\r
+        \r
+        ValueString = ValueString[1:-1]\r
+        if len(ValueString) + 1 > 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
+        try:\r
+            self.PcdValue=  pack('%ds' % Size, ValueString)\r
+        except:\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                            "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))                  \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
+        if (ValueString == ""):\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter ValueString %s of PCD %s!(File: %s Line: %s)" % (self.PcdUnpackValue, self.PcdCName, self.FileName, self.Lineno)) \r
+        \r
+        ValueString = ValueString.strip()\r
+        ValueString = ValueString.lstrip('{').strip('}')\r
+        ValueList = ValueString.split(',')\r
+        ValueList = [item.strip() for item in ValueList]\r
+        \r
+        if len(ValueList) > Size:\r
+            EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW, \r
+                            "The byte array %s is too large for size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))\r
+        \r
+        ReturnArray = array.array('B')\r
+        \r
+        for Index in xrange(len(ValueList)):\r
+            Value = None\r
+            if ValueList[Index].startswith('0x'):\r
+                # translate hex value\r
+                try:\r
+                    Value = int(ValueList[Index], 16)\r
+                except:\r
+                    EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                    "The value item %s in byte array %s is an invalid HEX value.(File: %s Line: %s)" % \\r
+                                    (ValueList[Index], ValueString, self.FileName, self.Lineno))\r
+            else:\r
+                # translate decimal value\r
+                try:\r
+                    Value = int(ValueList[Index], 10)\r
+                except:\r
+                    EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
+                                    "The value item %s in byte array %s is an invalid DECIMAL value.(File: %s Line: %s)" % \\r
+                                    (ValueList[Index], ValueString, self.FileName, self.Lineno))\r
+            \r
+            if Value > 255:\r
+                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                "The value item %s in byte array %s do not in range 0 ~ 0xFF(File: %s Line: %s)" %\\r
+                                (ValueList[Index], ValueString, self.FileName, self.Lineno))\r
+             \r
+            ReturnArray.append(Value)\r
+            \r
+        for Index in xrange(len(ValueList), Size):\r
+            ReturnArray.append(0)\r
+        \r
+        self.PcdValue =  ReturnArray.tolist()\r
+\r
+    ## Pack a unicode PCD value into byte array.\r
+    #  \r
+    #  A unicode string for a PCD should be in format as  L"".\r
+    #\r
+    def _PackUnicode(self, UnicodeString, Size):\r
+        if (Size < 0):        \r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" %\\r
+                             (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))\r
+        if (len(UnicodeString) < 3):\r
+            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "For PCD: %s ,ASCII string %s at least contains two!(File: %s Line: %s)" %\\r
+                            (self.PcdCName, self.PcdUnpackValue, self.FileName, self.Lineno))\r
+        \r
+        UnicodeString = UnicodeString[2:-1]\r
+        \r
+        if (len(UnicodeString) + 1) * 2 > Size:\r
+            EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,\r
+                            "The size of unicode string %s is too larger for size %s(File: %s Line: %s)" % \\r
+                            (UnicodeString, Size, self.FileName, self.Lineno))\r
+            \r
+        ReturnArray = array.array('B')\r
+        for Value in UnicodeString:\r
+            try:\r
+                ReturnArray.append(ord(Value))\r
+                ReturnArray.append(0)\r
+            except:\r
+                EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, \r
+                                "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
+            ReturnArray.append(0)\r
+            \r
+        self.PcdValue =  ReturnArray.tolist()    \r
+        \r
+class GenVPD :\r
+    \r
+    ## Constructor of DscBuildData\r
+    #\r
+    #  Initialize object of GenVPD\r
+    #   @Param      InputFileName   The filename include the vpd type pcd information\r
+    #   @param      MapFileName     The filename of map file that stores vpd type pcd information.\r
+    #                               This file will be generated by the BPDG tool after fix the offset\r
+    #                               and adjust the offset to make the pcd data aligned.\r
+    #   @param      VpdFileName     The filename of Vpd file that hold vpd pcd information.\r
+    #\r
+    def __init__(self, InputFileName, MapFileName, VpdFileName):\r
+        self.InputFileName           = InputFileName\r
+        self.MapFileName             = MapFileName\r
+        self.VpdFileName             = VpdFileName\r
+        self.FileLinesList           = []\r
+        self.PcdFixedOffsetSizeList  = []\r
+        self.PcdUnknownOffsetList    = []\r
+        try:\r
+            fInputfile = open(InputFileName, "r", 0)\r
+            try:\r
+                self.FileLinesList = fInputfile.readlines()\r
+            except:\r
+                EdkLogger.error("BPDG", BuildToolError.FILE_READ_FAILURE, "File read failed for %s" %InputFileName,None)\r
+            finally:\r
+                fInputfile.close()\r
+        except:\r
+            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
+    # from string to it's real format. Also remove the useless line in the input file.\r
+    # \r
+    def ParserInputFile (self):\r
+        count = 0        \r
+        for line in self.FileLinesList:\r
+            # Strip "\r\n" generated by readlines ().\r
+            line = line.strip()\r
+            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
+                # Store the line number\r
+                self.FileLinesList[count].append(str(count+1))\r
+            elif len(line) <= 1 :\r
+                # Set the blank line to "None"\r
+                self.FileLinesList[count] = None\r
+            else :\r
+                # Set the comment line to "None"\r
+                self.FileLinesList[count] = None\r
+            count += 1\r
+            \r
+        # The line count contain usage information\r
+        count = 0     \r
+        # Delete useless lines\r
+        while (True) :\r
+            try :\r
+                if (self.FileLinesList[count] == None) :\r
+                    del(self.FileLinesList[count])\r
+                else :\r
+                    count += 1\r
+            except :\r
+                break     \r
+        #\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
+        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
+                      \r
+        # Process the pcds one by one base on the pcd's value and size\r
+        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
+                # Strip the space char\r
+                PCD.PcdCName     = PCD.PcdCName.strip(' ')\r
+                PCD.PcdOffset    = PCD.PcdOffset.strip(' ')\r
+                PCD.PcdSize      = PCD.PcdSize.strip(' ')\r
+                PCD.PcdValue     = PCD.PcdValue.strip(' ')               \r
+                PCD.Lineno       = PCD.Lineno.strip(' ')\r
+                                      \r
+                #\r
+                # Store the original pcd value.\r
+                # This information will be useful while generate the output map file.\r
+                #\r
+                PCD.PcdUnpackValue    =  str(PCD.PcdValue)                              \r
+\r
+                #\r
+                # Translate PCD size string to an integer value.\r
+                PackSize = None\r
+                try:\r
+                    PackSize = int(PCD.PcdSize, 10)\r
+                    PCD.PcdBinSize = PackSize\r
+                except:\r
+                    try:\r
+                        PackSize = int(PCD.PcdSize, 16)\r
+                        PCD.PcdBinSize = PackSize\r
+                    except:\r
+                        EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid PCD size value %s at file: %s line: %s" % (PCD.PcdSize, self.InputFileName, PCD.Lineno))\r
+                    \r
+                if PCD._IsBoolean(PCD.PcdValue):\r
+                    PCD._PackBooleanValue(PCD.PcdValue)\r
+                    self.FileLinesList[count] = PCD\r
+                    count += 1\r
+                    continue\r
+                #\r
+                # Try to translate value to an integer firstly.\r
+                #\r
+                IsInteger = True\r
+                PackValue  = None\r
+                try:\r
+                    PackValue = int(PCD.PcdValue)\r
+                except:\r
+                    try:\r
+                        PackValue = int(PCD.PcdValue, 16)\r
+                    except:\r
+                        IsInteger = False\r
+                \r
+                if IsInteger:\r
+                    PCD._PackIntValue(PackValue, PackSize)\r
+                else:\r
+                    PCD._PackPtrValue(PCD.PcdValue, PackSize)\r
+                    \r
+                self.FileLinesList[count] = PCD\r
+                count += 1\r
+            else :\r
+                continue\r
+            \r
+    ##\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
+                self.PcdFixedOffsetSizeList.append(eachPcd)\r
+            else :\r
+                # Use pcd's CName as key, and pcd's Size as value\r
+                self.PcdUnknownOffsetList.append(eachPcd)\r
+                                        \r
+                            \r
+    ##\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
+    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
+        \r
+        self.PcdFixedOffsetSizeList.sort(lambda x,y: cmp(x.PcdBinOffset, y.PcdBinOffset))                            \r
+                \r
+        #\r
+        # Sort the un-fixed pcd's offset by it's size.\r
+        #\r
+        self.PcdUnknownOffsetList.sort(lambda x,y: cmp(x.PcdBinSize, y.PcdBinSize))\r
+        \r
+        #\r
+        # Process all Offset value are "*"\r
+        #\r
+        if (len(self.PcdFixedOffsetSizeList) == 0) and (len(self.PcdUnknownOffsetList) != 0) :\r
+            # The offset start from 0\r
+            NowOffset = 0\r
+            for Pcd in self.PcdUnknownOffsetList :                \r
+                Pcd.PcdBinOffset = NowOffset\r
+                Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))\r
+                NowOffset       += Pcd.PcdBinSize\r
+                \r
+            self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList\r
+            return\r
+                         \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
+        while (count < lenOfList - 1) :\r
+            PcdNow  = self.PcdFixedOffsetSizeList[count]\r
+            PcdNext = self.PcdFixedOffsetSizeList[count+1]\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
+            if PcdNow.PcdBinOffset + PcdNow.PcdBinSize > 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
+            if PcdNow.PcdBinOffset + PcdNow.PcdBinSize < 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
+        LastOffset              = self.PcdFixedOffsetSizeList[0].PcdBinOffset\r
+        FixOffsetSizeListCount  = 0\r
+        lenOfList               = len(self.PcdFixedOffsetSizeList)\r
+        lenOfUnfixedList        = len(self.PcdUnknownOffsetList)\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
+        while (FixOffsetSizeListCount < lenOfList) :\r
+            \r
+            eachFixedPcd     = self.PcdFixedOffsetSizeList[FixOffsetSizeListCount]                       \r
+            NowOffset        = eachFixedPcd.PcdBinOffset\r
+            \r
+            # Has free space               \r
+            if LastOffset < NowOffset :\r
+                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
+                            if needFixPcdSize <= (NowOffset - LastOffset) :\r
+                                # Change the offset value of un-fixed pcd\r
+                                eachUnfixedPcd.PcdOffset    = str(hex(LastOffset))\r
+                                eachUnfixedPcd.PcdBinOffset = LastOffset\r
+                                # Insert this pcd into fixed offset pcd list.\r
+                                self.PcdFixedOffsetSizeList.insert(FixOffsetSizeListCount,eachUnfixedPcd)\r
+                                \r
+                                # Delete the item's offset that has been fixed and added into fixed offset list\r
+                                self.PcdUnknownOffsetList.pop(countOfUnfixedList)\r
+                                \r
+                                # After item added, should enlarge the length of fixed pcd offset list\r
+                                lenOfList               += 1                                \r
+                                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
+                            else :\r
+                                # It can not insert into those two pcds, need to check stiil has other space can store it.\r
+                                FixOffsetSizeListCount += 1\r
+                                break                   \r
+                        else :\r
+                            continue\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
+            elif LastOffset == NowOffset :\r
+                LastOffset = NowOffset + eachFixedPcd.PcdBinSize\r
+                FixOffsetSizeListCount += 1\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
+        lenOfUnfixedList  = len(self.PcdUnknownOffsetList)\r
+        lenOfList         = len(self.PcdFixedOffsetSizeList)\r
+        while (lenOfUnfixedList > 0) :\r
+            # Still has items need to process\r
+            # The last pcd instance\r
+            LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]\r
+            NeedFixPcd = self.PcdUnknownOffsetList[0]\r
+            \r
+            NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdBinSize\r
+            NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))\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
+            lenOfList          += 1\r
+            lenOfUnfixedList   -= 1                                                                                                                \r
+    ##\r
+    # Write the final data into output files.\r
+    #   \r
+    def GenerateVpdFile (self, MapFileName, BinFileName):\r
+        #Open an VPD file to process\r
+\r
+        try:\r
+            fVpdFile  = open (BinFileName, "wb", 0)               \r
+        except:\r
+            # Open failed\r
+            EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" %self.VpdFileName,None)\r
+        \r
+        try :\r
+            fMapFile  = open (MapFileName, "w", 0)\r
+        except:\r
+            # Open failed\r
+            EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" %self.MapFileName,None)\r
+        \r
+        # Use a instance of StringIO to cache data\r
+        fStringIO = StringIO.StringIO('') \r
+        \r
+        # Write the header of map file.\r
+        try :\r
+            fMapFile.write (st.MAP_FILE_COMMENT_TEMPLATE + "\n")\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
+        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
+            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
+            # Write Vpd binary file\r
+            fStringIO.seek (eachPcd.PcdBinOffset)          \r
+            if isinstance(eachPcd.PcdValue, list):\r
+                ValueList = [chr(Item) for Item in eachPcd.PcdValue]\r
+                fStringIO.write(''.join(ValueList))      \r
+            else:                 \r
+                fStringIO.write (eachPcd.PcdValue)\r
+                                           \r
+        try :  \r
+            fVpdFile.write (fStringIO.getvalue())\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.VpdFileName,None)\r
+        \r
+        fStringIO.close ()\r
+        fVpdFile.close ()\r
+        fMapFile.close ()\r
+        \r
diff --git a/BaseTools/Source/Python/BPDG/StringTable.py b/BaseTools/Source/Python/BPDG/StringTable.py
new file mode 100644 (file)
index 0000000..0db282a
--- /dev/null
@@ -0,0 +1,79 @@
+## @file\r
+# This file is used to define strings used in the BPDG tool\r
+#\r
+# Copyright (c) 2010, 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+\r
+#string table starts here...\r
+\r
+#strings are classified as following types\r
+#    MSG_...: it is a message string\r
+#    ERR_...: it is a error string\r
+#    WRN_...: it is a warning string\r
+#    LBL_...: it is a UI label (window title, control label, etc.)\r
+#    MNU_...: it is a menu item label\r
+#    HLP_...: it is a help string\r
+#    CFG_...: it is a config string used in module. Do not need to translate it.\r
+#    XRC_...: it is a user visible string from xrc file\r
+\r
+MAP_FILE_COMMENT_TEMPLATE = \\r
+"""\r
+## @file\r
+#\r
+#  THIS IS AUTO-GENERATED FILE BY BPDG TOOLS AND PLEASE DO NOT MAKE MODIFICATION.\r
+#\r
+#  This file lists all VPD informations for a platform fixed/adjusted by BPDG tool.\r
+# \r
+# Copyright (c) 2010, 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+"""\r
+\r
+\r
+\r
+LBL_BPDG_LONG_UNI           = (u"Intel(r) Binary Product Data Generation Tool (Intel(r) BPDG)")\r
+LBL_BPDG_VERSION            = (u"0.1")\r
+LBL_BPDG_USAGE              = \\r
+(\r
+"""\r
+BPDG options -o Filename.bin -m Filename.map Filename.txt\r
+Intel(r) Binary Product Data Generation Tool (Intel(r) BPDG)\r
+Copyright (c) 2010 Intel Corporation All Rights Reserved.\r
+\r
+Required Flags:\r
+  -o VPD_FILENAME, --vpd-filename=VPD_FILENAME\r
+            Specify the file name for the VPD binary file\r
+  -m FILENAME, --map-filename=FILENAME\r
+            Generate file name for consumption during the build that contains \r
+            the mapping of Pcd name, offset, datum size and value derived \r
+            from the input file and any automatic calculations.\r
+""" \r
+)\r
+\r
+MSG_OPTION_HELP             = ("Show this help message and exit.")\r
+MSG_OPTION_DEBUG_LEVEL      = ("Print DEBUG statements, where DEBUG_LEVEL is 0-9.")\r
+MSG_OPTION_VERBOSE          = ("Print informational statements.")\r
+MSG_OPTION_SILENT           = ("Only the exit code will be returned, all informational and error messages will not be displayed.")\r
+MSG_OPTION_QUIET            = ("Returns the exit code and will display only error messages.")\r
+MSG_OPTION_VPD_FILENAME     = ("Specify the file name for the VPD binary file.")\r
+MSG_OPTION_MAP_FILENAME     = ("Generate file name for consumption during the build that contains the mapping of Pcd name, offset, datum size and value derived from the input file and any automatic calculations.")\r
+MSG_OPTION_FORCE            = ("Disable prompting the user for overwriting files as well as for missing input content.")\r
+\r
+ERR_INVALID_DEBUG_LEVEL     = ("Invalid level for debug message. Only "\r
+                                "'DEBUG', 'INFO', 'WARNING', 'ERROR', "\r
+                                "'CRITICAL' are supported for debugging "\r
+                                "messages.")\r
diff --git a/BaseTools/Source/Python/BPDG/__init__.py b/BaseTools/Source/Python/BPDG/__init__.py
new file mode 100644 (file)
index 0000000..358945c
--- /dev/null
@@ -0,0 +1,15 @@
+## @file\r
+# Python 'BPDG' package initialization file.\r
+#\r
+# This file is required to make Python interpreter treat the directory\r
+# as containing package.\r
+#\r
+# Copyright (c) 2010, 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r