diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld index 399e84745..e6bfa3be6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld @@ -22,7 +22,7 @@ MEMORY { - flash (rx) : ORIGIN = 0x60040000, LENGTH = 0x00100000 + flash (rx) : ORIGIN = 0x60100000, LENGTH = 0x00100000 sram (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00080000 itcm (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00020000 dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds index e42f2993e..6769453e6 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds @@ -53,8 +53,8 @@ STACK_SIZE = 0x4000; /* Specify the memory areas */ MEMORY { - m_interrupts (RX) : ORIGIN = 0x60040000, LENGTH = 0x00000400 - m_text (RX) : ORIGIN = 0x60040400, LENGTH = 0x000FFC00 + m_interrupts (RX) : ORIGIN = 0x60100000, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x60100400, LENGTH = 0x000FFC00 m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds index fea1de877..4ce000519 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds @@ -58,7 +58,7 @@ MEMORY /*bootloader*/ m_interrupts (RX) : ORIGIN = 0x60002000, LENGTH = 0x00000400 - m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0003DC00 + m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0007DC00 m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index bd9df1124..bf9278cb6 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -13,18 +13,20 @@ * @date 2023-04-03 */ +#include +#include #include "flash.h" -#include "stdio.h" -#include "xs_base.h" /******************************************************************************* * Definitions ******************************************************************************/ - +#define APP_FLASH_SIZE 0x100000 //Application package size is limited to 1M +#define FLASH_PAGE_SIZE 256 //每次写入256个字节 /******************************************************************************* * Prototypes ******************************************************************************/ - + +uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache /******************************************************************************* * Variables ******************************************************************************/ @@ -301,4 +303,134 @@ status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len) __enable_irq(); return status; +} + + /** + * @brief 擦除flash指定地址指定长度的空间 + * @param start_addr: 开始地址 + * @param byte_cnt : 要擦除的字节数 + * @retval kStatus_Success:擦除成功 + */ +status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) +{ + uint32_t addr; + status_t status; + + addr = start_addr; + while(addr < (byte_cnt + start_addr)) + { + status = FLASH_EraseSector(addr); + if(status != kStatus_Success) + { + return status; + } + addr += FLASH_GetSectorSize(); + } + return status; +} + + /** + * @brief 在flash指定地址写入指定长度的数据 + * @param start_addr: 开始地址 + * @param buf : 数据buffer + * @param byte_cnt : 要写入的字节数 + * @retval kStatus_Success:写入成功 + */ +status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) +{ + return FLASH_WritePage(start_addr, buf, byte_cnt); +} + + /** + * @brief 在flash指定开始读取一定长度的数据到缓存中 + * @param start_addr: 开始地址 + * @param buf : 数据buffer + * @param byte_cnt : 要读取的字节数 + * @retval kStatus_Success:读取成功 + */ +status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) +{ + /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ + if((addr >= 0x60000000) && (addr < 0x70000000)) + { + return FLASH_Read(addr, buf, len); + } + + else + { + void* result = memcpy(buf, (void*)addr, len); + if(result == NULL) + { + return (status_t)kStatus_Fail; + } + else + { + return (status_t)kStatus_Success; + } + + } +} + + /** + * @brief 实现两块连续flash地址空间之间的数据拷贝 + * @param srcAddr: 源flash的起始地址 + * @param dstAddr : 目标flash的起始地址 + * @param imageSize : 要拷贝的flash空间大小,单位为字节 + * @retval kStatus_Success:拷贝成功 + */ +status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) +{ + uint32_t PageNum, Remain, i; + status_t status; + + if((srcAddr == dstAddr) || imageSize > (APP_FLASH_SIZE + 1)) + { + return (status_t)kStatus_Fail; + } + + status = flash_erase(dstAddr,imageSize); + if(status != kStatus_Success) + { + KPrintf("Erase flash 0x%08x failure !\r\n",dstAddr); + return status; + } + + PageNum = imageSize/FLASH_PAGE_SIZE; + Remain = imageSize%FLASH_PAGE_SIZE; + + for(i=0;iVTOR = (uint32_t)0x60040000; + SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60100000]\n"); + SCB->VTOR = (uint32_t)0x60100000; JumpToApp(); } #endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index 47b33596d..46b96f58f 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -27,6 +27,10 @@ status_t FLASH_EraseSector(uint32_t addr); status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len); uint32_t FLASH_Test(uint32_t startAddr, uint32_t len); uint32_t FLASH_GetProgramCmd(void); +status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt); +status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt); +status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len); +status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); #endif