brcm80211-ivaldump 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. """
  3. # A small script to dump the contents of a brcm80211 initvals section
  4. #
  5. # Copyright (C) 2010 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 "brcm80211 initvals section dumper"
  19. print "Prints a .initvals assembly section to stdout."
  20. print ""
  21. print "Copyright (C) 2010 Michael Buesch <m@bues.ch>"
  22. print "Licensed under the GNU/GPL version 2"
  23. print ""
  24. print "Usage: brcm80211-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) == 0 or len(ivals) % 8 != 0:
  38. print "The input file is malformed."
  39. sys.exit(1)
  40. sectname = filename.split('/')[-1]
  41. if sectname.endswith(".fw"):
  42. sectname = sectname[:-3]
  43. print ".initvals(%s)" % sectname
  44. for idx in range(0, len(ivals), 8):
  45. addr = ord(ivals[idx + 0])
  46. addr |= ord(ivals[idx + 1]) << 8
  47. size = ord(ivals[idx + 2])
  48. size |= ord(ivals[idx + 3]) << 8
  49. value = ord(ivals[idx + 4])
  50. value |= ord(ivals[idx + 5]) << 8
  51. value |= ord(ivals[idx + 6]) << 16
  52. value |= ord(ivals[idx + 7]) << 24
  53. if addr == 0xFFFF:
  54. break
  55. if size == 4:
  56. print "\tmmio32\t0x%08X, 0x%04X" % (value, addr)
  57. elif size == 2:
  58. if value & 0xFFFF0000:
  59. print "The input file is malformed (invalid value for 16bit field)"
  60. sys.exit(1)
  61. print "\tmmio16\t0x%04X, 0x%04X" % (value, addr)
  62. else:
  63. print "The input file is malformed (invalid size field: 0x%04X)" % size
  64. sys.exit(1)