summaryrefslogtreecommitdiffstats
path: root/disassembler/b43-ivaldump
blob: eb87899bb949f3bfcfe496e51f92d60421ea77aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
"""
#   A small script to dump the contents of a b43 initvals file
#
#   Copyright (C) 2008  Michael Buesch <mb@bu3sch.de>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License version 2
#   as published by the Free Software Foundation.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
"""

import sys


def usage():
	print "b43 initvals file dumper"
	print "Prints a .initvals assembly section to stdout."
	print ""
	print "Copyright (C) 2008-2010 Michael Buesch <mb@bu3sch.de>"
	print "Licensed under the GNU/GPL version 2"
	print ""
	print "Usage: b43-ivaldump FILE"
	print ""
	print "FILE is the file that is going to be dumped"
	return

if len(sys.argv) != 2:
	usage()
	sys.exit(1)

filename = sys.argv[1]

try:
	ivals = file(filename).read()
except IOError, e:
	print "Could not read the initvals file: %s" % e.strerror
	sys.exit(1)

if len(ivals) < 8:
	print "The file is too small. This can not be an initvals file."
	sys.exit(1)

if ivals[0] != "i":
	print "This is not an initvals file. (Wrong header magic)."
	sys.exit(1)

if ord(ivals[1]) != 1:
	print "Initvals file version %d is not supported by this program." % ord(ivals[1])
	sys.exit(1)

sectname = filename.split('/')[-1]
if sectname.endswith(".fw"):
	sectname = sectname[:-3]
print ".initvals(%s)" % sectname
idx = 8 # skip header
while idx < len(ivals):
	off_sz = ord(ivals[idx + 0]) << 8
	off_sz |= ord(ivals[idx + 1])
	offset = off_sz & 0x7FFF
	dword = (off_sz & 0x8000) != 0

	if dword:
		data = ord(ivals[idx + 2]) << 24
		data |= ord(ivals[idx + 3]) << 16
		data |= ord(ivals[idx + 4]) << 8
		data |= ord(ivals[idx + 5]) << 0
		idx += 6
		print "\tmmio32\t0x%08X, 0x%04X" % (data, offset)
	else:
		data = ord(ivals[idx + 2]) << 8
		data |= ord(ivals[idx + 3]) << 0
		idx += 4
		print "\tmmio16\t0x%04X, 0x%04X" % (data, offset)
bues.ch cgit interface