b43-fwdump: Allow a binary SHM dump to stdout.
[b43-tools.git] / debug / b43-fwdump
index 928634abd7c56a1a0163f81adc6a7f09e8b41413..0e94a3026ee383965bae73190f7a5d9e47195232 100755 (executable)
@@ -36,21 +36,27 @@ def usage():
        print "-b|--binary BIN      The firmware binary. This is required for"
        print "                     an instruction dump."
        print "-d|--dasmopt OPT     Additional options to the disassembler."
+       print "-s|--shm             Also dump SHM."
+       print "-S|--shmbin          Do a binary SHM dump, only."
        return
 
 def parseArgs():
        global phy
        global binary
        global dasmopt
+       global dumpShm
+       global dumpShmBin
 
        phy = None # Autodetect
        binary = None # No instruction dump
        dasmopt = ""
+       dumpShm = False
+       dumpShmBin = False
 
        try:
                (opts, args) = getopt.getopt(sys.argv[1:],
-                       "hp:b:d:",
-                       [ "help", "phy=", "binary=", "dasmopt=" ])
+                       "hp:b:d:sS",
+                       [ "help", "phy=", "binary=", "dasmopt=", "shm", "shmbin" ])
        except getopt.GetoptError:
                usage()
                sys.exit(1)
@@ -65,6 +71,10 @@ def parseArgs():
                        binary = v
                if o in ("-d", "--dasmopt"):
                        dasmopt = v
+               if o in ("-s", "--shm"):
+                       dumpShm = True
+               if o in ("-S", "--shmbin"):
+                       dumpShmBin = True
        return
 
 
@@ -110,6 +120,11 @@ def makeShortDump(dasm, pc):
                pos += 1
        return ret
 
+def toAscii(char):
+       if char >= 32 and char <= 126:
+               return chr(char)
+       return "."
+
 def main():
        parseArgs()
 
@@ -120,11 +135,17 @@ def main():
        gpr = b43.getGprs()
        lr = b43.getLinkRegs()
        off = b43.getOffsetRegs()
-       shm = b43.shmSharedRead()
+       if dumpShm or dumpShmBin:
+               shm = b43.shmSharedRead()
        dbg = b43.getPsmDebug()
        psmcond = b43.getPsmConditions()
        b43.ucodeStart()
 
+       if dumpShmBin:
+               # Only do a binary SHM dump
+               stdout.write(shm)
+               sys.exit(0)
+
        print "--- B43 microcode state dump ---"
        print "PC: %03X  PSM-COND: %04X" % (dbg.getPc(), psmcond)
        print "Link registers:"
@@ -145,6 +166,22 @@ def main():
                print makeShortDump(dasm, dbg.getPc())
        else:
                print "<No binary supplied. See --binary option>"
+
+       if dumpShm:
+               print "Shared memory:"
+               ascii = ""
+               for i in range(0, len(shm)):
+                       if i % 16 == 0 and i != 0:
+                               stdout.write("  " + ascii + "\n")
+                               ascii = ""
+                       if i % 16 == 0:
+                               stdout.write("0x%04X:  " % i)
+                       c = ord(shm[i])
+                       stdout.write("%02X" % c)
+                       if (i % 2 != 0):
+                               stdout.write(" ")
+                       ascii += toAscii(c)
+               stdout.write("  " + ascii + "\n")
        return