more upgrade
authorNIIBE Yutaka <gniibe@fsij.org>
Fri, 18 May 2012 10:02:53 +0000 (19:02 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Fri, 18 May 2012 10:02:53 +0000 (19:02 +0900)
src/usb_prop.c
tool/gnuk_upgrade.py

index 7bddfc2..98c29e3 100644 (file)
@@ -228,7 +228,7 @@ gnuk_setup (uint8_t req, uint8_t req_no,
              if (addr < &_regnual_start || addr + len > &__heap_end__)
                return USB_UNSUPPORT;
 
              if (addr < &_regnual_start || addr + len > &__heap_end__)
                return USB_UNSUPPORT;
 
-             if (index == 0)
+             if (index == 0 && len != 256)
                memset (addr, 0, 256);
              usb_lld_set_data_to_recv (addr, len);
              return USB_SUCCESS;
                memset (addr, 0, 256);
              usb_lld_set_data_to_recv (addr, len);
              return USB_SUCCESS;
index 682d877..b9e3757 100755 (executable)
@@ -93,6 +93,33 @@ class gnuk_token:
         end = ((mem[7]*256 + mem[6])*256 + mem[5])*256 + mem[4]
         return (start, end)
 
         end = ((mem[7]*256 + mem[6])*256 + mem[5])*256 + mem[4]
         return (start, end)
 
+    def download(self, start, data):
+        addr = start
+        addr_end = start + len(data)
+        i = (addr - 0x20000000) / 0x100
+        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],
+                                        timeout = 10)
+            i = i+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:],
+                                        timeout = 10)
+
+    def execute(self):
+        self.__devhandle.controlMsg(requestType = 0x40, request = 2,
+                                    value = 0, index = 0, buffer = None,
+                                    timeout = 10)
+
     def icc_get_result(self):
         msg = self.__devhandle.bulkRead(self.__bulkin, 1024, self.__timeout)
         if len(msg) < 10:
     def icc_get_result(self):
         msg = self.__devhandle.bulkRead(self.__bulkin, 1024, self.__timeout)
         if len(msg) < 10:
@@ -242,12 +269,12 @@ def main(passwd, data_regnual, data_upgrade):
     signed = to_string(challenge)
     icc.cmd_external_authenticate(signed)
     icc.stop_icc() # disable all interfaces but control pipe
     signed = to_string(challenge)
     icc.cmd_external_authenticate(signed)
     icc.stop_icc() # disable all interfaces but control pipe
-    mem_info icc.mem_info()
-    print "%08x: %08x" % mem_info
-    # download flash install program
-    # exec
-    # ...
-    print "Downloading flash upgrade program"
+    mem_info icc.mem_info()
+    print "%08x:%08x" % mem_info
+    print "Downloading flash upgrade program..."
+    icc.download(mem_info[0], data_regnual)
+    print "Run flash upgrade program..."
+    icc.execute()
     # Then, send upgrade program...
     print "Downloading the program"
     return 0
     # Then, send upgrade program...
     print "Downloading the program"
     return 0