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"
50 (opts, args) = getopt.getopt(sys.argv[1:],
52 [ "help", "asmfile=", "binfile=", "defs=" ])
53 except getopt.GetoptError:
58 if o in ("-h", "--help"):
61 if o in ("-a", "--asmfile"):
63 print "Must not set both of --asmfile and --binfile"
66 if o in ("-b", "--binfile"):
68 print "Must not set both of --asmfile and --binfile"
71 if o in ("-d", "--defs"):
74 if not opt_asmfile and not opt_binfile:
75 print "Must set either --asmfile or --binfile"
78 print "Must set --defs"
87 asm = file(opt_asmfile).read()
89 print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
93 bin = file(opt_binfile).read()
95 print "Could not read binfile %s: %s" % (e.filename, e.strerror)
97 asm = Disassembler(bin, "").getAsm()
99 b = B43Beautifier(asm, opt_defsfiles)
100 sys.stdout.write(b.getAsm())