ota_upgrade.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief OTA upgrade interface
  9. */
  10. #ifndef __OTA_UPGRADE_H__
  11. #define __OTA_UPGRADE_H__
  12. struct ota_upgrade_info;
  13. struct ota_backend;
  14. /** ota state */
  15. enum ota_state
  16. {
  17. OTA_INIT = 0,
  18. OTA_RUNNING,
  19. OTA_DONE,
  20. OTA_FAIL,
  21. };
  22. typedef void (*ota_notify_t)(int state, int old_state);
  23. typedef void (*ota_ugrade_file_cb)(uint8_t file_id);
  24. /** structure of ota upgrade param, Initialized by the user*/
  25. struct ota_upgrade_param {
  26. const char *storage_name;
  27. #ifdef CONFIG_OTA_MUTIPLE_STORAGE
  28. const char *storage_ext_name;
  29. #endif
  30. ota_notify_t notify;
  31. ota_ugrade_file_cb file_cb;
  32. /* flags */
  33. unsigned int flag_use_recovery:1; /* use recovery */
  34. unsigned int flag_use_recovery_app:1; /* use recovery app */
  35. unsigned int no_version_control:1; /* OTA without version control */
  36. unsigned int flag_erase_part_for_upg:1; /* OTA upgrade erase part for upg*/
  37. unsigned int flag_keep_temp_part:1; /* OTA don't erase temp on init */
  38. };
  39. /**
  40. * @brief ota upgrade init funcion
  41. *
  42. * This routine calls init ota upgrade,called by ota app
  43. *
  44. * @param param init ota struct
  45. *
  46. * @return pointer to ota struct address.
  47. * @return NULL if init failed.
  48. */
  49. struct ota_upgrade_info *ota_upgrade_init(struct ota_upgrade_param *param);
  50. /**
  51. * @brief ota check and upgrade funcion
  52. *
  53. * This routine calls to do ota upgrade ,called by ota app
  54. *
  55. * @param ota pointer to the ota upgrade structure
  56. *
  57. * @return 0 if upgrade success.
  58. * @return others if init failed.
  59. */
  60. int ota_upgrade_check(struct ota_upgrade_info *ota);
  61. /**
  62. * @brief check the progress of ota
  63. *
  64. * This routine calls to check ota progress ,called by recovery_main
  65. *
  66. * @param ota pointer to the ota upgrade structure
  67. *
  68. * @return 0 if no in progress.
  69. * @return 1 if in progress.
  70. */
  71. int ota_upgrade_is_in_progress(struct ota_upgrade_info *ota);
  72. /**
  73. * @brief set the progress state of ota
  74. *
  75. * This routine calls to set ota progress state ,called by recovery_main
  76. *
  77. * @param ota pointer to the ota upgrade structure
  78. *
  79. * @return 0 if attach success.
  80. * @return others if attach fail.
  81. */
  82. int ota_upgrade_set_in_progress(struct ota_upgrade_info *ota);
  83. /**
  84. * @brief attach backend to ota
  85. *
  86. * This routine calls to attach backend to ota ,called by ota app
  87. *
  88. * @param ota pointer to the ota upgrade structure
  89. * @param backend pointer to backend structure
  90. * @return 0 if attach success.
  91. * @return others if attach fail.
  92. */
  93. int ota_upgrade_attach_backend(struct ota_upgrade_info *ota, struct ota_backend *backend);
  94. /**
  95. * @brief detach backend to ota
  96. *
  97. * This routine calls to detach backend to ota ,called by ota app for the end of ota
  98. *
  99. * @param ota pointer to the ota upgrade structure
  100. * @param backend pointer to backend structure
  101. */
  102. void ota_upgrade_detach_backend(struct ota_upgrade_info *ota, struct ota_backend *backend);
  103. #if defined(CONFIG_OTA_PRODUCT_SUPPORT) || defined(CONFIG_OTA_BLE_MASTER_SUPPORT)
  104. struct ota_host_upgrade_info;
  105. struct ota_trans;
  106. struct ota_upgrade_image_info;
  107. struct ota_host_upgrade_info *ota_host_upgrade_init(struct ota_upgrade_param *param);
  108. void ota_host_upgrade_exit(struct ota_host_upgrade_info *ota);
  109. int ota_host_upgrade_attach_backend(struct ota_host_upgrade_info *ota, struct ota_backend *backend);
  110. void ota_host_upgrade_detach_backend(struct ota_host_upgrade_info *ota, struct ota_backend *backend);
  111. int ota_host_upgrade_send_image(struct ota_host_upgrade_info *ota,int offset,int len);
  112. int ota_host_upgrade_check(struct ota_host_upgrade_info *ota);
  113. int ota_host_upgrade_attach_trans(struct ota_host_upgrade_info *ota, struct ota_trans *trans);
  114. void ota_host_update_state(struct ota_host_upgrade_info *ota, enum ota_state state);
  115. u32_t ota_host_upgrade_get_image_size(struct ota_host_upgrade_info *ota);
  116. u32_t ota_host_upgrade_get_image_ver(struct ota_host_upgrade_info *ota);
  117. u32_t ota_host_upgrade_get_head_crc(struct ota_host_upgrade_info *ota);
  118. #endif
  119. #endif /* __OTA_UPGRADE_H__ */