Page 1 of 1
ESP32 OTA INFORMATION
Posted: Wed Jun 23, 2021 4:00 pm
by lx393ale
I'm doing a project where OTA is needed. To reduce the updating time (the update size is about 2.3Mb), I'm searching a way to:
- Erasing the next partion in one time, instead of erasing and writing ciclically with esp_ota_write();
- And after update it;
It depeands the erasing time of a flash page. Anyone knows how much time takes the erasing operation?
Re: ESP32 OTA INFORMATION
Posted: Thu Jun 24, 2021 1:30 am
by ESP_Sprite
You can use esp_ota_get_next_update_partition() to figure out what the update partition that's going to be used is, then use esp_partition_erase_range(part, 0, part->size) to erase it. Duration typically depends on the size of the partition.
Re: ESP32 OTA INFORMATION
Posted: Thu Jun 24, 2021 10:29 am
by lx393ale
Thank you for the answer. I have another question:
If you go into the function esp_ota_write(), there is a cycle that erase and write for each block of data passed in function.
If I use esp_partition_erase_range(part, 0, part->size) to erase entire partition, after, for writing the update, there is a function that only writes the block of data without the erasing cycle?
Re: ESP32 OTA INFORMATION
Posted: Fri Jun 25, 2021 8:18 am
by ESP_Sprite
That's a good point... I imagine erasing an erased block again should take a lot less time, but I'm not sure there.
However, reading up on the OTA code, your assumption actually is wrong. The OTA logic doesn't erase the partition as it goes along; instead (unless you pass OTA_WITH_SEQUENTIAL_WRITES as the image size) it erases either the entire partition or the length of the image you're going to write as soon as you call esp_ota_begin().
Re: ESP32 OTA INFORMATION
Posted: Fri Jun 25, 2021 2:01 pm
by lx393ale
Actually my idea was to erase all at first, and after write.
In this way I can mask the erasing time in some way.
It seems is erasing sector by sector from
https://github.com/espressif/esp-idf/bl ... _ota_ops.c :
Code: Select all
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
{
const uint8_t *data_bytes = (const uint8_t *)data;
esp_err_t ret;
ota_ops_entry_t *it;
if (data == NULL) {
ESP_LOGE(TAG, "write data is invalid");
return ESP_ERR_INVALID_ARG;
}
// find ota handle in linked list
for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) {
if (it->handle == handle) {
if (it->need_erase) {
// must erase the partition before writing to it
uint32_t first_sector = it->wrote_size / SPI_FLASH_SEC_SIZE;
uint32_t last_sector = (it->wrote_size + size) / SPI_FLASH_SEC_SIZE;
ret = ESP_OK;
if ((it->wrote_size % SPI_FLASH_SEC_SIZE) == 0) {
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * SPI_FLASH_SEC_SIZE);
} else if (first_sector != last_sector) {
ret = esp_partition_erase_range(it->part, (first_sector + 1) * SPI_FLASH_SEC_SIZE, (last_sector - first_sector) * SPI_FLASH_SEC_SIZE);
}
if (ret != ESP_OK) {
return ret;
}
}
[...]
Re: ESP32 OTA INFORMATION
Posted: Sat Jun 26, 2021 5:21 am
by ESP_Sprite
It only does that when need_erase is true, which only happens when you pass OTA_WITH_SEQUENTIAL_WRITES as the image size. Don't do that and the erasing happens up front.