espflash icon indicating copy to clipboard operation
espflash copied to clipboard

OTA Example/Documentation

Open lohrm-stabl opened this issue 3 years ago • 7 comments

It would be great to have some instructions/examples on how to implement OTA.

Probably the first step would be to build a partition table supporting two OTA partitions, like this:

# Name,   Type, SubType, Offset,   Size,     Flags
nvs,      data, nvs,     0x009000, 0x4000,
otadata,  data, ota,     0x00d000, 0x2000,
phy_init, data, phy,     0x00f000, 0x1000,
ota_0,    app,  ota_0,   0x010000, 0x180000,
ota_1,    app,  ota_1,   0x190000, 0x180000,

Then flash the esp using:

espflash /dev/ttyUSB0 target/xtensa-esp32-espidf/debug/example --partition-table partitions.csv

At this point, the initial software version would be flashed.

Then to installing the first update:

I know that I can export the firmware to a .bin file using:

    espflash save-image ESP32 target/xtensa-esp32-espidf/debug/example test.bin

But this would include the bootloader, right? But I don't want to reflash the bootloader. I only want to have the OTA partition. So how would I save an image with only one partition?

The next step is probably to call espflash write-bin-to-flash? But using which arguments and how would one specify to only write to the OTA partition?

lohrm-stabl avatar Nov 16 '22 15:11 lohrm-stabl

You might have a look at my project https://github.com/taunusflieger/anemometer. I have an ota implementation based on esp-idf and scripts which create the application image without the boot loader.

taunusflieger avatar Nov 16 '22 21:11 taunusflieger

@taunusflieger thanks! That's actually very helpful. But you use cargo espflash save-image --release ESP32-S3 --flash-size 2MB ./bin/firmware-$version.bin (https://github.com/taunusflieger/anemometer/blob/master/create-ota-img.sh) to create an OTA image. But if I read the code right, this would include the bootloader.

lohrm-stabl avatar Nov 18 '22 09:11 lohrm-stabl

You might be right, but if you are I would not understand why you would create the image without the bootloader. This image gets written into one of the two OTA partitions. The boot process picks up one of the two partitions and loads the image from there. That works with the solution. So either it does not contain the boot loader and it is not required or it contains the boot loader as it is required. Why then would you want to create the image without a boot loader?

taunusflieger avatar Nov 18 '22 11:11 taunusflieger

Any update on this? It looks like there's still not a way to get a binary I can use for OTA updates. Given that save-image creates a full-sized binary and knows the partition table, it seems like it should just be able to (even after the fact) just slice out the partition where it stored the active ota binary.

dragazo avatar May 16 '23 16:05 dragazo

From looking at other issues/comments, it seems like the tool always puts the binary in the first app partition? Is that something I can actually rely on? It doesn't seem to be documented anywhere. If so, I think I'll just have to produce a full sized binary, manually parse the partition table, manually slice it out, and hope for the best...

dragazo avatar Sep 19 '23 19:09 dragazo