loboris / ESP32_TFT_library

Full featured TFT library for ESP32 with demo application
564 stars 219 forks source link

Load image spiffs after OTA #72

Closed elieDaan closed 5 years ago

elieDaan commented 5 years ago

Hello,

After a lot of research I can't yet fix my issue. I'm trying to update my program including the images inside with OTA. My program is based on the native_ota_example provided by Espressif.

I have two tasks. One is for download the .bin file contained my program and another task executed first to download the spiffs_image.img file into spiffs partition at 0x002b0000.

My partition table is :

boot: Partition Table:

Label Usage Type ST Offset Length

0 nvs WiFi data 01 02 00009000 00004000 1 otadata OTA data 01 00 0000d000 00002000 2 phy_init RF data 01 01 0000f000 00001000 3 factory factory app 00 00 00010000 000e0000 4 ota_0 OTA app 00 10 000f0000 000e0000 5 ota_1 OTA app 00 11 001d0000 000e0000 6 storage Unknown data 01 82 002b0000 00100000

To download the spiffs_image and write it into spiffs partition , I write this code :

/**

static void ota_spiffs_task(void pvParameter) { esp_err_t err; / update handle : set by esp_ota_begin(), must be freed via esp_ota_end() / esp_ota_handle_t update_handle = 0 ; const esp_partition_t update_partition = NULL; esp_partition_t *spiffs_partition=NULL; ESP_LOGI(TAG, "Starting OTA SPIFFS...");

const esp_partition_t *configured = esp_ota_get_boot_partition();
const esp_partition_t *running = esp_ota_get_running_partition();

/*Update SPIFFS : 1/ First we need to find SPIFFS partition  */

esp_partition_iterator_t spiffs_partition_iterator=esp_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS,NULL);
while(spiffs_partition_iterator !=NULL){
    spiffs_partition = (esp_partition_t *)esp_partition_get(spiffs_partition_iterator);
    printf("main: partition type = %d.\n", spiffs_partition->type);
    printf("main: partition subtype = %d.\n", spiffs_partition->subtype);
    printf("main: partition starting address = %x.\n", spiffs_partition->address);
    printf("main: partition size = %x.\n", spiffs_partition->size);
    printf("main: partition label = %s.\n", spiffs_partition->label);
    printf("main: partition subtype = %d.\n", spiffs_partition->encrypted);
    printf("\n");
    printf("\n");
    spiffs_partition_iterator=esp_partition_next(spiffs_partition_iterator);
}
vTaskDelay(1000/portTICK_RATE_MS);
esp_partition_iterator_release(spiffs_partition_iterator);

/* Wait for the callback to set the CONNECTED_BIT in the
   event group.
*/
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
                    false, true, portMAX_DELAY);
ESP_LOGI(TAG, "Connect to Wifi ! Start to Connect to Server....");

esp_http_client_config_t config = {
    .url = SPIFFS_SERVER_URL,
    .cert_pem = (char *)server_cert_pem_start,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == NULL) {
    ESP_LOGE(TAG, "Failed to initialise HTTP connection");
    task_fatal_error();
}
err = esp_http_client_open(client, 0);
if (err != ESP_OK) {
    ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
    esp_http_client_cleanup(client);
    task_fatal_error();
}
esp_http_client_fetch_headers(client);

/* 2: Delete SPIFFS Partition  */
err=esp_partition_erase_range(spiffs_partition,spiffs_partition->address,spiffs_partition->size);

int binary_file_length = 0;
/*deal with all receive packet*/
while (1) {
    int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE);
    if (data_read < 0) {
        ESP_LOGE(TAG, "Error: SSL data read error");
        http_cleanup(client);
        task_fatal_error();
    } else if (data_read > 0) {
        /* 3 : WRITE SPIFFS PARTITION */
        err = esp_partition_write(spiffs_partition,0x0,(const void *)ota_write_data, data_read);

        if (err != ESP_OK) {
            http_cleanup(client);
            task_fatal_error();
        }

        binary_file_length += data_read;
        ESP_LOGD(TAG, "Written image length %d", binary_file_length);
    } else if (data_read == 0) {
        ESP_LOGI(TAG, "Connection closed,all data received");
        break;
    }
}
ESP_LOGI(TAG, "Total Write binary data length : %d", binary_file_length);

ESP_LOGI(TAG, "Prepare to launch ota APP task or restart!");
xTaskCreate(&ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
vTaskDelete(NULL);

}

After reboot, the program is correctly executed but without the images. I get this log error : E (176) SPIFFS: mount failed, -10025 E (179) [SPIFFS Test]: Failed to mount or format filesystem

I need to run make flashfs to display images correctly.

Thanks a lot for your help