From c7913bc8c60fdd122c4b87b0979b372b39bb8fda Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 20 Jun 2008 00:23:34 +0200 Subject: [PATCH] b43-ivaldump: Add a tool for dumping initvals files. Signed-off-by: Michael Buesch --- disassembler/Makefile | 1 + disassembler/b43-ivaldump | 78 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 disassembler/b43-ivaldump diff --git a/disassembler/Makefile b/disassembler/Makefile index efb4125..8651626 100644 --- a/disassembler/Makefile +++ b/disassembler/Makefile @@ -22,6 +22,7 @@ $(BIN): $(OBJECTS) install: all -install -o 0 -g 0 -m 755 $(BIN) $(PREFIX)/bin/ + -install -o 0 -g 0 -m 755 b43-ivaldump $(PREFIX)/bin/ clean: -rm -f *~ *.o *.orig *.rej diff --git a/disassembler/b43-ivaldump b/disassembler/b43-ivaldump new file mode 100755 index 0000000..18164ee --- /dev/null +++ b/disassembler/b43-ivaldump @@ -0,0 +1,78 @@ +#!/usr/bin/env python +""" +# A small script to dump the contents of a b43 initvals file +# +# Copyright (C) 2008 Michael Buesch +# +# 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 "" + print "Copyright (C) 2008 Michael Buesch " + 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" + print "" + print "The dump will look like this:" + print "XX-bit 0xDEAD -> 0xBEEF" + print "This is an XX-bit write of the value 0xDEAD to register 0xBEEF" + 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) + +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 "32-bit 0x%08X -> 0x%04X" % (data, offset) + else: + data = ord(ivals[idx + 2]) << 8 + data |= ord(ivals[idx + 3]) << 0 + idx += 4 + print "16-bit 0x%04X -> 0x%04X" % (data, offset) -- 2.31.1