GF32 support in the new goodfet.bsl.
[goodfet] / client / goodfet.bsl
index 8da70fa..5923bd6 100755 (executable)
@@ -19,9 +19,9 @@
 #  - Make actionFromweb use board name to get the right firmware image
 #  - Program saved info after other programming is complete
 #  - Make saveinfo detect missing info (all 0xFF)
+#  - Download image from web before erasing
 # TODO:
 #  - Trim unnecessary BSL unlocks
-#  - Download image from web before erasing
 #  - Add param to override saveinfo with a provided info.txt
 #  - Figure out better way to saveinfo when -P is required
 #  - Maybe use the best guess from contrib/infos/ when nothing better is provided?
@@ -31,7 +31,7 @@
 
 import sys, time, string, cStringIO, struct
 #sys.path.append("/usr/lib/tinyos")  #We no longer require TinyOS.
-import serial, os, glob
+import serial, os, subprocess, glob
 
 #forked from TinyOS Telos version.
 VERSION = string.split("Revision: 1.39-goodfet-8 ")[1] 
@@ -228,9 +228,13 @@ BOARDS = {
     #'apimote1': "apimote1",
     'facedancer10': "facedancer10",
     'facedancer11': "facedancer11",
+    'facedancer20': "facedancer20",
+    'facedancer21': "facedancer21",
     'goodfet11': "goodfet11",
     'goodfet31': "goodfet31",
+    'goodfet32': "goodfet32",
     'goodfet41': "goodfet41",
+    'goodfet42': "goodfet42",
     'goodthopter10': "goodthopter10",
     'goodthopter11': "goodthopter11",
     'telosb': "telosb",
@@ -1289,13 +1293,24 @@ class BootStrapLoader(LowLevel):
         else:
             raise BSLException, "programming without data not possible"
 
-    def actionFromweb(self):
-        """Grab GoodFET firmware from the web, then flash it."""
+    def prepareFromweb(self):
+        """Grab GoodFET firmware from the web."""
         url="%s%s.hex" % (FIRMWARE_BASEURL, self.board);
         print "Grabbing %s firmware from %s" % (self.board, url);
         fn="/tmp/.%s.hex" % self.board
-        os.system("curl %s >%s" % (url,fn))
-        
+       try:
+           subprocess.call(['curl', '-sS', url, '-o', fn])
+       except OSError:
+           print "Failed to run curl, trying wget"
+           try:
+               subprocess.call(['wget', '-nv', url, '-O', fn])
+           except OSError:
+               print "Failed to fetch firmware.  Maybe you need to install curl or wget?"
+               sys.exit()
+
+    def actionFromweb(self):
+        """Flash the GoodFET firmware which has been downloaded in an earlier step."""
+        fn="/tmp/.%s.hex" % self.board
         fw=Memory(fn);
         
         sys.stderr.write("Program ...\n")
@@ -1448,7 +1463,7 @@ General options:
   --slow                Add delays when operating the conrol pins. Useful if
                         the pins/circuit has high capacitance.
   --dumpinfo           Print the info flash timing data so you can save a copy
-                        for later.  You must provide -P if flash is not empty.
+                        for later.  You must provide -P if flash is not        empty.
 
 Program Flow Specifiers:
   -e, --masserase       Mass Erase (clear all flash memory)
@@ -1543,58 +1558,7 @@ def main(itest=1):
     
     bsl.invertRST = 1
     bsl.invertTEST = itest
-    
-    if os.environ.get("board")==None:
-      if board==None:
-       print "Board not specified.  Defaulting to goodfet41.";
-       raw_input("Press Ctrl+C to cancel, or Enter to continue.");
-       board='goodfet41';
-      bsl.board=board;
-    else:
-      bsl.board=None;
-      try:
-       bsl.board=BOARDS[os.environ.get("board").lower()];
-      except:
-        pass;
-    if bsl.board==None:
-      print "Unknown board specified.  Try goodfet41, facedancer11, or similar.";
-      sys.exit(2);
-      
-    if bsl.board=='telosb':
-        bsl.swapRSTTEST = 1
-        bsl.telosI2C = 1
-        mayuseBSL = 0
-    if bsl.board=='z1':
-        bsl.z1 = 1
-    if bsl.board=='apimote':
-        bsl.swapRSTTEST = 1;
-    
-    
-    if comPort is None and os.environ.get("GOODFET")!=None:
-        glob_list = glob.glob(os.environ.get("GOODFET"));
-        if len(glob_list) > 0:
-            comPort = glob_list[0];
-    if comPort is None:
-        glob_list = glob.glob("/dev/tty.usbserial*");
-        if len(glob_list) > 0:
-            comPort = glob_list[0];
-    if comPort is None:
-        glob_list = glob.glob("/dev/ttyUSB*");
-        if len(glob_list) > 0:
-            comPort = glob_list[0];
-    if os.name=='nt':
-            from scanwin32 import winScan;
-            scan=winScan();
-            for order,comport,desc,hwid in sorted(scan.comports()):
-                try:
-                    if hwid.index('FTDI')==0:
-                        comPort=comport;
-                        #print "Using FTDI port %s" % port
-                except:
-                    #Do nothing.
-                    a=1;
-    sys.stderr.write("MSP430 Bootstrap Loader Version: %s\n" % VERSION)
-
+   
     try:
         opts, args = getopt.getopt(sys.argv[1:],
             "hc:P:wf:m:eEpvrg:UDudsxbITNB:S:V14",
@@ -1670,6 +1634,7 @@ def main(itest=1):
         elif o in ("-p", "--program"):
             todo.append(bsl.actionProgram)          #Program file
         elif o in ("--fromweb"):
+            deviceinit.append(bsl.prepareFromweb)         #Download firmware
             deviceinit.append(bsl.actionMassErase)        #Erase Flash
             todo.append(bsl.actionFromweb)          #Program GoodFET code
         elif o in ("-v", "--verify"):
@@ -1756,7 +1721,7 @@ def main(itest=1):
         elif o in ("--goodfet20", ):
             bsl.invertRST = 1
             bsl.invertTEST = 1
-        elif o in ("--goodfet30", "--goodfet31", "--goodthopter" ):
+        elif o in ("--goodfet30", "--goodfet31", "--goodfet32", "--goodthopter" ):
             bsl.invertRST = 1
             bsl.invertTEST = 0
         elif o in ("--goodfet40", ):
@@ -1825,6 +1790,58 @@ def main(itest=1):
         sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n")
         reset = 0
 
+
+    if os.environ.get("board")==None:
+      if board==None:
+       print "Board not specified.  Defaulting to goodfet41.";
+       raw_input("Press Ctrl+C to cancel, or Enter to continue.");
+       board='goodfet41';
+      bsl.board=board;
+    else:
+      bsl.board=None;
+      try:
+       bsl.board=BOARDS[os.environ.get("board").lower()];
+      except:
+        pass;
+    if bsl.board==None:
+      print "Unknown board specified.  Try goodfet41, facedancer11, or similar.";
+      sys.exit(2);
+      
+    if bsl.board=='telosb':
+        bsl.swapRSTTEST = 1
+        bsl.telosI2C = 1
+        mayuseBSL = 0
+    if bsl.board=='z1':
+        bsl.z1 = 1
+    if bsl.board=='apimote':
+        bsl.swapRSTTEST = 1;
+    
+    
+    if comPort is None and os.environ.get("GOODFET")!=None:
+        glob_list = glob.glob(os.environ.get("GOODFET"));
+        if len(glob_list) > 0:
+            comPort = glob_list[0];
+    if comPort is None:
+        glob_list = glob.glob("/dev/tty.usbserial*");
+        if len(glob_list) > 0:
+            comPort = glob_list[0];
+    if comPort is None:
+        glob_list = glob.glob("/dev/ttyUSB*");
+        if len(glob_list) > 0:
+            comPort = glob_list[0];
+    if os.name=='nt':
+            from scanwin32 import winScan;
+            scan=winScan();
+            for order,comport,desc,hwid in sorted(scan.comports()):
+                try:
+                    if hwid.index('FTDI')==0:
+                        comPort=comport;
+                        #print "Using FTDI port %s" % port
+                except:
+                    #Do nothing.
+                    a=1;
+    sys.stderr.write("MSP430 Bootstrap Loader Version: %s\n" % VERSION)
+
     sys.stderr.flush()
     
     #prepare data to download