You can use OTA update with 2 or 3 partition structure.
If using
2 partitions, after each update, the system wil boot from the last updated partition, no
factory partition is available.
Both partitions must be of type
app and subtype
ota_0 &
ota_1.
Here is example partition table from my MicroPython port (on 4 MB Falsh):
Code: Select all
# -------------------------------------------------------
# Name, Type, SubType, Offset, Size, Flags
# -------------------------------------------------------
nvs, data, nvs, 0x9000, 16K,
otadata, data, ota, 0xd000, 8K,
phy_init, data, phy, 0xf000, 4K,
MicroPython_1, app, ota_0, 0x10000, 1856K,
MicroPython_2, app, ota_1, , 1856K,
internalfs, data, fat, , 320K,
If using
3 partitions, after each update, the system wil boot from the last updated
ota partition.
First partitions subtype is
factory and the subtype of the 2nd and 3rd partition is
ota_0 &
ota_1.
After the first update, the system will
never boot from the
factory partition (if any of the
ota partitions are bootable), unless you change the bootloader (
bootloader_start.c) to enable
forced boot from factory partition, usually on some gpio level.
You can also select factory partition as boot partition from application software.
Here is example partition table from my MicroPython port (on 8 MB Falsh):
Code: Select all
# -------------------------------------------------------
# Name, Type, SubType, Offset, Size, Flags
# -------------------------------------------------------
nvs, data, nvs, 0x9000, 16K,
otadata, data, ota, 0xd000, 8K,
phy_init, data, phy, 0xf000, 4K,
MicroPython, app, factory, 0x10000, 1856K,
MicroPython_1, app, ota_0, , 1856K,
MicroPython_2, app, ota_1, , 1856K,
internalfs, data, fat, , 2560K,
Example of modified bootloader_start.c to enable forced boot from factory partition when GPIO02 is low.
Add function to
bootloader_start.c:
Code: Select all
static uint8_t ForceFactoryBoot(void)
{
#if CONFIG_GPIO_INPUT_FORCE_FACTORY
uint8_t timer = 0;
gpio_pad_select_gpio(2);
ets_delay_us(10000); //delay 10 msecs
while (GPIO_INPUT_GET(2)) {
if ((timer % 5) == 0) {
ESP_LOGE(TAG, "Force Factory boot Pin is Active!");
}
ets_delay_us(100000); // wait 100 ms
timer++;
if (timer == 30) {
ESP_LOGE(TAG, "Forcing boot to Factory partition");
return 1;
}
}
ESP_LOGW(TAG, "Normal boot");
#endif
return 0;
}
and change the line:
to:
Code: Select all
if (bs->ota_info.offset != 0 && !ForceFactoryBoot()) {