ESP32 OTA INFORMATION

lx393ale
Posts: 15
Joined: Fri Jan 10, 2020 12:41 pm

ESP32 OTA INFORMATION

Postby lx393ale » Wed Jun 23, 2021 4:00 pm

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?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 OTA INFORMATION

Postby ESP_Sprite » Thu Jun 24, 2021 1:30 am

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.

lx393ale
Posts: 15
Joined: Fri Jan 10, 2020 12:41 pm

Re: ESP32 OTA INFORMATION

Postby lx393ale » Thu Jun 24, 2021 10:29 am

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?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 OTA INFORMATION

Postby ESP_Sprite » Fri Jun 25, 2021 8:18 am

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().

lx393ale
Posts: 15
Joined: Fri Jan 10, 2020 12:41 pm

Re: ESP32 OTA INFORMATION

Postby lx393ale » Fri Jun 25, 2021 2:01 pm

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;
                }
            }
[...]            

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 OTA INFORMATION

Postby ESP_Sprite » Sat Jun 26, 2021 5:21 am

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.

Who is online

Users browsing this forum: No registered users and 435 guests