BLE OTA

gpgabriel
Posts: 3
Joined: Wed Oct 17, 2018 11:30 am

BLE OTA

Postby gpgabriel » Fri Oct 26, 2018 12:57 pm

Hi,

I'm trying to get the OTA to work over BLE.

I created 2 characteristics (1 for control and 1 for data), modified the Partition table to 'Factory app, two OTA definitions', build the project, wrote a simple script in JS (noble) script and sent the binary file over BLE. I added logs to see what data is being received and the compared it with the data from the binary file to make sure that the data is being sent in the correct order.

Code: Select all

I (696102) esp_image: reading image header @ 0x110000
I (696112) esp_image: image header: 0xe9 0x09 0x02 0x02 40081034
I (696112) esp_image: loading segment header 0 at offset 0x110018
I (696122) esp_image: segment data length 0x1c0c4 data starts 0x110020
I (696132) esp_image: segment 0 map_segment 1 segment_data_offs 0x110020 load_addr 0x3f400020
I (696142) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x1c0c4 (114884) map
I (696152) esp_image: free data page_count 0x0000003e
I (696212) esp_image: loading segment header 1 at offset 0x12c0e4
I (696212) esp_image: segment data length 0x33c4 data starts 0x12c0ec
I (696212) esp_image: segment 1 map_segment 0 segment_data_offs 0x12c0ec load_addr 0x3ffc0000
I (696222) esp_image: segment 1: paddr=0x0012c0ec vaddr=0x3ffc0000 size=0x033c4 ( 13252)
I (696232) esp_image: free data page_count 0x0000003e
I (696242) esp_image: loading segment header 2 at offset 0x12f4b0
I (696242) esp_image: segment data length 0x0 data starts 0x12f4b8
I (696252) esp_image: segment 2 map_segment 0 segment_data_offs 0x12f4b8 load_addr 0x3ffc33c4
I (696262) esp_image: segment 2: paddr=0x0012f4b8 vaddr=0x3ffc33c4 size=0x00000 (     0)
I (696272) esp_image: free data page_count 0x0000003e
I (696272) esp_image: loading segment header 3 at offset 0x12f4b8
I (696282) esp_image: segment data length 0x400 data starts 0x12f4c0
I (696292) esp_image: segment 3 map_segment 0 segment_data_offs 0x12f4c0 load_addr 0x40080000
0x40080000: _iram_start at /Users/gaborgabriel/Documents/Kano/SpeakerKit_ESP32/esp-idf/components/freertos/xtensa_vectors.S:1685

I (696292) esp_image: segment 3: paddr=0x0012f4c0 vaddr=0x40080000 size=0x00400 (  1024)
0x40080000: _iram_start at /Users/gaborgabriel/Documents/Kano/SpeakerKit_ESP32/esp-idf/components/freertos/xtensa_vectors.S:1685

I (696302) esp_image: free data page_count 0x0000003e
I (696312) esp_image: loading segment header 4 at offset 0x12f8c0
I (696322) esp_image: segment data length 0x748 data starts 0x12f8c8
I (696322) esp_image: segment 4 map_segment 0 segment_data_offs 0x12f8c8 load_addr 0x40080400
I (696332) esp_image: segment 4: paddr=0x0012f8c8 vaddr=0x40080400 size=0x00748 (  1864)
I (696342) esp_image: free data page_count 0x0000003e
I (696352) esp_image: loading segment header 5 at offset 0x130010
I (696352) esp_image: segment data length 0x6384c data starts 0x130018
I (696362) esp_image: segment 5 map_segment 1 segment_data_offs 0x130018 load_addr 0x400d0018
0x400d0018: _stext at ??:?

I (696372) esp_image: segment 5: paddr=0x00130018 vaddr=0x400d0018 size=0x6384c (407628) map
0x400d0018: _stext at ??:?

