Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Python3 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions debug/b43-beautifier
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
# b43 firmware assembly code beautifier
#
Expand All @@ -23,19 +23,19 @@ from libb43 import *


def usage():
print "b43 firmware assembly code beautifier"
print ""
print "Copyright (C) 2008 Michael Buesch <[email protected]>"
print "Licensed under the GNU/GPL version 3"
print ""
print "Usage: b43-beautifier [OPTIONS]"
print ""
print "-h|--help Print this help text"
print "-a|--asmfile [FILE] Assembly code source file"
print "-d|--defs [DIR] Directory containing the defs files"
print ""
print "The options -d and -a are essential."
print "The \"include\" directory can be used for --defs"
print("b43 firmware assembly code beautifier")
print("")
print("Copyright (C) 2008 Michael Buesch <[email protected]>")
print("Licensed under the GNU/GPL version 3")
print("")
print("Usage: b43-beautifier [OPTIONS]")
print("")
print("-h|--help Print this help text")
print("-a|--asmfile [FILE] Assembly code source file")
print("-d|--defs [DIR] Directory containing the defs files")
print("")
print("The options -d and -a are essential.")
print("The \"include\" directory can be used for --defs")

def parseArgs():
global opt_asmfile
Expand All @@ -62,19 +62,19 @@ def parseArgs():
opt_defsfiles = v

if not opt_asmfile:
print "Must provide --asmfile"
print("Must provide --asmfile")
sys.exit(1)
if not opt_defsfiles:
print "Must provide --defs"
print("Must provide --defs")
sys.exit(1)

def main():
parseArgs()

try:
asm = file(opt_asmfile).read()
except IOError, e:
print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not read asmfile %s: %s" % (e.filename, e.strerror))
return 1
try:
b = B43Beautifier(asm, opt_defsfiles)
Expand Down
54 changes: 27 additions & 27 deletions debug/b43-fwdump
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
# b43 firmware state dumper
#
Expand All @@ -25,21 +25,21 @@ import re


def usage():
print "b43 firmware state dumper"
print ""
print "Copyright (C) 2008 Michael Buesch <[email protected]>"
print "Licensed under the GNU/GPL version 3"
print ""
print "Usage: b43-fwdump [OPTIONS]"
print ""
print "-h|--help Print this help text"
print "-p|--phy WIPHY The WIPHY to use. For example phy0."
print " Can be omitted, if there is only one device in the system."
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."
print("b43 firmware state dumper")
print("")
print("Copyright (C) 2008 Michael Buesch <[email protected]>")
print("Licensed under the GNU/GPL version 3")
print("")
print("Usage: b43-fwdump [OPTIONS]")
print("")
print("-h|--help Print this help text")
print("-p|--phy WIPHY The WIPHY to use. For example phy0.")
print(" Can be omitted, if there is only one device in the system.")
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():
Expand Down Expand Up @@ -145,29 +145,29 @@ def main():
stdout.write(shm)
sys.exit(0)

print "--- B43 microcode state dump ---"
print "PC: %03X PSM-COND: %04X" % (dbg.getPc(), psmcond)
print "Link registers:"
print("--- B43 microcode state dump ---")
print("PC: %03X PSM-COND: %04X" % (dbg.getPc(), psmcond))
print("Link registers:")
dump_regs("lr", lr)
print "Offset registers:"
print("Offset registers:")
dump_regs("off", off)
print "General purpose registers:"
print("General purpose registers:")
dump_regs("r", gpr)

print "Code:"
print("Code:")
if binary:
try:
bintext = file(binary, "r").read()
except IOError, e:
print "Could not read binary file %s: %s" % (binary, e.strerror)
except IOError as e:
print("Could not read binary file %s: %s" % (binary, e.strerror))
sys.exit(1)
dasm = Disassembler(bintext, dasmopt + " --paddr").getAsm()
print makeShortDump(dasm, dbg.getPc())
print(makeShortDump(dasm, dbg.getPc()))
else:
print "<No binary supplied. See --binary option>"
print("<No binary supplied. See --binary option>")

if dumpShm:
print "Shared memory:"
print("Shared memory:")
ascii = ""
for i in range(0, len(shm)):
if i % 16 == 0 and i != 0:
Expand Down
2 changes: 1 addition & 1 deletion debug/install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Run this script as root to install the debugging tools
#
Expand Down
68 changes: 34 additions & 34 deletions debug/libb43.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ def __init__(self, phy=None):
try:
phys = os.listdir(b43_path)
except OSError:
print "Could not find B43's debugfs directory: %s" % b43_path
print("Could not find B43's debugfs directory: %s" % b43_path)
raise B43Exception
if not phys:
print "Could not find any b43 device"
print("Could not find any b43 device")
raise B43Exception
if len(phys) != 1:
print "Found multiple b43 devices."
print "You must call this tool with a phyX parameter to specify a device"
print("Found multiple b43 devices.")
print("You must call this tool with a phyX parameter to specify a device")
raise B43Exception
phy = phys[0]
b43_path += phy;
Expand All @@ -96,8 +96,8 @@ def __init__(self, phy=None):
self.f_shm16write = file(b43_path + "/shm16write", "w")
self.f_shm32read = file(b43_path + "/shm32read", "r+")
self.f_shm32write = file(b43_path + "/shm32write", "w")
except IOError, e:
print "Could not open debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not open debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception

self.b43_path = b43_path
Expand All @@ -114,7 +114,7 @@ def __debugfs_find(self):
path = m.group(1)
break
if not path:
print "Could not find debugfs in /etc/mtab"
print("Could not find debugfs in /etc/mtab")
raise B43Exception
return path

