3 # A small script to dump the contents of a b43 initvals file
5 # Copyright (C) 2008 Michael Buesch <m@bues.ch>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2
9 # as published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
21 print "b43 initvals file dumper"
22 print "Prints a .initvals assembly section to stdout."
24 print "Copyright (C) 2008-2010 Michael Buesch <m@bues.ch>"
25 print "Licensed under the GNU/GPL version 2"
27 print "Usage: b43-ivaldump FILE"
29 print "FILE is the file that is going to be dumped"
32 if len(sys.argv) != 2:
36 filename = sys.argv[1]
39 ivals = file(filename).read()
41 print "Could not read the initvals file: %s" % e.strerror
45 print "The file is too small. This can not be an initvals file."
49 print "This is not an initvals file. (Wrong header magic)."
52 if ord(ivals[1]) != 1:
53 print "Initvals file version %d is not supported by this program." % ord(ivals[1])
56 sectname = filename.split('/')[-1]
57 if sectname.endswith(".fw"):
58 sectname = sectname[:-3]
59 print ".initvals(%s)" % sectname
61 while idx < len(ivals):
62 off_sz = ord(ivals[idx + 0]) << 8
63 off_sz |= ord(ivals[idx + 1])
64 offset = off_sz & 0x7FFF
65 dword = (off_sz & 0x8000) != 0
68 data = ord(ivals[idx + 2]) << 24
69 data |= ord(ivals[idx + 3]) << 16
70 data |= ord(ivals[idx + 4]) << 8
71 data |= ord(ivals[idx + 5]) << 0
73 print "\tmmio32\t0x%08X, 0x%04X" % (data, offset)
75 data = ord(ivals[idx + 2]) << 8
76 data |= ord(ivals[idx + 3]) << 0
78 print "\tmmio16\t0x%04X, 0x%04X" % (data, offset)