ivmarkov / rust-esp32-std-demo

Rust on ESP32 STD demo app. A demo STD binary crate for the ESP32[XX] and ESP-IDF, which connects to WiFi, Ethernet, drives a small HTTP server and draws on a LED screen.
Apache License 2.0
785 stars 105 forks source link

ESP32-C3 OTA from buffer #148

Closed netanbi closed 1 year ago

netanbi commented 1 year ago

Hi i am using esp32-c3 program it with ota from HTTP request and everything work very good now i program a different project , i take hello world example and convert the .bin file to c file then i create header file with that "hello word" c file

this is the start of the .bin file in c just to explain how it look

ifndef BIN_FILEH

define BIN_FILEH

const unsigned char ota_buff[158432] = { 0xE9, 0x05, 0x02, 0x1F, 0x22, 0x03, 0x38, 0x40, 0xEE, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x03, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x02, 0x3C, 0xE0, 0x78, 0x00, 0x00, 0x32, 0x54, 0xCD, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

the program enter to ota state but i received error ; E (25341) esp_image: invalid segment length 0x696e6920

I (12591) http_server: http_server_configure: Starting server on port: '80' with task priority: '4' I (12601) http_server: http_server_configure: Registering URI handlers http_server_OTA_update_handler: Writing to partition subtype 17 at offset 0x200000 I (25331) esp_image: segment 0: paddr=00200020 vaddr=3c020020 size=078e0h ( 30944) map E (25341) esp_image: invalid segment length 0x696e6920 I (25341) http_server: http_server_OTA_update_handler: esp_ota_end ERROR!!! I (25351) pp: pp rom version: 9387209

this is the function : esp_err_t http_server_OTA_update_handler(void) { //printf("enter to OTA\r\n"); esp_ota_handle_t ota_handle; int content_length = DATA_LE; int content_received = 0; int recv_len =1001; bool flash_successful = false; static bool is_req_body_started = false;

const esp_partition_t *update_partition = esp_ota_get_next_update_partition(NULL);

do
    {
    //printf("fota fun enter\r\n");
    printf("http_server_OTA_update_handler: OTA RX: %d of %d\r", content_received, content_length);

    if (!is_req_body_started)
        {
            is_req_body_started = true;
            printf("http_server_OTA_update_handler: OTA file size: %d\r\n", content_length);

            esp_err_t err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle);
            if (err != ESP_OK)
            {
                printf("http_server_OTA_update_handler: Error with OTA begin, cancelling OTA\r\n");
                return ESP_FAIL;
            }
            else
            {
                printf("http_server_OTA_update_handler: Writing to partition subtype %d at offset 0x%x\r\n", update_partition->subtype, (unsigned int)update_partition->address);
            }
        }
    else
            {
        // Write OTA data
        esp_ota_write(ota_handle, ota_buff, MIN(recv_len, (content_length-content_received)));
        content_received += MIN(recv_len, (content_length-content_received));
        vTaskDelay(100 / portTICK_PERIOD_MS);
        //printf("recv_len %d\r\n", recv_len);
        //printf("content_length %d\r\n", content_length);
        //printf("content_received %d\r\n", content_received);
        //printf("min %d\r\n",  MIN(recv_len, (content_length-content_received)));
            }

    }

 while ( recv_len > 0 && content_received < content_length);

if (esp_ota_end(ota_handle) == ESP_OK)
{
    // Lets update the partition
    if (esp_ota_set_boot_partition(update_partition) == ESP_OK)
    {
        const esp_partition_t *boot_partition = esp_ota_get_boot_partition();
        ESP_LOGI(TAG, "http_server_OTA_update_handler: Next boot partition subtype %d at offset 0x%x", boot_partition->subtype, (unsigned int)boot_partition->address);
        flash_successful = true;
    }
    else
    {
        ESP_LOGI(TAG, "http_server_OTA_update_handler: FLASHED ERROR!!!");
    }
}
else
{
    ESP_LOGI(TAG, "http_server_OTA_update_handler: esp_ota_end ERROR!!!");
}

// We won't update the global variables throughout the file, so send the message about the status
//if (flash_successful) { http_server_monitor_send_message(HTTP_MSG_OTA_UPDATE_SUCCESSFUL); } else { http_server_monitor_send_message(HTTP_MSG_OTA_UPDATE_FAILED); }

return ESP_OK;

}

please advice how i can fix that , because i see he enter to segment 0 but filed to continue

ivmarkov commented 1 year ago

Are you pasting a C example to a Rust project? What are you trying to do, actually?

netanbi commented 1 year ago

Hi i already fix that , thenks

בתאריך יום ג׳, 13 ביוני 2023, 10:29, מאת ivmarkov @.***

:

Are you pasting a C example to a Rust project? What are you trying to do, actually?

— Reply to this email directly, view it on GitHub https://github.com/ivmarkov/rust-esp32-std-demo/issues/148#issuecomment-1588707989, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZRXJCIZB43OOAOSAQKLZTXLAJGBANCNFSM6AAAAAAWMAEJTE . You are receiving this because you authored the thread.Message ID: @.***>