hv_comm_Ota.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @file hv_comm_Ota.h
  3. * @brief Header file of OTA Utilities module.
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. *
  10. * @endverbatim
  11. *
  12. * @author HiView SoC Software Team
  13. * @version 1.0.0
  14. * @date 2022-08-22
  15. */
  16. #ifndef __SDK_COMMON_UTIL_UTILITIES_INC_OTA_H__
  17. #define __SDK_COMMON_UTIL_UTILITIES_INC_OTA_H__
  18. #include "hv_comm_DataType.h"
  19. #define ALIGN_4K(x) (((x) + 0xFFF) & ~0xFFF)
  20. #define STRING_SBLKPMSB "SBLKPMSB"
  21. #define STRING_SBLKBOOT "SBLKBOOT" //第一启动分区的Boot
  22. #define STRING_SBLKBTBK "SBLKBTBK" //第二启动分区的Boot
  23. #define STRING_SBLKCODE "SBLKCODE"
  24. #define SBLK_HEADER "SBLK"
  25. #define SBLK_MAGIC_STRING_LENGTH (8)
  26. #define VALID_LEN_OFFSET (0x08)
  27. #define START_ADDR_OFFSET (0x0C)
  28. #define CRC_OFFSET (0x1C)
  29. #define SBLK_PER_SIZE (32)
  30. #define MAX_RESERVED_PARTITIONS (32)
  31. #define MAX_SBLK_SIZE (MAX_RESERVED_PARTITIONS * SBLK_PER_SIZE)
  32. /* PM51和SBLK分区的地址和长度是固定的,所以在这里用宏定义;
  33. 其余的Boot、Code分区的起始地址和长度则通过解析SBLK的信息来得到
  34. | PM51 | 51Data | SB | Boot1 | Boot2 | Code | ------
  35. Start(0x) 0 7000 8000 9000 x x
  36. Len | 7000 | 1000 | 1000 | x | x |
  37. */
  38. #define PM51_PARTATION_ADDR (0x00000000)
  39. #define PM51_DATA_ADDR (0x00007000)
  40. #define SBLK_PARTATION_ADDR (0x00008000)
  41. #define PM51_PARTATION_LEN (0x00007000)
  42. #define PM51_DATA_LEN (0x00001000)
  43. #define SBLK_PARTATION_LEN (0x00001000)
  44. /**
  45. * @brief 双分区中CodeBak分区起始地址 = Code分区起始地址 + 2M
  46. */
  47. #define CODEBAK_PART_OFFSET (0x200000)
  48. /**
  49. * @brief 定义SBLK分区中Code段的CRC长度
  50. */
  51. #define OTA_SBLK_CRC_LEN (4)
  52. /**
  53. * @brief Enumeration definition of the boot partition
  54. */
  55. typedef enum _OtaPart
  56. {
  57. OTA_PART_A = 0,
  58. OTA_PART_B,
  59. OTA_PART_MAX,
  60. OTA_PART_SHORT_PATCH,
  61. } OtaPartDef;
  62. /**
  63. * @brief 描述Flash分区表结构
  64. */
  65. typedef struct _PartitionSBLKInfo
  66. {
  67. UCHAR8 ucSBLKName[8];
  68. UINT32 uiValidLen;
  69. UINT32 uiStartAddr;
  70. UINT32 uiCRC;
  71. UINT32 uiTotalLen;
  72. } PartitionSBLKInfo;
  73. /**
  74. * @brief OTA后更新OTA_Flag,和Code_CRC
  75. * @param[in] pucCodeCrc 指向Code CRC值的指针, 必须传递4个字节! 且值全为0时不写入!
  76. * @param[in] ucCrcLen 表示Code CRC的长度, 必须设为4
  77. * @return Status
  78. */
  79. Status Hv_Comm_OTA_UpdateParams(UCHAR8 *pucCodeCrc, UCHAR8 ucCrcLen);
  80. /**
  81. * @brief 把4个字节按照Big Endian顺序组成UINT32数据
  82. * @param[in] pucData 指向UCHAR8数据块的指针
  83. * @param[in] uiOffset 偏移值,表示取UCHAR8数据块中指定偏移位置后的4个字节
  84. * @return UINT32
  85. */
  86. UINT32 Hv_Comm_OTA_ConvertToUint32(const UCHAR8 *pucData, UINT32 uiOffset);
  87. /**
  88. * @brief 获取本次OTA要升级到哪个分区,返回与当前正运行分区相反的分区号
  89. * @return OtaPartDef 指示待更新的分区号
  90. */
  91. OtaPartDef Hv_Comm_OTA_GetUpgradePart(VOID);
  92. /**
  93. * @brief 根据分区地址更新该分区对应的CRC
  94. * @return Status
  95. */
  96. Status Hv_Comm_OTA_UpdatePartitionCrcByAddr(UCHAR8 *pucCrc, UCHAR8 ucCrcLen, UINT32 uiPartitionAddr);
  97. /**
  98. * @brief 根据分区名字查找Flash上对应分区的信息
  99. * @return Status
  100. */
  101. Status Hv_Comm_OTA_GetPartitionInfoByName(UCHAR8* pucName, UCHAR8 ucLen, PartitionSBLKInfo *pstPartInfo);
  102. /**
  103. * @brief 根据分区起始地址查找Flash上对应分区的信息
  104. * @return Status
  105. */
  106. Status Hv_Comm_OTA_GetPartitionInfoByStartAddr(UINT32 uiPartStartAddr, PartitionSBLKInfo *pstPartInfo);
  107. /**
  108. * @brief 根据要升级到哪个分区来获取Boot和Code的写入地址
  109. * @return Status
  110. */
  111. Status Hv_Comm_OTA_GetFlashWriteAddr(OtaPartDef enToWhich, UINT32 *uiBootWriteAddr, UINT32 *uiCodeWriteAddr);
  112. #endif