From 9325f2a7a4cd8ce7a6b82f074b7b389561c51d1b Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 18 Sep 2017 22:43:03 +0800 Subject: [PATCH] nvs_flash: emulator: fix issues in load function, add save function --- .../nvs_flash/test_nvs_host/spi_flash_emulation.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/nvs_flash/test_nvs_host/spi_flash_emulation.h b/components/nvs_flash/test_nvs_host/spi_flash_emulation.h index 14e56bab6..d8099322d 100644 --- a/components/nvs_flash/test_nvs_host/spi_flash_emulation.h +++ b/components/nvs_flash/test_nvs_host/spi_flash_emulation.h @@ -148,10 +148,20 @@ public: fseek(f, 0, SEEK_END); off_t size = ftell(f); assert(size % SPI_FLASH_SEC_SIZE == 0); - mData.resize(size); + mData.resize(size / sizeof(uint32_t)); fseek(f, 0, SEEK_SET); auto s = fread(mData.data(), SPI_FLASH_SEC_SIZE, size / SPI_FLASH_SEC_SIZE, f); assert(s == static_cast(size / SPI_FLASH_SEC_SIZE)); + fclose(f); + } + + void save(const char* filename) + { + FILE* f = fopen(filename, "wb"); + auto n_sectors = mData.size() * sizeof(uint32_t) / SPI_FLASH_SEC_SIZE; + auto s = fwrite(mData.data(), SPI_FLASH_SEC_SIZE, n_sectors, f); + assert(s == n_sectors); + fclose(f); } void clearStats()