Changing running app partition without reseting ESP

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

Changing running app partition without reseting ESP

Postby gunar.kroeger » Fri Jul 27, 2018 7:09 pm

Is there a way to jump to another app without using

Code: Select all

esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
and resetting ESP?

This is our partition table:

Code: Select all

# Name,		Type,	SubType, Offset,   Size
nvs,		data,	nvs,     0x9000,  	0x4000
otadata,	data,	ota,     0xd000,  	0x2000
phy_init,	data,	phy,     0xf000,  	0x1000
ota_0,		app, 	ota_0,	0x10000, 	0x80000
ota_1,		app,	ota_1, 		   , 	0x360000
storage,	data,	fat, 		   ,	0x10000
We are using OTA update with one small partition which contains the code to look for new firmware inside the SD card and write it onto the big partition.

The big partition contains code that can download new firmware from Wifi or Bluetooth into the SD card and also update the small partition binary.

But we always want the small partition to boot first and check for new firmware, in case we get a brick on the big partition which prevents it from changing the boot partition back to the small one. This way the user could unbrick the device simply by inserting the new firmware in the SD card.

Is this possible? I was looking into the bootloader functions in
esp-idf/components/bootloader_support/include_priv/bootloader_utility.h
but it seems that they are not accessible to use.

Thank you
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Changing running app partition without reseting ESP

Postby kolban » Sat Jul 28, 2018 8:23 pm

The bootloader component found here is most definitetly available for user applications to tweak/change.

https://github.com/espressif/esp-idf/tr ... bootloader

This would be recommended place to determine which partition to boot from. Rather than thinking about switching partitions at run-time to "load" a whole new application, try and think through discrete applications that do one thing and how to choose which application runs.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

Re: Changing running app partition without reseting ESP

Postby gunar.kroeger » Mon Jul 30, 2018 2:31 pm

Thank you for the reply
try and think through discrete applications that do one thing and how to choose which application runs.
What are the options on how to switch the running application? I know that there is a way to use GPIO to define which app starts but that is not an option for us. The other option I know of is using this function:

Code: Select all

esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
But what if in a future release the program freezes due to a bug and never reaches this function? There would be no way to update the binary without opening the equipment and using a serial flasher.. and that is not something we would want the user having to do.

So is there a 3rd option?

Sorry if there is something obvious I didn't understand

Thanks
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Changing running app partition without reseting ESP

Postby kolban » Wed Aug 01, 2018 12:46 am

We should assume that there is some "signal" that can be used to indicate that something has gone wrong and you want to "fall back". Options would be:

1) A signal on a GPIO. eg a button held down at boot.
2) The reason that the ESP32 boots. There is a code that indicates why the ESP32 has booted. Is it a virgin power on, is it a watchdog reset, was it a crash/panic etc. You could use this as an indication for what to do next.
3) Positive logic in your app. Set something in non-volatile storage immediately after boot that should be cleared when your app is in a happy and running state. If either at next boot it is not cleared or after a timer expires it is not cleared then that might be an indication that something is not right.
4) ... likely others.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

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

Re: Changing running app partition without reseting ESP

Postby WiFive » Wed Aug 01, 2018 4:11 am

Right now the bootloader reads the otadata partition to decide which app to boot but it could also read data out of rtc ram that tells it which app to boot, data that was written by the previous running app.

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

Re: Changing running app partition without reseting ESP

Postby gunar.kroeger » Wed Aug 01, 2018 3:12 pm

Hmm interesting. So, a simple solution would be to boot on ota0 partition if there was a "virgin power on" so that if this partition calls esp_reset() it would fall into another reason and start the ota1 partition binary.

Is this supported in the current bootloader by changing settings in menuconfig or would I have to write my own to implement this logic?

Thanks again
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

Who is online

Users browsing this forum: hml9083@hotmail.com, jollayc, PeterR and 58 guests