OTA

API Reference

Macros

ESP_ERR_OTA_BASE 0x1500

base error code for ota_ops api

ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01)

want to write or erase current running partition

ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02)

ota data partition info is error

ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03)

validate ota image failed

Type Definitions

typedef uint32_t esp_ota_handle_t

Opaque handle for application update obtained from app_ops.

Functions

esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp_ota_handle_t *out_handle)

format input partition in flash to 0xFF as input image size, if unkown image size ,pass 0x0 or 0xFFFFFFFF, it will erase all the partition ,Otherwise, erase the required range

Return
:
  • ESP_OK: if format ota image OK
  • ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
  • ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
Parameters
  • partition: Pointer to partition structure which need to be updated Must be non-NULL.
  • image_size: size of image need to be updated
  • out_handle: handle which should be used for esp_ota_write or esp_ota_end call

esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)

Write data to input input partition.

Return
:
  • ESP_OK: if write flash data OK
  • ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
  • ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
Parameters
  • handle: Handle obtained from esp_ota_begin
  • data: Pointer to data write to flash
  • size: data size of recieved data

esp_err_t esp_ota_end(esp_ota_handle_t handle)

Finish the update and validate written data.

Return
:
  • ESP_OK: if validate ota image pass
  • ESP_ERR_OTA_VALIDATE_FAILED: validate the ota image is invalid
Parameters
  • handle: Handle obtained from esp_ota_begin

esp_err_t esp_ota_set_boot_partition(const esp_partition_t *partition)

Set next boot partition, call system_restart() will switch to run it.

Note
if you want switch to run a bin file has never been checked before,please validate it’s signature firstly
Return
:
  • ESP_OK: if set next boot partition OK
  • ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
Parameters
  • partition: Pointer to partition structure which need to boot

const esp_partition_t *esp_ota_get_boot_partition(void)

Get partition info of current running image.

Return
pointer to esp_partition_t structure, or NULL if no partition is found or operate flash failed,This pointer is valid for the lifetime of the application.