Page 1 of 1

Back to factory APP (OTA)

Posted: Sat Jan 13, 2018 11:22 pm
by urbanze
Once the OTA's updates are made in the OTA sections, the Factory APP is intact, so what is the procedure to return to the first code, stored in the Factory?

Re: Back to factory APP (OTA)

Posted: Sun Jan 14, 2018 3:57 am
by chegewara

Re: Back to factory APP (OTA)

Posted: Sun Jan 14, 2018 4:17 am
by p-rimes
That thread is very interesting indeed.

A couple things were not finalized in that thread:
  • Are the patches to the bootloader still needed at this point? Is there any way for a typical "factory reset" other than duplicating the bootloader sources into each app, and making a similar patch (and presumably keeping everything in lockstep with esp-idf forever afterwards)?
  • Is there a way to transfer control flow to a different partition (i.e. the just-programmed one, or back to factory), WITHOUT a reboot?
  • Does the esp-idf bootloader do a fallback boot to factory, in case of a corrupt image?

Re: Back to factory APP (OTA)

Posted: Sun Jan 14, 2018 5:16 am
by chegewara

Re: Back to factory APP (OTA)

Posted: Sun Jan 14, 2018 12:37 pm
by urbanze
p-rimes wrote:That thread is very interesting indeed.

A couple things were not finalized in that thread:
  • Are the patches to the bootloader still needed at this point? Is there any way for a typical "factory reset" other than duplicating the bootloader sources into each app, and making a similar patch (and presumably keeping everything in lockstep with esp-idf forever afterwards)?
  • Is there a way to transfer control flow to a different partition (i.e. the just-programmed one, or back to factory), WITHOUT a reboot?
  • Does the esp-idf bootloader do a fallback boot to factory, in case of a corrupt image?

I made some tests with image (binary) sending and all editions (simple) that I tested, returned error when finalizing the update, that is, we are already prevented from several inconveniences like loss of bytes when transferring the data through WiFi/etc.
I tried to lose bytes in the transfer and also to exchange bytes for others, to simulate a corrupted byte such as 0x45 by 0x46. Both tests I did several times were not loaded and the current boot partition kept running.

The function that always returns this error is "esp_ota_end (update_handle)" "(ESP_ERR_OTA_VALIDATE_FAILED)"

I know they are simple tests but they are the easiest to do in practice mainly with Wireless communications, I believe. This is great for us!
However, if the binary is correct (but not the code, for example an infinite loop), we can try to make a RESET REASON check and thus booting the APP factory, it's simple and maybe it works very well!

Re: Back to factory APP (OTA)

Posted: Sun Jan 14, 2018 12:39 pm
by urbanze
Oh, I had not seen this partitions reference, there is a function in that reference that can return the pointer to the factory app and so loads it, thanks! :lol:

Re: Back to factory APP (OTA)

Posted: Wed Jan 17, 2018 10:49 am
by Edzelf
You could execute this snippet to restore the factory version:

Code: Select all

//***********************************************************************************************
//                                B A C K T O F A C T O R Y                                     *
//***********************************************************************************************
// Return to factory version.                                                                   *
// This will set the otadata to boot from the factory image, ignoring previous OTA updates.     *
//***********************************************************************************************
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 ( tag, "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 ( tag, "Failed to set boot partition" ) ;
	}
	else
	{
            esp_restart() ;                                         // Restart ESP
        }
    }
}

Re: Back to factory APP (OTA)

Posted: Sun Jan 21, 2018 4:15 am
by chegewara
I thought about changing bootloader to have option to restart esp32 from factory partition.
Pros:
- i dont need to add code snippet to each application and i can use for example vanilla esp-idf examples to ota update (my current project)
Cons:
- gpio used to revert to factory partition is hardcoded in bootloader and cant be changed in different applications.

Re: Back to factory APP (OTA)

Posted: Mon Sep 11, 2023 3:47 pm
by solam4
Are bootloader patch requirements still required? Is there a way to perform a "factory reset" without duplicated bootloader sources for each app?
Can control flows be transferred between partitions without requiring a reboot?
Does the esp-idd bootloader support fallback boot to factory in case of image corruption?