Expand All @@ -126,8 +126,8 @@ def read16(self, reg):
self.f_mmio16read.flush()
self.f_mmio16read.seek(0)
val = self.f_mmio16read.read()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return int(val, 16)

Expand All @@ -139,8 +139,8 @@ def read32(self, reg):
self.f_mmio32read.flush()
self.f_mmio32read.seek(0)
val = self.f_mmio32read.read()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return int(val, 16)

Expand All @@ -152,8 +152,8 @@ def maskSet16(self, reg, mask, set):
self.f_mmio16write.seek(0)
self.f_mmio16write.write("0x%X 0x%X 0x%X" % (reg, mask, set))
self.f_mmio16write.flush()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return

Expand All @@ -170,8 +170,8 @@ def maskSet32(self, reg, mask, set):
self.f_mmio32write.seek(0)
self.f_mmio32write.write("0x%X 0x%X 0x%X" % (reg, mask, set))
self.f_mmio32write.flush()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return

Expand All @@ -188,8 +188,8 @@ def shmRead16(self, routing, offset):
self.f_shm16read.flush()
self.f_shm16read.seek(0)
val = self.f_shm16read.read()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return int(val, 16)

Expand All @@ -201,8 +201,8 @@ def shmMaskSet16(self, routing, offset, mask, set):
self.f_shm16write.seek(0)
self.f_shm16write.write("0x%X 0x%X 0x%X 0x%X" % (routing, offset, mask, set))
self.f_shm16write.flush()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return

Expand All @@ -219,8 +219,8 @@ def shmRead32(self, routing, offset):
self.f_shm32read.flush()
self.f_shm32read.seek(0)
val = self.f_shm32read.read()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return int(val, 16)

Expand All @@ -232,8 +232,8 @@ def shmMaskSet32(self, routing, offset, mask, set):
self.f_shm32write.seek(0)
self.f_shm32write.write("0x%X 0x%X 0x%X 0x%X" % (routing, offset, mask, set))
self.f_shm32write.flush()
except IOError, e:
print "Could not access debugfs file %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("Could not access debugfs file %s: %s" % (e.filename, e.strerror))
raise B43Exception
return

Expand Down Expand Up @@ -345,9 +345,9 @@ def __init__(self, index, line):
def __init__(self, text, expected_md5sum):
sum = hashlib.md5(text).hexdigest()
if sum != expected_md5sum:
print "Patcher: The text does not match the expected MD5 sum"
print "Expected: " + expected_md5sum
print "Calculated: " + sum
print("Patcher: The text does not match the expected MD5 sum")
print("Expected: " + expected_md5sum)
print("Calculated: " + sum)
raise B43Exception
text = text.splitlines()
self.lines = []
Expand Down Expand Up @@ -375,7 +375,7 @@ def delLine(self, linenumber):
if l.index == linenumber:
l.deleted = True
return
print "Patcher deleteLine: Did not find the line!"
print("Patcher deleteLine: Did not find the line!")
raise B43Exception

def addText(self, beforeLineNumber, text):
Expand All @@ -388,7 +388,7 @@ def addText(self, beforeLineNumber, text):
break
index += 1
if index >= len(self.lines):
print "Patcher addText: Did not find the line!"
print("Patcher addText: Did not find the line!")
raise B43Exception
for l in text:
self.lines.insert(index, TextPatcher.TextLine(-1, l))
Expand All @@ -402,8 +402,8 @@ def __init__(self, header_file):
assembly file containing the symbolic SPR definitions."""
try:
defs = file(header_file).readlines()
except IOError, e:
print "B43SymbolicSpr: Could not read %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("B43SymbolicSpr: Could not read %s: %s" % (e.filename, e.strerror))
B43Exception
# Parse the definitions
self.spr_names = { }
Expand Down Expand Up @@ -438,8 +438,8 @@ def __init__(self, header_file):
assembly file containing the symbolic SHM definitions."""
try:
defs = file(header_file).readlines()
except IOError, e:
print "B43SymbolicShm: Could not read %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("B43SymbolicShm: Could not read %s: %s" % (e.filename, e.strerror))
raise B43Exception
# Parse the definitions
self.shm_names = { }
Expand Down Expand Up @@ -477,8 +477,8 @@ def __init__(self, header_file):
assembly file containing the symbolic condition definitions."""
try:
defs = file(header_file).readlines()
except IOError, e:
print "B43SymbolicCondition: Could not read %s: %s" % (e.filename, e.strerror)
except IOError as e:
print("B43SymbolicCondition: Could not read %s: %s" % (e.filename, e.strerror))
raise B43Exception
# Parse the definitions
self.cond_names = { }
Expand Down
6 changes: 3 additions & 3 deletions debug/patcher-template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
# Copyright (C) 2008 Michael Buesch <[email protected]>
#
Expand All @@ -20,7 +20,7 @@ from libb43 import *


if len(sys.argv) != 3 and len(sys.argv) != 2:
print "Usage: %s INPUT_FILE [OUTPUT_FILE]" % sys.argv[0]
print("Usage: %s INPUT_FILE [OUTPUT_FILE]" % sys.argv[0])
sys.exit(1)

infile = sys.argv[1]
Expand All @@ -43,5 +43,5 @@ try:
sys.stdout.write(p.getText())

except B43Exception:
print "Could not patch. Do you use the correct input file?"
print("Could not patch. Do you use the correct input file?")
sys.exit(1)
Loading