X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenPatchPcdTable%2FGenPatchPcdTable.py;h=dc2ceaf775d88c5a179930c4430ee74212aa5307;hp=9cfdad3171a4127a18118ff549e8d4652944f365;hb=1563349a967d7e02c43492ba853babb9c660a083;hpb=e4ac870fe95adc7d178a79b73ad2792e0c8bfeb8 diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py index 9cfdad3171..dc2ceaf775 100644 --- a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py +++ b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py @@ -5,7 +5,7 @@ # PCD Name Offset in binary # ======== ================ # -# Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -18,7 +18,7 @@ #====================================== External Libraries ======================================== import optparse -import os +import Common.LongFilePathOs as os import re import array @@ -26,6 +26,7 @@ from Common.BuildToolError import * import Common.EdkLogger as EdkLogger from Common.Misc import PeImageClass from Common.BuildVersion import gBUILD_VERSION +from Common.LongFilePathSupport import OpenLongFilePath as open # Version and Copyright __version_number__ = ("0.10" + " " + gBUILD_VERSION) @@ -36,7 +37,7 @@ __copyright__ = "Copyright (c) 2008 - 2010, Intel Corporation. All rights reserv #============================================== Code =============================================== secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE) -symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+) +([\da-fA-F]+)', re.UNICODE) +symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE) def parsePcdInfoFromMapFile(mapfilepath, efifilepath): """ Parse map file to get binary patch pcd information @@ -57,15 +58,32 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath): if (firstline.startswith("Archive member included ") and firstline.endswith(" file (symbol)")): return _parseForGCC(lines, efifilepath) + if firstline.startswith("# Path:"): + return _parseForXcode(lines, efifilepath) return _parseGeneral(lines, efifilepath) +def _parseForXcode(lines, efifilepath): + status = 0 + pcds = [] + for line in lines: + line = line.strip() + if status == 0 and line == "# Symbols:": + status = 1 + continue + if status == 1 and len(line) != 0: + if '_gPcd_BinaryPatch_' in line: + m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))', line) + if m is not None: + pcds.append((m.groups(0)[3], int(m.groups(0)[0], 16))) + return pcds + def _parseForGCC(lines, efifilepath): """ Parse map file generated by GCC linker """ status = 0 imageBase = -1 sections = [] bpcds = [] - for line in lines: + for index, line in enumerate(lines): line = line.strip() # status machine transection if status == 0 and line == "Memory Configuration": @@ -79,18 +97,22 @@ def _parseForGCC(lines, efifilepath): continue # status handler - if status == 2: + if status == 3: m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line) - if m != None: + if m is not None: sections.append(m.groups(0)) - if status == 2: - m = re.match("^([\da-fA-Fx]+) +[_]+gPcd_BinaryPatch_([\w_\d]+)$", line) - if m != None: - bpcds.append((m.groups(0)[1], int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0])) + if status == 3: + m = re.match('^.data._gPcd_BinaryPatch_([\w_\d]+)$', line) + if m is not None: + if lines[index + 1]: + PcdName = m.groups(0)[0] + m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip()) + if m is not None: + bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0])) # get section information from efi file efisecs = PeImageClass(efifilepath).SectionHeaderList - if efisecs == None or len(efisecs) == 0: + if efisecs is None or len(efisecs) == 0: return None #redirection redirection = 0 @@ -111,11 +133,11 @@ def _parseGeneral(lines, efifilepath): @param lines line array for map file @return a list which element hold (PcdName, Offset, SectionName) - """ + """ status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table - secs = [] # key = section name + secs = [] # key = section name bPcds = [] - + for line in lines: line = line.strip() @@ -127,21 +149,21 @@ def _parseGeneral(lines, efifilepath): continue if re.match("^entry point at", line): status = 3 - continue + continue if status == 1 and len(line) != 0: - m = secRe.match(line) - assert m != None, "Fail to parse the section in map file , line is %s" % line + m = secRe.match(line) + assert m is not None, "Fail to parse the section in map file , line is %s" % line sec_no, sec_start, sec_length, sec_name, sec_class = m.groups(0) secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_length, 16), sec_name, sec_class]) if status == 2 and len(line) != 0: m = symRe.match(line) - assert m != None, "Fail to parse the symbol in map file, line is %s" % line + assert m is not None, "Fail to parse the symbol in map file, line is %s" % line sec_no, sym_offset, sym_name, vir_addr = m.groups(0) - sec_no = int(sec_no, 16) + sec_no = int(sec_no, 16) sym_offset = int(sym_offset, 16) - vir_addr = int(vir_addr, 16) + vir_addr = int(vir_addr, 16) m2 = re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name) - if m2 != None: + if m2 is not None: # fond a binary pcd entry in map file for sec in secs: if sec[0] == sec_no and (sym_offset >= sec[1] and sym_offset < sec[1] + sec[2]): @@ -151,7 +173,7 @@ def _parseGeneral(lines, efifilepath): # get section information from efi file efisecs = PeImageClass(efifilepath).SectionHeaderList - if efisecs == None or len(efisecs) == 0: + if efisecs is None or len(efisecs) == 0: return None pcds = [] @@ -178,7 +200,7 @@ def generatePcdTable(list, pcdpath): f.close() #print 'Success to generate Binary Patch PCD table at %s!' % pcdpath - + if __name__ == '__main__': UsageString = "%prog -m -e -o " AdditionalNotes = "\nPCD table is generated in file name with .BinaryPcdTable.txt postfix" @@ -192,15 +214,15 @@ if __name__ == '__main__': (options, args) = parser.parse_args() - if options.mapfile == None or options.efifile == None: + if options.mapfile is None or options.efifile is None: print parser.get_usage() elif os.path.exists(options.mapfile) and os.path.exists(options.efifile): - list = parsePcdInfoFromMapFile(options.mapfile, options.efifile) - if list != None: - if options.outfile != None: + list = parsePcdInfoFromMapFile(options.mapfile, options.efifile) + if list is not None: + if options.outfile is not None: generatePcdTable(list, options.outfile) else: - generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt')) + generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt')) else: print 'Fail to generate Patch PCD Table based on map file and efi file' else: