Is it possible to read my OTA partition application image size at runtime

MichaelS
Posts: 29
Joined: Mon Jul 08, 2024 12:08 am

Is it possible to read my OTA partition application image size at runtime

Postby MichaelS » Sun Sep 01, 2024 11:00 am

I am developing (because I couldn't find an IDF example app) an application where my ROOT_MESH will download and update itself with an OTA image from an HTTPS server (from working example), and then proceed to read the current working OTA partition and send it in fragments of 1024 bytes across the WIFI mesh network using esp_mesh_send.

Going well so far but have run into a snag finding out how large the app in the current partition is when I am reading it using esp_partition_read. I expected the size would be returned in the esp_ota_get_partition_description but it is not. I don't want to send the entire OTA partition when my application is much less.

I added a work around test detecting when I read a block (1024 bytes) entirely consisting of 0xff and assuming this is empty flash. My concern is I would like to use the SHA256 of the esp_app_desc_t as part of my detection the image has changed at the MESH_NODE and I am assuming this won't match if I have added a bunch of 0xff bytes on the end.

I have tested adding a bunch of 0xffs to my current .bin file and then OTA updating it to the ROOT_NODE using https OTA, and doesn't seem to mind them. I also found I could change the contents of the bin file at the start in the description block changing the App name, version and date, and the OTA update still loaded and ran fine. This really surprised me as it demonstrates there is no form of file integrity check (eg checksum or CRC) in the bin file itself. I am not sure what the sha256 in the application description does? Maybe this will become a problem if I enable "Require signed app images" later.

I would really like to know the original image size, is this possible to obtain at runtime?

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Is it possible to read my OTA partition application image size at runtime

Postby MicroController » Sun Sep 01, 2024 3:22 pm

Can't you get the image size when downloading the image from the server, or when writing the new image to flash?
Store that size somewhere (NVS,...) and retrieve it when needed.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: Is it possible to read my OTA partition application image size at runtime

Postby boarchuz » Sun Sep 01, 2024 4:13 pm

You can use esp_image_get_metadata(): https://github.com/espressif/esp-idf/bl ... #L115-L127

MichaelS
Posts: 29
Joined: Mon Jul 08, 2024 12:08 am

Re: Is it possible to read my OTA partition application image size at runtime

Postby MichaelS » Mon Sep 02, 2024 7:55 am

Thanks both of you for your responses.
MicroController: yes I could do this but I was not wanting to reinvent the wheel.
boarchuz: Thanks, this is exactly what I needed
Cheers

Who is online

Users browsing this forum: No registered users and 101 guests