#\r
\r
#====================================== External Libraries ========================================\r
+from __future__ import print_function\r
import optparse\r
import Common.LongFilePathOs as os\r
import re\r
\r
from Common.BuildToolError import *\r
import Common.EdkLogger as EdkLogger\r
-from Common.Misc import PeImageClass\r
+from Common.Misc import PeImageClass, startPatternGeneral, addressPatternGeneral, valuePatternGcc, pcdPatternGcc, secReGeneral\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
__version__ = "%prog Version " + __version_number__\r
-__copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved."\r
+__copyright__ = "Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved."\r
\r
#====================================== Internal Libraries ========================================\r
\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
\r
def parsePcdInfoFromMapFile(mapfilepath, efifilepath):\r
\r
def _parseForGCC(lines, efifilepath):\r
""" Parse map file generated by GCC linker """\r
- valuePattern = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')\r
dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')\r
- pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')\r
status = 0\r
imageBase = -1\r
sections = []\r
\r
# status handler\r
if status == 3:\r
- m = valuePattern.match(line)\r
+ m = valuePatternGcc.match(line)\r
if m is not None:\r
sections.append(m.groups(0))\r
if status == 3:\r
if m is not None:\r
if lines[index + 1]:\r
PcdName = m.groups(0)[0]\r
- m = pcdPattern.match(lines[index + 1].strip())\r
+ m = pcdPatternGcc.match(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
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table\r
secs = [] # key = section name\r
bPcds = []\r
- startPattern = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")\r
- addressPattern = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")\r
symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')\r
\r
for line in lines:\r
line = line.strip()\r
- if startPattern.match(line):\r
+ if startPatternGeneral.match(line):\r
status = 1\r
continue\r
- if addressPattern.match(line):\r
+ if addressPatternGeneral.match(line):\r
status = 2\r
continue\r
if line.startswith("entry point at"):\r
status = 3\r
continue\r
if status == 1 and len(line) != 0:\r
- m = secRe.match(line)\r
+ m = secReGeneral.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
(options, args) = parser.parse_args()\r
\r
if options.mapfile is None or options.efifile is None:\r
- print parser.get_usage()\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 is not None:\r
else:\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
+ print('Fail to generate Patch PCD Table based on map file and efi file')\r
else:\r
- print 'Fail to generate Patch PCD Table for fail to find map file or efi file!'\r
+ print('Fail to generate Patch PCD Table for fail to find map file or efi file!')\r