fix stlinkv2.py
authorNIIBE Yutaka <gniibe@fsij.org>
Tue, 18 Sep 2012 06:32:12 +0000 (15:32 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Tue, 18 Sep 2012 06:32:12 +0000 (15:32 +0900)
ChangeLog
doc/note/firmware-update
tool/stlinkv2.py

index 8cb5d48..8261f7c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-09-18  Niibe Yutaka  <gniibe@fsij.org>
+
+       * tool/stlinkv2.py (stlinkv2.option_bytes_erase)
+       (stlinkv2.flash_erase_all, stlinkv2.flash_erase_page): : Fix
+       OperationFailure (was OperationError).
+       (main): Call option_bytes_erase if it's not 0xff.
+
 2012-09-12  Niibe Yutaka  <gniibe@fsij.org>
 
        * src/sha256.c: Include <stdint.h>.
index 52ff93f..686bae7 100644 (file)
@@ -38,14 +38,12 @@ We can examine key information of gpg-agent by "KEYINFO" command.
 Here is my example::
 
    $ gpg-connect-agent "KEYINFO --list" /bye
-   S KEYINFO 4970A0D537CA2EF7CE6A106E47AD89B0EFB684C8 D - - - - -
    S KEYINFO 65F67E742101C7FE6D5B33FCEFCF4F65EAF0688C T D276000124010200F517000000010000 OPENPGP.2 - - -
-   S KEYINFO 5D6C89682D07CCFC034AF508420BF2276D8018ED T D276000124010200F517000000010000 OPENPGP.3 - - -
-   S KEYINFO 7D180C0C2A991B25204110A92F5F92A5A509845B D - - - - -
    S KEYINFO 101DE7B639FE29F4636BDEECF442A9273AFA6565 T D276000124010200F517000000010000 OPENPGP.1 - - -
+   S KEYINFO 5D6C89682D07CCFC034AF508420BF2276D8018ED T D276000124010200F517000000010000 OPENPGP.3 - - -
    OK
 
-I have two local keys (in my PC) and three keys in my token.
+I have three keys in my token.
 
 With the script below, I extract public key of the keygrip
 5D6C89682D07CCFC034AF508420BF2276D8018ED into the file: 5D6C8968.bin::
@@ -63,7 +61,7 @@ Here is the script, get_public_key.py::
        result = check_output(["gpg-connect-agent", "READKEY %s" % keygrip, "/bye"])
        key = ""
        while True:
-              i = result.find('%')
+           i = result.find('%')
            if i < 0:
                key += result
                break
index d2af143..a14a986 100755 (executable)
@@ -356,7 +356,7 @@ class stlinkv2(object):
 
         self.write_memory_u32(FLASH_CR, FLASH_CR_LOCK)
        if (status & FLASH_SR_EOP) == 0:
-            raise OperationError("option bytes erase")
+            raise OperationFailure("option bytes erase")
 
     def flash_write_internal(self, addr, data, off, size):
         prog = gen_prog_flash_write(addr,size)
@@ -415,7 +415,7 @@ class stlinkv2(object):
         self.write_memory_u32(FLASH_CR, FLASH_CR_LOCK)
 
        if (status & FLASH_SR_EOP) == 0:
-            raise OperationError("flash erase all")
+            raise OperationFailure("flash erase all")
 
     def flash_erase_page(self, addr):
         self.write_memory_u32(FLASH_KEYR, FLASH_KEY1)
@@ -439,7 +439,7 @@ class stlinkv2(object):
         self.write_memory_u32(FLASH_CR, FLASH_CR_LOCK)
 
        if (status & FLASH_SR_EOP) == 0:
-            raise OperationError("flash page erase")
+            raise OperationFailure("flash page erase")
 
     def start(self):
         mode = self.stl_mode()
@@ -564,6 +564,9 @@ def main(show_help, erase_only, no_protect, spi_flash_check,
     stl.setup_gpio()
 
     if unlock:
+        if option_bytes != 0xff:
+            stl.reset_sys()
+            stl.option_bytes_erase()
         stl.reset_sys()
         stl.option_bytes_write(OPTION_BYTES_ADDR,RDP_KEY)
         stl.usb_disconnect()