diff --git a/components/wear_levelling/Partition.cpp b/components/wear_levelling/Partition.cpp index a4618053f4..c97f45ba60 100644 --- a/components/wear_levelling/Partition.cpp +++ b/components/wear_levelling/Partition.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -54,6 +54,11 @@ size_t Partition::get_sector_size() return SPI_FLASH_SEC_SIZE; } +bool Partition::is_readonly() +{ + return this->partition->readonly; +} + Partition::~Partition() { diff --git a/components/wear_levelling/WL_Ext_Perf.cpp b/components/wear_levelling/WL_Ext_Perf.cpp index 3e7c137a3f..03fbfdce7e 100644 --- a/components/wear_levelling/WL_Ext_Perf.cpp +++ b/components/wear_levelling/WL_Ext_Perf.cpp @@ -1,9 +1,10 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "WL_Ext_Perf.h" +#include "Partition.h" #include #include "esp_log.h" @@ -25,7 +26,7 @@ WL_Ext_Perf::~WL_Ext_Perf() free(this->sector_buffer); } -esp_err_t WL_Ext_Perf::config(WL_Config_s *cfg, Flash_Access *flash_drv) +esp_err_t WL_Ext_Perf::config(WL_Config_s *cfg, Partition *partition) { wl_ext_cfg_t *ext_cfg = (wl_ext_cfg_t *)cfg; @@ -44,7 +45,7 @@ esp_err_t WL_Ext_Perf::config(WL_Config_s *cfg, Flash_Access *flash_drv) return ESP_ERR_NO_MEM; } - return WL_Flash::config(cfg, flash_drv); + return WL_Flash::config(cfg, partition); } esp_err_t WL_Ext_Perf::init() diff --git a/components/wear_levelling/WL_Ext_Safe.cpp b/components/wear_levelling/WL_Ext_Safe.cpp index bb9ad3beac..695b6829ce 100644 --- a/components/wear_levelling/WL_Ext_Safe.cpp +++ b/components/wear_levelling/WL_Ext_Safe.cpp @@ -49,11 +49,11 @@ WL_Ext_Safe::~WL_Ext_Safe() { } -esp_err_t WL_Ext_Safe::config(WL_Config_s *cfg, Flash_Access *flash_drv) +esp_err_t WL_Ext_Safe::config(WL_Config_s *cfg, Partition *partition) { esp_err_t result = ESP_OK; - result = WL_Ext_Perf::config(cfg, flash_drv); + result = WL_Ext_Perf::config(cfg, partition); WL_EXT_RESULT_CHECK(result); /* two extra sectors will be reserved to store buffer transaction state WL_Ext_Safe_State and temporary storage of the actual sector data from the sector which is to be erased*/ diff --git a/components/wear_levelling/WL_Flash.cpp b/components/wear_levelling/WL_Flash.cpp index aa15bfc959..d82b250b9f 100644 --- a/components/wear_levelling/WL_Flash.cpp +++ b/components/wear_levelling/WL_Flash.cpp @@ -6,6 +6,7 @@ #include #include "esp_random.h" #include "esp_log.h" +#include "Partition.h" #include "WL_Flash.h" #include #include "crc32.h" @@ -37,7 +38,7 @@ WL_Flash::~WL_Flash() free(this->temp_buff); } -esp_err_t WL_Flash::config(wl_config_t *cfg, Flash_Access *flash_drv) +esp_err_t WL_Flash::config(wl_config_t *cfg, Partition *partition) { ESP_LOGV(TAG, "%s partition_start_addr=0x%08x, wl_partition_size=0x%08x, wl_page_size=0x%08x, flash_sector_size=0x%08x, wl_update_rate=0x%08x, wl_pos_update_record_size=0x%08x, version=0x%08x, wl_temp_buff_size=0x%08x", __func__, (uint32_t) cfg->wl_partition_start_addr, @@ -59,8 +60,8 @@ esp_err_t WL_Flash::config(wl_config_t *cfg, Flash_Access *flash_drv) if (cfg == NULL) { result = ESP_ERR_INVALID_ARG; } - this->flash_drv = flash_drv; - if (flash_drv == NULL) { + this->partition = partition; + if (partition == NULL) { result = ESP_ERR_INVALID_ARG; } if ((this->cfg.flash_sector_size % this->cfg.wl_temp_buff_size) != 0) { @@ -118,10 +119,10 @@ esp_err_t WL_Flash::init() // If flow will be interrupted by error, then this flag will be false this->initialized = false; // Init states if it is first time... - this->flash_drv->read(this->addr_state1, &this->state, sizeof(wl_state_t)); + this->partition->read(this->addr_state1, &this->state, sizeof(wl_state_t)); wl_state_t sa_copy; wl_state_t *state_copy = &sa_copy; - result = this->flash_drv->read(this->addr_state2, state_copy, sizeof(wl_state_t)); + result = this->partition->read(this->addr_state2, state_copy, sizeof(wl_state_t)); WL_RESULT_CHECK(result); int check_size = WL_STATE_CRC_LEN_V2; @@ -149,19 +150,19 @@ esp_err_t WL_Flash::init() WL_RESULT_CHECK(result); } else { if (crc1 != crc2) {// we did not update second structure. - result = this->flash_drv->erase_range(this->addr_state2, this->state_size); + result = this->partition->erase_range(this->addr_state2, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); for (size_t i = 0; i < ((this->cfg.wl_partition_size / this->cfg.flash_sector_size)); i++) { bool pos_bits; - result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); pos_bits = this->OkBuffSet(i); if (pos_bits == true) { //this->fillOkBuff(i); - result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); } } @@ -184,41 +185,41 @@ esp_err_t WL_Flash::init() } else { // recover broken state if (crc1 == this->state.crc32) {// we have to recover state 2 - result = this->flash_drv->erase_range(this->addr_state2, this->state_size); + result = this->partition->erase_range(this->addr_state2, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); for (size_t i = 0; i < ((this->cfg.wl_partition_size / this->cfg.flash_sector_size)); i++) { bool pos_bits; - result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); pos_bits = this->OkBuffSet(i); if (pos_bits == true) { - result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); } } - result = this->flash_drv->read(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->read(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); } else { // we have to recover state 1 - result = this->flash_drv->erase_range(this->addr_state1, this->state_size); + result = this->partition->erase_range(this->addr_state1, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state1, state_copy, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state1, state_copy, sizeof(wl_state_t)); WL_RESULT_CHECK(result); for (size_t i = 0; i < ((this->cfg.wl_partition_size / this->cfg.flash_sector_size)); i++) { bool pos_bits; - result = this->flash_drv->read(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->read(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); pos_bits = this->OkBuffSet(i); if (pos_bits == true) { - result = this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); } } - result = this->flash_drv->read(this->addr_state1, &this->state, sizeof(wl_state_t)); + result = this->partition->read(this->addr_state1, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); this->state.wl_dummy_sec_pos = this->state.wl_part_max_sec_pos - 1; } @@ -247,7 +248,7 @@ esp_err_t WL_Flash::recoverPos() for (size_t i = 0; i < this->state.wl_part_max_sec_pos; i++) { bool pos_bits; position = i; - result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); pos_bits = this->OkBuffSet(i); WL_RESULT_CHECK(result); 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); @@ -285,19 +286,19 @@ esp_err_t WL_Flash::initSections() this->state.crc32 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); - result = this->flash_drv->erase_range(this->addr_state1, this->state_size); + result = this->partition->erase_range(this->addr_state1, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state1, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); // write state copy - result = this->flash_drv->erase_range(this->addr_state2, this->state_size); + result = this->partition->erase_range(this->addr_state2, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); - result = this->flash_drv->erase_range(this->addr_cfg, this->cfg_size); + result = this->partition->erase_range(this->addr_cfg, this->cfg_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t)); + result = this->partition->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t)); WL_RESULT_CHECK(result); ESP_LOGD(TAG, "%s - this->state->wl_max_sec_erase_cycle_count= 0x%08x, this->state->wl_part_max_sec_pos= 0x%08x", __func__, this->state.wl_max_sec_erase_cycle_count, this->state.wl_part_max_sec_pos); @@ -327,7 +328,7 @@ esp_err_t WL_Flash::updateV1_V2() uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size); wl_state_t sa_copy; wl_state_t *state_copy = &sa_copy; - result = this->flash_drv->read(this->addr_state2, state_copy, sizeof(wl_state_t)); + result = this->partition->read(this->addr_state2, state_copy, sizeof(wl_state_t)); WL_RESULT_CHECK(result); uint32_t crc2 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)state_copy, check_size); @@ -344,7 +345,7 @@ esp_err_t WL_Flash::updateV1_V2() for (size_t i = 0; i < this->state.wl_part_max_sec_pos; i++) { uint8_t pos_bits; - result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, &pos_bits, 1); + result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, &pos_bits, 1); WL_RESULT_CHECK(result); 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; @@ -364,28 +365,28 @@ esp_err_t WL_Flash::updateV1_V2() memset(this->state.reserved, 0, sizeof(this->state.reserved)); this->state.crc32 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); - result = this->flash_drv->erase_range(this->addr_state1, this->state_size); + result = this->partition->erase_range(this->addr_state1, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state1, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); memset(this->temp_buff, 0, this->cfg.wl_pos_update_record_size); 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.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); } - result = this->flash_drv->erase_range(this->addr_state2, this->state_size); + result = this->partition->erase_range(this->addr_state2, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08x, pos= 0x%08x", __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos); memset(this->temp_buff, 0, this->cfg.wl_pos_update_record_size); 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.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); + result = this->partition->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size); WL_RESULT_CHECK(result); } this->state.wl_dummy_sec_pos = pos; @@ -437,7 +438,7 @@ esp_err_t WL_Flash::updateWL() } data_addr = this->cfg.wl_partition_start_addr + data_addr * this->cfg.wl_page_size; this->dummy_addr = this->cfg.wl_partition_start_addr + this->state.wl_dummy_sec_pos * this->cfg.wl_page_size; - result = this->flash_drv->erase_range(this->dummy_addr, this->cfg.wl_page_size); + result = this->partition->erase_range(this->dummy_addr, this->cfg.wl_page_size); if (result != ESP_OK) { ESP_LOGE(TAG, "%s - erase wl dummy sector result= 0x%08x", __func__, result); this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time @@ -446,13 +447,13 @@ esp_err_t WL_Flash::updateWL() size_t copy_count = this->cfg.wl_page_size / this->cfg.wl_temp_buff_size; for (size_t i = 0; i < copy_count; i++) { - result = this->flash_drv->read(data_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size); + result = this->partition->read(data_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size); if (result != ESP_OK) { ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result= 0x%08x", __func__, result); this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time return result; } - result = this->flash_drv->write(this->dummy_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size); + result = this->partition->write(this->dummy_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size); if (result != ESP_OK) { ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result= 0x%08x", __func__, result); this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time @@ -465,14 +466,14 @@ esp_err_t WL_Flash::updateWL() uint32_t byte_pos = this->state.wl_dummy_sec_pos * this->cfg.wl_pos_update_record_size; this->fillOkBuff(this->state.wl_dummy_sec_pos); // 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.wl_pos_update_record_size); + result |= this->partition->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wl_pos_update_record_size); if (result != ESP_OK) { ESP_LOGE(TAG, "%s - update position 1 result= 0x%08x", __func__, result); this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time return result; } this->fillOkBuff(this->state.wl_dummy_sec_pos); - result |= this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wl_pos_update_record_size); + result |= this->partition->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wl_pos_update_record_size); if (result != ESP_OK) { ESP_LOGE(TAG, "%s - update position 2 result= 0x%08x", __func__, result); this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time @@ -490,13 +491,13 @@ esp_err_t WL_Flash::updateWL() // write main state this->state.crc32 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); - result = this->flash_drv->erase_range(this->addr_state1, this->state_size); + result = this->partition->erase_range(this->addr_state1, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state1, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); - result = this->flash_drv->erase_range(this->addr_state2, this->state_size); + result = this->partition->erase_range(this->addr_state2, this->state_size); WL_RESULT_CHECK(result); - result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); + result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t)); WL_RESULT_CHECK(result); ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08x, wl_dummy_sec_pos= 0x%08x, ", __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos); } @@ -548,7 +549,7 @@ esp_err_t WL_Flash::erase_sector(size_t sector) result = this->updateWL(); WL_RESULT_CHECK(result); size_t virt_addr = this->calcAddr(sector * this->cfg.flash_sector_size); - result = this->flash_drv->erase_sector((this->cfg.wl_partition_start_addr + virt_addr) / this->cfg.flash_sector_size); + result = this->partition->erase_sector((this->cfg.wl_partition_start_addr + virt_addr) / this->cfg.flash_sector_size); WL_RESULT_CHECK(result); return result; } @@ -580,11 +581,11 @@ esp_err_t WL_Flash::write(size_t dest_addr, const void *src, size_t size) uint32_t count = (size - 1) / this->cfg.wl_page_size; for (size_t i = 0; i < count; i++) { size_t virt_addr = this->calcAddr(dest_addr + i * this->cfg.wl_page_size); - result = this->flash_drv->write(this->cfg.wl_partition_start_addr + virt_addr, &((uint8_t *)src)[i * this->cfg.wl_page_size], this->cfg.wl_page_size); + result = this->partition->write(this->cfg.wl_partition_start_addr + virt_addr, &((uint8_t *)src)[i * this->cfg.wl_page_size], this->cfg.wl_page_size); WL_RESULT_CHECK(result); } size_t virt_addr_last = this->calcAddr(dest_addr + count * this->cfg.wl_page_size); - result = this->flash_drv->write(this->cfg.wl_partition_start_addr + virt_addr_last, &((uint8_t *)src)[count * this->cfg.wl_page_size], size - count * this->cfg.wl_page_size); + result = this->partition->write(this->cfg.wl_partition_start_addr + virt_addr_last, &((uint8_t *)src)[count * this->cfg.wl_page_size], size - count * this->cfg.wl_page_size); WL_RESULT_CHECK(result); return result; } @@ -600,18 +601,18 @@ esp_err_t WL_Flash::read(size_t src_addr, void *dest, size_t size) for (size_t i = 0; i < count; i++) { size_t virt_addr = this->calcAddr(src_addr + i * this->cfg.wl_page_size); ESP_LOGV(TAG, "%s - real_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) (this->cfg.wl_partition_start_addr + virt_addr), (uint32_t) size); - result = this->flash_drv->read(this->cfg.wl_partition_start_addr + virt_addr, &((uint8_t *)dest)[i * this->cfg.wl_page_size], this->cfg.wl_page_size); + result = this->partition->read(this->cfg.wl_partition_start_addr + virt_addr, &((uint8_t *)dest)[i * this->cfg.wl_page_size], this->cfg.wl_page_size); WL_RESULT_CHECK(result); } size_t virt_addr_last = this->calcAddr(src_addr + count * this->cfg.wl_page_size); - result = this->flash_drv->read(this->cfg.wl_partition_start_addr + virt_addr_last, &((uint8_t *)dest)[count * this->cfg.wl_page_size], size - count * this->cfg.wl_page_size); + result = this->partition->read(this->cfg.wl_partition_start_addr + virt_addr_last, &((uint8_t *)dest)[count * this->cfg.wl_page_size], size - count * this->cfg.wl_page_size); WL_RESULT_CHECK(result); return result; } -Flash_Access *WL_Flash::get_drv() +Partition *WL_Flash::get_part() { - return this->flash_drv; + return this->partition; } wl_config_t *WL_Flash::get_cfg() { diff --git a/components/wear_levelling/private_include/Partition.h b/components/wear_levelling/private_include/Partition.h index be5e7c54cc..695bfd6fa4 100644 --- a/components/wear_levelling/private_include/Partition.h +++ b/components/wear_levelling/private_include/Partition.h @@ -32,6 +32,7 @@ public: virtual esp_err_t read(size_t src_addr, void *dest, size_t size); virtual size_t get_sector_size(); + virtual bool is_readonly(); virtual ~Partition(); protected: diff --git a/components/wear_levelling/private_include/WL_Ext_Perf.h b/components/wear_levelling/private_include/WL_Ext_Perf.h index 2b520790b9..809e5176ec 100644 --- a/components/wear_levelling/private_include/WL_Ext_Perf.h +++ b/components/wear_levelling/private_include/WL_Ext_Perf.h @@ -6,6 +6,7 @@ #ifndef _WL_Ext_Perf_H_ #define _WL_Ext_Perf_H_ +#include "Partition.h" #include "WL_Flash.h" #include "WL_Ext_Cfg.h" @@ -15,7 +16,7 @@ public: WL_Ext_Perf(); ~WL_Ext_Perf() override; - esp_err_t config(WL_Config_s *cfg, Flash_Access *flash_drv) override; + esp_err_t config(WL_Config_s *cfg, Partition *partition) override; esp_err_t init() override; size_t get_flash_size() override; diff --git a/components/wear_levelling/private_include/WL_Ext_Safe.h b/components/wear_levelling/private_include/WL_Ext_Safe.h index f63f780fc3..45e1e63c37 100644 --- a/components/wear_levelling/private_include/WL_Ext_Safe.h +++ b/components/wear_levelling/private_include/WL_Ext_Safe.h @@ -6,6 +6,7 @@ #ifndef _WL_Ext_Safe_H_ #define _WL_Ext_Safe_H_ +#include "Partition.h" #include "WL_Flash.h" #include "WL_Ext_Cfg.h" #include "WL_Ext_Perf.h" @@ -16,7 +17,7 @@ public: WL_Ext_Safe(); ~WL_Ext_Safe() override; - esp_err_t config(WL_Config_s *cfg, Flash_Access *flash_drv) override; + esp_err_t config(WL_Config_s *cfg, Partition *partition) override; esp_err_t init() override; size_t get_flash_size() override; diff --git a/components/wear_levelling/private_include/WL_Flash.h b/components/wear_levelling/private_include/WL_Flash.h index b7d652b4dd..58899ce831 100644 --- a/components/wear_levelling/private_include/WL_Flash.h +++ b/components/wear_levelling/private_include/WL_Flash.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include "esp_err.h" #include "Flash_Access.h" +#include "Partition.h" #include "WL_Config.h" #include "WL_State.h" @@ -21,7 +22,7 @@ public : WL_Flash(); ~WL_Flash() override; - virtual esp_err_t config(wl_config_t *cfg, Flash_Access *flash_drv); + virtual esp_err_t config(wl_config_t *cfg, Partition *flash_drv); virtual esp_err_t init(); size_t get_flash_size() override; @@ -35,7 +36,7 @@ public : esp_err_t flush() override; - Flash_Access *get_drv(); + Partition *get_part(); wl_config_t *get_cfg(); protected: @@ -43,7 +44,7 @@ protected: bool initialized = false; wl_state_t state; wl_config_t cfg; - Flash_Access *flash_drv = NULL; + Partition *partition = NULL; size_t addr_cfg; size_t addr_state1; diff --git a/components/wear_levelling/wear_levelling.cpp b/components/wear_levelling/wear_levelling.cpp index dd568f0c5b..66baf6e3f7 100644 --- a/components/wear_levelling/wear_levelling.cpp +++ b/components/wear_levelling/wear_levelling.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -177,9 +177,9 @@ esp_err_t wl_unmount(wl_handle_t handle) // We have to flush state of the component result = s_instances[handle].instance->flush(); // We use placement new in wl_mount, so call destructor directly - Flash_Access *drv = s_instances[handle].instance->get_drv(); - drv->~Flash_Access(); - free(drv); + Partition *part = s_instances[handle].instance->get_part(); + part->~Partition(); + free(part); s_instances[handle].instance->~WL_Flash(); free(s_instances[handle].instance); s_instances[handle].instance = NULL;