Esp-idf: [TW#28632] esptool write_flash: error: argument <address> <filename>: Detected overlap at address: 0x8000 for file: native_ota_example/build/partitions_two_ota.bin

Created on 31 Jan 2019  路  4Comments  路  Source: espressif/esp-idf

Environment

  • Development Kit: ESP32-DevKitC
  • Kit version (DevKitC): [v1]
  • Module or chip used: ESP32-WROOM-32
  • IDF version (run git describe --tags to find it):
    v3.3-beta1-316-g4b2feb316
  • Build System: [Make]
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    1.22.0-80-g6c4433a
  • Operating System: [linux]
  • Power Supply: [USB]

Problem Description

When trying to flash my esp32 I got these message:
esptool write_flash: error: argument

: Detected overlap at address: 0x8000 for file: /home/borch/Documents/Robotica/esp/esp32-reedswitch/native_ota_example/build/partitions_two_ota.bin
/home/borch/Documents/Robotica/esp/esp-idf-master/esp-idf/components/esptool_py/Makefile.projbuild:62: recipe for target 'flash' failed
make: * [flash] Error 2

Expected Behavior

make should flash correctly the example.

Actual Behavior

make flash fails

Steps to repropduce

  1. git clone lastest version of IDF
  2. copied the native_ota_example folder to another separate location
  3. run make menuconfig and setup the wireless setting and file URI
  4. run make builds the app successfully
  5. make erase_flash executes successfully.
  6. make flash fails with stated error.

Code to reproduce this issue

This is the native_ota_example without modifications

/* OTA example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"

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

#include "nvs.h"
#include "nvs_flash.h"

#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
#define EXAMPLE_SERVER_URL CONFIG_FIRMWARE_UPG_URL
#define BUFFSIZE 1024

static const char *TAG = "native_ota_example";
/*an ota data write buffer ready to write to the flash*/
static char ota_write_data[BUFFSIZE + 1] = { 0 };
extern const uint8_t server_cert_pem_start[] asm("_binary_ca_cert_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end");

/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t wifi_event_group;

/* The event group allows multiple bits for each event,
   but we only care about one event - are we connected
   to the AP with an IP? */
const int CONNECTED_BIT = BIT0;

static esp_err_t event_handler(void *ctx, system_event_t *event)
{
    switch (event->event_id) {
    case SYSTEM_EVENT_STA_START:
        esp_wifi_connect();
        break;
    case SYSTEM_EVENT_STA_GOT_IP:
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
        esp_wifi_connect();
        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
        break;
    default:
        break;
    }
    return ESP_OK;
}

static void initialise_wifi(void)
{
    tcpip_adapter_init();
    wifi_event_group = xEventGroupCreate();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_WIFI_SSID,
            .password = EXAMPLE_WIFI_PASS,
        },
    };
    ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
}

static void http_cleanup(esp_http_client_handle_t client)
{
    esp_http_client_close(client);
    esp_http_client_cleanup(client);
}

static void __attribute__((noreturn)) task_fatal_error()
{
    ESP_LOGE(TAG, "Exiting task due to fatal error...");
    (void)vTaskDelete(NULL);

    while (1) {
        ;
    }
}

static void ota_example_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_LOGI(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);

    /* 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 = EXAMPLE_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);

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

    err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
        http_cleanup(client);
        task_fatal_error();
    }
    ESP_LOGI(TAG, "esp_ota_begin succeeded");

    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) {
            err = esp_ota_write( update_handle, (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);

    if (esp_ota_end(update_handle) != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_end failed!");
        http_cleanup(client);
        task_fatal_error();
    }
    err = esp_ota_set_boot_partition(update_partition);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
        http_cleanup(client);
        task_fatal_error();
    }
    ESP_LOGI(TAG, "Prepare to restart system!");
    esp_restart();
    return ;
}

void app_main()
{
    // Initialize NVS.
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        // OTA app partition table has a smaller NVS partition size than the non-OTA
        // partition table. This size mismatch may cause NVS initialization to fail.
        // If this happens, we erase NVS partition and initialize NVS again.
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK( err );

    initialise_wifi();
    xTaskCreate(&ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
}

// If your code is longer than 30 lines, GIST is preferred.

Debug Logs

Other items if possible

  • [ ] sdkconfig file (attach the sdkconfig file from your project folder)
    sdkconfig.txt

  • [ ] elf file in the build folder (note this may contain all the code details and symbols of your project.)

  • [ ] coredump (This provides stacks of tasks.)

Most helpful comment

Try increase this CONFIG_PARTITION_TABLE_OFFSET option. 0x8000 -> 0x10000. It will help you.

(or change CONFIG_LOG_BOOTLOADER_LEVEL from VERBOSE to INFO. It also resolves it)

All 4 comments

Try increase this CONFIG_PARTITION_TABLE_OFFSET option. 0x8000 -> 0x10000. It will help you.

(or change CONFIG_LOG_BOOTLOADER_LEVEL from VERBOSE to INFO. It also resolves it)

Hi @KonstantinKondrashov, I changed from VERBOSE to INFO and it was able to flash esp. I was struggling with project's configuration settings. I did not realize this overlapping was related to the verbosity level. How is it related to the partition table? Thank you.

Hi @borch84.

Here is the output of the make command.

To flash all build output, run 'make flash' or:
python /home/virtpc/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM4 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio - flash_freq 40m --flash_size detect
0x1000 /home/virtpc/esp/esp-idf/examples/system/ota/native_ota_example/build/bootloader/bootloader.bin
0x10000 /home/virtpc/esp/esp-idf/examples/system/ota/native_ota_example/build/sntp.bin
0x8000 /home/virtpc/esp/esp-idf/examples/system/ota/native_ota_example/build/partitions_two_ota.bin

Here you can see that 3 bin files are written to the following addresses:
0x1000 bootloader.bin,
0x8000 partitions_two_ota.bin.
0x10000 native_ota_example.bin - application,

The overlap error occurs due to the fact that the bootloader did not fit into the allocated space between 0x1000-0x8000 and began to overlap with the next section of the partitions_two_ota, this happened because of the CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE option that adds a lot of code to the bootloader. Reducing the logging level allowed to flash it.

If you want to leave the logging level as VERBOSE. To do this, you need to move partitions_two_ota and native_ota_example. This is done simply by changing the CONFIG_PARTITION_TABLE_OFFSET option from 0x8000 -> 0x10000.

Thank you @KonstantinKondrashov for the clarification. I will play with these VERBOSE level and the offset value around. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

hex007 picture hex007  路  4Comments

okasha55 picture okasha55  路  3Comments

feelfreelinux picture feelfreelinux  路  4Comments

waayst picture waayst  路  4Comments