aboutsummaryrefslogtreecommitdiff
path: root/stm-keystore.c
diff options
context:
space:
mode:
Diffstat (limited to 'stm-keystore.c')
-rw-r--r--stm-keystore.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/stm-keystore.c b/stm-keystore.c
index 43e22fa..d5d8adb 100644
--- a/stm-keystore.c
+++ b/stm-keystore.c
@@ -52,17 +52,18 @@ int keystore_read_data(uint32_t offset, uint8_t *buf, const uint32_t len)
int keystore_write_data(uint32_t offset, const uint8_t *buf, const uint32_t len)
{
- return n25q128_write_data(&keystore_ctx, offset, buf, len);
+ return n25q128_write_data(&keystore_ctx, offset, buf, len, 0);
}
-int keystore_erase_sectors(uint32_t start, uint32_t stop)
+static int keystore_erase_something(uint32_t start, uint32_t stop, uint32_t limit,
+ int (*eraser)(struct spiflash_ctx *, uint32_t))
{
- uint32_t sector;
+ uint32_t something;
- if (start > N25Q128_NUM_SECTORS) return -2;
- if (stop > N25Q128_NUM_SECTORS || stop < start) return -3;
+ if (start > limit) return -2;
+ if (stop > limit || stop < start) return -3;
- for (sector = start; sector <= stop; sector++) {
+ for (something = start; something <= stop; something++) {
int timeout = 200; /* times 10ms = 2 seconds timeout */
while (timeout--) {
int i = n25q128_get_wip_flag(&keystore_ctx);
@@ -72,9 +73,21 @@ int keystore_erase_sectors(uint32_t start, uint32_t stop)
}
if (! timeout) return 0;
- if (! n25q128_erase_sector(&keystore_ctx, sector)) {
+ if (! eraser(&keystore_ctx, something)) {
return -1;
}
}
return 1;
}
+
+int keystore_erase_sectors(uint32_t start, uint32_t stop)
+{
+ return keystore_erase_something(start, stop, N25Q128_NUM_SECTORS,
+ n25q128_erase_sector);
+}
+
+int keystore_erase_subsectors(uint32_t start, uint32_t stop)
+{
+ return keystore_erase_something(start, stop, N25Q128_NUM_SUBSECTORS,
+ n25q128_erase_subsector);
+}