ota_flash.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. #ifndef _OTA_FLASH_H
  29. #define _OTA_FLASH_H
  30. #include "types.h"
  31. #define OTAF_PARTITION_NUM_MAX 16
  32. enum{
  33. OTAF_SINGLE_BANK = 0,
  34. OTAF_DUAL_BANK_0 = 1,
  35. OTAF_DUAL_BANK_1 = 2
  36. };
  37. #define OTA_MAGIC_CODE 0x32af08cb //random data
  38. #define OTAF_SECTOR_SIZE (1024*4) //4k size
  39. #define OTA_DUMMY_BANK 0 //undefined mode, will report error
  40. #define OTA_SINGLE_BANK 1
  41. #define OTA_DUAL_BANK 2
  42. #ifndef CFG_OTA_BANK_MODE
  43. #define CFG_OTA_BANK_MODE OTA_DUMMY_BANK
  44. #endif
  45. #ifndef USE_FCT
  46. #define USE_FCT 0
  47. #endif
  48. #ifndef CFG_FLASH
  49. #define CFG_FLASH 0
  50. #endif
  51. #if(CFG_FLASH == 128 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
  52. #define OTAF_BASE_ADDR 0x11000000
  53. #define OTAF_1st_BOOTINFO_ADDR 0x11002000 //4k bytes
  54. #define OTAF_1st_BOOTINFO_SIZE 0x1000 //4k bytes
  55. #define OTAF_2nd_BOOTINFO_ADDR 0x11003000 //4k bytes
  56. #define OTAF_APP_BANK_0_ADDR 0x1100c000 //72K bytes
  57. #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE //Dummy
  58. #define OTAF_APP_BANK_SIZE (1024*64)
  59. #define OTAF_NVM_ADDR 0x1100c000 //8K bytes
  60. #define OTAF_APPLICATION_RUN 0x1fff4000 //??? need confirm
  61. #elif(CFG_FLASH >= 512 && USE_FCT==1 && CFG_OTA_BANK_MODE==OTA_DUAL_BANK)
  62. #define OTAF_BASE_ADDR 0x11000000
  63. #define OTAF_1st_BOOTINFO_ADDR 0x11002000 //4k bytes
  64. #define OTAF_1st_BOOTINFO_SIZE 0x1000 //4k bytes
  65. #define OTAF_2nd_BOOTINFO_ADDR 0x11009000 //4k bytes
  66. #define OTAF_APP_FCT_ADDR 0x11012000 //120K bytes, first 4k is FCT boot info
  67. #define OTAF_APP_BANK_0_ADDR 0x11030000 //128K bytes
  68. #define OTAF_APP_BANK_1_ADDR 0x11050000 //128K bytes
  69. #define OTAF_APP_BANK_SIZE (1024*128)
  70. #define OTAF_NVM_ADDR 0x11070000 //64K bytes
  71. #define OTAF_APPLICATION_RUN 0x1fff4000 //??? need confirm
  72. #elif(CFG_FLASH >= 512 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_DUAL_BANK)
  73. #define OTAF_BASE_ADDR 0x11000000
  74. #define OTAF_1st_BOOTINFO_ADDR 0x11002000 //4k bytes
  75. #define OTAF_1st_BOOTINFO_SIZE 0x1000 //4k bytes
  76. #define OTAF_2nd_BOOTINFO_ADDR 0x11009000 //4k bytes
  77. #define OTAF_APP_BANK_0_ADDR 0x11012000 //128K bytes
  78. #define OTAF_APP_BANK_1_ADDR 0x11032000 //128K bytes
  79. #define OTAF_APP_BANK_SIZE (1024*128)
  80. #define OTAF_NVM_ADDR 0x11052000 //64K bytes
  81. #define OTAF_APPLICATION_RUN 0x1fff4000 //??? need confirm
  82. #elif(CFG_FLASH >= 512 && USE_FCT==1 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
  83. #define OTAF_BASE_ADDR 0x11000000
  84. #define OTAF_1st_BOOTINFO_ADDR 0x11002000 //4k bytes
  85. #define OTAF_1st_BOOTINFO_SIZE 0x1000 //4k bytes
  86. #define OTAF_2nd_BOOTINFO_ADDR 0x11009000 //4k bytes
  87. #define OTAF_APP_FCT_ADDR 0x11012000 //120K bytes, first 4k is FCT boot info
  88. #define OTAF_APP_BANK_0_ADDR 0x11030000 //128K bytes
  89. #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE //Dummy
  90. #define OTAF_APP_BANK_SIZE (1024*128)
  91. #define OTAF_NVM_ADDR 0x11050000 //64K bytes
  92. #define OTAF_APPLICATION_RUN 0x1fff4000 //??? need confirm
  93. #elif(CFG_FLASH >= 512 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
  94. #define OTAF_BASE_ADDR 0x11000000
  95. #define OTAF_1st_BOOTINFO_ADDR 0x11002000 //4k bytes
  96. #define OTAF_1st_BOOTINFO_SIZE 0x1000 //4k bytes
  97. #define OTAF_2nd_BOOTINFO_ADDR 0x11009000 //4k bytes
  98. #define OTAF_APP_BANK_0_ADDR 0x11012000 //128K bytes
  99. #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE //Dummy
  100. #define OTAF_APP_BANK_SIZE (1024*128)
  101. #define OTAF_NVM_ADDR 0x11032000 //64K bytes
  102. #define OTAF_APPLICATION_RUN 0x1fff4000 //??? need confirm
  103. #else
  104. #error "unsupported OTA config, please check these micro:CFG_FLASH, USE_FCT,CFG_OTA_BANK_MODE!"
  105. #endif
  106. #if(CFG_FLASH == 128)
  107. #define OTAF_START_ADDR 0x11003000
  108. #define OTAF_END_ADDR 0x1101ffff
  109. #elif(CFG_FLASH == 512)
  110. #define OTAF_START_ADDR 0x11009000
  111. #define OTAF_END_ADDR 0x1107ffff
  112. #elif(CFG_FLASH == 4096)
  113. #define OTAF_START_ADDR 0x11009000
  114. #define OTAF_END_ADDR 0x111fffff
  115. #else
  116. #error "unsupported OTA config, please check these micro:CFG_FLASH!"
  117. #endif
  118. #define MAX_SECT_SUPPORT 16
  119. typedef struct{
  120. uint32_t flash_addr;
  121. uint32_t run_addr;
  122. uint32_t size;
  123. uint16_t checksum;
  124. }ota_fw_part_t;
  125. typedef struct{
  126. uint8_t part_num;
  127. uint8_t part_current;
  128. uint32_t total_size;
  129. uint32_t total_offset;
  130. uint32_t offset;
  131. ota_fw_part_t part[MAX_SECT_SUPPORT];
  132. }ota_fw_t;
  133. #if(CFG_FLASH >= 512)
  134. int ota_flash_load_fct(void);
  135. #endif
  136. int ota_flash_load_app(void);
  137. int ota_flash_write_partition(uint32 addr, uint32_t* p_sect, uint32_t size);
  138. int ota_flash_write_boot_sector(uint32_t* p_sect, uint32_t size, uint32_t offset);
  139. int ota_flash_erase(uint32_t addr);
  140. int ota_flash_erase_area(uint32_t flash_addr, uint32_t size);
  141. int ota_flash_read_bootsector(uint32_t* bank_addr);
  142. #endif