aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-11-01 12:17:44 -0400
committerRob Austein <sra@hactrn.net>2016-11-01 12:17:44 -0400
commitfd3a9b8f032d5a696d0c7e283fdd2f7f0771306e (patch)
tree543c358baf4e5afafff53691c4aab0c9043b5683
parent002f019f8c6db7e3e8a2f1517de7693878f975be (diff)
Don't return from flash write calls until WIP flag clears.
Absence of this check created a nasty race condition in sw/libhal/ks_flash.c, which didn't show up until we had test code which attempted to delete a long series of keys in quick succession. I'm not aware of any sane reason why we would ever want to skip this check, so it's unconditional and applies to all of the SPI flash code, not just the keystore flash code.
-rw-r--r--spiflash_n25q128.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/spiflash_n25q128.c b/spiflash_n25q128.c
index 728db7e..0c2abd7 100644
--- a/spiflash_n25q128.c
+++ b/spiflash_n25q128.c
@@ -356,6 +356,12 @@ int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t
*/
}
+ /*
+ * Wait until last write finishes.
+ */
+
+ if (! _wait_while_wip(ctx, 1000)) return -7;
+
return 1;
}