|
|
|
@ -12,11 +12,13 @@
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "esp_system.h"
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
|
#include "WL_Flash.h"
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "crc32.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
static const char *TAG = "wl_flash";
|
|
|
|
|
#ifndef WL_CFG_CRC_CONST
|
|
|
|
@ -143,7 +145,7 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
this->state.pos,
|
|
|
|
|
this->state.move_count);
|
|
|
|
|
|
|
|
|
|
ESP_LOGD(TAG, "%s starts: crc1=%i, crc2 = %i, this->state.crc=%i, state_copy->crc=%i, version=%i, read_version=%i", __func__, crc1, crc2, this->state.crc, state_copy->crc, this->cfg.version, this->state.version);
|
|
|
|
|
ESP_LOGD(TAG, "%s starts: crc1= 0x%08x, crc2 = 0x%08x, this->state.crc= 0x%08x, state_copy->crc= 0x%08x, version=%i, read_version=%i", __func__, crc1, crc2, this->state.crc, state_copy->crc, this->cfg.version, this->state.version);
|
|
|
|
|
if ((crc1 == this->state.crc) && (crc2 == state_copy->crc)) {
|
|
|
|
|
// The state is OK. Check the ID
|
|
|
|
|
if (this->state.version != this->cfg.version) {
|
|
|
|
@ -158,7 +160,7 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size)*this->cfg.wr_size); i++) {
|
|
|
|
|
bool pos_bits = 0;
|
|
|
|
|
bool pos_bits;
|
|
|
|
|
result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
pos_bits = this->OkBuffSet(i);
|
|
|
|
@ -169,14 +171,16 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s: crc1=%i, crc2 = %i, result=%i", __func__, crc1, crc2, result);
|
|
|
|
|
ESP_LOGD(TAG, "%s: crc1=0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__, crc1, crc2, (uint32_t)result);
|
|
|
|
|
result = this->recoverPos();
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
}
|
|
|
|
|
} else if ((crc1 != this->state.crc) && (crc2 != state_copy->crc)) { // This is just new flash or new version
|
|
|
|
|
// Check if this is new version or just new instance of WL
|
|
|
|
|
ESP_LOGD(TAG, "%s: try to update version - crc1= 0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__, (uint32_t)crc1, (uint32_t)crc2, (uint32_t)result);
|
|
|
|
|
result = this->updateVersion();
|
|
|
|
|
if (result == ESP_FAIL) {
|
|
|
|
|
ESP_LOGD(TAG, "%s: init flash sections", __func__);
|
|
|
|
|
result = this->initSections();
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
}
|
|
|
|
@ -190,7 +194,7 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size) * this->cfg.wr_size); i++) {
|
|
|
|
|
bool pos_bits = 0;
|
|
|
|
|
bool pos_bits;
|
|
|
|
|
result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
pos_bits = this->OkBuffSet(i);
|
|
|
|
@ -207,7 +211,7 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
result = this->flash_drv->write(this->addr_state1, state_copy, sizeof(wl_state_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size) * this->cfg.wr_size); i++) {
|
|
|
|
|
bool pos_bits = 0;
|
|
|
|
|
bool pos_bits;
|
|
|
|
|
result = this->flash_drv->read(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
@ -230,11 +234,11 @@ esp_err_t WL_Flash::init()
|
|
|
|
|
}
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
this->initialized = false;
|
|
|
|
|
ESP_LOGE(TAG, "%s: returned 0x%x", __func__, (uint32_t)result);
|
|
|
|
|
ESP_LOGE(TAG, "%s: returned 0x%08x", __func__, (uint32_t)result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
this->initialized = true;
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count=%08x", __func__, (uint32_t)this->state.move_count);
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count= 0x%08x", __func__, (uint32_t)this->state.move_count);
|
|
|
|
|
return ESP_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -244,12 +248,12 @@ esp_err_t WL_Flash::recoverPos()
|
|
|
|
|
size_t position = 0;
|
|
|
|
|
ESP_LOGV(TAG, "%s start", __func__);
|
|
|
|
|
for (size_t i = 0; i < this->state.max_pos; i++) {
|
|
|
|
|
bool pos_bits = false;
|
|
|
|
|
bool pos_bits;
|
|
|
|
|
position = i;
|
|
|
|
|
result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
pos_bits = this->OkBuffSet(i);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
ESP_LOGV(TAG, "%s - check pos: result=%i, position=%i, pos_bits=0x%08x", __func__, (uint32_t)result, (uint32_t)position, (uint32_t)pos_bits);
|
|
|
|
|
ESP_LOGV(TAG, "%s - check pos: result=0x%08x, position= %i, pos_bits= 0x%08x", __func__, (uint32_t)result, (uint32_t)position, (uint32_t)pos_bits);
|
|
|
|
|
if (pos_bits == false) {
|
|
|
|
|
break; // we have found position
|
|
|
|
|
}
|
|
|
|
@ -259,8 +263,8 @@ esp_err_t WL_Flash::recoverPos()
|
|
|
|
|
if (this->state.pos == this->state.max_pos) {
|
|
|
|
|
this->state.pos--;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s - this->state.pos=0x%08x, position=0x%08x, result=%08x, max_pos=%08x", __func__, (uint32_t)this->state.pos, (uint32_t)position, (uint32_t)result, (uint32_t)this->state.max_pos);
|
|
|
|
|
ESP_LOGV(TAG, "%s done", __func__);
|
|
|
|
|
ESP_LOGD(TAG, "%s - this->state.pos= 0x%08x, position= 0x%08x, result= 0x%08x, max_pos= 0x%08x", __func__, (uint32_t)this->state.pos, (uint32_t)position, (uint32_t)result, (uint32_t)this->state.max_pos);
|
|
|
|
|
ESP_LOGV(TAG, "%s done", __func__);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -277,8 +281,8 @@ esp_err_t WL_Flash::initSections()
|
|
|
|
|
}
|
|
|
|
|
this->state.version = this->cfg.version;
|
|
|
|
|
this->state.block_size = this->cfg.page_size;
|
|
|
|
|
this->used_bits = 0;
|
|
|
|
|
this->state.device_id = rand();
|
|
|
|
|
this->state.device_id = esp_random();
|
|
|
|
|
memset(this->state.reserved, 0, sizeof(this->state.reserved));
|
|
|
|
|
|
|
|
|
|
this->state.max_pos = 1 + this->flash_size / this->cfg.page_size;
|
|
|
|
|
|
|
|
|
@ -299,8 +303,8 @@ esp_err_t WL_Flash::initSections()
|
|
|
|
|
result = this->flash_drv->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
|
|
|
|
|
ESP_LOGD(TAG, "%s - this->state->max_count=%08x, this->state->max_pos=%08x", __func__, this->state.max_count, this->state.max_pos);
|
|
|
|
|
ESP_LOGD(TAG, "%s - result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGD(TAG, "%s - this->state->max_count= 0x%08x, this->state->max_pos= 0x%08x", __func__, this->state.max_count, this->state.max_pos);
|
|
|
|
|
ESP_LOGD(TAG, "%s - result= 0x%08x", __func__, result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -309,7 +313,7 @@ esp_err_t WL_Flash::updateVersion()
|
|
|
|
|
esp_err_t result = ESP_OK;
|
|
|
|
|
|
|
|
|
|
result = this->updateV1_V2();
|
|
|
|
|
if (ESP_OK == result) return result;
|
|
|
|
|
if (result == ESP_OK) return result;
|
|
|
|
|
// check next version
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -319,7 +323,7 @@ esp_err_t WL_Flash::updateV1_V2()
|
|
|
|
|
esp_err_t result = ESP_OK;
|
|
|
|
|
// Check crc for old version and old version
|
|
|
|
|
ESP_LOGV(TAG, "%s start", __func__);
|
|
|
|
|
int check_size = offsetof(wl_state_t, crc) - sizeof(uint32_t);
|
|
|
|
|
int check_size = offsetof(wl_state_t, device_id);
|
|
|
|
|
// Chech CRC and recover state
|
|
|
|
|
uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size);
|
|
|
|
|
// For V1 crc in place of device_id and version
|
|
|
|
@ -329,14 +333,14 @@ esp_err_t WL_Flash::updateV1_V2()
|
|
|
|
|
|
|
|
|
|
if ((crc1 == v1_crc) && (this->state.version == 1)){
|
|
|
|
|
// Here we have to update all internal structures
|
|
|
|
|
ESP_LOGV(TAG, "%s Update from V1 to V2", __func__);
|
|
|
|
|
ESP_LOGI(TAG, "%s Update from V1 to V2", __func__);
|
|
|
|
|
uint32_t pos = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < this->state.max_pos; i++) {
|
|
|
|
|
uint8_t pos_bits = 0;
|
|
|
|
|
uint8_t pos_bits;
|
|
|
|
|
result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, &pos_bits, 1);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
ESP_LOGV(TAG, "%s- result=%i, pos=%i, pos_bits=0x%08x", __func__, (uint32_t)result, (uint32_t)pos, (uint32_t)pos_bits);
|
|
|
|
|
ESP_LOGV(TAG, "%s- result= 0x%08x, pos= %i, pos_bits= 0x%08x", __func__, (uint32_t)result, (uint32_t)pos, (uint32_t)pos_bits);
|
|
|
|
|
pos = i;
|
|
|
|
|
if (pos_bits == 0xff) {
|
|
|
|
|
break; // we have found position
|
|
|
|
@ -350,7 +354,7 @@ esp_err_t WL_Flash::updateV1_V2()
|
|
|
|
|
this->state.version = 2;
|
|
|
|
|
this->state.pos = 0;
|
|
|
|
|
this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, offsetof(wl_state_t, crc));
|
|
|
|
|
this->state.device_id = rand();
|
|
|
|
|
this->state.device_id = esp_random();
|
|
|
|
|
|
|
|
|
|
result = this->flash_drv->erase_range(this->addr_state1, this->state_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
@ -358,7 +362,7 @@ esp_err_t WL_Flash::updateV1_V2()
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
|
|
|
|
|
memset(this->temp_buff, 0, this->cfg.wr_size);
|
|
|
|
|
for (int i=0 ; i< pos; i++) {
|
|
|
|
|
for (uint32_t i=0 ; i<= pos; i++) {
|
|
|
|
|
this->fillOkBuff(i);
|
|
|
|
|
result = this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
@ -368,10 +372,10 @@ esp_err_t WL_Flash::updateV1_V2()
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count=%08x, pos=%08x, ", __func__, this->state.move_count, this->state.pos);
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count= 0x%08x, pos= 0x%08x", __func__, this->state.move_count, this->state.pos);
|
|
|
|
|
|
|
|
|
|
memset(this->temp_buff, 0, this->cfg.wr_size);
|
|
|
|
|
for (int i=0 ; i< pos; i++) {
|
|
|
|
|
for (uint32_t i=0 ; i<= pos; i++) {
|
|
|
|
|
this->fillOkBuff(i);
|
|
|
|
|
result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
@ -415,7 +419,7 @@ esp_err_t WL_Flash::updateWL()
|
|
|
|
|
}
|
|
|
|
|
// Here we have to move the block and increase the state
|
|
|
|
|
this->state.access_count = 0;
|
|
|
|
|
ESP_LOGV(TAG, "%s - access_count=0x%08x, pos=0x%08x", __func__, this->state.access_count, this->state.pos);
|
|
|
|
|
ESP_LOGV(TAG, "%s - access_count= 0x%08x, pos= 0x%08x", __func__, this->state.access_count, this->state.pos);
|
|
|
|
|
// copy data to dummy block
|
|
|
|
|
size_t data_addr = this->state.pos + 1; // next block, [pos+1] copy to [pos]
|
|
|
|
|
if (data_addr >= this->state.max_pos) {
|
|
|
|
@ -425,7 +429,7 @@ esp_err_t WL_Flash::updateWL()
|
|
|
|
|
this->dummy_addr = this->cfg.start_addr + this->state.pos * this->cfg.page_size;
|
|
|
|
|
result = this->flash_drv->erase_range(this->dummy_addr, this->cfg.page_size);
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
ESP_LOGE(TAG, "%s - erase wl dummy sector result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - erase wl dummy sector result= 0x%08x", __func__, result);
|
|
|
|
|
this->state.access_count = this->state.max_count - 1; // we will update next time
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -434,13 +438,13 @@ esp_err_t WL_Flash::updateWL()
|
|
|
|
|
for (size_t i = 0; i < copy_count; i++) {
|
|
|
|
|
result = this->flash_drv->read(data_addr + i * this->cfg.temp_buff_size, this->temp_buff, this->cfg.temp_buff_size);
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result= 0x%08x", __func__, result);
|
|
|
|
|
this->state.access_count = this->state.max_count - 1; // we will update next time
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result = this->flash_drv->write(this->dummy_addr + i * this->cfg.temp_buff_size, this->temp_buff, this->cfg.temp_buff_size);
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result= 0x%08x", __func__, result);
|
|
|
|
|
this->state.access_count = this->state.max_count - 1; // we will update next time
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -453,14 +457,14 @@ esp_err_t WL_Flash::updateWL()
|
|
|
|
|
// write state to mem. We updating only affected bits
|
|
|
|
|
result |= this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
ESP_LOGE(TAG, "%s - update position 1 result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - update position 1 result= 0x%08x", __func__, result);
|
|
|
|
|
this->state.access_count = this->state.max_count - 1; // we will update next time
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
this->fillOkBuff(this->state.pos);
|
|
|
|
|
result |= this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wr_size);
|
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
|
ESP_LOGE(TAG, "%s - update position 2 result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - update position 2 result= 0x%08x", __func__, result);
|
|
|
|
|
this->state.access_count = this->state.max_count - 1; // we will update next time
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -484,13 +488,13 @@ esp_err_t WL_Flash::updateWL()
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t));
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count=%08x, pos=%08x, ", __func__, this->state.move_count, this->state.pos);
|
|
|
|
|
ESP_LOGD(TAG, "%s - move_count= 0x%08x, pos= 0x%08x, ", __func__, this->state.move_count, this->state.pos);
|
|
|
|
|
}
|
|
|
|
|
// Save structures to the flash... and check result
|
|
|
|
|
if (result == ESP_OK) {
|
|
|
|
|
ESP_LOGV(TAG, "%s - result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result);
|
|
|
|
|
} else {
|
|
|
|
|
ESP_LOGE(TAG, "%s - result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGE(TAG, "%s - result= 0x%08x", __func__, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -503,7 +507,7 @@ size_t WL_Flash::calcAddr(size_t addr)
|
|
|
|
|
} else {
|
|
|
|
|
result += this->cfg.page_size;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGV(TAG, "%s - addr=0x%08x -> result=0x%08x, dummy_addr=0x%08x", __func__, (uint32_t) addr, (uint32_t) result, (uint32_t)dummy_addr);
|
|
|
|
|
ESP_LOGV(TAG, "%s - addr= 0x%08x -> result= 0x%08x, dummy_addr= 0x%08x", __func__, (uint32_t) addr, (uint32_t) result, (uint32_t)dummy_addr);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -530,7 +534,7 @@ esp_err_t WL_Flash::erase_sector(size_t sector)
|
|
|
|
|
if (!this->initialized) {
|
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s - sector=0x%08x", __func__, (uint32_t) sector);
|
|
|
|
|
ESP_LOGD(TAG, "%s - sector= 0x%08x", __func__, (uint32_t) sector);
|
|
|
|
|
result = this->updateWL();
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
size_t virt_addr = this->calcAddr(sector * this->cfg.sector_size);
|
|
|
|
@ -544,14 +548,14 @@ esp_err_t WL_Flash::erase_range(size_t start_address, size_t size)
|
|
|
|
|
if (!this->initialized) {
|
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s - start_address=0x%08x, size=0x%08x", __func__, (uint32_t) start_address, (uint32_t) size);
|
|
|
|
|
ESP_LOGD(TAG, "%s - start_address= 0x%08x, size= 0x%08x", __func__, (uint32_t) start_address, (uint32_t) size);
|
|
|
|
|
size_t erase_count = (size + this->cfg.sector_size - 1) / this->cfg.sector_size;
|
|
|
|
|
size_t start_sector = start_address / this->cfg.sector_size;
|
|
|
|
|
for (size_t i = 0; i < erase_count; i++) {
|
|
|
|
|
result = this->erase_sector(start_sector + i);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGV(TAG, "%s - result=%08x", __func__, result);
|
|
|
|
|
ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -561,7 +565,7 @@ esp_err_t WL_Flash::write(size_t dest_addr, const void *src, size_t size)
|
|
|
|
|
if (!this->initialized) {
|
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s - dest_addr=0x%08x, size=0x%08x", __func__, (uint32_t) dest_addr, (uint32_t) size);
|
|
|
|
|
ESP_LOGD(TAG, "%s - dest_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) dest_addr, (uint32_t) size);
|
|
|
|
|
uint32_t count = (size - 1) / this->cfg.page_size;
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
|
size_t virt_addr = this->calcAddr(dest_addr + i * this->cfg.page_size);
|
|
|
|
@ -580,11 +584,11 @@ esp_err_t WL_Flash::read(size_t src_addr, void *dest, size_t size)
|
|
|
|
|
if (!this->initialized) {
|
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGD(TAG, "%s - src_addr=0x%08x, size=0x%08x", __func__, (uint32_t) src_addr, (uint32_t) size);
|
|
|
|
|
ESP_LOGD(TAG, "%s - src_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) src_addr, (uint32_t) size);
|
|
|
|
|
uint32_t count = (size - 1) / this->cfg.page_size;
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
|
size_t virt_addr = this->calcAddr(src_addr + i * this->cfg.page_size);
|
|
|
|
|
ESP_LOGV(TAG, "%s - real_addr=0x%08x, size=0x%08x", __func__, (uint32_t) this->cfg.start_addr + virt_addr, (uint32_t) size);
|
|
|
|
|
ESP_LOGV(TAG, "%s - real_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) (this->cfg.start_addr + virt_addr), (uint32_t) size);
|
|
|
|
|
result = this->flash_drv->read(this->cfg.start_addr + virt_addr, &((uint8_t *)dest)[i * this->cfg.page_size], this->cfg.page_size);
|
|
|
|
|
WL_RESULT_CHECK(result);
|
|
|
|
|
}
|
|
|
|
@ -608,6 +612,6 @@ esp_err_t WL_Flash::flush()
|
|
|
|
|
esp_err_t result = ESP_OK;
|
|
|
|
|
this->state.access_count = this->state.max_count - 1;
|
|
|
|
|
result = this->updateWL();
|
|
|
|
|
ESP_LOGD(TAG, "%s - result=%08x, move_count=%08x", __func__, result, this->state.move_count);
|
|
|
|
|
ESP_LOGD(TAG, "%s - result= 0x%08x, move_count= 0x%08x", __func__, result, this->state.move_count);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|