forked from xuos/xiuos
1、Modifying Flash Partitions:
Bootloader:0x60000000-0x6007FFFF 512K APP:0x60100000-0x601FFFFF 1024K Backup:0x60300000-0x603FFFFF 1024K Download:0x60500000-0x605FFFFF 1024K OTAFlag:0x60700000-0x6071FFFF 128K 2、add four flash function:flash_erase,flash_write,flash_read and flash_copy
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -13,18 +13,20 @@
|
||||
* @date 2023-04-03
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <xs_base.h>
|
||||
#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 //ÿ<><C3BF>д<EFBFBD><D0B4>256<35><36><EFBFBD>ֽ<EFBFBD>
|
||||
/*******************************************************************************
|
||||
* 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 <20><><EFBFBD><EFBFBD>flashָ<68><D6B8><EFBFBD><EFBFBD>ַָ<D6B7><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵĿռ<C4BF>
|
||||
* @param start_addr: <20><>ʼ<EFBFBD><CABC>ַ
|
||||
* @param byte_cnt : Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
* @retval kStatus_Success<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
||||
*/
|
||||
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 <20><>flashָ<68><D6B8><EFBFBD><EFBFBD>ַд<D6B7><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param start_addr: <20><>ʼ<EFBFBD><CABC>ַ
|
||||
* @param buf : <20><><EFBFBD><EFBFBD>buffer
|
||||
* @param byte_cnt : Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
* @retval kStatus_Success<73><73>д<EFBFBD><D0B4><EFBFBD>ɹ<EFBFBD>
|
||||
*/
|
||||
status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt)
|
||||
{
|
||||
return FLASH_WritePage(start_addr, buf, byte_cnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20><>flashָ<68><D6B8><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param start_addr: <20><>ʼ<EFBFBD><CABC>ַ
|
||||
* @param buf : <20><><EFBFBD><EFBFBD>buffer
|
||||
* @param byte_cnt : Ҫ<><D2AA>ȡ<EFBFBD><C8A1><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
* @retval kStatus_Success<73><73><EFBFBD><EFBFBD>ȡ<EFBFBD>ɹ<EFBFBD>
|
||||
*/
|
||||
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 ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>flash<73><68>ַ<EFBFBD>ռ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>
|
||||
* @param srcAddr: Դflash<73><68><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
* @param dstAddr : Ŀ<><C4BF>flash<73><68><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
* @param imageSize : Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>flash<73>ռ<EFBFBD><D5BC><EFBFBD>С,<2C><>λΪ<CEBB>ֽ<EFBFBD>
|
||||
* @retval kStatus_Success<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
||||
*/
|
||||
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;i<PageNum;i++)
|
||||
{
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
status = flash_read(srcAddr + i*FLASH_PAGE_SIZE, buffer, sizeof(buffer));
|
||||
if(status != kStatus_Success)
|
||||
{
|
||||
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
|
||||
return status;
|
||||
}
|
||||
status = flash_write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, FLASH_PAGE_SIZE);
|
||||
if(status != kStatus_Success)
|
||||
{
|
||||
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if(Remain)
|
||||
{
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
status = flash_read(srcAddr + i*FLASH_PAGE_SIZE, buffer, Remain);
|
||||
if(status != kStatus_Success)
|
||||
{
|
||||
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
|
||||
return status;
|
||||
}
|
||||
status = flash_write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, Remain);
|
||||
if(status != kStatus_Success)
|
||||
{
|
||||
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return (status_t)kStatus_Success;
|
||||
}
|
||||
@@ -20,11 +20,11 @@
|
||||
#ifdef MCUBOOT_BOOTLOADER
|
||||
static void JumpToApp(void)
|
||||
{
|
||||
asm volatile("LDR R0, = 0x60040000");
|
||||
asm volatile("LDR R0, = 0x60100000");
|
||||
asm volatile("LDR R0, [R0]");
|
||||
asm volatile("MOV SP, R0");
|
||||
|
||||
asm volatile("LDR R0, = 0x60040000+4");
|
||||
asm volatile("LDR R0, = 0x60100000+4");
|
||||
asm volatile("LDR R0, [R0]");
|
||||
asm volatile("BX R0");
|
||||
}
|
||||
@@ -79,8 +79,8 @@ void BootLoaderJumpApp(void)
|
||||
|
||||
UartConfig();
|
||||
|
||||
SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60040000]\n");
|
||||
SCB->VTOR = (uint32_t)0x60040000;
|
||||
SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60100000]\n");
|
||||
SCB->VTOR = (uint32_t)0x60100000;
|
||||
JumpToApp();
|
||||
}
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user