Firmware Update OTA

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Firmware Update OTA

Postby Brunosugui » Tue May 26, 2020 3:58 pm

Hi, my name is Bruno and I'm having some issue on the firmware update procedure over the air.

Actually this happens only on my custom board. On my evk it works fine. Both boards uses ESP32_WROVERB. My evk is Esp32_DevKitC_v4;

I'm using ESP-IDF version 3.3 commit: 722043f73

I'm using the code from advanced_https_ota example.

What happens is that the OTA procedure finishes successfully (all procedures seems to be done Ok) and after reboot (esp_restart()) the bootloader fails to read ota data sequence on my custom board, i get this message:

"OTA sequence numbers both empty (all-0xFF) or partition table does not have bootable ota_apps (app_count=2)" and it boots to the first ota partition when it should boot the second one.

My partition table is structured this way:

nvs, data, nvs, , 0x23000
otadata, data, ota, , 0x2000
phy_init, data, phy, , 0x1000
ota_0, app, ota_0, , 0x1e0000
ota_1, app, ota_1, , 0x1e0000
nvs_key, data, nvs_keys, , 0x1000

For flashing my application in my custom board i'm using Esp-prog board and i created a .bat script using openocd, i'm calling

Code: Select all

openocd.exe -f esp32_devkitj_v1.cfg -f esp32-wrover.cfg -c "program_esp32 [BIN] [ADDRESS] verify exit"
I'm flashing:
  • bootloader.bin @0x1000
  • partitions_custom.bin @0x8000
  • ota_data_initial.bin @0x2c000
  • app.bin @0x30000
Since i did not specified the address on my partition table, it will be filled when compiling my project, right? I can see, through the bootloader INFO logs (on my custom board) that the partition table is successfully detected and the addresses of ota data and app are the same i hardcoded on my flash script, so, i assume it's "looking into the right place".

The application is working fine on my custom board, the only problem is in booting the correct OTA app partition. On the evk everything goes ok.

Could someone please help me?

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

Re: Firmware Update OTA

Postby chegewara » Tue May 26, 2020 7:51 pm

I did not have opportunity to use advanced OTA example, but from your description it looks like one of final steps are missing or failed. This is part of native OTA code, that should be called under hood in advanced example:
https://github.com/espressif/esp-idf/bl ... #L313-L328

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Re: Firmware Update OTA

Postby Brunosugui » Wed May 27, 2020 1:06 pm

Hi chegewara, thanks for the response!

Actually, the advanced OTA example uses the esp_https_ota_finish procedure to switch the boot partition to the next running ota partition (equivalent to esp_ota_set_boot_partition), free the esp https ota context(equivalent to esp_ota_end) and close http connection (equivalent http_cleanup). I also have already tried the native ota example and the same error occurs... I can't manage to make it work on my custom board even though on the evk everything works great.

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

Re: Firmware Update OTA

Postby chegewara » Thu May 28, 2020 12:12 pm

Ok, i think i know what is wrong.
Brunosugui wrote: nvs, data, nvs, , 0x23000
otadata, data, ota, , 0x2000
As far as i remember otadata partition has to be aligned to 16. Please try to change both partitions order.

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Re: Firmware Update OTA

Postby Brunosugui » Thu May 28, 2020 2:45 pm

You mean just rever se the order of these partitions, like

otadata, data, ota, , 0x2000
nvs, data, nvs, , 0x23000
phy_init, data, phy, , 0x1000
ota_0, app, ota_0, , 0x1e0000
ota_1, app, ota_1, , 0x1e0000
nvs_key, data, nvs_keys, , 0x1000

?

I will give it a try! Thank you very much!

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Re: Firmware Update OTA

Postby Brunosugui » Fri May 29, 2020 7:23 pm

Hi chegewara,

I tried to change the partitions order, but no progress, still got the same error.

Used this partition table
otadata, data, ota, , 0x2000
nvs, data, nvs, , 0x23000
phy_init, data, phy, , 0x1000
ota_0, app, ota_0, , 0x1e0000
ota_1, app, ota_1, , 0x1e0000
nvs_key, data, nvs_keys, , 0x1000
and after running the code on my evk, got the address generated from new partition table and flashed my custom board with these address:
  • bootloader.bin @0x1000
  • partitions_custom.bin @0x8000
  • ota_data_initial.bin @0x9000
  • app.bin @0x30000

I also implemented a test routine for trying to read the otadata sequence right after the ota procedure (before restarting):

I ran the esp_partition_find() for retrieving the esp_partition_t structure of ota data, then called esp_partition_read() for getting the ota data.
On my evk, they seem to be right, since on my first update their values are :
[0].ota_seq=1
[1].ota_seq = 2

i also checked the bootloader_common_get_active_otadata() and it returns 1.

On the other hand, this procedure on my custom board gives me the sequences:
[0].ota_seq=ffffffff
[1].ota_seq=ffffffff

and the bootloader_common_get_active_otadata() returns -1.

Looks like even the esp_https_ota_finish() returning ESP_OK there is a problem while writing the ota data or set correctly the ota data.

Any thoughts?

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

Re: Firmware Update OTA

Postby chegewara » Fri May 29, 2020 8:56 pm

ota_data_initial.bin @0x9000
This address is still not 16 bytes aligned. In that case you have to set start address, 0x10000 for example.
Remember the same rule, address aligned, needs to be used for factory and ota partitions. Thats why most common are 0x10000, 0x20000 in case of first app partition, if you will search for custom partition tables.

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Re: Firmware Update OTA

Postby Brunosugui » Mon Jun 08, 2020 2:26 pm

Sorry for the delayed answer, but now i'm struggling to run my application on my custom board. Openocd returns the flash and verify were successfully terminated but the application is not starting....

by the way, my new partition table:

# name, type, subtype, offset, size, flags
phy_init, data, phy, 0x9000, 0x1000,
nvs_key, data, nvs_keys, , 0x1000,
otadata, data, ota, 0x10000, 0x2000,
nvs, data, nvs, , 0x23000,
ota_0, app, ota_0, , 0x1e0000,
ota_1, app, ota_1, , 0x1e0000,

and the addresses i'm flashing the binaries are:

bootloader.bin 0x1000
partition_table 0x8000
ota_data_initial.bin 0x10000
app.bin 0x40000

should work now, right? Anything i may be missing?

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

Re: Firmware Update OTA

Postby chegewara » Tue Jun 09, 2020 1:35 am

Nope, still wrong start address for ota_0 and ota_1.

Brunosugui
Posts: 8
Joined: Wed Mar 18, 2020 6:26 pm

Re: Firmware Update OTA

Postby Brunosugui » Wed Jun 10, 2020 6:50 pm

When i left undefined the offset address of ota_0 and ota_1 it automatically filled it with 0x40000 and 0x220000, so i used the 0x40000 to flash my application, it worked. But I filled manually each of the offsets from my partition table just in case:

phy_init, data, phy, 0x9000, 0x1000,
nvs_key, data, nvs_keys, 0xa000, 0x1000,
otadata, data, ota, 0x10000, 0x2000,
nvs, data, nvs, 0x12000, 0x23000,
ota_0, app, ota_0, 0x40000, 0x1e0000,
ota_1, app, ota_1, 0x220000, 0x1e0000,

My application is running on my custom board, but the OTA update still fails... (on the evk it's everything working 100%). Any clues on what might be wrong?

Who is online

Users browsing this forum: Majestic-12 [Bot] and 271 guests