[Cryptech-Commits] [sw/stm32] 02/02: Bugfix erasing sector 0.

git at cryptech.is git at cryptech.is
Sat May 21 12:40:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

fredrik at thulin.net pushed a commit to branch master
in repository sw/stm32.

commit fd60daaeb372759f2990f059ce027616439fac28
Author: Fredrik Thulin <fredrik at thulin.net>
AuthorDate: Sat May 21 14:40:32 2016 +0200

    Bugfix erasing sector 0.
---
 stm-fpgacfg.c  | 10 ++++++----
 stm-keystore.c | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/stm-fpgacfg.c b/stm-fpgacfg.c
index 9e2a307..6f6114d 100644
--- a/stm-fpgacfg.c
+++ b/stm-fpgacfg.c
@@ -94,19 +94,21 @@ int fpgacfg_check_done(void)
 
 int fpgacfg_erase_sectors(int num)
 {
-    if (num > N25Q128_NUM_SECTORS - 1 || num < 0) num = N25Q128_NUM_SECTORS - 1;
+    if (num > N25Q128_NUM_SECTORS || num < 0) num = N25Q128_NUM_SECTORS;
     while (num) {
-	int timeout = 1000;
+	int timeout = 200; /* times 10ms = 2 seconds timeout */
 	while (timeout--) {
 	    int i = n25q128_get_wip_flag(&fpgacfg_ctx);
 	    if (i < 0) return 0;
 	    if (! i) break;
 	    HAL_Delay(10);
 	}
+	if (! timeout) return 0;
 
-	if (! n25q128_erase_sector(&fpgacfg_ctx, num--)) {
-            return 0;
+	if (! n25q128_erase_sector(&fpgacfg_ctx, num - 1)) {
+            return -1;
         }
+	num--;
     }
     return 1;
 }
diff --git a/stm-keystore.c b/stm-keystore.c
index 575cda0..74826d0 100644
--- a/stm-keystore.c
+++ b/stm-keystore.c
@@ -57,19 +57,21 @@ int keystore_write_data(uint32_t offset, const uint8_t *buf, const uint32_t len)
 
 int keystore_erase_sectors(int num)
 {
-    if (num > N25Q128_NUM_SECTORS - 1 || num < 0) num = N25Q128_NUM_SECTORS - 1;
+    if (num > N25Q128_NUM_SECTORS || num < 0) num = N25Q128_NUM_SECTORS;
     while (num) {
-	int timeout = 1000;
+	int timeout = 200; /* times 10ms = 2 seconds timeout */
 	while (timeout--) {
 	    int i = n25q128_get_wip_flag(&keystore_ctx);
 	    if (i < 0) return 0;
 	    if (! i) break;
 	    HAL_Delay(10);
 	}
+	if (! timeout) return 0;
 
-	if (! n25q128_erase_sector(&keystore_ctx, num--)) {
-            return 0;
+	if (! n25q128_erase_sector(&keystore_ctx, num - 1)) {
+            return -1;
         }
+	num--;
     }
     return 1;
 }



More information about the Commits mailing list