diff options
author | Fredrik Thulin <fredrik@thulin.net> | 2016-05-21 14:40:11 +0200 |
---|---|---|
committer | Fredrik Thulin <fredrik@thulin.net> | 2016-05-21 14:40:11 +0200 |
commit | ac2357b001b970ff281d05566697c3d73f66ea4a (patch) | |
tree | ba877047fcf3538eebd2ae43941301e5bae00725 /spiflash_n25q128.c | |
parent | 3d16ad028d69acc581095430d20463ed66f65779 (diff) |
Add code to test reading, writing and erasing keystore data.
Diffstat (limited to 'spiflash_n25q128.c')
-rw-r--r-- | spiflash_n25q128.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spiflash_n25q128.c b/spiflash_n25q128.c index 985e727..6e35a41 100644 --- a/spiflash_n25q128.c +++ b/spiflash_n25q128.c @@ -333,3 +333,22 @@ int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t return 1; } +/* This function reads zero or more pages from the SPI flash. */ +int n25q128_read_data(struct spiflash_ctx *ctx, uint32_t offset, uint8_t *buf, const uint32_t len) +{ + uint32_t page; + + /* Ensure alignment */ + if ((offset % N25Q128_PAGE_SIZE) != 0) return -1; + if ((len % N25Q128_PAGE_SIZE) != 0) return -2; + + for (page = 0; page < len / N25Q128_PAGE_SIZE; page++) { + if (! n25q128_read_page(ctx, offset / N25Q128_PAGE_SIZE, buf)) { + return -3; + } + buf += N25Q128_PAGE_SIZE; + offset += N25Q128_PAGE_SIZE; + } + + return 1; +} |