ESP32: Slow OTA on encrypted flash

boborjan
Posts: 9
Joined: Thu Sep 19, 2019 5:46 pm

ESP32: Slow OTA on encrypted flash

Postby boborjan » Thu Nov 09, 2023 2:25 pm

Hi, I have a problem with flash write speed on encrypted flash when using esp_ota_write().
The time needed to flash a 8kByte array increases from 25ms to ~400ms after flash encryption and secure boot v2 is enabled.
Esptool.py wite times increase from 17s to only 22s which I assume as correct (this is the write time of a 1.2M image). This implies that the bare flash write+encryption is fast but for some reason esp_ota_write() is slow.
Has anyone encountered such issue?

Thanks,
Viktor

boborjan
Posts: 9
Joined: Thu Sep 19, 2019 5:46 pm

Re: ESP32: Slow OTA on encrypted flash

Postby boborjan » Fri Nov 10, 2023 9:43 pm

I made a simple test that runs on the encrypted board:

Code: Select all


    esp_partition_t* partition = esp_partition_find_first(
        ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, "ota_0");

    if(partition) {
        int64_t beginT, endT;
        //const int RUNS = 1000;
        static uint8_t data[8192];
        esp_fill_random(data, sizeof(data));

        for(;;) {
            ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, sizeof(data)));//sizeof(data)));

            beginT = esp_timer_get_time();
            partition->encrypted = 1;
            ESP_ERROR_CHECK(esp_partition_write(partition, 0, data, sizeof(data)));
            endT = esp_timer_get_time();
            printf("esp_partition_write: %dms\n", (uint32_t)(endT - beginT)/1000);

            ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, sizeof(data)));//sizeof(data)));

            beginT = esp_timer_get_time();
            partition->encrypted = 0;
            ESP_ERROR_CHECK(esp_partition_write(partition, 0, data, sizeof(data)));
            endT = esp_timer_get_time();
            printf("esp_partition_write: %dms\n", (uint32_t)(endT - beginT)/1000);

            vTaskDelay(1000);
        }
    }
Results (write times of a 8kbyte block):
25ms (plaintext), 105ms (encrypted). Is this normal?

boborjan
Posts: 9
Joined: Thu Sep 19, 2019 5:46 pm

Re: ESP32: Slow OTA on encrypted flash

Postby boborjan » Sun Nov 12, 2023 8:23 pm

I found the reason for the slow encrypted writes, details can be found here: https://github.com/espressif/esp-idf/issues/12553

pacucha42
Posts: 33
Joined: Fri Mar 29, 2019 12:56 pm

Re: ESP32: Slow OTA on encrypted flash

Postby pacucha42 » Thu Nov 16, 2023 6:34 am

Hi @boborjan,
thank you for the report, your findings are correct. Our teams is already taking a look into it, you can watch the progress in your https://github.com/espressif/esp-idf/issues/12505 issue.

Who is online

Users browsing this forum: No registered users and 60 guests