Proper cached-flash to phys address translation.

This commit is contained in:
Johny Mattsson 2015-12-08 10:25:05 +11:00 committed by Johny Mattsson
parent c4e8b04fbf
commit d84a24fc9a
4 changed files with 27 additions and 1 deletions

View File

@ -149,7 +149,7 @@ uint32_t platform_flash_get_first_free_block_address( uint32_t *psect )
uint32_t start, end, sect;
NODE_DBG("_flash_used_end:%08x\n", (uint32_t)_flash_used_end);
if(_flash_used_end>0){ // find the used sector
sect = flashh_find_sector( ( uint32_t )_flash_used_end - INTERNAL_FLASH_MAPPED_ADDRESS - 1, NULL, &end );
sect = flashh_find_sector( platform_flash_mapped2phys ( (uint32_t)_flash_used_end - 1), NULL, &end );
if( psect )
*psect = sect + 1;
return end + 1;

View File

@ -68,4 +68,9 @@
#define flash_read spi_flash_read
#endif // defined(FLASH_SAFE_API)
#define CACHE_FLASH_CTRL_REG 0x3ff0000c
#define CACHE_FLASH_ACTIVE 0x00000100
#define CACHE_FLASH_MAPPED0 0x02000000
#define CACHE_FLASH_MAPPED1 0x00010000
#endif // #ifndef __CPU_ESP8266_H__

View File

@ -579,3 +579,14 @@ int platform_flash_erase_sector( uint32_t sector_id )
system_soft_wdt_feed ();
return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR;
}
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr)
{
uint32_t cache_ctrl = READ_PERI_REG(CACHE_FLASH_CTRL_REG);
if (!(cache_ctrl & CACHE_FLASH_ACTIVE))
return -1;
bool b0 = (cache_ctrl & CACHE_FLASH_MAPPED0) ? 1 : 0;
bool b1 = (cache_ctrl & CACHE_FLASH_MAPPED1) ? 1 : 0;
uint32_t meg = (b1 << 1) | b0;
return mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg * 0x100000;
}

View File

@ -237,6 +237,16 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size );
uint32_t platform_flash_get_num_sectors(void);
int platform_flash_erase_sector( uint32_t sector_id );
/**
* Translated a mapped address to a physical flash address, based on the
* current flash cache mapping.
* @param mapped_addr Address to translate (>= INTERNAL_FLASH_MAPPED_ADDRESS)
* @return the corresponding physical flash address, or -1 if flash cache is
* not currently active.
* @see Cache_Read_Enable.
*/
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr);
// *****************************************************************************
// Allocator support