b43-beautifier fixes
authorMichael Buesch <mb@bu3sch.de>
Fri, 24 Sep 2010 21:42:28 +0000 (23:42 +0200)
committerMichael Buesch <mb@bu3sch.de>
Fri, 24 Sep 2010 21:42:28 +0000 (23:42 +0200)
Signed-off-by: Michael Buesch <mb@bu3sch.de>
debug/b43-beautifier
debug/libb43.py

index b07d493eb04b0ab4f1bbaf4484fea808ac633b17..ce18aec75d1c76fa6568d9eee232ade77031550c 100755 (executable)
@@ -2,7 +2,7 @@
 """
 #  b43 firmware assembly code beautifier
 #
-#  Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
+#  Copyright (C) 2008-2010 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 3
@@ -32,26 +32,22 @@ def usage():
        print ""
        print "-h|--help            Print this help text"
        print "-a|--asmfile [FILE]  Assembly code source file"
-       print "-b|--binfile [FILE]  Binary code source file"
        print "-d|--defs [DIR]      Directory containing the defs files"
        print ""
-       print "The options  -d AND (-a XOR -b)  are essential."
-       print "The --defs directory is the \"common\" subdirectory in the"
-       print "b43-ucode assembly source tree."
+       print "The options  -d  and  -a  are essential."
+       print "The \"include\" directory can be used for --defs"
 
 def parseArgs():
        global opt_asmfile
-       global opt_binfile
        global opt_defsfiles
 
        opt_asmfile = None
-       opt_binfile = None
        opt_defsfiles = None
 
        try:
                (opts, args) = getopt.getopt(sys.argv[1:],
-                       "ha:b:d:",
-                       [ "help", "asmfile=", "binfile=", "defs=" ])
+                       "ha:d:",
+                       [ "help", "asmfile=", "defs=" ])
        except getopt.GetoptError:
                usage()
                sys.exit(1)
@@ -61,47 +57,32 @@ def parseArgs():
                        usage()
                        sys.exit(0)
                if o in ("-a", "--asmfile"):
-                       if opt_binfile:
-                               print "Must not set both of --asmfile and --binfile"
-                               sys.exit(1)
                        opt_asmfile = v
-               if o in ("-b", "--binfile"):
-                       if opt_asmfile:
-                               print "Must not set both of --asmfile and --binfile"
-                               sys.exit(1)
-                       opt_binfile = v
                if o in ("-d", "--defs"):
                        opt_defsfiles = v
 
-       if not opt_asmfile and not opt_binfile:
-               print "Must set either --asmfile or --binfile"
+       if not opt_asmfile:
+               print "Must provide --asmfile"
                sys.exit(1)
        if not opt_defsfiles:
-               print "Must set --defs"
+               print "Must provide --defs"
                sys.exit(1)
 
 def main():
        parseArgs()
 
-       # Get the assembly
-       if opt_asmfile:
-               try:
-                       asm = file(opt_asmfile).read()
-               except IOError, e:
-                       print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
-                       sys.exit(1)
-       else:
-               try:
-                       bin = file(opt_binfile).read()
-               except IOError, e:
-                       print "Could not read binfile %s: %s" % (e.filename, e.strerror)
-                       sys.exit(1)
-               asm = Disassembler(bin, "").getAsm()
+       try:
+               asm = file(opt_asmfile).read()
+       except IOError, e:
+               print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
+               return 1
+       try:
+               b = B43Beautifier(asm, opt_defsfiles)
+               sys.stdout.write(b.getAsm())
+       except B43Exception:
+               return 1
+       return 0
 
-       b = B43Beautifier(asm, opt_defsfiles)
-       sys.stdout.write(b.getAsm())
+if __name__ == "__main__":
+       sys.exit(main())
 
-try:
-       main()
-except B43Exception:
-       sys.exit(1)
index cf8a7cec1a8a8a781479efbe8053d52f55593348..55ff4856f237413c187f29e28fee92764596de20 100644 (file)
@@ -1,7 +1,7 @@
 """
 #  b43 debugging library
 #
-#  Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
+#  Copyright (C) 2008-2010 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 3
@@ -622,13 +622,15 @@ class B43Beautifier(B43AsmParser):
        def __init__(self, asm_code, headers_dir):
                """asm_code is the assembly code. headers_dir is a full
                path to the directory containing the symbolic SPR,SHM,etc... definitions"""
+               if headers_dir.endswith("/"):
+                       headers_dir = headers_dir[:-1]
                B43AsmParser.__init__(self, asm_code)
                self.symSpr = B43SymbolicSpr(headers_dir + "/spr.inc")
                self.symShm = B43SymbolicShm(headers_dir + "/shm.inc")
                self.symCond = B43SymbolicCondition(headers_dir + "/cond.inc")
-               self.preamble = "#include <%s/spr.inc>\n" % headers_dir
-               self.preamble += "#include <%s/shm.inc>\n" % headers_dir
-               self.preamble += "#include <%s/cond.inc>\n" % headers_dir
+               self.preamble = "#include \"%s/spr.inc\"\n" % headers_dir
+               self.preamble += "#include \"%s/shm.inc\"\n" % headers_dir
+               self.preamble += "#include \"%s/cond.inc\"\n" % headers_dir
                self.preamble += "\n"
                self.__process_code()