3 # Script for creating a "struct extract" list for fwcutter_list.h
5 # Copyright (c) 2008 Michael Buesch <mb@bu3sch.de>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
18 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 if len(sys.argv) != 2:
36 print "Usage: %s path/to/wl.o" % sys.argv[0]
40 pipe = os.popen("objdump -t %s" % fn)
41 syms = pipe.readlines()
42 pipe = os.popen("objdump --headers %s" % fn)
43 headers = pipe.readlines()
45 # Get the .rodata fileoffset
46 rodata_fileoffset = None
47 rofileoff_re = re.compile(r"\d+\s+\.rodata\s+[0-9a-fA-F]+\s+[0-9a-fA-F]+\s+[0-9a-fA-F]+\s+([0-9a-fA-F]+)\s+.")
50 m = rofileoff_re.match(line)
52 rodata_fileoffset = int(m.group(1), 16)
54 if rodata_fileoffset == None:
55 print "ERROR: Could not find .rodata fileoffset"
58 md5sum = hashlib.md5(file(fn, "r").read())
60 print "static struct extract _%s[] =" % md5sum.hexdigest()
63 sym_re = re.compile(r"([0-9a-fA-F]+)\s+g\s+O\s+\.rodata\s+([0-9a-fA-F]+) d11([-_\s\w0-9]+)")
64 ucode_re = re.compile(r"ucode(\d+)")
71 pos = int(m.group(1), 16) + rodata_fileoffset
72 size = int(m.group(2), 16)
78 if "initvals" in name:
83 if "bommajor" in name:
84 print "\t/* ucode major version at offset 0x%x */" % pos
86 if "bomminor" in name:
87 print "\t/* ucode minor version at offset 0x%x */" % pos
89 if "ucode_2w" in name:
91 m = ucode_re.match(name)
93 corerev = int(m.group(1))
96 elif corerev >= 5 and corerev <= 14:
101 print "\t/* ERROR: Could not guess data type for: %s */" % name
104 print "\t{ .name = \"%s\", .offset = 0x%X, .type = %s, .length = 0x%X }," % (name, pos, type, size)
105 print "\tEXTRACT_LIST_END"