diff options
-rw-r--r-- | spiflash_n25q128.c | 21 | ||||
-rw-r--r-- | spiflash_n25q128.h | 2 | ||||
-rw-r--r-- | stm-fpgacfg.c | 7 | ||||
-rw-r--r-- | stm-keystore.c | 2 |
4 files changed, 12 insertions, 20 deletions
diff --git a/spiflash_n25q128.c b/spiflash_n25q128.c index 35a2fcf..133ecb4 100644 --- a/spiflash_n25q128.c +++ b/spiflash_n25q128.c @@ -360,8 +360,10 @@ static int _n25q128_get_wel_flag(struct spiflash_ctx *ctx) } -/* This function performs erasure if needed, and then writing of a number of pages to the flash memory */ -int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t *buf, const uint32_t len, const int auto_erase) +/* This function writes of a number of pages to the flash memory. + * The caller is responsible for ensuring that the pages have been erased. + */ +int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t *buf, const uint32_t len) { uint32_t page; @@ -369,21 +371,6 @@ int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t if ((offset % N25Q128_PAGE_SIZE) != 0) return -1; if ((len % N25Q128_PAGE_SIZE) != 0) return -2; - if (auto_erase && (offset % N25Q128_SECTOR_SIZE) == 0) { - /* - * first page in sector, need to erase sector - * - * So why do we only do this when the buffer starts on the - * sector, as opposed to performing this check for every page? - * Also, might be better to do this by subsectors rather than - * sectors. - */ - - if (! n25q128_erase_sector(ctx, offset / N25Q128_SECTOR_SIZE)) { - return -4; - } - } - for (page = 0; page < len / N25Q128_PAGE_SIZE; page++) { if (! n25q128_write_page(ctx, offset / N25Q128_PAGE_SIZE, buf)) { return -6; diff --git a/spiflash_n25q128.h b/spiflash_n25q128.h index c01629d..ff14c34 100644 --- a/spiflash_n25q128.h +++ b/spiflash_n25q128.h @@ -77,6 +77,6 @@ extern int n25q128_erase_sector(struct spiflash_ctx *ctx, uint32_t sector_offset extern int n25q128_erase_subsector(struct spiflash_ctx *ctx, uint32_t subsector_offset); extern int n25q128_erase_bulk(struct spiflash_ctx *ctx); -extern int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t *buf, const uint32_t len, const int auto_erase); +extern int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t *buf, const uint32_t len); extern int n25q128_read_data(struct spiflash_ctx *ctx, uint32_t offset, uint8_t *buf, const uint32_t len); #endif /* __STM32_SPIFLASH_N25Q128_H */ diff --git a/stm-fpgacfg.c b/stm-fpgacfg.c index d3a9aec..16c490b 100644 --- a/stm-fpgacfg.c +++ b/stm-fpgacfg.c @@ -48,7 +48,12 @@ int fpgacfg_check_id() int fpgacfg_write_data(uint32_t offset, const uint8_t *buf, const uint32_t len) { - return n25q128_write_data(&fpgacfg_ctx, offset, buf, len, 1); + if ((offset % N25Q128_SECTOR_SIZE) == 0) + // first page in sector, need to erase sector + if (! n25q128_erase_sector(&fpgacfg_ctx, offset / N25Q128_SECTOR_SIZE)) + return -4; + + return n25q128_write_data(&fpgacfg_ctx, offset, buf, len); } void fpgacfg_access_control(enum fpgacfg_access_ctrl access) diff --git a/stm-keystore.c b/stm-keystore.c index 633d554..86fad91 100644 --- a/stm-keystore.c +++ b/stm-keystore.c @@ -52,7 +52,7 @@ 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, 0); + return n25q128_write_data(&keystore_ctx, offset, buf, len); } static int keystore_erase_something(uint32_t start, uint32_t stop, uint32_t limit, |