- return pcds
-
-def _parseGeneral(lines, efifilepath):
- """ For MSFT, ICC, EBC
- @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
- bPcds = []
-
-
- for line in lines:
- line = line.strip()
- if re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):
- status = 1
- continue
- if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):
- status = 2
- continue
- if re.match("^entry point at", line):
- status = 3
- 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
- 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
- sec_no, sym_offset, sym_name, vir_addr = m.groups(0)
- sec_no = int(sec_no, 16)
- sym_offset = int(sym_offset, 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
- for sec in secs:
- if sec[0] == sec_no and (sym_offset >= sec[1] and sym_offset < sec[1] + sec[2]):
- bPcds.append([m2.groups(0)[0], sec[3], sym_offset, vir_addr, sec_no])
-
- if len(bPcds) == 0: return None
-
- # get section information from efi file
- efisecs = PeImageClass(efifilepath).SectionHeaderList
- if efisecs == None or len(efisecs) == 0:
- return None
-
- pcds = []
- for pcd in bPcds:
- index = 0
- for efisec in efisecs:
- index = index + 1
- if pcd[1].strip() == efisec[0].strip():
- pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]])
- elif pcd[4] == index:
- pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]])
- return pcds
-
-def generatePcdTable(list, pcdpath):
- try:
- f = open(pcdpath, 'w')
- except:
- pass
-
- f.write('PCD Name Offset Section Name\r\n')
-
- for pcditem in list:
- f.write('%-30s 0x%-08X %-6s\r\n' % (pcditem[0], pcditem[1], pcditem[2]))
- f.close()
-
- #print 'Success to generate Binary Patch PCD table at %s!' % pcdpath
-
-if __name__ == '__main__':
- UsageString = "%prog -m <MapFile> -e <EfiFile> -o <OutFile>"
- AdditionalNotes = "\nPCD table is generated in file name with .BinaryPcdTable.txt postfix"
- parser = optparse.OptionParser(description=__copyright__, version=__version__, usage=UsageString)
- parser.add_option('-m', '--mapfile', action='store', dest='mapfile',
- help='Absolute path of module map file.')
- parser.add_option('-e', '--efifile', action='store', dest='efifile',
- help='Absolute path of EFI binary file.')
- parser.add_option('-o', '--outputfile', action='store', dest='outfile',
- help='Absolute path of output file to store the got patchable PCD table.')
-
- (options, args) = parser.parse_args()
-
- 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)
- if list != None:
- if options.outfile != None:
- generatePcdTable(list, options.outfile)
- else:
- generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt'))
- else:
- print 'Fail to generate Patch PCD Table based on map file and efi file'
- else:
- print 'Fail to generate Patch PCD Table for fail to find map file or efi file!'
+ return pcds\r
+ \r
+def _parseGeneral(lines, efifilepath):\r
+ """ For MSFT, ICC, EBC \r
+ @param lines line array for map file\r
+ \r
+ @return a list which element hold (PcdName, Offset, SectionName)\r
+ """\r
+ status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table\r
+ secs = [] # key = section name\r
+ bPcds = []\r
+\r
+\r
+ for line in lines:\r
+ line = line.strip()\r
+ if re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):\r
+ status = 1\r
+ continue\r
+ if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):\r
+ status = 2\r
+ continue\r
+ if re.match("^entry point at", line):\r
+ status = 3\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
+ 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
+ sec_no, sym_offset, sym_name, vir_addr = m.groups(0)\r
+ sec_no = int(sec_no, 16)\r
+ sym_offset = int(sym_offset, 16)\r
+ vir_addr = int(vir_addr, 16)\r
+ m2 = re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name)\r
+ if m2 != 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
+ bPcds.append([m2.groups(0)[0], sec[3], sym_offset, vir_addr, sec_no])\r
+\r
+ if len(bPcds) == 0: return None\r
+\r
+ # get section information from efi file\r
+ efisecs = PeImageClass(efifilepath).SectionHeaderList\r
+ if efisecs == None or len(efisecs) == 0:\r
+ return None\r
+ \r
+ pcds = []\r
+ for pcd in bPcds:\r
+ index = 0\r
+ for efisec in efisecs:\r
+ index = index + 1\r
+ if pcd[1].strip() == efisec[0].strip():\r
+ pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]])\r
+ elif pcd[4] == index:\r
+ pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]])\r
+ return pcds\r
+ \r
+def generatePcdTable(list, pcdpath):\r
+ try:\r
+ f = open(pcdpath, 'w')\r
+ except:\r
+ pass\r
+\r
+ f.write('PCD Name Offset Section Name\r\n')\r
+ \r
+ for pcditem in list:\r
+ f.write('%-30s 0x%-08X %-6s\r\n' % (pcditem[0], pcditem[1], pcditem[2]))\r
+ f.close()\r
+\r
+ #print 'Success to generate Binary Patch PCD table at %s!' % pcdpath \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
+ parser = optparse.OptionParser(description=__copyright__, version=__version__, usage=UsageString)\r
+ parser.add_option('-m', '--mapfile', action='store', dest='mapfile',\r
+ help='Absolute path of module map file.')\r
+ parser.add_option('-e', '--efifile', action='store', dest='efifile',\r
+ help='Absolute path of EFI binary file.')\r
+ parser.add_option('-o', '--outputfile', action='store', dest='outfile',\r
+ help='Absolute path of output file to store the got patchable PCD table.')\r
+ \r
+ (options, args) = parser.parse_args()\r
+\r
+ if options.mapfile == None or options.efifile == 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
+ generatePcdTable(list, options.outfile)\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
+ else:\r
+ print 'Fail to generate Patch PCD Table for fail to find map file or efi file!'\r