Chapter 2. API Reference
esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, size_t size,
uint32_t offset)
Write OTA update data to partition.
This function can write data in non contiguous manner. If flash encryption is enabled, data should be 16 byte
aligned.
Note While performing OTA, if the packets arrive out of order, esp_ota_write_with_offset() can be used
to write data in non contiguous manner. Use of esp_ota_write_with_offset() in combination with
esp_ota_write() is not recommended.
Return
• ESP_OK: Data was written to flash successfully.
• ESP_ERR_INVALID_ARG: handle is invalid.
• ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
• ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
• ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
Parameters
• handle: Handle obtained from esp_ota_begin
• data: Data buffer to write
• size: Size of data buffer in bytes
• offset: Offset in flash partition
esp_err_t esp_ota_end(esp_ota_handle_t handle)
Finish OTA update and validate newly written app image.
Note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed
(regardless of result).
Return
• ESP_OK: Newly written OTA app image is valid.
• ESP_ERR_NOT_FOUND: OTA handle was not found.
• ESP_ERR_INVALID_ARG: Handle was never written to.
• ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or -
if secure boot is enabled - signature failed to verify.)
• ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error
writing the final encrypted bytes to flash.
Parameters
• handle: Handle obtained from esp_ota_begin().
esp_err_t esp_ota_abort(esp_ota_handle_t handle)
Abort OTA update, free the handle and memory associated with it.
Return
• ESP_OK: Handle and its associated memory is freed successfully.
• ESP_ERR_NOT_FOUND: OTA handle was not found.
Parameters
• handle: obtained from esp_ota_begin().
esp_err_t esp_ota_set_boot_partition(const esp_partition_t *partition)
Configure OTA data for a new boot partition.
Note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition.
Return
• ESP_OK: OTA data updated, next reboot will use specified partition.
• ESP_ERR_INVALID_ARG: partition argument was NULL or didn’t point to a valid OTA partition
of type “app”.
• ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if
secure boot is enabled and signature validation failed.
• ESP_ERR_NOT_FOUND: OTA data partition not found.
• ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed.
Parameters
• partition: Pointer to info for partition containing app image to boot.
Espressif Systems 1023
Submit Document Feedback
Release v4.4