3 # A small script to dump the contents of a brcm80211 initvals section
5 # Copyright (C) 2010 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 "brcm80211 initvals section dumper"
22 print "Prints a .initvals assembly section to stdout."
24 print "Copyright (C) 2010 Michael Buesch <mb@bu3sch.de>"
25 print "Licensed under the GNU/GPL version 2"
27 print "Usage: brcm80211-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
44 if len(ivals) == 0 or len(ivals) % 8 != 0:
45 print "The input file is malformed."
48 sectname = filename.split('/')[-1]
49 if sectname.endswith(".fw"):
50 sectname = sectname[:-3]
51 print ".initvals(%s)" % sectname
52 for idx in range(0, len(ivals), 8):
53 addr = ord(ivals[idx + 0])
54 addr |= ord(ivals[idx + 1]) << 8
55 size = ord(ivals[idx + 2])
56 size |= ord(ivals[idx + 3]) << 8
57 value = ord(ivals[idx + 4])
58 value |= ord(ivals[idx + 5]) << 8
59 value |= ord(ivals[idx + 6]) << 16
60 value |= ord(ivals[idx + 7]) << 24
65 print "\tmmio32\t0x%08X, 0x%04X" % (value, addr)
67 if value & 0xFFFF0000:
68 print "The input file is malformed (invalid value for 16bit field)"
70 print "\tmmio16\t0x%04X, 0x%04X" % (value, addr)
72 print "The input file is malformed (invalid size field: 0x%04X)" % size