b43-ivaldump 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python
  2. """
  3. # A small script to dump the contents of a b43 initvals file
  4. #
  5. # Copyright (C) 2008 Michael Buesch <m@bues.ch>
  6. #
  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.
  10. #
  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.
  15. """
  16. import sys
  17. def usage():
  18. print "b43 initvals file dumper"
  19. print "Prints a .initvals assembly section to stdout."
  20. print ""
  21. print "Copyright (C) 2008-2010 Michael Buesch <m@bues.ch>"
  22. print "Licensed under the GNU/GPL version 2"
  23. print ""
  24. print "Usage: b43-ivaldump FILE"
  25. print ""
  26. print "FILE is the file that is going to be dumped"
  27. return
  28. if len(sys.argv) != 2:
  29. usage()
  30. sys.exit(1)
  31. filename = sys.argv[1]
  32. try:
  33. ivals = file(filename).read()
  34. except IOError, e:
  35. print "Could not read the initvals file: %s" % e.strerror
  36. sys.exit(1)
  37. if len(ivals) < 8:
  38. print "The file is too small. This can not be an initvals file."
  39. sys.exit(1)
  40. if ivals[0] != "i":
  41. print "This is not an initvals file. (Wrong header magic)."
  42. sys.exit(1)
  43. if ord(ivals[1]) != 1:
  44. print "Initvals file version %d is not supported by this program." % ord(ivals[1])
  45. sys.exit(1)
  46. sectname = filename.split('/')[-1]
  47. if sectname.endswith(".fw"):
  48. sectname = sectname[:-3]
  49. print ".initvals(%s)" % sectname
  50. idx = 8 # skip header
  51. while idx < len(ivals):
  52. off_sz = ord(ivals[idx + 0]) << 8
  53. off_sz |= ord(ivals[idx + 1])
  54. offset = off_sz & 0x7FFF
  55. dword = (off_sz & 0x8000) != 0
  56. if dword:
  57. data = ord(ivals[idx + 2]) << 24
  58. data |= ord(ivals[idx + 3]) << 16
  59. data |= ord(ivals[idx + 4]) << 8
  60. data |= ord(ivals[idx + 5]) << 0
  61. idx += 6
  62. print "\tmmio32\t0x%08X, 0x%04X" % (data, offset)
  63. else:
  64. data = ord(ivals[idx + 2]) << 8
  65. data |= ord(ivals[idx + 3]) << 0
  66. idx += 4
  67. print "\tmmio16\t0x%04X, 0x%04X" % (data, offset)