Commit 1259f8d7 authored by Bernd Meyer's avatar Bernd Meyer Committed by Johny Mattsson
Browse files

Deal with unaligned destination parameter to flash read

(Occurs e.g. when SPIFFS cache is disabled.)

Implementation mirrors the existing handling in the write path.
parent 125db659
...@@ -220,7 +220,7 @@ uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size ) ...@@ -220,7 +220,7 @@ uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size )
#else // #ifindef INTERNAL_FLASH_READ_UNIT_SIZE #else // #ifindef INTERNAL_FLASH_READ_UNIT_SIZE
uint32_t temp, rest, ssize = size; uint32_t temp, rest, ssize = size;
unsigned i; unsigned i;
char tmpdata[ INTERNAL_FLASH_READ_UNIT_SIZE ]; char tmpdata[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE)));
uint8_t *pto = ( uint8_t* )to; uint8_t *pto = ( uint8_t* )to;
const uint32_t blksize = INTERNAL_FLASH_READ_UNIT_SIZE; const uint32_t blksize = INTERNAL_FLASH_READ_UNIT_SIZE;
const uint32_t blkmask = INTERNAL_FLASH_READ_UNIT_SIZE - 1; const uint32_t blkmask = INTERNAL_FLASH_READ_UNIT_SIZE - 1;
......
...@@ -460,6 +460,11 @@ spi_data_type platform_spi_send_recv( unsigned id, spi_data_type data ) ...@@ -460,6 +460,11 @@ spi_data_type platform_spi_send_recv( unsigned id, spi_data_type data )
// **************************************************************************** // ****************************************************************************
// Flash access functions // Flash access functions
/*
* Assumptions:
* > toaddr is INTERNAL_FLASH_WRITE_UNIT_SIZE aligned
* > size is a multiple of INTERNAL_FLASH_WRITE_UNIT_SIZE
*/
uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size ) uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size )
{ {
toaddr -= INTERNAL_FLASH_START_ADDRESS; toaddr -= INTERNAL_FLASH_START_ADDRESS;
...@@ -484,12 +489,37 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz ...@@ -484,12 +489,37 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz
} }
} }
/*
* Assumptions:
* > fromaddr is INTERNAL_FLASH_READ_UNIT_SIZE aligned
* > size is a multiple of INTERNAL_FLASH_READ_UNIT_SIZE
*/
uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
{ {
if (size==0)
return 0;
fromaddr -= INTERNAL_FLASH_START_ADDRESS; fromaddr -= INTERNAL_FLASH_START_ADDRESS;
SpiFlashOpResult r; SpiFlashOpResult r;
WRITE_PERI_REG(0x60000914, 0x73); WRITE_PERI_REG(0x60000914, 0x73);
r = flash_read(fromaddr, (uint32 *)to, size);
const uint32_t blkmask = (INTERNAL_FLASH_READ_UNIT_SIZE - 1);
if( ((uint32_t)to) & blkmask )
{
uint32_t size2=size-INTERNAL_FLASH_READ_UNIT_SIZE;
uint32* to2=(uint32*)((((uint32_t)to)&(~blkmask))+INTERNAL_FLASH_READ_UNIT_SIZE);
r = flash_read(fromaddr, to2, size2);
if(SPI_FLASH_RESULT_OK == r)
{
os_memmove(to,to2,size2);
char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE)));
r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE);
os_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE);
}
}
else
r = flash_read(fromaddr, (uint32 *)to, size);
if(SPI_FLASH_RESULT_OK == r) if(SPI_FLASH_RESULT_OK == r)
return size; return size;
else{ else{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment