OTA of factory app

kostyan5
Posts: 50
Joined: Mon Mar 06, 2017 3:16 pm

OTA of factory app

Postby kostyan5 » Fri Apr 07, 2017 6:22 pm

In our project, the factory app is simply a bootloader that grabs the image from an http server. The OTA example shows how to update partitions OTA1 and OTA2. Is it possible to update factory partition using OTA as well, in case we want to push updates to the bootloader itself?

rsimpsonbusa
Posts: 77
Joined: Tue May 17, 2016 8:12 pm

Re: OTA of factory app

Postby rsimpsonbusa » Fri Apr 07, 2017 11:58 pm

As I understand it, there is no such thing as Factory Partition. Either partition (assuming two A and B) is available by a system flag that tells it which was the LAST partition loaded from OTA and to boot that partition (lets say A). When you download a new app via OTA it puts this "new" app in the "other" partition (say B), complete the download and then tells the system that the "current" Partition is now B. If OTA fails for whatever reason, nothing happens and you keep your old App in Partition A.

When OTA is successful it will now boot from B EVEN if you do a USB/SERIAL download to A (most likely) !!!!! :shock: To get unstuck from booting from the last OTA download, you need to

Code: Select all

make erase_flash
and then USB/SERIAL download. :D

kostyan5
Posts: 50
Joined: Mon Mar 06, 2017 3:16 pm

Re: OTA of factory app

Postby kostyan5 » Sat Apr 08, 2017 12:04 am

The partition table for two OTA has a factory partition:

nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000
factory, 0, 0, 0x10000, 1M
ota_0, 0, ota_0, , 1M
ota_1, 0, ota_1, , 1M

I think the idea is that you always want to be able to revert to factory, even if you load a bad (malfunctioning) software into a partition and make it active.

ESP_Angus
Posts: 2201
Joined: Sun May 08, 2016 4:11 am

Re: OTA of factory app

Postby ESP_Angus » Mon Apr 10, 2017 2:08 am

kostyan5 wrote:In our project, the factory app is simply a bootloader that grabs the image from an http server. The OTA example shows how to update partitions OTA1 and OTA2. Is it possible to update factory partition using OTA as well, in case we want to push updates to the bootloader itself?
The short answer is no, if you call esp_ota_begin() with a factory partition then it will fail. The idea is that even if both OTA partitions are somehow corrupted beyond the ability to boot, you can return to the factory partition and start the update process fresh from there. In this configuration, the only thing the factory partition needs to be able to do is to successfully complete an OTA update into a newer firmware.

That said, If you edit the "is_ota_partition()" static function in components/app_update/esp_ota_ops.c then I believe this is the only check which prevents you from OTA flashing non-OTA partitions. So you could theoretically weaken this check (it's not something we're likely to support in IDF, though.)

It is possible to make a custom partition table that doesn't have a factory partition, in which case the first OTA app partition becomes the "factory" initial boot partition, and then each OTA slot is updated with subsequent updates. This is the recommended option if your SPI flash is too small to dedicate a factory partition.

iosixllc
Posts: 69
Joined: Fri Mar 17, 2017 12:13 am

Re: OTA of factory app

Postby iosixllc » Fri May 05, 2017 7:36 am

How do you instruct the tool to use OTA0 as the factory flash location? I put the correct offset into menuconfig, but I still get this:

I (12) boot: compile time 03:25:01
I (13) boot: Enabling RNG early entropy source...
I (13) qio_mode: Enabling QIO for flash chip ISSI
I (14) boot: SPI Speed : 80MHz
I (15) boot: SPI Mode : QIO
I (15) boot: SPI Flash Size : 2MB
I (16) boot: Partition Table:
I (17) boot: ## Label Usage Type ST Offset Length
I (18) boot: 0 nvs WiFi data 01 02 00009000 00004000
I (19) boot: 1 otadata OTA data 01 00 0000d000 00002000
I (21) boot: 2 phy_init RF data 01 01 0000f000 00001000
I (22) boot: 3 ota_0 OTA app 00 10 00010000 000f8000
I (23) boot: 4 ota_1 OTA app 00 11 00108000 000f8000
I (25) boot: End of partition table
E (25) boot: ota data partition invalid and no factory, can't boot

phatpaul
Posts: 67
Joined: Fri Aug 24, 2018 1:14 pm

Re: OTA of factory app

Postby phatpaul » Tue Jun 25, 2019 8:50 pm

@ESP_Angus thanks for the explanation of the concept of the factory partition. I understand that it defeats the purpose of having a fail-safe factory app if one is able to write to it in the field.

But there will be (unusual) instances when we need to upgrade the factory partition via OTA.
And of course, my boss wants me to do just that.

We recently fixed a bug and will be incorporating the bugfix into newly built products,
But we have a bunch of already built-up product in inventory which is not accessible via UART- just Eth/Wifi OTA for programming. The boss doesn't want to just upload the fixed app to an OTA partition because if a user performs a factory reset it would revert to the old firmware with the bug.

I guess the IDF should have an "OTA factory override" function that I could use to create a special OTA which can write to the factory partition?

Also how hard would it be to create an OTA image which wraps the factory .bin file with some minimal code to flash it to the factory partition?

User avatar
luisonoff
Posts: 40
Joined: Fri Feb 09, 2018 12:20 pm

Re: OTA of factory app

Postby luisonoff » Fri Aug 30, 2019 12:53 pm

For future users who find this: changing factory app thru OTA should be doable.
I explain how we changed partition table in this other topic, using a very similar approach you should be able to change factory app I think: viewtopic.php?f=2&t=11482&p=48589#p48589

phatpaul
Posts: 67
Joined: Fri Aug 24, 2018 1:14 pm

Re: OTA of factory app

Postby phatpaul » Wed Jan 08, 2020 6:39 pm

I'll shared my hack to allow update of the factory app partition. Please see here:
https://github.com/chmorgan/libesphttpd/pull/81

Enjoy, no warranties, use at your own risk, of course.

Who is online

Users browsing this forum: No registered users and 42 guests