OTA requires to erase flash

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

OTA requires to erase flash

Postby burkulesomesh43 » Wed Aug 29, 2018 12:00 pm

Hi all,
I am updating my firmware using OTA example given in esp idf.
when I am flashing the code to esp32, it needs to erase flash before flashing the code in esp32. so I am using command "make erase_flash flash" and after that my code works with startup.

is there any API to flash entire flash in esp32?
--
Somesh Burkule

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

Re: OTA requires to erase flash

Postby fly135 » Wed Aug 29, 2018 12:47 pm

I'm more interested in why you are asking the question than the answer. If you erase the entire flash with the API your application will likely crash because you erased it. The OTA example erases the appropriate location in the flash before writing the update to it.

John A

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: OTA requires to erase flash

Postby burkulesomesh43 » Wed Aug 29, 2018 12:56 pm

fly135 wrote:I'm more interested in why you are asking the question than the answer. If you erase the entire flash with the API your application will likely crash because you erased it. The OTA example erases the appropriate location in the flash before writing the update to it.

John A
actually problem is that when i want to update the firmware using ota example, i need to erase entire flash. if i cant erase it, the firmware will not update. and if i want to erase flash without connecting esp32 to my system then how can i erase the flash?
--
Somesh Burkule

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

Re: OTA requires to erase flash

Postby fly135 » Wed Aug 29, 2018 3:27 pm

burkulesomesh43 wrote:actually problem is that when i want to update the firmware using ota example, i need to erase entire flash. if i cant erase it, the firmware will not update. and if i want to erase flash without connecting esp32 to my system then how can i erase the flash?
Seems like the post I made above was adequate to indicate to you that your notion of needing to erase the entire flash was wrong. In addition I indicated that the OTA example will erase the regions of flash needed to perform the update. The OTA example will download a new firmware build and reboot with your new firmware in flash. You don't need to erase the flash yourself.

John A

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: OTA requires to erase flash

Postby burkulesomesh43 » Wed Aug 29, 2018 4:30 pm

fly135 wrote:
burkulesomesh43 wrote:actually problem is that when i want to update the firmware using ota example, i need to erase entire flash. if i cant erase it, the firmware will not update. and if i want to erase flash without connecting esp32 to my system then how can i erase the flash?
Seems like the post I made above was adequate to indicate to you that your notion of needing to erase the entire flash was wrong. In addition I indicated that the OTA example will erase the regions of flash needed to perform the update. The OTA example will download a new firmware build and reboot with your new firmware in flash. You don't need to erase the flash yourself.

John A
when I am flashing the code of ota for updated firmware without erasing the flash, it will not work. esp32 runs the previous code which is flashed. but as I flash updated firmware code of ota with erasing the flash using make erase_flash flash command, the esp32 runs the ota code and update the firmware..
So what is the issue? I can't understand.
--
Somesh Burkule

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: OTA requires to erase flash

Postby WiFive » Wed Aug 29, 2018 5:00 pm

make erase_ota - Erase ota_data partition. After that will boot first bootable partition (factory or OTAx).

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

Re: OTA requires to erase flash

Postby fly135 » Wed Aug 29, 2018 5:56 pm

burkulesomesh43 wrote:when I am flashing the code of ota for updated firmware without erasing the flash, it will not work. esp32 runs the previous code which is flashed. but as I flash updated firmware code of ota with erasing the flash using make erase_flash flash command, the esp32 runs the ota code and update the firmware..
So what is the issue? I can't understand.
After you burn the first OTA the device always boots off an OTA partition. It will never boot from the factory partition after that unless you erase the OTADATA partition, which is instructing the 2nd stage bootloader to boot from OTA. WiFive's post is telling you how to erase the OTADATA partition.

John A

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: OTA requires to erase flash

Postby loboris » Wed Aug 29, 2018 10:10 pm

fly135 wrote:After you burn the first OTA the device always boots off an OTA partition.. It will never boot from the factory partition after that unless you erase the OTADATA partition, which is instructing the 2nd stage bootloader to boot from OTA....
From application, it is quite easy to set from which partition, including factory, you want to boot on the next restart using esp_ota_set_boot_partition(part).
You can find the bootable partition by name and type using:

Code: Select all

const esp_partition_t *boot_part1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, part_name);
const esp_partition_t *boot_part2 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, part_name);
const esp_partition_t *boot_part3 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, part_name);

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: OTA requires to erase flash

Postby burkulesomesh43 » Thu Aug 30, 2018 5:56 am

loboris wrote:
fly135 wrote:After you burn the first OTA the device always boots off an OTA partition.. It will never boot from the factory partition after that unless you erase the OTADATA partition, which is instructing the 2nd stage bootloader to boot from OTA....
From application, it is quite easy to set from which partition, including factory, you want to boot on the next restart using esp_ota_set_boot_partition(part).
You can find the bootable partition by name and type using:

Code: Select all

const esp_partition_t *boot_part1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, part_name);
const esp_partition_t *boot_part2 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, part_name);
const esp_partition_t *boot_part3 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, part_name);
Ok. thank you.
Now I am trying to understand how ota works. how partitions work to update fiemware with factory app, ota0, ota1...
then I will try your way.
--
Somesh Burkule

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: OTA requires to erase flash

Postby burkulesomesh43 » Thu Aug 30, 2018 6:40 am

fly135 wrote:
burkulesomesh43 wrote:when I am flashing the code of ota for updated firmware without erasing the flash, it will not work. esp32 runs the previous code which is flashed. but as I flash updated firmware code of ota with erasing the flash using make erase_flash flash command, the esp32 runs the ota code and update the firmware..
So what is the issue? I can't understand.
After you burn the first OTA the device always boots off an OTA partition. It will never boot from the factory partition after that unless you erase the OTADATA partition, which is instructing the 2nd stage bootloader to boot from OTA. WiFive's post is telling you how to erase the OTADATA partition.

John A
see the post
viewtopic.php?t=1624#p7544
--
Somesh Burkule

Who is online

Users browsing this forum: No registered users and 91 guests