From fd3a9b8f032d5a696d0c7e283fdd2f7f0771306e Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 1 Nov 2016 12:17:44 -0400 Subject: 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. --- spiflash_n25q128.c | 6 ++++++ 1 file changed, 6 insertions(+) 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; } -- cgit v1.2.3