Hello,
I wanted to inquire if it was possible to setup a 2 OTA partitions scheme where one contains the simple ota example for instance and its role would be to update then boot on the second partition (my actual application). Is it possible to OTA update just this second partition and for instance reboot the esp32 (from my main application) to the first partition where I can then wait for OTA ?
The way i have used it so far is that my first and second partition are actually the same in size and content (both contain OTA code AND my application code). If it's possible to separate both then I can have the smallest first OTA parition just for update and a second partition with just my application code (and a lot bigger in size). It seems to me that we have three partitions in the case of simple_ota_example : factory, ota_0 and ota_1. When I compile my code and flash it with usb, I assume it goes to factory and later when OTA happens it either goes to ota_0 or ota_1. Why then do we have 3 app partitions and not just let's say factory and ota_0 ?
Does what i'm saying make sense ? I have tried to dissect the example of simple_ota_example but cannot seem to see where the choice of partition to update happens. Also, I would also need to know how to reboot the ESP32 on a specific partition.
Thanks in advance guys
OTA update : 2 partitions one with OTA program and second with application program
Re: OTA update : 2 partitions one with OTA program and second with application program
Yes you could have a single OTA app partition and a small factory app partition with the sole purpose of updating and booting the OTA partition.
1. From the OTA app, erase the OTA data partition and reset in order to force the bootloader to boot the factory partition. In the factory app (or bootloader), check if the OTA app is valid and restore the OTA data.
2. Customise the bootloader. For example, from the OTA app, use rtc_retain_mem_t to set a flag indicating that a factory boot is desired; within the bootloader, check/clear the flag and select the boot partition accordingly.
Typically, the factory app would be a fallback option, while the OTA app partitions alternate as they update and activate each other. You can't have a single OTA app partition if you intend to update while running from that partition because, aside from itself, the factory partition is the only other app partition and that should never be altered.Why then do we have 3 app partitions and not just let's say factory and ota_0 ?
I don't think IDF has any existing way to one-time boot a different partition from within a running app. Couple ideas:how to reboot the ESP32 on a specific partition
1. From the OTA app, erase the OTA data partition and reset in order to force the bootloader to boot the factory partition. In the factory app (or bootloader), check if the OTA app is valid and restore the OTA data.
2. Customise the bootloader. For example, from the OTA app, use rtc_retain_mem_t to set a flag indicating that a factory boot is desired; within the bootloader, check/clear the flag and select the boot partition accordingly.
Re: OTA update : 2 partitions one with OTA program and second with application program
Thanks for the reply boarchuz !
I kept looking at this in the meanwhile and understood what you mentioned exactly. I got the example working and i can switch between the factory and OTA app through reboot. The following code snippet (found here : https://www.esp32.com/viewtopic.php?t=4210) allows to boot to factory
I'm running a 1M factory and 6M OTA APP this way.
Thanks again for all the clarification
I kept looking at this in the meanwhile and understood what you mentioned exactly. I got the example working and i can switch between the factory and OTA app through reboot. The following code snippet (found here : https://www.esp32.com/viewtopic.php?t=4210) allows to boot to factory
Code: Select all
void backtofactory()
{
esp_partition_iterator_t pi ; // Iterator for find
const esp_partition_t* factory ; // Factory partition
esp_err_t err ;
pi = esp_partition_find ( ESP_PARTITION_TYPE_APP, // Get partition iterator for
ESP_PARTITION_SUBTYPE_APP_FACTORY, // factory partition
"factory" ) ;
if ( pi == NULL ) // Check result
{
ESP_LOGE ( "FACTORY", "Failed to find factory partition" ) ;
}
else
{
factory = esp_partition_get ( pi ) ; // Get partition struct
esp_partition_iterator_release ( pi ) ; // Release the iterator
err = esp_ota_set_boot_partition ( factory ) ; // Set partition for boot
if ( err != ESP_OK ) // Check error
{
ESP_LOGE ( "FACTORY", "Failed to set boot partition" ) ;
}
else
{
esp_restart() ; // Restart ESP
}
}
}
Thanks again for all the clarification
Re: OTA update : 2 partitions one with OTA program and second with application program
You probably will learn this hard way, but as far as i know esp32 wont handle that big application. IIRC limit is around 3MB.shirogeek wrote: I'm running a 1M factory and 6M OTA APP this way.
Thanks again for all the clarification
Who is online
Users browsing this forum: No registered users and 350 guests