summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libtoprammer/bitfile.py5
-rw-r--r--libtoprammer/chip.py12
-rw-r--r--libtoprammer/toprammer_main.py46
-rwxr-xr-xtests/run-tests.sh11
-rw-r--r--tests/top2049/001-atmega32dip40.test2
-rw-r--r--tests/top2049/002-at89c2051dip20.test2
-rw-r--r--tests/top2049/003-w29ee011dip32.test2
-rwxr-xr-xtoprammer30
-rwxr-xr-xtoprammer-layout6
-rwxr-xr-xtoprammer-unitest8
10 files changed, 68 insertions, 56 deletions
diff --git a/libtoprammer/bitfile.py b/libtoprammer/bitfile.py
index f4e0546..e141602 100644
--- a/libtoprammer/bitfile.py
+++ b/libtoprammer/bitfile.py
@@ -131,8 +131,9 @@ def bitfileFind(filename):
"Search some standard paths for a bitfile"
if not filename.endswith(".bit"):
filename += ".bit"
- if __probeFile(filename):
- return filename
+ if filename.startswith("/"):
+ if __probeFile(filename):
+ return filename
paths = ( ".", "./libtoprammer/bit", )
for path in paths:
fullpath = path + "/" + filename
diff --git a/libtoprammer/chip.py b/libtoprammer/chip.py
index 3998188..3750f61 100644
--- a/libtoprammer/chip.py
+++ b/libtoprammer/chip.py
@@ -188,12 +188,13 @@ class Chip:
registeredChips = []
class RegisteredChip:
- def __init__(self, chipImplClass, bitfile,
+ def __init__(self, chipImplClass, bitfile, chipID="",
description="", packages=None, comment="",
broken=False):
"""Register a chip implementation class.
chipImplClass => The implementation class of the chip.
bitfile => The bitfile ID of the chip.
+ chipID => The chip-ID. Will default to the value of bitfile.
description => Human readable chip description string.
packages => List of supported packages.
Each entry is a tuple of two strings: ("PACKAGE", "description")
@@ -201,8 +202,11 @@ class RegisteredChip:
broken => Boolean flag to mark the implementation as broken.
"""
+ if not chipID:
+ chipID = bitfile
self.chipImplClass = chipImplClass
self.bitfile = bitfile
+ self.chipID = chipID
self.description = description
self.packages = packages
self.comment = comment
@@ -215,10 +219,10 @@ class RegisteredChip:
for chip in registeredChips:
if chip.broken and not allowBroken:
continue
- if chip.bitfile.lower() == chipID.lower():
+ if chip.chipID.lower() == chipID.lower():
instance = chip.chipImplClass()
- instance.setChipID(chip.bitfile)
- return instance
+ instance.setChipID(chip.chipID)
+ return (chip, instance)
return None
@staticmethod
diff --git a/libtoprammer/toprammer_main.py b/libtoprammer/toprammer_main.py
index 05d2196..8192ed0 100644
--- a/libtoprammer/toprammer_main.py
+++ b/libtoprammer/toprammer_main.py
@@ -48,30 +48,18 @@ from chip_w29ee011dip32 import *
class TOP:
- def __init__(self, bitfileName, busDev=None, verbose=0,
+ def __init__(self, busDev=None, verbose=0,
forceLevel=0, noqueue=False, usebroken=False):
- """bitfileName is the path to the .bit file.
- busDev is a tuple (BUSID, DEVID) or None."""
+ """busDev is a tuple (BUSID, DEVID) or None."""
self.verbose = verbose
self.forceLevel = forceLevel
self.noqueue = noqueue
self.usebroken = usebroken
+ self.chip = None
self.commandQueue = []
- self.bitfile = Bitfile()
- self.bitfile.parseFile(bitfileName)
-
- # Find a chip handler for the given bitfile.
- chipID = self.bitfile.getSrcFile().lower()
- if chipID.endswith(".ncd"):
- chipID = chipID[0:-4]
- self.chip = RegisteredChip.find(chipID, usebroken)
- if not self.chip:
- raise TOPException("Did not find an implementation for the chip %s" % chipID)
- self.chip.setTOP(self)
-
# Find the device
for bus in usb.busses():
if busDev and bus.dirname != "%03d" % busDev[0]:
@@ -133,9 +121,32 @@ class TOP:
self.__initializeHardware()
- def shutdown(self):
+ def initializeChip(self, chipID):
+ "Initialize the programmer for a chip"
+ # If a chip is initialized, shut it down first.
+ if self.chip:
+ self.shutdownChip()
+ # Find the implementation of the chip.
+ (descriptor, self.chip) = RegisteredChip.find(chipID, self.usebroken)
+ if not self.chip:
+ raise TOPException("Did not find an implementation for the chip %s" % chipID)
+ self.chip.setTOP(self)
+ # Find the bitfile for the chip.
+ bitfile = bitfileFind(descriptor.bitfile)
+ if not bitfile:
+ self.chip = None
+ raise TOPException("Did not find BIT-file for chip implementation %s" % chipID)
+ # Open and parse the bitfile.
+ self.bitfile = Bitfile()
+ self.bitfile.parseFile(bitfile)
+ # Initialize the hardware.
+ self.__bitfileUpload()
+ self.chip.initializeChip()
+
+ def shutdownChip(self):
self.chip.shutdownChip()
self.flushCommands()
+ self.chip = None
def getForceLevel(self):
return self.forceLevel
@@ -203,9 +214,6 @@ class TOP:
if stat != 0x0000686C:
raise TOPException("Init: Unexpected status register (b): 0x%08X" % stat)
- self.__bitfileUpload()
- self.chip.initializeChip()
-
def __bitfileUpload(self):
self.printDebug("Uploading bitfile %s..." % self.bitfile.getFilename())
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index bee9a36..15af820 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -28,6 +28,12 @@ function error
echo "ERROR $current_test: $@"
}
+function abort
+{
+ cleanup
+ exit 1
+}
+
function die
{
error $@
@@ -79,6 +85,7 @@ function request
{
read -s -n1 -p "$@" res
echo
+ [ "$res" = "a" ] && abort
[ "$res" = "x" ] && return 1
return 0
}
@@ -87,12 +94,12 @@ function request_DUT # $1=DUT-name
{
local dut="$1"
toprammer_layout -d "$current_device" -p "$dut" --only-insert
- request "Please insert a $dut into the ZIF socket (x to skip)..."
+ request "Please insert a $dut into the ZIF socket (x to skip; a to abort)..."
}
function request_TOP # $1=TOPxxxx
{
- request "Please connect the $@ programmer (x to skip)..."
+ request "Please connect the $@ programmer (x to skip; a to abort)..."
}
function create_random_file # $1=file $2=bs $3=count
diff --git a/tests/top2049/001-atmega32dip40.test b/tests/top2049/001-atmega32dip40.test
index 6845c55..cc5f324 100644
--- a/tests/top2049/001-atmega32dip40.test
+++ b/tests/top2049/001-atmega32dip40.test
@@ -8,7 +8,7 @@ function test_init
function test_run
{
- local args="--bitfile atmega32dip40 -I bin -O bin"
+ local args="-c atmega32dip40 -I bin -O bin"
# Check signature
toprammer $args --read-sig "$tmpfile"
diff --git a/tests/top2049/002-at89c2051dip20.test b/tests/top2049/002-at89c2051dip20.test
index 50fa8e6..37bc88b 100644
--- a/tests/top2049/002-at89c2051dip20.test
+++ b/tests/top2049/002-at89c2051dip20.test
@@ -8,7 +8,7 @@ function test_init
function test_run
{
- local args="--bitfile at89c2051dip20 -I bin -O bin"
+ local args="-c at89c2051dip20 -I bin -O bin"
# Check signature
toprammer $args --read-sig "$tmpfile"
diff --git a/tests/top2049/003-w29ee011dip32.test b/tests/top2049/003-w29ee011dip32.test
index 676dd34..385960a 100644
--- a/tests/top2049/003-w29ee011dip32.test
+++ b/tests/top2049/003-w29ee011dip32.test
@@ -8,7 +8,7 @@ function test_init
function test_run
{
- local args="--bitfile w29ee011dip32 -I bin -O bin"
+ local args="-c w29ee011dip32 -I bin -O bin"
toprammer $args --erase
diff --git a/toprammer b/toprammer
index 8e4a738..89cbe3a 100755
--- a/toprammer
+++ b/toprammer
@@ -30,10 +30,8 @@ def usage():
print ""
print "Usage: %s [OPTIONS]" % sys.argv[0]
print ""
- print " -b|--bitfile The *.bit file (mandatory)"
- print " A full path to the bitfile is not required. Specifying the"
- print " chip-ID (see --list) usually is sufficient. The .bit file will"
- print " be searched for in the standard paths then."
+ print " -c|--chip-id The ID of the handled chip. (mandatory)"
+ print " See -t|--list for a list of supported chips."
print ""
print "Actions:"
print " -s|--read-sig FILE Read the signature bytes"
@@ -225,7 +223,7 @@ def fileIn(filename, format):
def main(argv):
opt_verbose = 1
opt_forceLevel = 0
- opt_bitfile = None
+ opt_chipID = None
opt_device = None
opt_action = None
opt_file = None
@@ -235,8 +233,8 @@ def main(argv):
opt_outformat = "bin"
try:
(opts, args) = getopt.getopt(sys.argv[1:],
- "hb:d:V:Qs:xp:P:e:E:f:F:o:l:L:BtI:O:",
- [ "help", "bitfile=", "device=", "verbose=", "noqueue",
+ "hc:d:V:Qs:xp:P:e:E:f:F:o:l:L:BtI:O:",
+ [ "help", "chip-id=", "device=", "verbose=", "noqueue",
"read-sig=", "erase", "read-prog=", "write-prog=",
"read-eeprom=", "write-eeprom=", "read-fuse=", "write-fuse=",
"read-lock=", "write-lock=",
@@ -245,8 +243,8 @@ def main(argv):
if o in ("-h", "--help"):
usage()
return 0
- if o in ("-b", "--bitfile"):
- opt_bitfile = v
+ if o in ("-c", "--chip-id"):
+ opt_chipID = v
if o in ("-t", "--list"):
opt_action = "print-list"
if o in ("-d", "--device"):
@@ -300,8 +298,8 @@ def main(argv):
except (getopt.GetoptError, ValueError), e:
usage()
return 1
- if opt_action and opt_action != "print-list" and not opt_bitfile:
- print "-b|--bitfile is mandatory!"
+ if opt_action and opt_action != "print-list" and not opt_chipID:
+ print "-c|--chip-id is mandatory!"
return 1
if not opt_action:
print "An action is mandatory!"
@@ -318,14 +316,10 @@ def main(argv):
RegisteredChip.dumpAll(sys.stdout, verbose=opt_verbose, showBroken=True)
return 0
- bitfile = bitfileFind(opt_bitfile)
- if not bitfile:
- print "Bitfile " + opt_bitfile + " not found"
- print "See --list for a list of supported devices"
- return 1
- top = TOP(bitfileName = bitfile, busDev = opt_device,
+ top = TOP(busDev = opt_device,
verbose = opt_verbose, forceLevel = opt_forceLevel,
noqueue = opt_noqueue, usebroken = opt_usebroken)
+ top.initializeChip(opt_chipID)
if opt_action == "read-sig":
fileOut(opt_file, opt_outformat, top.readSignature())
elif opt_action == "erase":
@@ -348,7 +342,7 @@ def main(argv):
top.writeLockbits(fileIn(opt_file, opt_informat))
else:
assert(0)
- top.shutdown()
+ top.shutdownChip()
except (TOPException, BitfileException, IOError), e:
print e
return 1
diff --git a/toprammer-layout b/toprammer-layout
index d0f314f..781df92 100755
--- a/toprammer-layout
+++ b/toprammer-layout
@@ -71,8 +71,10 @@ def main(argv):
if o in ("-d", "--device"):
programmer = v
if o in ("-p", "--package"):
- chip = RegisteredChip.find(v)
- if not chip:
+ result = RegisteredChip.find(v)
+ if result:
+ (unused, chip) = result
+ else:
generator = createLayoutGenerator(v)
if o in ("-v", "--vccx"):
vccxPin = int(v)
diff --git a/toprammer-unitest b/toprammer-unitest
index b7803a5..f9e6eae 100755
--- a/toprammer-unitest
+++ b/toprammer-unitest
@@ -31,13 +31,9 @@ class MainWidget(QWidget):
QWidget.__init__(self, mainwnd)
self.mainwnd = mainwnd
- self.bitpath = bitfileFind("unitest.bit")
- if not self.bitpath:
- QMessageBox.critical(self, self.tr("Bitfile not found"),
- self.tr("Could not find the Bitfile unitest.bit"))
- raise TOPException()
try:
- self.top = TOP(bitfileName=self.bitpath, verbose=2)
+ self.top = TOP(verbose=2)
+ self.top.initializeChip("unitest")
except (TOPException), e:
QMessageBox.critical(self, self.tr("TOP init failed"),
self.tr("Initialization of TOP device failed:\n") +\
bues.ch cgit interface