From a15a0a6e91c75381c42b92bddede647cb21c1a6f Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Tue, 9 Feb 2010 00:03:19 +0100 Subject: Add lock bit support Signed-off-by: Michael Buesch --- chip.py | 8 ++++++++ chip_atmega8dip28.py | 27 +++++++++++++++++++++++++++ toprammer | 29 ++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/chip.py b/chip.py index 96ded13..568dc6e 100644 --- a/chip.py +++ b/chip.py @@ -96,6 +96,14 @@ class Chip: # Override me in the subclass, if required. raise TOPException("Fuse writing not supported on " + self.chipID) + def readLockbits(self): + # Override me in the subclass, if required. + raise TOPException("Lockbit reading not supported on " + self.chipID) + + def writeLockbits(self, image): + # Override me in the subclass, if required. + raise TOPException("Lockbit writing not supported on " + self.chipID) + def chipFind(chipID): for chip in supportedChips: if chip.getID().lower() == chipID.lower(): diff --git a/chip_atmega8dip28.py b/chip_atmega8dip28.py index b5f4776..cc4d9cb 100644 --- a/chip_atmega8dip28.py +++ b/chip_atmega8dip28.py @@ -140,6 +140,7 @@ class ATMega8DIP28(Chip): self.__pulseWR() self.__waitForRDY() self.top.unblockCommands() + self.printInfo("100%") def readEEPROM(self): self.__checkDUTPresence() @@ -225,6 +226,32 @@ class ATMega8DIP28(Chip): self.top.unblockCommands() self.printInfo("100%") + def readLockbits(self): + self.__checkDUTPresence() + self.__initPins() + + self.printInfo("Reading lock bits...", newline=False) + (fuses, lockbits) = self.__readFuseAndLockBits() + self.printInfo("100%") + + return lockbits + + def writeLockbits(self, image): + if len(image) != 1: + self.throwError("Invalid lock-bits image size %d (expected %d)" %\ + (len(image), 1)) + self.__checkDUTPresence() + self.__initPins() + + self.printInfo("Writing lock bits...", newline=False) + self.top.blockCommands() + self.__loadCommand(self.CMD_WRITELOCK) + self.__loadDataLow(ord(image[0])) + self.__pulseWR() + self.__waitForRDY() + self.top.unblockCommands() + self.printInfo("100%") + def __readSigAndCalib(self): """Reads the signature and calibration bytes and returns them. This function expects a DUT present and pins initialized.""" diff --git a/toprammer b/toprammer index c70a58f..69f4fb2 100755 --- a/toprammer +++ b/toprammer @@ -257,6 +257,19 @@ class TOP: self.chip.writeFuse(image) self.printDebug("Done writing image.") + def readLockbits(self): + """Reads the Lock bits image and returns it.""" + self.printDebug("Reading lock-bits from chip...") + image = self.chip.readLockbits() + self.printDebug("Done reading %d bytes." % len(image)) + return image + + def writeLockbits(self, image): + """Writes a Lock bits image to the chip.""" + self.printDebug("Writing %d bytes of lock-bits to chip..." % len(image)) + self.chip.writeLockbits(image) + self.printDebug("Done writing image.") + def cmdFlush(self, count=1): """Send 'count' flush requests.""" assert(count >= 1) @@ -434,6 +447,9 @@ def usage(): print " -f|--read-fuse FILE Read the fuse bits" print " -F|--write-fuse FILE Write the fuse bits" print "" + print " -l|--read-lock FILE Read the lock bits" + print " -L|--write-lock FILE Write the lock bits" + print "" print "Optional:" print " -d|--device BUS.DEV Use the programmer at BUS.DEV" print " First found programmer is used, if not given." @@ -464,10 +480,11 @@ def main(argv): opt_noqueue = False try: (opts, args) = getopt.getopt(sys.argv[1:], - "hb:d:V:Qs:xp:P:e:E:f:F:o:", + "hb:d:V:Qs:xp:P:e:E:f:F:o:l:L:", [ "help", "bitfile=", "device=", "verbose=", "noqueue", "read-sig=", "erase", "read-prog=", "write-prog=", "read-eeprom=", "write-eeprom=", "read-fuse=", "write-fuse=", + "read-lock=", "write-lock=", "force=", ]) for (o, v) in opts: if o in ("-h", "--help"): @@ -511,6 +528,12 @@ def main(argv): if o in ("-f", "--read-fuse"): opt_action = "read-fuse" opt_file = v + if o in ("-l", "--read-lock"): + opt_action = "read-lock" + opt_file = v + if o in ("-L", "--write-lock"): + opt_action = "write-lock" + opt_file = v except (getopt.GetoptError, ValueError), e: usage() return 1 @@ -541,6 +564,10 @@ def main(argv): fileOut(opt_file, top.readFuse()) elif opt_action == "write-fuse": top.writeFuse(fileIn(opt_file)) + elif opt_action == "read-lock": + fileOut(opt_file, top.readLockbits()) + elif opt_action == "write-lock": + top.writeLockbits(fileIn(opt_file)) else: assert(0) top.shutdown() -- cgit v1.2.3