X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenPatchPcdTable%2FGenPatchPcdTable.py;h=d30a9a2baa8bb7d71de1ae444e059b45e16c8ccd;hp=50d99f7267a381b26ce333d20f0e20f792ca1776;hb=e52aed0d855218f23cbd94629561eb4155936cec;hpb=1be2ed90a20618d71ddf34b8a07d038da0b36854 diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py index 50d99f7267..d30a9a2baa 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 - 2014, 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 @@ -37,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 @@ -58,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 != 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": @@ -80,14 +97,18 @@ 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: sections.append(m.groups(0)) - if status == 2: - m = re.match("^([\da-fA-Fx]+) +[_]+gPcd_BinaryPatch_([\w_\d]+)$", line) + if status == 3: + m = re.match('^.data._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 lines[index + 1]: + PcdName = m.groups(0)[0] + m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip()) + if m != 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 @@ -112,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() @@ -128,9 +149,9 @@ 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) + m = secRe.match(line) assert m != 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]) @@ -138,9 +159,9 @@ def _parseGeneral(lines, efifilepath): m = symRe.match(line) assert m != 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: # fond a binary pcd entry in map file @@ -179,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" @@ -196,12 +217,12 @@ if __name__ == '__main__': if options.mapfile == None or options.efifile == None: print parser.get_usage() elif os.path.exists(options.mapfile) and os.path.exists(options.efifile): - list = parsePcdInfoFromMapFile(options.mapfile, options.efifile) + list = parsePcdInfoFromMapFile(options.mapfile, options.efifile) if list != None: if options.outfile != 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: