3 # b43 firmware assembly code beautifier
5 # Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
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 3
9 # as published by the Free Software Foundation.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 print "b43 firmware assembly code beautifier"
28 print "Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>"
29 print "Licensed under the GNU/GPL version 3"
31 print "Usage: b43-beautifier [OPTIONS]"
33 print "-h|--help Print this help text"
34 print "-a|--asmfile [FILE] Assembly code source file"
35 print "-b|--binfile [FILE] Binary code source file"
36 print "-d|--defs [DIR] Directory containing the defs files"
38 print "The options -d AND (-a XOR -b) are essential."
39 print "The --defs directory is the \"common\" subdirectory in the"
40 print "b43-ucode assembly source tree."
52 (opts, args) = getopt.getopt(sys.argv[1:],
54 [ "help", "asmfile=", "binfile=", "defs=" ])
55 except getopt.GetoptError:
60 if o in ("-h", "--help"):
63 if o in ("-a", "--asmfile"):
65 print "Must not set both of --asmfile and --binfile"
68 if o in ("-b", "--binfile"):
70 print "Must not set both of --asmfile and --binfile"
73 if o in ("-d", "--defs"):
76 if not opt_asmfile and not opt_binfile:
77 print "Must set either --asmfile or --binfile"
80 print "Must set --defs"
89 asm = file(opt_asmfile).read()
91 print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
95 bin = file(opt_binfile).read()
97 print "Could not read binfile %s: %s" % (e.filename, e.strerror)
99 asm = Disassembler(bin, "").getAsm()
101 b = B43Beautifier(asm, opt_defsfiles)
102 sys.stdout.write(b.getAsm())