I (696382) esp_image: free data page_count 0x0000003e
I (696582) esp_image: loading segment header 6 at offset 0x193864
I (696582) esp_image: segment data length 0x10940 data starts 0x19386c
I (696582) esp_image: segment 6 map_segment 0 segment_data_offs 0x19386c load_addr 0x40080b48
I (696592) esp_image: segment 6: paddr=0x0019386c vaddr=0x40080b48 size=0x10940 ( 67904)
I (696602) esp_image: free data page_count 0x0000003e
I (696642) esp_image: loading segment header 7 at offset 0x1a41ac
I (696642) esp_image: segment data length 0x0 data starts 0x1a41b4
I (696642) esp_image: segment 7 map_segment 0 segment_data_offs 0x1a41b4 load_addr 0x400c0000
I (696652) esp_image: segment 7: paddr=0x001a41b4 vaddr=0x400c0000 size=0x00000 (     0)
I (696662) esp_image: free data page_count 0x0000003e
I (696662) esp_image: loading segment header 8 at offset 0x1a41b4
I (696672) esp_image: segment data length 0x0 data starts 0x1a41bc
I (696682) esp_image: segment 8 map_segment 0 segment_data_offs 0x1a41bc load_addr 0x50000000
I (696692) esp_image: segment 8: paddr=0x001a41bc vaddr=0x50000000 size=0x00000 (     0)
I (696702) esp_image: free data page_count 0x0000003e
I (696702) esp_image: image start 0x00110000 end of last section 0x001a41bc
I (696712) esp_image: Calculated hash: 8e2ae049
E (696712) esp_image: Image hash failed - image is corrupt
I (696722) esp_image: Expected hash: 46a7c8af
It fails because there's a difference in the generated hash.

At the moment I'm using the binary from `build/{my_project}.bin`, I don't touch that file at all before I send it over BLE. I'm not sure if that's correct or if there's a different process to generated the binary for the OTA.

I'm running out of ideas, not sure what else to try to get this to work.

PS. I'm using `esp_ota_ops.h` to initialise/write/end the OTA and `esp_ota_get_next_update_partition` to get the next available partition. There are no errors logged until the end of the OTA.

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE OTA

Postby chegewara » Sun Dec 02, 2018 8:24 am

I just finished and tested my OTA over BLE example code. This is raw code that i have atm to write ota partition:

Code: Select all

#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"

#include "esp_system.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_ota_ops.h"

#include "sdkconfig.h"

static int binary_file_length = 0;
static char* TAG = "TAG";
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;

static void task_fatal_error()
{
    ESP_LOGE(__func__, "FATAL ERROR");
}

extern void ota_begin()
{
    esp_err_t err;
    /* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */

    ESP_LOGE(TAG, "Starting OTA example...");

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

    if (configured != running) {
        ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x",
                 configured->address, running->address);
        ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become corrupted somehow.)");
    }
    ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
             running->type, running->subtype, running->address);

    ESP_LOGI(TAG, "Connect to Wifi ! Start to Connect to Server....");


    update_partition = esp_ota_get_next_update_partition(NULL);
    assert(update_partition != NULL);
    ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
             update_partition->subtype, update_partition->address);

    err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_begin failed, error=%d", err);
        task_fatal_error();
    }
    ESP_LOGI(TAG, "esp_ota_begin succeeded");
}
#define BUFFSIZE 517
#define TEXT_BUFFSIZE 517
static char ota_write_data[BUFFSIZE + 1] = { 0 };

extern void ota_chunk(uint8_t* text, size_t buff_len) 
{
    ESP_LOG_BUFFER_HEX_LEVEL(__func__, text, 32, ESP_LOG_INFO);
    esp_err_t err = esp_ota_write( update_handle, (const void *)text, buff_len);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Error: esp_ota_write failed! err=0x%x", err);
        task_fatal_error();
    }
    binary_file_length += buff_len;
    // ESP_LOGI(TAG, "Have written image length %d", binary_file_length);
    // }
}

extern void ota_finalize() 
{
    ESP_LOGI(TAG, "Total Write binary data length : %d", binary_file_length);

    if (esp_ota_end(update_handle) != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_end failed!");
        task_fatal_error();
    }
    esp_err_t err = esp_ota_set_boot_partition(update_partition);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_set_boot_partition failed! err=0x%x", err);
        task_fatal_error();
    }
    ESP_LOGI(TAG, "Prepare to restart system!");
    esp_restart();
    return ;
}
Its basically copy/paste logic from old esp-idf ota example.

Who is online

Users browsing this forum: arnoldb1778, Kopplin and 278 guests