mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-23 08:45:22 +03:00
Support for multiple FileSystem instances
This commit is contained in:
@ -146,79 +146,3 @@ uint32_t flashmem_get_sector_of_address( uint32_t addr ){
|
||||
return (addr - INTERNAL_FLASH_START_ADDRESS) / INTERNAL_FLASH_SECTOR_SIZE;;
|
||||
}
|
||||
|
||||
/*
|
||||
SPIFFS BOOTSTRAP
|
||||
*/
|
||||
|
||||
//SPIFFS Address Range (defined in eagle ld)
|
||||
extern uint32_t _SPIFFS_start;
|
||||
extern uint32_t _SPIFFS_end;
|
||||
|
||||
//SPIFFS Storage Handle
|
||||
spiffs _filesystemStorageHandle;
|
||||
|
||||
//SPIFFS Buffers (INTERNAL_FLASH_PAGE_SIZE = 256) Total 1792 bytes
|
||||
static u8_t spiffs_work_buf[INTERNAL_FLASH_PAGE_SIZE*2]; //512 bytes
|
||||
static u8_t spiffs_fds[32*4]; //128 bytes
|
||||
static u8_t spiffs_cache[(INTERNAL_FLASH_PAGE_SIZE+32)*4]; //1152 bytes
|
||||
|
||||
//SPIFFS API Read CallBack
|
||||
static s32_t api_spiffs_read(u32_t addr, u32_t size, u8_t *dst){
|
||||
SPIFFS_API_DBG_V("api_spiffs_read: 0x%08x len: %u\n", addr, size);
|
||||
flashmem_read(dst, addr, size);
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
|
||||
//SPIFFS API Write CallBack
|
||||
static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src){
|
||||
SPIFFS_API_DBG_V("api_spiffs_write: 0x%08x len: %u\n", addr, size);
|
||||
flashmem_write(src, addr, size);
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
|
||||
//SPIFFS API Erase CallBack
|
||||
static s32_t api_spiffs_erase(u32_t addr, u32_t size){
|
||||
SPIFFS_API_DBG_V("api_spiffs_erase: 0x%08x len: %u\n", addr, size);
|
||||
u32_t sect_first = flashmem_get_sector_of_address(addr);
|
||||
u32_t sect_last = flashmem_get_sector_of_address(addr+size);
|
||||
while( sect_first <= sect_last )
|
||||
if( !flashmem_erase_sector( sect_first ++ ) )
|
||||
return SPIFFS_ERR_INTERNAL;
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
|
||||
// Our own SPIFFS Setup Method
|
||||
// All of the above gets put in the configuration
|
||||
// and a mount attempt is made, initializing the storage handle
|
||||
// that is used in all further api calls
|
||||
s32_t spiffs_mount(){
|
||||
u32_t start_address = (u32_t)&_SPIFFS_start;
|
||||
u32_t end_address = (u32_t)&_SPIFFS_end;
|
||||
if (start_address == 0 || start_address >= end_address){
|
||||
SPIFFS_API_DBG_E("Can't start file system, wrong address");
|
||||
return SPIFFS_ERR_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
spiffs_config cfg = {0};
|
||||
cfg.phys_addr = start_address;
|
||||
cfg.phys_size = end_address - start_address;
|
||||
cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet
|
||||
cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 2; // Important to make large
|
||||
cfg.log_page_size = INTERNAL_FLASH_PAGE_SIZE; // according to datasheet
|
||||
cfg.hal_read_f = api_spiffs_read;
|
||||
cfg.hal_write_f = api_spiffs_write;
|
||||
cfg.hal_erase_f = api_spiffs_erase;
|
||||
|
||||
SPIFFS_API_DBG_V("spiffs_mount: start:%x, size:%d Kb\n", cfg.phys_addr, cfg.phys_size / 1024);
|
||||
|
||||
s32_t res = SPIFFS_mount(&_filesystemStorageHandle,
|
||||
&cfg,
|
||||
spiffs_work_buf,
|
||||
spiffs_fds,
|
||||
sizeof(spiffs_fds),
|
||||
spiffs_cache,
|
||||
sizeof(spiffs_cache),
|
||||
NULL);
|
||||
SPIFFS_API_DBG_V("spiffs_mount: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
@ -24,14 +24,11 @@ The small 4KB sectors allow for greater flexibility in applications that require
|
||||
#define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
|
||||
#define INTERNAL_FLASH_READ_UNIT_SIZE 4
|
||||
|
||||
extern spiffs _filesystemStorageHandle;
|
||||
|
||||
extern uint32_t flashmem_write( const void *from, uint32_t toaddr, uint32_t size );
|
||||
extern uint32_t flashmem_read( void *to, uint32_t fromaddr, uint32_t size );
|
||||
extern bool flashmem_erase_sector( uint32_t sector_id );
|
||||
uint32_t flashmem_find_sector( uint32_t address, uint32_t *pstart, uint32_t *pend );
|
||||
uint32_t flashmem_get_sector_of_address( uint32_t addr );
|
||||
s32_t spiffs_mount();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user