3 # A small script to dump the contents of a b43 initvals file
5 # Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
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"
23 print "Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>"
24 print "Licensed under the GNU/GPL version 2"
26 print "Usage: b43-ivaldump FILE"
28 print "FILE is the file that is going to be dumped"
30 print "The dump will look like this:"
31 print "XX-bit 0xDEAD -> 0xBEEF"
32 print "This is an XX-bit write of the value 0xDEAD to register 0xBEEF"
35 if len(sys.argv) != 2:
39 filename = sys.argv[1]
42 ivals = file(filename).read()
44 print "Could not read the initvals file: %s" % e.strerror
48 print "The file is too small. This can not be an initvals file."
52 print "This is not an initvals file. (Wrong header magic)."
55 if ord(ivals[1]) != 1:
56 print "Initvals file version %d is not supported by this program." % ord(ivals[1])
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 "32-bit 0x%08X -> 0x%04X" % (data, offset)
75 data = ord(ivals[idx + 2]) << 8
76 data |= ord(ivals[idx + 3]) << 0
78 print "16-bit 0x%04X -> 0x%04X" % (data, offset)