mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Version update from V1 to V2 now done in correct way.
Before this works only first time. The source and test updated. State length was changed to macro.
This commit is contained in:
parent
7c29a39d6f
commit
82eca97300
@ -132,7 +132,7 @@ esp_err_t WL_Flash::init()
|
||||
result = this->flash_drv->read(this->addr_state2, state_copy, sizeof(wl_state_t));
|
||||
WL_RESULT_CHECK(result);
|
||||
|
||||
int check_size = offsetof(wl_state_t, crc);
|
||||
int check_size = WL_STATE_CRC_LEN_V2;
|
||||
// Chech CRC and recover state
|
||||
uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size);
|
||||
uint32_t crc2 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)state_copy, check_size);
|
||||
@ -288,7 +288,7 @@ esp_err_t WL_Flash::initSections()
|
||||
|
||||
this->state.max_pos = 1 + this->flash_size / this->cfg.page_size;
|
||||
|
||||
this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, offsetof(wl_state_t, crc));
|
||||
this->state.crc = 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);
|
||||
WL_RESULT_CHECK(result);
|
||||
@ -327,7 +327,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, device_id);
|
||||
int check_size = WL_STATE_CRC_LEN_V1;
|
||||
// Chech CRC and recover state
|
||||
uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size);
|
||||
wl_state_t sa_copy;
|
||||
@ -365,9 +365,9 @@ 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 = esp_random();
|
||||
memset(this->state.reserved, 0, sizeof(this->state.reserved));
|
||||
this->state.crc = 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);
|
||||
WL_RESULT_CHECK(result);
|
||||
@ -493,7 +493,7 @@ esp_err_t WL_Flash::updateWL()
|
||||
this->state.move_count = 0;
|
||||
}
|
||||
// write main state
|
||||
this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, offsetof(wl_state_t, crc));
|
||||
this->state.crc = 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);
|
||||
WL_RESULT_CHECK(result);
|
||||
|
@ -45,5 +45,7 @@ public:
|
||||
static_assert(sizeof(wl_state_t) % 16 == 0, "Size of wl_state_t structure should be compatible with flash encryption");
|
||||
#endif // _MSC_VER
|
||||
|
||||
#define WL_STATE_CRC_LEN_V1 offsetof(wl_state_t, device_id)
|
||||
#define WL_STATE_CRC_LEN_V2 offsetof(wl_state_t, crc)
|
||||
|
||||
#endif // _WL_State_H_
|
||||
|
@ -279,27 +279,29 @@ TEST_CASE("Version update test", "[wear_levelling]")
|
||||
esp_partition_erase_range(&fake_partition, 0, fake_partition.size);
|
||||
|
||||
esp_partition_write(&fake_partition, 0, test_partition_v1_bin_start, fake_partition.size);
|
||||
for (int i=0 ; i< 3 ; i++)
|
||||
{
|
||||
printf("Pass %i\n", i);
|
||||
wl_handle_t handle;
|
||||
TEST_ESP_OK(wl_mount(&fake_partition, &handle));
|
||||
size_t sector_size = wl_sector_size(handle);
|
||||
uint32_t* buff = (uint32_t*)malloc(sector_size);
|
||||
|
||||
wl_handle_t handle;
|
||||
TEST_ESP_OK(wl_mount(&fake_partition, &handle));
|
||||
size_t sector_size = wl_sector_size(handle);
|
||||
uint32_t* buff = (uint32_t*)malloc(sector_size);
|
||||
uint32_t init_val = COMPARE_START_CONST;
|
||||
int test_count = fake_partition.size/sector_size - 4;
|
||||
|
||||
uint32_t init_val = COMPARE_START_CONST;
|
||||
int test_count = fake_partition.size/sector_size - 4;
|
||||
|
||||
for (int m=0 ; m < test_count; m++) {
|
||||
TEST_ESP_OK(wl_read(handle, sector_size * m, buff, sector_size));
|
||||
for (int i=0 ; i< sector_size/sizeof(uint32_t) ; i++) {
|
||||
uint32_t compare_val = init_val + i + m*sector_size;
|
||||
if (buff[i] != compare_val)
|
||||
{
|
||||
printf("error compare: 0x%08x != 0x%08x \n", buff[i], compare_val);
|
||||
for (int m=0 ; m < test_count; m++) {
|
||||
TEST_ESP_OK(wl_read(handle, sector_size * m, buff, sector_size));
|
||||
for (int i=0 ; i< sector_size/sizeof(uint32_t) ; i++) {
|
||||
uint32_t compare_val = init_val + i + m*sector_size;
|
||||
if (buff[i] != compare_val)
|
||||
{
|
||||
printf("error compare: 0x%08x != 0x%08x \n", buff[i], compare_val);
|
||||
}
|
||||
TEST_ASSERT_EQUAL( buff[i], compare_val);
|
||||
}
|
||||
TEST_ASSERT_EQUAL( buff[i], compare_val);
|
||||
}
|
||||
free(buff);
|
||||
wl_unmount(handle);
|
||||
}
|
||||
|
||||
free(buff);
|
||||
wl_unmount(handle);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user