ota_breakpoint.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief OTA breakpoint interface
  9. */
  10. #ifndef __OTA_BREAKPOINT_H__
  11. #define __OTA_BREAKPOINT_H__
  12. #include <kernel.h>
  13. #define OTA_BP_SAVE_SIZE (512*1024)
  14. #define OTA_FW_MAX_FILE 8
  15. #define OTA_BP_STATE_UNKOWN 0x0
  16. #define OTA_BP_STATE_CLEAN 0x1
  17. #define OTA_BP_STATE_WRITING_IMG 0x2
  18. #define OTA_BP_STATE_UPGRADE_PENDING 0x3
  19. #define OTA_BP_STATE_UPGRADE_WRITING 0x4
  20. #define OTA_BP_STATE_UPGRADE_DONE 0xa
  21. #define OTA_BP_STATE_WRITING_IMG_FAIL 0xe
  22. #define OTA_BP_STATE_UPGRADING_FAIL 0xf
  23. #define OTA_BP_FILE_STATE_UNKOWN 0x0
  24. #define OTA_BP_FILE_STATE_CLEAN 0x1
  25. #define OTA_BP_FILE_STATE_WRITE_START 0x2
  26. #define OTA_BP_FILE_STATE_WRITING 0x3
  27. #define OTA_BP_FILE_STATE_WRITING_DIRTY 0x4
  28. #define OTA_BP_FILE_STATE_WRITING_CLEAN 0x5
  29. #define OTA_BP_FILE_STATE_WRITE_DONE 0x6
  30. #define OTA_BP_FILE_STATE_VERIFY_PASS 0x7
  31. #define OTA_BP_FILE_STATE_WRITE_FAIL 0xe
  32. #define OTA_BP_FILE_STATE_VERIFY_FAIL 0xf
  33. struct ota_breakpoint_file_state {
  34. uint8_t file_id;
  35. uint8_t state;
  36. };
  37. struct ota_breakpoint {
  38. uint8_t bp_id;
  39. uint8_t mirror_id;
  40. uint8_t backend_type;
  41. uint8_t state;
  42. uint32_t old_version;
  43. uint32_t new_version;
  44. uint8_t total_file_num;
  45. uint8_t write_done_file_num;
  46. struct ota_file cur_file;
  47. uint32_t cur_file_write_offset;
  48. uint32_t cur_orig_write_offset;
  49. struct ota_breakpoint_file_state file_state[OTA_FW_MAX_FILE];
  50. uint32_t data_checksum;
  51. } __attribute__((packed));
  52. struct ota_breakpoint_file {
  53. uint8_t bp_id;
  54. uint8_t file_id;
  55. uint8_t reserved[2];
  56. uint32_t write_offset;
  57. } __attribute__((packed));
  58. void ota_breakpoint_dump(struct ota_breakpoint *bp);
  59. int ota_breakpoint_save(struct ota_breakpoint *bp);
  60. int ota_breakpoint_load(struct ota_breakpoint *bp);
  61. int ota_breakpoint_get_current_state(struct ota_breakpoint *bp);
  62. int ota_breakpoint_set_file_state(struct ota_breakpoint *bp, int file_id, int state);
  63. int ota_breakpoint_get_file_state(struct ota_breakpoint *bp, int file_id);
  64. int ota_breakpoint_update_state(struct ota_breakpoint *bp, int state);
  65. int ota_breakpoint_update_file_state(struct ota_breakpoint *bp, struct ota_file *file,
  66. int state, int cur_file_offset, int cur_orig_offset, int force);
  67. int ota_breakpoint_init_default_value(struct ota_breakpoint *bp);
  68. int ota_breakpoint_init(struct ota_breakpoint *bp);
  69. void ota_breakpoint_exit(struct ota_breakpoint *bp);
  70. #endif /* __OTA_BREAKPOINT_H__ */