Rev 268 | Rev 288 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 268 | Rev 270 | ||
---|---|---|---|
1 | #!/usr/bin/env python |
1 | #!/usr/bin/env python |
2 | 2 | ||
3 | import sys |
3 | import sys |
4 | import struct |
4 | import struct |
5 | import re |
5 | import re |
6 | 6 | ||
7 | symline = re.compile(r'(0x[a-f0-9]+)\s+([^\s]+)$') |
7 | symline = re.compile(r'(0x[a-f0-9]+)\s+([^\s]+)$') |
8 | symtabfmt = "<Q32s" |
8 | fileline = re.compile(r'[^\s]+\s+0x[a-f0-9]+\s+0x[a-f0-9]+\s+([^\s]+\.o)$') |
- | 9 | ||
9 | MAXSTRING=31 |
10 | MAXSTRING=63 |
- | 11 | symtabfmt = "<Q%ds" % (MAXSTRING+1) |
|
10 | 12 | ||
11 | def read_symbols(inp): |
13 | def read_symbols(inp): |
12 | while 1: |
14 | while 1: |
13 | line = inp.readline() |
15 | line = inp.readline() |
14 | if not line: |
16 | if not line: |
15 | return |
17 | return |
16 | if 'memory map' in line: |
18 | if 'memory map' in line: |
17 | break |
19 | break |
18 | 20 | ||
19 | symtable = {} |
21 | symtable = {} |
- | 22 | filename = '' |
|
20 | while 1: |
23 | while 1: |
21 | line = inp.readline() |
24 | line = inp.readline() |
22 | if not line.strip(): |
25 | if not line.strip(): |
23 | continue |
26 | continue |
24 | if line[0] not in (' ','.'): |
27 | if line[0] not in (' ','.'): |
25 | break |
28 | break |
26 | line = line.strip() |
29 | line = line.strip() |
- | 30 | # Search for file name |
|
- | 31 | res = fileline.match(line) |
|
- | 32 | if res: |
|
- | 33 | filename = res.group(1) |
|
27 | # Search only for symbols |
34 | # Search for symbols |
28 | res = symline.match(line) |
35 | res = symline.match(line) |
29 | if res: |
36 | if res: |
30 | symtable[int(res.group(1),16)] = res.group(2) |
37 | symtable[int(res.group(1),16)] = filename + ':' + res.group(2) |
31 | return symtable |
38 | return symtable |
32 | 39 | ||
33 | def generate(inp, out): |
40 | def generate(inp, out): |
34 | symtab = read_symbols(inp) |
41 | symtab = read_symbols(inp) |
35 | if not symtab: |
42 | if not symtab: |
36 | print "Bad kernel.map format, empty." |
43 | print "Bad kernel.map format, empty." |
37 | sys.exit(1) |
44 | sys.exit(1) |
38 | addrs = symtab.keys() |
45 | addrs = symtab.keys() |
39 | addrs.sort() |
46 | addrs.sort() |
40 | for addr in addrs: |
47 | for addr in addrs: |
41 | # Do not write address 0, it indicates end of data |
48 | # Do not write address 0, it indicates end of data |
42 | if addr == 0: |
49 | if addr == 0: |
43 | continue |
50 | continue |
44 | data = struct.pack(symtabfmt,addr,symtab[addr][:MAXSTRING]) |
51 | data = struct.pack(symtabfmt,addr,symtab[addr][:MAXSTRING]) |
45 | out.write(data) |
52 | out.write(data) |
46 | out.write(struct.pack(symtabfmt,0,'')) |
53 | out.write(struct.pack(symtabfmt,0,'')) |
47 | 54 | ||
48 | def main(): |
55 | def main(): |
49 | if len(sys.argv) != 3: |
56 | if len(sys.argv) != 3: |
50 | print "Usage: %s <kernel.map> <output.bin>" % sys.argv[0] |
57 | print "Usage: %s <kernel.map> <output.bin>" % sys.argv[0] |
51 | sys.exit(1) |
58 | sys.exit(1) |
52 | 59 | ||
53 | inp = open(sys.argv[1],'r') |
60 | inp = open(sys.argv[1],'r') |
54 | out = open(sys.argv[2],'w') |
61 | out = open(sys.argv[2],'w') |
55 | generate(inp,out) |
62 | generate(inp,out) |
56 | inp.close() |
63 | inp.close() |
57 | out.close() |
64 | out.close() |
58 | 65 | ||
59 | if __name__ == '__main__': |
66 | if __name__ == '__main__': |
60 | main() |
67 | main() |
61 | 68 |