OTA partition data format?

zliudr
Posts: 366
Joined: Thu Oct 03, 2019 5:15 am

OTA partition data format?

Postby zliudr » Sun Mar 29, 2020 9:01 pm

I'm learning OTA. It seems that the simple https_ota is not hard to incorporate in my existing project (after much reading and testing of course). On the other hand, I didn't not observe rollback (I didn't enable it first). I'm now interested in understanding the otadata partition data format. For now I only OTA once and the new firmware has no OTA. The otadata partition is mostly un-programmed except for the first 32 bytes:

Code: Select all

01 20 20 20 ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff 9a 98 43 47
I scoured the internet for the data format for couldn't find anything. I'm not trying to alter the data myself but it helps me to have a whole picture of the simple ota and possibly adopt the not so simple version so that my device can download firmware to sd card and update itself at its own time. Thanks.

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: OTA partition data format?

Postby vonnieda » Mon Mar 30, 2020 3:00 pm

I haven't seen it documented, but it's open source, so you could always check there: https://github.com/espressif/esp-idf/tr ... er_support

Jason

zliudr
Posts: 366
Joined: Thu Oct 03, 2019 5:15 am

Re: OTA partition data format?

Postby zliudr » Mon Mar 30, 2020 6:55 pm

Thanks for the help. I did some digging and found this include file:
esp-idf/components/bootloader_support/include/esp_flash_partitions.h

It has the states and the data structure defined as below:

Code: Select all

/// OTA_DATA states for checking operability of the app.
typedef enum {
    ESP_OTA_IMG_NEW             = 0x0U,         /*!< Monitor the first boot. In bootloader this state is changed to ESP_OTA_IMG_PENDING_VERIFY. */
    ESP_OTA_IMG_PENDING_VERIFY  = 0x1U,         /*!< First boot for this app was. If while the second boot this state is then it will be changed to ABORTED. */
    ESP_OTA_IMG_VALID           = 0x2U,         /*!< App was confirmed as workable. App can boot and work without limits. */
    ESP_OTA_IMG_INVALID         = 0x3U,         /*!< App was confirmed as non-workable. This app will not selected to boot at all. */
    ESP_OTA_IMG_ABORTED         = 0x4U,         /*!< App could not confirm the workable or non-workable. In bootloader IMG_PENDING_VERIFY state will be changed to IMG_ABORTED. This app will not selected to boot at all. */
    ESP_OTA_IMG_UNDEFINED       = 0xFFFFFFFFU,  /*!< Undefined. App can boot and work without limits. */
} esp_ota_img_states_t;

/* OTA selection structure (two copies in the OTA data partition.)
   Size of 32 bytes is friendly to flash encryption */
typedef struct {
    uint32_t ota_seq;
    uint8_t  seq_label[20];
    uint32_t ota_state;
    uint32_t crc; /* CRC32 of ota_seq field only */
} esp_ota_select_entry_t;
So the first 4 bytes are sequence number, the last 4 bytes are CRC of the sequence number, the second 4 bytes to the last 4 bytes are the state of the OTA partition, with ff ff ff ff meaning undefined, so it's good to boot, since I didn't enable rollback:

Code: Select all

01 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff 9a 98 43 47
Notice that the 20 in my OP was error from copy pasting in a hex editor pulg-in of NPP. Should all be 00.

Once rollback is enabled and cancel_rollback() is called and a reboot is done, state changes into VALID (02 00 00 00):

Code: Select all

01 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 
ff ff ff ff ff ff ff ff 02 00 00 00 9a 98 43 47

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 2 guests