Bugfix for write size. The write size for encryption have to be rounded to 16 bytes.

A wl_config structure size now ounded to 16.
Flash Emulator updated to work with defined minimum size.
Tests are updated.
pull/1735/head
Dmitry 2018-03-06 10:26:21 +03:00
rodzic 17e8d49f26
commit 7b287c25b1
6 zmienionych plików z 37 dodań i 12 usunięć

Wyświetl plik

@ -318,13 +318,13 @@ esp_err_t WL_Flash::updateWL()
uint32_t byte_pos = this->state.pos * this->cfg.wr_size; uint32_t byte_pos = this->state.pos * this->cfg.wr_size;
this->used_bits = 0; this->used_bits = 0;
// write state to mem. We updating only affected bits // write state to mem. We updating only affected bits
result |= this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, &this->used_bits, 1); result |= this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, &this->used_bits, this->cfg.wr_size);
if (result != ESP_OK) { if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - update position 1 result=%08x", __func__, result); ESP_LOGE(TAG, "%s - update position 1 result=%08x", __func__, result);
this->state.access_count = this->state.max_count - 1; // we will update next time this->state.access_count = this->state.max_count - 1; // we will update next time
return result; return result;
} }
result |= this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, &this->used_bits, 1); result |= this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, &this->used_bits, this->cfg.wr_size);
if (result != ESP_OK) { if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - update position 2 result=%08x", __func__, result); ESP_LOGE(TAG, "%s - update position 2 result=%08x", __func__, result);
this->state.access_count = this->state.max_count - 1; // we will update next time this->state.access_count = this->state.max_count - 1; // we will update next time

Wyświetl plik

@ -29,8 +29,15 @@ typedef struct WL_Config_s {
uint32_t wr_size; /*!< Minimum amount of bytes per one block at write operation: 1...*/ uint32_t wr_size; /*!< Minimum amount of bytes per one block at write operation: 1...*/
uint32_t version; /*!< A version of current implementatioon. To erase and reallocate complete memory this ID must be different from id before.*/ uint32_t version; /*!< A version of current implementatioon. To erase and reallocate complete memory this ID must be different from id before.*/
size_t temp_buff_size; /*!< Size of temporary allocated buffer to copy from one flash area to another. The best way, if this value will be equal to sector size.*/ size_t temp_buff_size; /*!< Size of temporary allocated buffer to copy from one flash area to another. The best way, if this value will be equal to sector size.*/
uint32_t reserved[3]; /*!< dummy array to make wl_config_t size compatible with flash encryption (divided by 16)*/
uint32_t crc; /*!< CRC for this config*/ uint32_t crc; /*!< CRC for this config*/
public:
WL_Config_s()
{
for (int i=0 ; i< 3 ; i++) this->reserved[i] = 0;
}
} wl_config_t; } wl_config_t;
_Static_assert((sizeof(wl_config_t) % 16) == 0, "Size of wl_config_t structure should be compatible with flash encryption");
#endif // _WL_Config_H_ #endif // _WL_Config_H_

Wyświetl plik

