cleanup for upgrade
authorNIIBE Yutaka <gniibe@fsij.org>
Mon, 14 Sep 2015 09:41:28 +0000 (18:41 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Mon, 14 Sep 2015 09:41:28 +0000 (18:41 +0900)
ChangeLog
chopstx
src/gnuk.h
src/main.c
src/usb-icc.c
src/usb_ctrl.c
tool/upgrade_by_passwd.py

index 4878b58..4813d71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-09-14  Niibe Yutaka  <gniibe@fsij.org>
+
+       * src/gnuk.h (LED_GNUK_EXEC): New.
+       * src/main.c, src/usb-icc.c, src/usb_ctrl.c: icc_state_p access
+       clean up.
+
 2015-09-11  Niibe Yutaka  <gniibe@fsij.org>
 
        * tool/upgrade_by_passwd.py (main): Loop until finding reGNUal
diff --git a/chopstx b/chopstx
index 4705e2f..ae0e475 160000 (submodule)
--- a/chopstx
+++ b/chopstx
@@ -1 +1 @@
-Subproject commit 4705e2fb15ae58cc47a3df100949b07931d53526
+Subproject commit ae0e47537372ba86a39bb5cfe3313914b47db99d
index 80ac338..9cf95e8 100644 (file)
@@ -418,13 +418,14 @@ void flash_do_write_internal (const uint8_t *p, int nr,
 
 extern const uint8_t gnuk_string_serial[];
 
-#define LED_ONESHOT             1
-#define LED_TWOSHOTS            2
-#define LED_SHOW_STATUS                 4
-#define LED_START_COMMAND       8
-#define LED_FINISH_COMMAND     16
-#define LED_FATAL              32
-#define LED_USB_RESET          64
+#define LED_ONESHOT              1
+#define LED_TWOSHOTS             2
+#define LED_SHOW_STATUS                  4
+#define LED_START_COMMAND        8
+#define LED_FINISH_COMMAND      16
+#define LED_FATAL               32
+#define LED_USB_RESET           64
+#define LED_GNUK_EXEC          128
 void led_blink (int spec);
 
 #if defined(PINPAD_SUPPORT)
index b9d553a..ee40094 100644 (file)
@@ -210,13 +210,8 @@ static eventmask_t emit_led (int on_time, int off_time)
 
 static eventmask_t display_status_code (void)
 {
-  enum icc_state icc_state;
   eventmask_t m;
-
-  if (icc_state_p == NULL)
-    icc_state = ICC_STATE_START;
-  else
-    icc_state = *icc_state_p;
+  enum icc_state icc_state = *icc_state_p;
 
   if (icc_state == ICC_STATE_START)
     return emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP);
@@ -331,8 +326,8 @@ main (int argc, char *argv[])
   stdout_init ();
 #endif
 
-  ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid,
-                            __stacksize_ccid, USBthread, NULL);
+  ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid, __stacksize_ccid,
+                            USBthread, NULL);
 
 #ifdef PINPAD_CIR_SUPPORT
   cir_init ();
@@ -358,9 +353,6 @@ main (int argc, char *argv[])
     {
       eventmask_t m;
 
-      if (icc_state_p != NULL && *icc_state_p == ICC_STATE_EXEC_REQUESTED)
-       break;
-
       m = eventflag_wait_timeout (&led_event, MAIN_TIMEOUT_INTERVAL);
     got_it:
       count++;
@@ -398,6 +390,8 @@ main (int argc, char *argv[])
          ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid,
                                     __stacksize_ccid, USBthread, NULL);
          break;
+       case LED_GNUK_EXEC:
+         goto exec;
        default:
          if ((m = emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP)))
            goto got_it;
@@ -415,6 +409,7 @@ main (int argc, char *argv[])
 #endif
     }
 
+ exec:
   random_fini ();
 
   set_led (1);
index 15e90a7..9244982 100644 (file)
@@ -179,8 +179,6 @@ struct icc_header {
 } __attribute__((packed));
 
 
-enum icc_state *icc_state_p;
-
 /* Data structure handled by CCID layer */
 struct ccid {
   enum icc_state icc_state;
@@ -1297,6 +1295,7 @@ icc_handle_timeout (struct ccid *c)
 }
 
 static struct ccid ccid;
+enum icc_state *icc_state_p = &ccid.icc_state;
 
 /*
  * Another Tx done callback
@@ -1458,6 +1457,5 @@ ccid_thread (chopstx_t thd)
       c->application = 0;
     }
 
-  icc_state_p = NULL;
   return NULL;
 }
index b8d5122..0d69f05 100644 (file)
@@ -280,7 +280,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
 
          if (req_no == USB_FSIJ_GNUK_DOWNLOAD)
            {
-             if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED)
+             if (*icc_state_p != ICC_STATE_EXITED)
                return USB_UNSUPPORT;
 
              if (addr < &_regnual_start || addr + detail->len > __heap_end__)
@@ -294,7 +294,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
            }
          else if (req_no == USB_FSIJ_GNUK_EXEC && detail->len == 0)
            {
-             if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED)
+             if (*icc_state_p != ICC_STATE_EXITED)
                return USB_UNSUPPORT;
 
              if (((uint32_t)addr & 0x03))
@@ -398,12 +398,12 @@ usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
     {
       if (USB_SETUP_SET (req) && req_no == USB_FSIJ_GNUK_EXEC)
        {
-         if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED)
+         if (*icc_state_p != ICC_STATE_EXITED)
            return;
 
          (void)value; (void)index;
          usb_lld_prepare_shutdown (); /* No further USB communication */
-         *icc_state_p = ICC_STATE_EXEC_REQUESTED;
+         led_blink (LED_GNUK_EXEC);    /* Notify the main.  */
        }
     }
 #ifdef HID_CARD_CHANGE_SUPPORT
index 244c5d0..ba03234 100755 (executable)
@@ -78,8 +78,6 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
                 break
             except:
                 pass
-    print("Wait 3 seconds...")
-    time.sleep(3)
     # Then, send upgrade program...
     mem_info = reg.mem_info()
     print("%08x:%08x" % mem_info)
@@ -92,8 +90,8 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
 
 from getpass import getpass
 
-# This should be event driven, not guessing some period.
-DEFAULT_WAIT_FOR_REENUMERATION=3
+# This should be event driven, not guessing some period, or polling.
+DEFAULT_WAIT_FOR_REENUMERATION=1
 
 if __name__ == '__main__':
     if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):