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