123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #ifndef _OTA_FLASH_H
- #define _OTA_FLASH_H
- #include "types.h"
- #define OTAF_PARTITION_NUM_MAX 16
- enum{
- OTAF_SINGLE_BANK = 0,
- OTAF_DUAL_BANK_0 = 1,
- OTAF_DUAL_BANK_1 = 2
- };
- #define OTA_MAGIC_CODE 0x32af08cb
- #define OTAF_SECTOR_SIZE (1024*4)
- #define OTA_DUMMY_BANK 0
- #define OTA_SINGLE_BANK 1
- #define OTA_DUAL_BANK 2
- #ifndef CFG_OTA_BANK_MODE
- #define CFG_OTA_BANK_MODE OTA_DUMMY_BANK
- #endif
- #ifndef USE_FCT
- #define USE_FCT 0
- #endif
- #ifndef CFG_FLASH
- #define CFG_FLASH 0
- #endif
- #if(CFG_FLASH == 128 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
- #define OTAF_BASE_ADDR 0x11000000
- #define OTAF_1st_BOOTINFO_ADDR 0x11002000
- #define OTAF_1st_BOOTINFO_SIZE 0x1000
- #define OTAF_2nd_BOOTINFO_ADDR 0x11003000
- #define OTAF_APP_BANK_0_ADDR 0x1100c000
- #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE
- #define OTAF_APP_BANK_SIZE (1024*64)
-
- #define OTAF_NVM_ADDR 0x1100c000
- #define OTAF_APPLICATION_RUN 0x1fff4000
- #elif(CFG_FLASH >= 512 && USE_FCT==1 && CFG_OTA_BANK_MODE==OTA_DUAL_BANK)
- #define OTAF_BASE_ADDR 0x11000000
- #define OTAF_1st_BOOTINFO_ADDR 0x11002000
- #define OTAF_1st_BOOTINFO_SIZE 0x1000
-
- #define OTAF_2nd_BOOTINFO_ADDR 0x11009000
- #define OTAF_APP_FCT_ADDR 0x11012000
- #define OTAF_APP_BANK_0_ADDR 0x11030000
- #define OTAF_APP_BANK_1_ADDR 0x11050000
- #define OTAF_APP_BANK_SIZE (1024*128)
- #define OTAF_NVM_ADDR 0x11070000
- #define OTAF_APPLICATION_RUN 0x1fff4000
- #elif(CFG_FLASH >= 512 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_DUAL_BANK)
- #define OTAF_BASE_ADDR 0x11000000
- #define OTAF_1st_BOOTINFO_ADDR 0x11002000
- #define OTAF_1st_BOOTINFO_SIZE 0x1000
-
- #define OTAF_2nd_BOOTINFO_ADDR 0x11009000
- #define OTAF_APP_BANK_0_ADDR 0x11012000
- #define OTAF_APP_BANK_1_ADDR 0x11032000
- #define OTAF_APP_BANK_SIZE (1024*128)
- #define OTAF_NVM_ADDR 0x11052000
- #define OTAF_APPLICATION_RUN 0x1fff4000
- #elif(CFG_FLASH >= 512 && USE_FCT==1 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
- #define OTAF_BASE_ADDR 0x11000000
- #define OTAF_1st_BOOTINFO_ADDR 0x11002000
- #define OTAF_1st_BOOTINFO_SIZE 0x1000
-
- #define OTAF_2nd_BOOTINFO_ADDR 0x11009000
- #define OTAF_APP_FCT_ADDR 0x11012000
- #define OTAF_APP_BANK_0_ADDR 0x11030000
- #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE
- #define OTAF_APP_BANK_SIZE (1024*128)
- #define OTAF_NVM_ADDR 0x11050000
- #define OTAF_APPLICATION_RUN 0x1fff4000
- #elif(CFG_FLASH >= 512 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
- #define OTAF_BASE_ADDR 0x11000000
- #define OTAF_1st_BOOTINFO_ADDR 0x11002000
- #define OTAF_1st_BOOTINFO_SIZE 0x1000
- #define OTAF_2nd_BOOTINFO_ADDR 0x11009000
- #define OTAF_APP_BANK_0_ADDR 0x11012000
- #define OTAF_APP_BANK_1_ADDR OTA_MAGIC_CODE
- #define OTAF_APP_BANK_SIZE (1024*128)
- #define OTAF_NVM_ADDR 0x11032000
- #define OTAF_APPLICATION_RUN 0x1fff4000
- #else
- #error "unsupported OTA config, please check these micro:CFG_FLASH, USE_FCT,CFG_OTA_BANK_MODE!"
- #endif
- #if(CFG_FLASH == 128)
- #define OTAF_START_ADDR 0x11003000
- #define OTAF_END_ADDR 0x1101ffff
- #elif(CFG_FLASH == 512)
- #define OTAF_START_ADDR 0x11009000
- #define OTAF_END_ADDR 0x1107ffff
- #elif(CFG_FLASH == 4096)
- #define OTAF_START_ADDR 0x11009000
- #define OTAF_END_ADDR 0x111fffff
- #else
- #error "unsupported OTA config, please check these micro:CFG_FLASH!"
- #endif
- #define MAX_SECT_SUPPORT 16
- typedef struct{
- uint32_t flash_addr;
- uint32_t run_addr;
- uint32_t size;
- uint16_t checksum;
- }ota_fw_part_t;
- typedef struct{
- uint8_t part_num;
- uint8_t part_current;
- uint32_t total_size;
- uint32_t total_offset;
- uint32_t offset;
- ota_fw_part_t part[MAX_SECT_SUPPORT];
- }ota_fw_t;
- #if(CFG_FLASH >= 512)
- int ota_flash_load_fct(void);
- #endif
- int ota_flash_load_app(void);
- int ota_flash_write_partition(uint32 addr, uint32_t* p_sect, uint32_t size);
- int ota_flash_write_boot_sector(uint32_t* p_sect, uint32_t size, uint32_t offset);
- int ota_flash_erase(uint32_t addr);
- int ota_flash_erase_area(uint32_t flash_addr, uint32_t size);
- int ota_flash_read_bootsector(uint32_t* bank_addr);
- #endif
|