esp_ota_ops.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _OTA_OPS_H
  14. #define _OTA_OPS_H
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include <stddef.h>
  18. #include "esp_err.h"
  19. #include "esp_partition.h"
  20. #include "esp_spi_flash.h"
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #define OTA_SIZE_UNKNOWN 0xffffffff
  26. #define ESP_ERR_OTA_BASE 0x1500 /*!< base error code for ota_ops api */
  27. #define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< want to write or erase current running partition */
  28. #define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< ota data partition info is error */
  29. #define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< validate ota image failed */
  30. /**
  31. * @brief Opaque handle for application update obtained from app_ops.
  32. */
  33. typedef uint32_t esp_ota_handle_t;
  34. /**
  35. * @brief format input partition in flash to 0xFF as input image size,
  36. * if unkown image size ,pass 0x0 or 0xFFFFFFFF, it will erase all the
  37. * partition ,Otherwise, erase the required range
  38. *
  39. * @param partition Pointer to partition structure which need to be updated
  40. * Must be non-NULL.
  41. * @param image_size size of image need to be updated
  42. * @param out_handle handle which should be used for esp_ota_write or esp_ota_end call
  43. * @return:
  44. * - ESP_OK: if format ota image OK
  45. * - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
  46. * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
  47. */
  48. esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
  49. /**
  50. * @brief Write data to input input partition
  51. *
  52. * @param handle Handle obtained from esp_ota_begin
  53. * @param data Pointer to data write to flash
  54. * @param size data size of recieved data
  55. *
  56. * @return:
  57. * - ESP_OK: if write flash data OK
  58. * - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
  59. * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
  60. */
  61. esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
  62. /**
  63. * @brief Finish the update and validate written data
  64. *
  65. * @param handle Handle obtained from esp_ota_begin
  66. *
  67. * @return:
  68. * - ESP_OK: if validate ota image pass
  69. * - ESP_ERR_OTA_VALIDATE_FAILED: validate the ota image is invalid
  70. */
  71. esp_err_t esp_ota_end(esp_ota_handle_t handle);
  72. /**
  73. * @brief Set next boot partition, call system_restart() will switch to run it
  74. *
  75. * @note if you want switch to run a bin file
  76. * has never been checked before,please validate it's signature firstly
  77. *
  78. * @param partition Pointer to partition structure which need to boot
  79. *
  80. * @return:
  81. * - ESP_OK: if set next boot partition OK
  82. * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
  83. */
  84. esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
  85. /**
  86. * @brief Get partition info of current running image
  87. *
  88. * @return pointer to esp_partition_t structure, or NULL if no partition is found or
  89. * operate flash failed,This pointer is valid for the lifetime of the application.
  90. */
  91. const esp_partition_t* esp_ota_get_boot_partition(void);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* OTA_OPS_H */