Page 1 of 2

OTA requires to erase flash

Posted: Wed Aug 29, 2018 12:00 pm
by burkulesomesh43
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?

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 12:47 pm
by fly135
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

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 12:56 pm
by burkulesomesh43
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?

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 3:27 pm
by fly135
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

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 4:30 pm
by burkulesomesh43
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.

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 5:00 pm
by WiFive
make erase_ota - Erase ota_data partition. After that will boot first bootable partition (factory or OTAx).

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 5:56 pm
by fly135
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

Re: OTA requires to erase flash

Posted: Wed Aug 29, 2018 10:10 pm
by loboris
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);

Re: OTA requires to erase flash

Posted: Thu Aug 30, 2018 5:56 am
by burkulesomesh43
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.

Re: OTA requires to erase flash

Posted: Thu Aug 30, 2018 6:40 am
by burkulesomesh43
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