Rev 288 | Rev 297 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
268 | palkovsky | 1 | #!/usr/bin/env python |
2 | |||
3 | import sys |
||
4 | import struct |
||
5 | import re |
||
6 | |||
270 | palkovsky | 7 | MAXSTRING=63 |
8 | symtabfmt = "<Q%ds" % (MAXSTRING+1) |
||
9 | |||
268 | palkovsky | 10 | |
293 | palkovsky | 11 | objline = re.compile(r'([0-9a-f]+)\s+[lg]\s+F\s+\.text\s+[0-9a-f]+\s+(.*)$') |
12 | fileexp = re.compile(r'([^\s]+):\s+file format') |
||
13 | def read_obdump(inp): |
||
14 | result = {} |
||
15 | fname = '' |
||
16 | for line in inp: |
||
268 | palkovsky | 17 | line = line.strip() |
293 | palkovsky | 18 | res = objline.match(line) |
270 | palkovsky | 19 | if res: |
293 | palkovsky | 20 | result.setdefault(fname,[]).append((int(res.group(1),16), |
21 | res.group(2))) |
||
22 | res = fileexp.match(line) |
||
268 | palkovsky | 23 | if res: |
293 | palkovsky | 24 | fname = res.group(1) |
25 | continue |
||
268 | palkovsky | 26 | |
293 | palkovsky | 27 | return result |
28 | |||
29 | startfile = re.compile(r'\.text\s+(0x[0-9a-f]+)\s+0x[0-9a-f]+\s+(.*)$') |
||
30 | def generate(kmapf, obmapf, out): |
||
31 | obdump = read_obdump(obmapf) |
||
32 | |||
33 | def sorter(x,y): |
||
34 | return cmp(x[0],y[0]) |
||
35 | |||
36 | for line in kmapf: |
||
37 | line = line.strip() |
||
38 | res = startfile.match(line) |
||
39 | if res and obdump.has_key(res.group(2)): |
||
40 | offset = int(res.group(1),16) |
||
41 | fname = res.group(2) |
||
42 | symbols = obdump[fname] |
||
43 | symbols.sort(sorter) |
||
44 | for addr,symbol in symbols: |
||
45 | value = fname + ':' + symbol |
||
46 | data = struct.pack(symtabfmt,addr+offset,value[:MAXSTRING]) |
||
47 | out.write(data) |
||
48 | |||
268 | palkovsky | 49 | out.write(struct.pack(symtabfmt,0,'')) |
50 | |||
51 | def main(): |
||
293 | palkovsky | 52 | if len(sys.argv) != 4: |
53 | print "Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0] |
||
268 | palkovsky | 54 | sys.exit(1) |
55 | |||
293 | palkovsky | 56 | kmapf = open(sys.argv[1],'r') |
57 | obmapf = open(sys.argv[2],'r') |
||
58 | out = open(sys.argv[3],'w') |
||
59 | generate(kmapf,obmapf,out) |
||
60 | kmapf.close() |
||
61 | obmapf.close() |
||
268 | palkovsky | 62 | out.close() |
63 | |||
64 | if __name__ == '__main__': |
||
65 | main() |