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);
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);
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;
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);
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);
esp_partition_erase_range(&fake_partition, 0, fake_partition.size);
esp_partition_write(&fake_partition, 0, test_partition_v1_bin_start, fake_partition.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;
-
- 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 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);
+
+ 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);
+ }
+ TEST_ASSERT_EQUAL( buff[i], compare_val);
}
- TEST_ASSERT_EQUAL( buff[i], compare_val);
}
+ free(buff);
+ wl_unmount(handle);
}
-
- free(buff);
- wl_unmount(handle);
}