fix tool/upgrade_by_passwd.py
authorNIIBE Yutaka <gniibe@fsij.org>
Fri, 11 Sep 2015 06:04:15 +0000 (15:04 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Fri, 11 Sep 2015 08:09:28 +0000 (17:09 +0900)
ChangeLog
chopstx
tool/upgrade_by_passwd.py

index c228342..4878b58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-11  Niibe Yutaka  <gniibe@fsij.org>
+
+       * tool/upgrade_by_passwd.py (main): Loop until finding reGNUal
+       device.
+
 2015-09-10  Niibe Yutaka  <gniibe@fsij.org>
 
        * src/call-rsa.c (rsa_cleanup): New.
diff --git a/chopstx b/chopstx
index acd4460..14ad395 160000 (submodule)
--- a/chopstx
+++ b/chopstx
@@ -1 +1 @@
-Subproject commit acd4460a6ee0f7caa1d7871acd51cdcf6bb4264c
+Subproject commit 14ad39552361815e17ddf9764228a093489555f7
index 3992f9c..244c5d0 100755 (executable)
@@ -32,7 +32,7 @@ BY_ADMIN = 3
 
 KEYNO_FOR_AUTH=2 
 
-def main(keyno, passwd, data_regnual, data_upgrade):
+def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
     l = len(data_regnual)
     if (l & 0x03) != 0:
         data_regnual = data_regnual.ljust(l + 4 - (l & 0x03), chr(0))
@@ -67,17 +67,20 @@ def main(keyno, passwd, data_regnual, data_upgrade):
     del gnuk
     gnuk = None
     #
+    reg = None
+    while reg == None:
+        print("Wait %d seconds..." % wait_e)
+        time.sleep(wait_e)
+        for dev in gnuk_devices_by_vidpid():
+            try:
+                reg = regnual(dev)
+                print("Device: %s" % dev.filename)
+                break
+            except:
+                pass
     print("Wait 3 seconds...")
     time.sleep(3)
     # Then, send upgrade program...
-    reg = None
-    for dev in gnuk_devices_by_vidpid():
-        try:
-            reg = regnual(dev)
-            print("Device: %s" % dev.filename)
-            break
-        except:
-            pass
     mem_info = reg.mem_info()
     print("%08x:%08x" % mem_info)
     print("Downloading the program")
@@ -89,6 +92,9 @@ def main(keyno, passwd, data_regnual, data_upgrade):
 
 from getpass import getpass
 
+# This should be event driven, not guessing some period.
+DEFAULT_WAIT_FOR_REENUMERATION=3
+
 if __name__ == '__main__':
     if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):
         print("Please change working directory to: %s" % os.path.dirname(os.path.abspath(__file__)))
@@ -96,11 +102,15 @@ if __name__ == '__main__':
 
     keyno = 0
     passwd = None
+    wait_e = DEFAULT_WAIT_FOR_REENUMERATION
     while len(sys.argv) > 3:
         option = sys.argv[1]
         sys.argv.pop(1)
         if option == '-f':      # F for Factory setting
             passwd = DEFAULT_PW3
+        elif option == '-e':    # E for Enumeration
+            wait_e = int(sys.argv[1])
+            sys.argv.pop(1)
         elif option == '-k':    # K for Key number
             keyno = int(sys.argv[1])
             sys.argv.pop(1)
@@ -119,4 +129,4 @@ if __name__ == '__main__':
     f.close()
     print("%s: %d" % (filename_upgrade, len(data_upgrade)))
     # First 4096-byte in data_upgrade is SYS, so, skip it.
-    main(keyno, passwd, data_regnual, data_upgrade[4096:])
+    main(wait_e, keyno, passwd, data_regnual, data_upgrade[4096:])