upgrade: gnuk side working now
This commit is contained in:
@@ -114,7 +114,7 @@ SECTIONS
|
||||
|
||||
PROVIDE(end = .);
|
||||
_end = .;
|
||||
. = ALIGN(256);
|
||||
. = ALIGN(512);
|
||||
_regnual_start = .;
|
||||
|
||||
@CERTDO_SUPPORT_START@
|
||||
|
||||
17
src/main.c
17
src/main.c
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "gnuk.h"
|
||||
#include "usb_lld.h"
|
||||
#include "usb-cdc.h"
|
||||
@@ -473,9 +474,23 @@ main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
usb_lld_shutdown ();
|
||||
/* erase by mass erase */
|
||||
USB_Cable_Config (0);
|
||||
set_led (1);
|
||||
chThdSleep (MS2ST (100));
|
||||
port_disable ();
|
||||
/* set vector */
|
||||
SCB->VTOR = (uint32_t)&_regnual_start;
|
||||
#if 0
|
||||
/* SYSRESETREQ to invoke regnual */
|
||||
NVIC_SystemReset ();
|
||||
#else
|
||||
{
|
||||
/* Not yet: erase by mass erase and go to entry */
|
||||
void (**func)(void) = (void (**)(void))(&_regnual_start + 4);
|
||||
|
||||
(**func) ();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ static const uint8_t data_rate_table[] = { 0x80, 0x25, 0, 0, }; /* dwDataRate */
|
||||
static const uint8_t lun_table[] = { 0, 0, 0, 0, };
|
||||
#endif
|
||||
|
||||
static const uint8_t *mem_info[] = { &_regnual_start, &__heap_end__, };
|
||||
static const uint8_t *const mem_info[] = { &_regnual_start, &__heap_end__, };
|
||||
|
||||
#define USB_FSIJ_GNUK_MEMINFO 0
|
||||
#define USB_FSIJ_GNUK_DOWNLOAD 1
|
||||
@@ -197,6 +197,14 @@ static const uint8_t *mem_info[] = { &_regnual_start, &__heap_end__, };
|
||||
|
||||
static int download_check_crc32 (const uint8_t *p)
|
||||
{
|
||||
uint32_t crc32 = 0;
|
||||
|
||||
crc32 += (*--p << 24);
|
||||
crc32 += (*--p << 16);
|
||||
crc32 += (*--p << 8);
|
||||
crc32 += (*--p);
|
||||
|
||||
/* Not yet: Calculate crc32 from &_regnual_start to p, then compare */
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -238,7 +246,7 @@ gnuk_setup (uint8_t req, uint8_t req_no,
|
||||
if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED)
|
||||
return USB_UNSUPPORT;
|
||||
|
||||
/* There is a trailer at addr: size, crc32 */
|
||||
/* There is a trailer at addr: crc32 */
|
||||
return download_check_crc32 (addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,29 +95,33 @@ class gnuk_token:
|
||||
|
||||
def download(self, start, data):
|
||||
addr = start
|
||||
addr_end = start + len(data)
|
||||
addr_end = (start + len(data)) & 0xffffff00
|
||||
i = (addr - 0x20000000) / 0x100
|
||||
j = 0
|
||||
print "start %08x" % addr
|
||||
print "end %08x" % addr_end
|
||||
while addr < addr_end:
|
||||
print "# %08x: %d : %d" % (addr, i, 256)
|
||||
self.__devhandle.controlMsg(requestType = 0x40, request = 1,
|
||||
value = i, index = 0,
|
||||
buffer = data[i*256:i*256+256],
|
||||
buffer = data[j*256:j*256+256],
|
||||
timeout = 10)
|
||||
i = i+1
|
||||
j = j+1
|
||||
addr = addr + 256
|
||||
residue = len(data) % 256
|
||||
if residue != 0:
|
||||
print "# %08x: %d : %d" % (addr, i, residue)
|
||||
self.__devhandle.controlMsg(requestType = 0x40, request = 1,
|
||||
value = i, index = 0,
|
||||
buffer = data[i*256:],
|
||||
buffer = data[j*256:],
|
||||
timeout = 10)
|
||||
|
||||
def execute(self):
|
||||
def execute(self, last_addr):
|
||||
i = (last_addr - 0x20000000) / 0x100
|
||||
o = (last_addr - 0x20000000) % 0x100
|
||||
self.__devhandle.controlMsg(requestType = 0x40, request = 2,
|
||||
value = 0, index = 0, buffer = None,
|
||||
value = i, index = o, buffer = None,
|
||||
timeout = 10)
|
||||
|
||||
def icc_get_result(self):
|
||||
@@ -254,6 +258,8 @@ def to_string(t):
|
||||
return result
|
||||
|
||||
def main(passwd, data_regnual, data_upgrade):
|
||||
data_regnual += pack('<i', binascii.crc32(data_regnual))
|
||||
|
||||
dev, config, intf = get_device()
|
||||
print "Device: ", dev.filename
|
||||
print "Configuration: ", config.value
|
||||
@@ -274,9 +280,9 @@ def main(passwd, data_regnual, data_upgrade):
|
||||
print "Downloading flash upgrade program..."
|
||||
icc.download(mem_info[0], data_regnual)
|
||||
print "Run flash upgrade program..."
|
||||
icc.execute()
|
||||
icc.execute(mem_info[1] + len(data_regnual))
|
||||
# Then, send upgrade program...
|
||||
print "Downloading the program"
|
||||
print "NOT YET: Downloading the program"
|
||||
return 0
|
||||
|
||||
DEFAULT_PW3 = "12345678"
|
||||
|
||||
Reference in New Issue
Block a user