Need help with OTA [Solved]

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Need help with OTA [Solved]

Postby fly135 » Fri Apr 20, 2018 5:48 pm

I'm running code in a factory partition and want to perform an OTA update.

When I try to perform the update I get the message that OTA update saw an invalid magic byte.(expected 0xE9, saw 0x3c)

I'm using the bin file in my app's build directory. And the docs say that any bin file is fine. So I'm not sure what's up.
You've probably noticed there is nothing special about the "hello world" example when used for OTA updates. This is because any .bin app file which is built by esp-idf can be used as an app image for OTA. The only difference is whether it is written to a factory partition or an OTA partition.
John A
Last edited by fly135 on Sat Apr 21, 2018 11:54 pm, edited 1 time in total.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Need help with OTA

Postby fly135 » Fri Apr 20, 2018 8:09 pm

I just realized after looking at it again, my binary file does begin with 0xE9. So I need to figure out why the software doesn't see it.

John A

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Need help with OTA

Postby fly135 » Fri Apr 20, 2018 8:10 pm

BTW, the documentation claims that OTA partitions must be type data and subtype ota, which is contrary to the partition file used by the example, which uses type=app and subtype=ota_x (x=0..n)

John A

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

Re: Need help with OTA

Postby chegewara » Fri Apr 20, 2018 8:20 pm

Long time ago ive got the same issue:
https://github.com/espressif/esp-idf/is ... -345602666
Last edited by chegewara on Fri Apr 20, 2018 8:42 pm, edited 1 time in total.

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

Re: Need help with OTA

Postby chegewara » Fri Apr 20, 2018 8:22 pm

fly135 wrote:BTW, the documentation claims that OTA partitions must be type data and subtype ota, which is contrary to the partition file used by the example, which uses type=app and subtype=ota_x (x=0..n)

John A
It does not matter what partition is setup for OTA bin file, its important when you flash bootloader, partition image and application from which you gonna update.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Need help with OTA

Postby fly135 » Fri Apr 20, 2018 11:03 pm

I get the OTA partition and write the bin file to it, but when it goes to set the boot partition it returns an ESP_ERR_NOT_FOUND.

I took a look at the code in esp_ota_set_boot_partition that returns not found and it is confusing me. The OTA partition I give as a parameter is type=ESP_PARTITION_TYPE_APP and subtype=ESP_PARTITION_SUBTYPE_APP_OTA_0. The code looks like it is searching for ESP_PARTITION_TYPE_DATA/ESP_PARTITION_SUBTYPE_DATA_OTA.

I figure it should fail the test "partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY" and then go to the else statement where it searches for partitions of the wrong type.

Code: Select all

    // if set boot partition to factory bin ,just format ota info partition
    if (partition->type == ESP_PARTITION_TYPE_APP) {
        if (partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) {
            find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
            if (find_partition != NULL) {
                return esp_partition_erase_range(find_partition, 0, find_partition->size);
            } else {
                return ESP_ERR_NOT_FOUND;
            }
        } else {
            // try to find this partition in flash,if not find it ,return error
            find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
            if (find_partition != NULL) {
                return esp_rewrite_ota_data(partition->subtype);
            } else {
                return ESP_ERR_NOT_FOUND;
            }
        }
    } else {
        return ESP_ERR_INVALID_ARG;
    }

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

Re: Need help with OTA

Postby chegewara » Sat Apr 21, 2018 12:01 am

How your partition table looks like?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Need help with OTA

Postby fly135 » Sat Apr 21, 2018 1:36 am

chegewara wrote:How your partition table looks like?
I have a 16MB flash.

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 2M,
storage,  data, spiffs,  ,        0xF0000,
ota_0,    0, ota_0,     0x400000, 2M,
ota_1,    0, ota_1,     0x600000, 2M,
This line indicates that it got the next update partition, which is the same partition the code sends to ota_get_next_update_partition.

Writing to partition subtype 16 at offset 0x400000

eprintf(eLOG_OTA, "Writing to partition subtype %d at offset 0x%x\n",update_partition->subtype, update_partition->address);

then later this call fails with the not found...

esp_ota_set_boot_partition(update_partition);

John A

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

Re: Need help with OTA

Postby chegewara » Sat Apr 21, 2018 1:53 am

This is default ota partition table:

Code: Select all

# Espressif ESP32 Partition Table
# Name,   Type, SubType, Offset,  Size
nvs,      data, nvs,     0x9000,  0x4000
otadata,  data, ota,     0xd000,  0x2000
phy_init, data, phy,     0xf000,  0x1000
factory,  0,    0,       0x10000, 1M
ota_0,    0,    ota_0,   ,        1M
ota_1,    0,    ota_1,   ,        1M
http://esp-idf.readthedocs.io/en/latest ... ion-tables

As you can see you are missing this type partition, its very important partition:

Code: Select all

otadata,  data, ota,
http://esp-idf.readthedocs.io/en/latest ... -partition

Now your code. You have to find partition ESP_PARTITION_TYPE_APP:
if (partition->type == ESP_PARTITION_TYPE_APP) {
if (partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) {
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); <--- here is error, it needs to be ESP_PARTITION_TYPE_APP
and here is the same:
else {
// try to find this partition in flash,if not find it ,return error
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); <--- here is error, it needs to be ESP_PARTITION_TYPE_APP
You can also search for proper OTA partition this way:
https://github.com/espressif/esp-idf/bl ... ain.c#L236

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Need help with OTA

Postby fly135 » Sat Apr 21, 2018 11:43 pm

chegewara wrote:This is default ota partition table:

Code: Select all

# Espressif ESP32 Partition Table
# Name,   Type, SubType, Offset,  Size
nvs,      data, nvs,     0x9000,  0x4000
otadata,  data, ota,     0xd000,  0x2000
phy_init, data, phy,     0xf000,  0x1000
factory,  0,    0,       0x10000, 1M
ota_0,    0,    ota_0,   ,        1M
ota_1,    0,    ota_1,   ,        1M
http://esp-idf.readthedocs.io/en/latest ... ion-tables

As you can see you are missing this type partition, its very important partition:

Code: Select all

otadata,  data, ota,
http://esp-idf.readthedocs.io/en/latest ... -partition
Oh wow! totally missed that. Thank you!

The other code I posted is in the SDK, so I assume it's fine.

John A

Who is online

Users browsing this forum: Baidu [Spider] and 164 guests