Hi,

I needed to be able to selectively erase the "info" flash memory
segments and ended up with the following patch. It also fixes a couple
of typos. I'm not sure it's a good idea to hardcode the info memory
segment addresses though...


RCS file: /cvsroot/mspgcc/pyjtag/jtag.py,v
retrieving revision 1.12
diff -u -5 -p -r1.12 jtag.py
--- jtag.py	2 Jun 2003 00:03:44 -0000	1.12
+++ jtag.py	26 Jun 2003 17:04:18 -0000
@@ -243,10 +243,20 @@ class JTAG:
     def actionMainErase(self):
         """Erase the MAIN flash memory, leave the INFO mem"""
         sys.stderr.write("Erase Main Flash...\n")
         _parjtag.memerase(ERASE_MAIN, 0xfffe)
 
+    def makeActionSegmentErase(self, address):
+        """Selective segment erase"""
+        class SegmentEraser:
+            def __init__(self, segaddr):
+                self.address = segaddr
+            def __call__(self):
+                sys.stderr.write("Erase Segment @ 0x%04x...\n" % self.address)
+                _parjtag.memerase(ERASE_SGMT, self.address)
+        return SegmentEraser(address)
+
     def actionEraseCheck(self):
         """check the erasure of required flash cells."""
         sys.stderr.write("Erase Check by file ...\n")
         if self.data is not None:
             for seg in self.data:
@@ -327,12 +337,14 @@ General options:
 
 Program Flow Specifiers:
 
   -e, --masserase       Mass Erase (clear all flash memory)
   -m, --mainerase       Erase main flash memory only
+  --eraseinfo           Erase info flash memory only
+  --erase=address       Selectively erase segment at the specified address
   -E, --erasecheck      Erase Check by file
-  -p, --programm        Program file
+  -p, --program         Program file
   -v, --verify          Verify by file
 
 The order of the above options matters! The table is ordered by normal
 execution order. For the options "Epv" a file must be specified.
 Program flow specifiers default to "p" if a file is given.
@@ -383,11 +395,12 @@ def main():
     sys.stderr.write("MSP430 parallel JTAG programmer Version: %s\n" % VERSION)
     try:
         opts, args = getopt.getopt(sys.argv[1:],
             "hl:weEmpvrg:Du:d:s:xbiITfR:S",
             ["help", "lpt=", "wait"
-             "masserase", "erasecheck", "mainerase", "programm",
+             "masserase", "erasecheck", "mainerase", "erase=",
+             "eraseinfo", "program",
              "verify", "reset", "go=", "debug",
              "upload=", "download=", "size=", "hex", "bin", "ihex",
              "intelhex", "titext", "funclet", "ramsize=", "progress"]
         )
     except getopt.GetoptError:
@@ -407,11 +420,21 @@ def main():
             toinit.append(jtag.actionMassErase)         #Erase Flash
         elif o in ("-E", "--erasecheck"):
             toinit.append(jtag.actionEraseCheck)        #Erase Check (by file)
         elif o in ("-m", "--mainerase"):
             toinit.append(jtag.actionMainErase)         #Erase main Flash
-        elif o in ("-p", "--programm"):
+        elif o == "--erase":
+            try:
+                seg = int(a, 0)
+                toinit.append(jtag.makeActionSegmentErase(seg))
+            except ValueError:
+                sys.stderr.write("segment address must be a valid number in dec, hex or octal\n")                
+                sys.exit(2)
+        elif o == "--eraseinfo":
+            toinit.append(jtag.makeActionSegmentErase(0x1000))
+            toinit.append(jtag.makeActionSegmentErase(0x1080))
+        elif o in ("-p", "--program"):
             todo.append(jtag.actionProgram)             #Program file
         elif o in ("-v", "--verify"):
             todo.append(jtag.actionVerify)              #Verify file
         elif o in ("-r", "--reset"):
             reset = 1

Best wishes,
   --Daniel

Reply via email to