cleanup for upgrade
This commit is contained in:
@@ -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>
|
2015-09-11 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* tool/upgrade_by_passwd.py (main): Loop until finding reGNUal
|
* tool/upgrade_by_passwd.py (main): Loop until finding reGNUal
|
||||||
|
|||||||
2
chopstx
2
chopstx
Submodule chopstx updated: 4705e2fb15...ae0e475373
15
src/gnuk.h
15
src/gnuk.h
@@ -418,13 +418,14 @@ void flash_do_write_internal (const uint8_t *p, int nr,
|
|||||||
|
|
||||||
extern const uint8_t gnuk_string_serial[];
|
extern const uint8_t gnuk_string_serial[];
|
||||||
|
|
||||||
#define LED_ONESHOT 1
|
#define LED_ONESHOT 1
|
||||||
#define LED_TWOSHOTS 2
|
#define LED_TWOSHOTS 2
|
||||||
#define LED_SHOW_STATUS 4
|
#define LED_SHOW_STATUS 4
|
||||||
#define LED_START_COMMAND 8
|
#define LED_START_COMMAND 8
|
||||||
#define LED_FINISH_COMMAND 16
|
#define LED_FINISH_COMMAND 16
|
||||||
#define LED_FATAL 32
|
#define LED_FATAL 32
|
||||||
#define LED_USB_RESET 64
|
#define LED_USB_RESET 64
|
||||||
|
#define LED_GNUK_EXEC 128
|
||||||
void led_blink (int spec);
|
void led_blink (int spec);
|
||||||
|
|
||||||
#if defined(PINPAD_SUPPORT)
|
#if defined(PINPAD_SUPPORT)
|
||||||
|
|||||||
17
src/main.c
17
src/main.c
@@ -210,13 +210,8 @@ static eventmask_t emit_led (int on_time, int off_time)
|
|||||||
|
|
||||||
static eventmask_t display_status_code (void)
|
static eventmask_t display_status_code (void)
|
||||||
{
|
{
|
||||||
enum icc_state icc_state;
|
|
||||||
eventmask_t m;
|
eventmask_t m;
|
||||||
|
enum icc_state icc_state = *icc_state_p;
|
||||||
if (icc_state_p == NULL)
|
|
||||||
icc_state = ICC_STATE_START;
|
|
||||||
else
|
|
||||||
icc_state = *icc_state_p;
|
|
||||||
|
|
||||||
if (icc_state == ICC_STATE_START)
|
if (icc_state == ICC_STATE_START)
|
||||||
return emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP);
|
return emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP);
|
||||||
@@ -331,8 +326,8 @@ main (int argc, char *argv[])
|
|||||||
stdout_init ();
|
stdout_init ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid,
|
ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid, __stacksize_ccid,
|
||||||
__stacksize_ccid, USBthread, NULL);
|
USBthread, NULL);
|
||||||
|
|
||||||
#ifdef PINPAD_CIR_SUPPORT
|
#ifdef PINPAD_CIR_SUPPORT
|
||||||
cir_init ();
|
cir_init ();
|
||||||
@@ -358,9 +353,6 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
eventmask_t m;
|
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);
|
m = eventflag_wait_timeout (&led_event, MAIN_TIMEOUT_INTERVAL);
|
||||||
got_it:
|
got_it:
|
||||||
count++;
|
count++;
|
||||||
@@ -398,6 +390,8 @@ main (int argc, char *argv[])
|
|||||||
ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid,
|
ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid,
|
||||||
__stacksize_ccid, USBthread, NULL);
|
__stacksize_ccid, USBthread, NULL);
|
||||||
break;
|
break;
|
||||||
|
case LED_GNUK_EXEC:
|
||||||
|
goto exec;
|
||||||
default:
|
default:
|
||||||
if ((m = emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP)))
|
if ((m = emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP)))
|
||||||
goto got_it;
|
goto got_it;
|
||||||
@@ -415,6 +409,7 @@ main (int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec:
|
||||||
random_fini ();
|
random_fini ();
|
||||||
|
|
||||||
set_led (1);
|
set_led (1);
|
||||||
|
|||||||
@@ -179,8 +179,6 @@ struct icc_header {
|
|||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
|
||||||
enum icc_state *icc_state_p;
|
|
||||||
|
|
||||||
/* Data structure handled by CCID layer */
|
/* Data structure handled by CCID layer */
|
||||||
struct ccid {
|
struct ccid {
|
||||||
enum icc_state icc_state;
|
enum icc_state icc_state;
|
||||||
@@ -1297,6 +1295,7 @@ icc_handle_timeout (struct ccid *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct ccid ccid;
|
static struct ccid ccid;
|
||||||
|
enum icc_state *icc_state_p = &ccid.icc_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another Tx done callback
|
* Another Tx done callback
|
||||||
@@ -1458,6 +1457,5 @@ ccid_thread (chopstx_t thd)
|
|||||||
c->application = 0;
|
c->application = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
icc_state_p = NULL;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 (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;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (addr < &_regnual_start || addr + detail->len > __heap_end__)
|
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)
|
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;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (((uint32_t)addr & 0x03))
|
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 (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;
|
return;
|
||||||
|
|
||||||
(void)value; (void)index;
|
(void)value; (void)index;
|
||||||
usb_lld_prepare_shutdown (); /* No further USB communication */
|
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
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
|
|||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
print("Wait 3 seconds...")
|
|
||||||
time.sleep(3)
|
|
||||||
# Then, send upgrade program...
|
# Then, send upgrade program...
|
||||||
mem_info = reg.mem_info()
|
mem_info = reg.mem_info()
|
||||||
print("%08x:%08x" % 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
|
from getpass import getpass
|
||||||
|
|
||||||
# This should be event driven, not guessing some period.
|
# This should be event driven, not guessing some period, or polling.
|
||||||
DEFAULT_WAIT_FOR_REENUMERATION=3
|
DEFAULT_WAIT_FOR_REENUMERATION=1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):
|
if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):
|
||||||
|
|||||||
Reference in New Issue
Block a user