@ -17,12 +17,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "esp_log.h"
Flash_Emulator::Flash_Emulator(size_t size, size_t sector_sise) static const char *TAG = "Flash_Emulator";
Flash_Emulator::Flash_Emulator(size_t size, size_t sector_sise, size_t min_size)
{ {
this->reset_count = 0x7fffffff; this->reset_count = 0x7fffffff;
this->size = size; this->size = size;
this->sector_sise = sector_sise; this->sector_sise = sector_sise;
this->min_size = min_size;
this->buff = (uint8_t *)malloc(this->size); this->buff = (uint8_t *)malloc(this->size);
this->access_count = new uint32_t[this->size / this->sector_sise]; this->access_count = new uint32_t[this->size / this->sector_sise];
memset(this->access_count, 0, this->size / this->sector_sise * sizeof(uint32_t)); memset(this->access_count, 0, this->size / this->sector_sise * sizeof(uint32_t));
@ -81,6 +85,18 @@ esp_err_t Flash_Emulator::erase_range(size_t start_address, size_t size)
esp_err_t Flash_Emulator::write(size_t dest_addr, const void *src, size_t size) esp_err_t Flash_Emulator::write(size_t dest_addr, const void *src, size_t size)
{ {
esp_err_t result = ESP_OK; esp_err_t result = ESP_OK;
if ((size % this->min_size) != 0)
{
result = ESP_ERR_INVALID_SIZE;
ESP_LOGE(TAG, "%s - wrond size, result=%08x, size=%08x", __func__, result, size);
return result;
}
if ((dest_addr % this->min_size) != 0)
{
result = ESP_ERR_INVALID_SIZE;
ESP_LOGE(TAG, "%s - wrong address, result=%08x, address=%08x", __func__, result, dest_addr);
return result;
}
if ((this->reset_count != 0x7fffffff) && (this->reset_count != 0)) { if ((this->reset_count != 0x7fffffff) && (this->reset_count != 0)) {
this->reset_count--; this->reset_count--;
} }

Wyświetl plik

@ -25,7 +25,7 @@ class Flash_Emulator : public Flash_Access
{ {
public: public:
Flash_Emulator(size_t size, size_t sector_sise); Flash_Emulator(size_t size, size_t sector_sise, size_t min_size);
virtual size_t chip_size(); virtual size_t chip_size();
@ -43,6 +43,7 @@ public:
public: public:
size_t size; size_t size;
size_t sector_sise; size_t sector_sise;
size_t min_size;
uint8_t *buff; uint8_t *buff;
uint32_t *access_count; uint32_t *access_count;

Wyświetl plik

@ -25,7 +25,7 @@
#define FLASH_PAGE_SIZE FLASH_SECTOR_SIZE*1 #define FLASH_PAGE_SIZE FLASH_SECTOR_SIZE*1
#define FLASH_UPDATERATE 3 #define FLASH_UPDATERATE 3
#define FLASH_TEMP_SIZE FLASH_SECTOR_SIZE #define FLASH_TEMP_SIZE FLASH_SECTOR_SIZE
#define FLASH_WR_BLOCK_SIZE 2 #define FLASH_WR_BLOCK_SIZE 16
static const char *TAG = "wl_test_host"; static const char *TAG = "wl_test_host";
Flash_Access *s_flash; Flash_Access *s_flash;
@ -47,7 +47,7 @@ TEST_CASE("flash starts with all bytes == 0xff", "[spi_flash_emu]")
wl->wr_size = FLASH_WR_BLOCK_SIZE; wl->wr_size = FLASH_WR_BLOCK_SIZE;
WL_Flash *wl_flash = new WL_Flash(); WL_Flash *wl_flash = new WL_Flash();
Flash_Emulator *emul = new Flash_Emulator(FLASH_ACCESS_SIZE + FLASH_START_ADDR, FLASH_SECTOR_SIZE); Flash_Emulator *emul = new Flash_Emulator(FLASH_ACCESS_SIZE + FLASH_START_ADDR, FLASH_SECTOR_SIZE, FLASH_WR_BLOCK_SIZE);
CHECK(wl_flash->config(wl, emul) == ESP_OK); CHECK(wl_flash->config(wl, emul) == ESP_OK);
test_power_down(wl_flash, emul, TEST_COUNT_MAX); test_power_down(wl_flash, emul, TEST_COUNT_MAX);

Wyświetl plik

@ -76,11 +76,6 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
break; break;
} }
} }
if (*out_handle == WL_INVALID_HANDLE) {
ESP_LOGE(TAG, "MAX_WL_HANDLES=%d instances already allocated", MAX_WL_HANDLES);
result = ESP_ERR_NO_MEM;
goto out;
}
wl_ext_cfg_t cfg; wl_ext_cfg_t cfg;
cfg.full_mem_size = partition->size; cfg.full_mem_size = partition->size;
@ -94,6 +89,12 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
// FAT sector size by default will be 512 // FAT sector size by default will be 512
cfg.fat_sector_size = CONFIG_WL_SECTOR_SIZE; cfg.fat_sector_size = CONFIG_WL_SECTOR_SIZE;
if (*out_handle == WL_INVALID_HANDLE) {
ESP_LOGE(TAG, "MAX_WL_HANDLES=%d instances already allocated", MAX_WL_HANDLES);
result = ESP_ERR_NO_MEM;
goto out;
}
// Allocate memory for a Partition object, and then initialize the object // Allocate memory for a Partition object, and then initialize the object
// using placement new operator. This way we can recover from out of // using placement new operator. This way we can recover from out of
// memory condition. // memory condition.