Back to factory APP (OTA)

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Back to factory APP (OTA)

Postby urbanze » Sat Jan 13, 2018 11:22 pm

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?

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

Re: Back to factory APP (OTA)

Postby chegewara » Sun Jan 14, 2018 3:57 am


p-rimes
Posts: 89
Joined: Thu Jun 08, 2017 6:20 pm

Re: Back to factory APP (OTA)

Postby p-rimes » Sun Jan 14, 2018 4:17 am

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?


User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Back to factory APP (OTA)

Postby urbanze » Sun Jan 14, 2018 12:37 pm

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!

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Back to factory APP (OTA)

Postby urbanze » Sun Jan 14, 2018 12:39 pm

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:

Edzelf
Posts: 1
Joined: Wed Jan 17, 2018 10:37 am

Re: Back to factory APP (OTA)

Postby Edzelf » Wed Jan 17, 2018 10:49 am

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
        }
    }
}

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

Re: Back to factory APP (OTA)

Postby chegewara » Sun Jan 21, 2018 4:15 am

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.

solam4
Posts: 1
Joined: Mon Sep 11, 2023 3:07 pm

Re: Back to factory APP (OTA)

Postby solam4 » Mon Sep 11, 2023 3:47 pm

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?

Who is online

Users browsing this forum: No registered users and 116 guests