diff options
author | Paul Selkirk <paul@psgd.org> | 2017-02-20 19:51:03 -0500 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2017-02-20 19:52:19 -0500 |
commit | 0c298a1c2d0ab40760bf38b27fec43d8b8f3afb5 (patch) | |
tree | d86ff70d09a6e422e005da8c2e780b3929ac79c0 /stm-fpgacfg.c | |
parent | e9011a1ae42333fdcbebf9b85ced6ea942f3547c (diff) |
Move dangerous auto_erase functionality to where it's actually used.
Diffstat (limited to 'stm-fpgacfg.c')
-rw-r--r-- | stm-fpgacfg.c | 7 |
1 files changed, 6 insertions, 1 deletions
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) |