]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
BaseTools: use set instead of list for a variable to be used with in
[mirror_edk2.git] / BaseTools / Source / Python / GenPatchPcdTable / GenPatchPcdTable.py
index b6227d24fb1b2cbaec380daabaf8ec4c0f8d075f..dc2ceaf775d88c5a179930c4430ee74212aa5307 100644 (file)
@@ -5,7 +5,7 @@
 #    PCD Name    Offset in binary\r
 #    ========    ================\r
 #\r
-# Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 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
@@ -18,7 +18,7 @@
 \r
 #======================================  External Libraries ========================================\r
 import optparse\r
-import os\r
+import Common.LongFilePathOs as os\r
 import re\r
 import array\r
 \r
@@ -26,6 +26,7 @@ from Common.BuildToolError import *
 import Common.EdkLogger as EdkLogger\r
 from Common.Misc import PeImageClass\r
 from Common.BuildVersion import gBUILD_VERSION\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 # Version and Copyright\r
 __version_number__ = ("0.10" + " " + gBUILD_VERSION)\r
@@ -36,7 +37,7 @@ __copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation. All rights reserv
 \r
 #============================================== Code ===============================================\r
 secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)\r
-symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+) +([\da-fA-F]+)', re.UNICODE)\r
+symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)\r
 \r
 def parsePcdInfoFromMapFile(mapfilepath, efifilepath):\r
     """ Parse map file to get binary patch pcd information \r
@@ -53,17 +54,36 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
         return None\r
     \r
     if len(lines) == 0: return None\r
-    if lines[0].strip().find("Archive member included because of file (symbol)") != -1:\r
+    firstline = lines[0].strip()\r
+    if (firstline.startswith("Archive member included ") and\r
+        firstline.endswith(" file (symbol)")):\r
         return _parseForGCC(lines, efifilepath)\r
+    if firstline.startswith("# Path:"):\r
+        return _parseForXcode(lines, efifilepath)\r
     return _parseGeneral(lines, efifilepath)\r
 \r
+def _parseForXcode(lines, efifilepath):\r
+    status = 0\r
+    pcds = []\r
+    for line in lines:\r
+        line = line.strip()\r
+        if status == 0 and line == "# Symbols:":\r
+            status = 1\r
+            continue\r
+        if status == 1 and len(line) != 0:\r
+            if '_gPcd_BinaryPatch_' in line:\r
+                m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))', line)\r
+                if m is not None:\r
+                    pcds.append((m.groups(0)[3], int(m.groups(0)[0], 16)))\r
+    return pcds\r
+\r
 def _parseForGCC(lines, efifilepath):\r
     """ Parse map file generated by GCC linker """\r
     status = 0\r
     imageBase = -1\r
     sections = []\r
     bpcds = []\r
-    for line in lines:\r
+    for index, line in enumerate(lines):\r
         line = line.strip()\r
         # status machine transection\r
         if status == 0 and line == "Memory Configuration":\r
@@ -77,18 +97,22 @@ def _parseForGCC(lines, efifilepath):
             continue\r
 \r
         # status handler\r
-        if status == 2:\r
+        if status == 3:\r
             m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)\r
-            if m != None:\r
+            if m is not None:\r
                 sections.append(m.groups(0))\r
-        if status == 2:\r
-            m = re.match("^([\da-fA-Fx]+) +[_]+gPcd_BinaryPatch_([\w_\d]+)$", line)\r
-            if m != None:\r
-                bpcds.append((m.groups(0)[1], int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
+        if status == 3:\r
+            m = re.match('^.data._gPcd_BinaryPatch_([\w_\d]+)$', line)\r
+            if m is not None:\r
+                if lines[index + 1]:\r
+                    PcdName = m.groups(0)[0]\r
+                    m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip())\r
+                    if m is not None:\r
+                        bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
                 \r
     # get section information from efi file\r
     efisecs = PeImageClass(efifilepath).SectionHeaderList\r
-    if efisecs == None or len(efisecs) == 0:\r
+    if efisecs is None or len(efisecs) == 0:\r
         return None\r
     #redirection\r
     redirection = 0\r
@@ -109,11 +133,11 @@ def _parseGeneral(lines, efifilepath):
     @param lines    line array for map file\r
     \r
     @return a list which element hold (PcdName, Offset, SectionName)\r
-    """    \r
+    """\r
     status = 0    #0 - beginning of file; 1 - PE section definition; 2 - symbol table\r
-    secs  = []    # key = section name\r
+    secs = []    # key = section name\r
     bPcds = []\r
-    \r
+\r
 \r
     for line in lines:\r
         line = line.strip()\r
@@ -125,21 +149,21 @@ def _parseGeneral(lines, efifilepath):
             continue\r
         if re.match("^entry point at", line):\r
             status = 3\r
-            continue        \r
+            continue\r
         if status == 1 and len(line) != 0:\r
-            m =  secRe.match(line)\r
-            assert m != None, "Fail to parse the section in map file , line is %s" % line\r
+            m = secRe.match(line)\r
+            assert m is not None, "Fail to parse the section in map file , line is %s" % line\r
             sec_no, sec_start, sec_length, sec_name, sec_class = m.groups(0)\r
             secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_length, 16), sec_name, sec_class])\r
         if status == 2 and len(line) != 0:\r
             m = symRe.match(line)\r
-            assert m != None, "Fail to parse the symbol in map file, line is %s" % line\r
+            assert m is not None, "Fail to parse the symbol in map file, line is %s" % line\r
             sec_no, sym_offset, sym_name, vir_addr = m.groups(0)\r
-            sec_no     = int(sec_no,     16)\r
+            sec_no = int(sec_no, 16)\r
             sym_offset = int(sym_offset, 16)\r
-            vir_addr   = int(vir_addr,   16)\r
+            vir_addr = int(vir_addr, 16)\r
             m2 = re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name)\r
-            if m2 != None:\r
+            if m2 is not None:\r
                 # fond a binary pcd entry in map file\r
                 for sec in secs:\r
                     if sec[0] == sec_no and (sym_offset >= sec[1] and sym_offset < sec[1] + sec[2]):\r
@@ -149,7 +173,7 @@ def _parseGeneral(lines, efifilepath):
 \r
     # get section information from efi file\r
     efisecs = PeImageClass(efifilepath).SectionHeaderList\r
-    if efisecs == None or len(efisecs) == 0:\r
+    if efisecs is None or len(efisecs) == 0:\r
         return None\r
     \r
     pcds = []\r
@@ -176,7 +200,7 @@ def generatePcdTable(list, pcdpath):
     f.close()\r
 \r
     #print 'Success to generate Binary Patch PCD table at %s!' % pcdpath \r
-    \r
+\r
 if __name__ == '__main__':\r
     UsageString = "%prog -m <MapFile> -e <EfiFile> -o <OutFile>"\r
     AdditionalNotes = "\nPCD table is generated in file name with .BinaryPcdTable.txt postfix"\r
@@ -190,15 +214,15 @@ if __name__ == '__main__':
   \r
     (options, args) = parser.parse_args()\r
 \r
-    if options.mapfile == None or options.efifile == None:\r
+    if options.mapfile is None or options.efifile is None:\r
         print parser.get_usage()\r
     elif os.path.exists(options.mapfile) and os.path.exists(options.efifile):\r
-        list = parsePcdInfoFromMapFile(options.mapfile, options.efifile) \r
-        if list != None:\r
-            if options.outfile != None:\r
+        list = parsePcdInfoFromMapFile(options.mapfile, options.efifile)\r
+        if list is not None:\r
+            if options.outfile is not None:\r
                 generatePcdTable(list, options.outfile)\r
             else:\r
-                generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt')) \r
+                generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt'))\r
         else:\r
             print 'Fail to generate Patch PCD Table based on map file and efi file'\r
     else:\r