Revert "Update spiffs to latest."
This commit is contained in:
parent
f7a6183853
commit
1f798dabf7
|
@ -4,8 +4,8 @@
|
||||||
* 2014-12-31
|
* 2014-12-31
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#include "user_config.h"
|
#include "user_config.h"
|
||||||
#include "osapi.h"
|
|
||||||
#include "flash_api.h"
|
#include "flash_api.h"
|
||||||
|
#include "spi_flash.h"
|
||||||
#include "c_stdio.h"
|
#include "c_stdio.h"
|
||||||
|
|
||||||
static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
||||||
|
@ -103,40 +103,43 @@ uint8_t flash_rom_get_size_type(void)
|
||||||
uint32_t flash_rom_get_size_byte(void)
|
uint32_t flash_rom_get_size_byte(void)
|
||||||
{
|
{
|
||||||
static uint32_t flash_size = 0;
|
static uint32_t flash_size = 0;
|
||||||
switch (flash_rom_getinfo().size)
|
if (flash_size == 0)
|
||||||
{
|
{
|
||||||
case SIZE_2MBIT:
|
switch (flash_rom_getinfo().size)
|
||||||
// 2Mbit, 256kByte
|
{
|
||||||
flash_size = 256 * 1024;
|
case SIZE_2MBIT:
|
||||||
break;
|
// 2Mbit, 256kByte
|
||||||
case SIZE_4MBIT:
|
flash_size = 256 * 1024;
|
||||||
// 4Mbit, 512kByte
|
break;
|
||||||
flash_size = 512 * 1024;
|
case SIZE_4MBIT:
|
||||||
break;
|
// 4Mbit, 512kByte
|
||||||
case SIZE_8MBIT:
|
flash_size = 512 * 1024;
|
||||||
// 8Mbit, 1MByte
|
break;
|
||||||
flash_size = 1 * 1024 * 1024;
|
case SIZE_8MBIT:
|
||||||
break;
|
// 8Mbit, 1MByte
|
||||||
case SIZE_16MBIT:
|
flash_size = 1 * 1024 * 1024;
|
||||||
// 16Mbit, 2MByte
|
break;
|
||||||
flash_size = 2 * 1024 * 1024;
|
case SIZE_16MBIT:
|
||||||
break;
|
// 16Mbit, 2MByte
|
||||||
case SIZE_32MBIT:
|
flash_size = 2 * 1024 * 1024;
|
||||||
// 32Mbit, 4MByte
|
break;
|
||||||
flash_size = 4 * 1024 * 1024;
|
case SIZE_32MBIT:
|
||||||
break;
|
// 32Mbit, 4MByte
|
||||||
case SIZE_64MBIT:
|
flash_size = 4 * 1024 * 1024;
|
||||||
// 64Mbit, 8MByte
|
break;
|
||||||
flash_size = 8 * 1024 * 1024;
|
case SIZE_64MBIT:
|
||||||
break;
|
// 64Mbit, 8MByte
|
||||||
case SIZE_128MBIT:
|
flash_size = 8 * 1024 * 1024;
|
||||||
// 128Mbit, 16MByte
|
break;
|
||||||
flash_size = 16 * 1024 * 1024;
|
case SIZE_128MBIT:
|
||||||
break;
|
// 128Mbit, 16MByte
|
||||||
default:
|
flash_size = 16 * 1024 * 1024;
|
||||||
// Unknown flash size, fall back mode.
|
break;
|
||||||
flash_size = 512 * 1024;
|
default:
|
||||||
break;
|
// Unknown flash size, fall back mode.
|
||||||
|
flash_size = 512 * 1024;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return flash_size;
|
return flash_size;
|
||||||
}
|
}
|
||||||
|
@ -146,21 +149,21 @@ bool flash_rom_set_size_type(uint8_t size)
|
||||||
// Dangerous, here are dinosaur infested!!!!!
|
// Dangerous, here are dinosaur infested!!!!!
|
||||||
// Reboot required!!!
|
// Reboot required!!!
|
||||||
// If you don't know what you're doing, your nodemcu may turn into stone ...
|
// If you don't know what you're doing, your nodemcu may turn into stone ...
|
||||||
FLASH_DEBUG("\nBEGIN SET FLASH HEADER\n");
|
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
|
||||||
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
|
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
|
||||||
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
||||||
{
|
{
|
||||||
((SPIFlashInfo *)(&data[0]))->size = size;
|
((SPIFlashInfo *)(&data[0]))->size = size;
|
||||||
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
|
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("\nERASE SUCCESS\n");
|
NODE_DBG("\nERASE SUCCESS\n");
|
||||||
}
|
}
|
||||||
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("\nWRITE SUCCESS, %u\n", size);
|
NODE_DBG("\nWRITE SUCCESS, %u\n", size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLASH_DEBUG("\nEND SET FLASH HEADER\n");
|
NODE_DBG("\nEND SET FLASH HEADER\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +281,7 @@ bool flash_rom_set_speed(uint32_t speed)
|
||||||
// Dangerous, here are dinosaur infested!!!!!
|
// Dangerous, here are dinosaur infested!!!!!
|
||||||
// Reboot required!!!
|
// Reboot required!!!
|
||||||
// If you don't know what you're doing, your nodemcu may turn into stone ...
|
// If you don't know what you're doing, your nodemcu may turn into stone ...
|
||||||
FLASH_DEBUG("\nBEGIN SET FLASH HEADER\n");
|
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
|
||||||
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
|
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
|
||||||
uint8_t speed_type = SPEED_40MHZ;
|
uint8_t speed_type = SPEED_40MHZ;
|
||||||
if (speed < 26700000)
|
if (speed < 26700000)
|
||||||
|
@ -302,14 +305,14 @@ bool flash_rom_set_speed(uint32_t speed)
|
||||||
((SPIFlashInfo *)(&data[0]))->speed = speed_type;
|
((SPIFlashInfo *)(&data[0]))->speed = speed_type;
|
||||||
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
|
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("\nERASE SUCCESS\n");
|
NODE_DBG("\nERASE SUCCESS\n");
|
||||||
}
|
}
|
||||||
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("\nWRITE SUCCESS, %u\n", speed_type);
|
NODE_DBG("\nWRITE SUCCESS, %u\n", speed_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLASH_DEBUG("\nEND SET FLASH HEADER\n");
|
NODE_DBG("\nEND SET FLASH HEADER\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +393,7 @@ uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index)
|
||||||
{
|
{
|
||||||
if ( (((uint32_t)aligned_array) % 4) != 0 )
|
if ( (((uint32_t)aligned_array) % 4) != 0 )
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("aligned_array is not 4-byte aligned.\n");
|
NODE_DBG("aligned_array is not 4-byte aligned.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 4 ];
|
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 4 ];
|
||||||
|
@ -402,7 +405,7 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
|
||||||
{
|
{
|
||||||
if ( (((uint32_t)aligned_array) % 4) != 0 )
|
if ( (((uint32_t)aligned_array) % 4) != 0 )
|
||||||
{
|
{
|
||||||
FLASH_DEBUG("aligned_array is not 4-byte aligned.\n");
|
NODE_DBG("aligned_array is not 4-byte aligned.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ];
|
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ];
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef __FLASH_API_H__
|
#ifndef __FLASH_API_H__
|
||||||
#define __FLASH_API_H__
|
#define __FLASH_API_H__
|
||||||
|
#include "ets_sys.h"
|
||||||
#include "user_config.h"
|
#include "user_config.h"
|
||||||
#include "user_interface.h"
|
#include "cpu_esp8266.h"
|
||||||
#include "spi_flash.h"
|
|
||||||
|
|
||||||
#define FLASH_ADDRESS_START_MAP (INTERNAL_FLASH_START_ADDRESS)
|
#define FLASH_ADDRESS_START_MAP (INTERNAL_FLASH_START_ADDRESS)
|
||||||
|
|
||||||
|
@ -22,8 +22,6 @@
|
||||||
#define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
|
#define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
|
||||||
#define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
|
#define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
|
||||||
|
|
||||||
#define FLASH_DEBUG
|
|
||||||
|
|
||||||
#define FLASH_SAFEMODE_ENTER() \
|
#define FLASH_SAFEMODE_ENTER() \
|
||||||
do { \
|
do { \
|
||||||
extern SpiFlashChip * flashchip; \
|
extern SpiFlashChip * flashchip; \
|
||||||
|
@ -87,7 +85,7 @@ typedef struct
|
||||||
} size : 4;
|
} size : 4;
|
||||||
uint32_t entry_point;
|
uint32_t entry_point;
|
||||||
uint32_t memory_offset;
|
uint32_t memory_offset;
|
||||||
uint32_t segment_size;
|
uint32_t segment_size;
|
||||||
} ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo;
|
} ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo;
|
||||||
|
|
||||||
uint32_t flash_detect_size_byte(void);
|
uint32_t flash_detect_size_byte(void);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include "c_stdio.h"
|
#include "c_stdio.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "spiffs.h"
|
#include "spiffs.h"
|
||||||
|
//#undef NODE_DBG
|
||||||
|
//#define NODE_DBG c_printf
|
||||||
|
|
||||||
spiffs fs;
|
spiffs fs;
|
||||||
|
|
||||||
#define LOG_PAGE_SIZE (256*2)
|
#define LOG_PAGE_SIZE 256
|
||||||
|
|
||||||
static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
|
static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
|
||||||
static u8_t spiffs_fds[32*4];
|
static u8_t spiffs_fds[32*4];
|
||||||
|
@ -49,9 +51,9 @@ void myspiffs_mount() {
|
||||||
cfg.phys_addr &= 0xFFFFC000; // align to 4 sector.
|
cfg.phys_addr &= 0xFFFFC000; // align to 4 sector.
|
||||||
cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS );
|
cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS );
|
||||||
cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet
|
cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet
|
||||||
cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 16; // let us not complicate things
|
cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE; // let us not complicate things
|
||||||
cfg.log_page_size = LOG_PAGE_SIZE; // as we said
|
cfg.log_page_size = LOG_PAGE_SIZE; // as we said
|
||||||
SPIFFS_DBG("fs.start:%x,max:%x\n",cfg.phys_addr,cfg.phys_size);
|
NODE_DBG("fs.start:%x,max:%x\n",cfg.phys_addr,cfg.phys_size);
|
||||||
|
|
||||||
cfg.hal_read_f = my_spiffs_read;
|
cfg.hal_read_f = my_spiffs_read;
|
||||||
cfg.hal_write_f = my_spiffs_write;
|
cfg.hal_write_f = my_spiffs_write;
|
||||||
|
@ -66,7 +68,7 @@ void myspiffs_mount() {
|
||||||
sizeof(spiffs_cache),
|
sizeof(spiffs_cache),
|
||||||
// myspiffs_check_callback);
|
// myspiffs_check_callback);
|
||||||
0);
|
0);
|
||||||
SPIFFS_DBG("mount res: %i\n", res);
|
NODE_DBG("mount res: %i\n", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void myspiffs_unmount() {
|
void myspiffs_unmount() {
|
||||||
|
@ -77,13 +79,10 @@ void myspiffs_unmount() {
|
||||||
// Returns 1 if OK, 0 for error
|
// Returns 1 if OK, 0 for error
|
||||||
int myspiffs_format( void )
|
int myspiffs_format( void )
|
||||||
{
|
{
|
||||||
#if 1
|
#if 0
|
||||||
myspiffs_unmount();
|
SPIFFS_unmount(&fs);
|
||||||
myspiffs_mount();
|
|
||||||
myspiffs_unmount();
|
|
||||||
if(0 == SPIFFS_format(&fs))
|
if(0 == SPIFFS_format(&fs))
|
||||||
{
|
{
|
||||||
myspiffs_mount();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -98,7 +97,7 @@ int myspiffs_format( void )
|
||||||
sect_first = platform_flash_get_sector_of_address(sect_first);
|
sect_first = platform_flash_get_sector_of_address(sect_first);
|
||||||
sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4;
|
sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4;
|
||||||
sect_last = platform_flash_get_sector_of_address(sect_last);
|
sect_last = platform_flash_get_sector_of_address(sect_last);
|
||||||
SPIFFS_DBG("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
|
NODE_DBG("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
|
||||||
while( sect_first <= sect_last )
|
while( sect_first <= sect_last )
|
||||||
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
|
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -117,11 +116,7 @@ int myspiffs_check( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
int myspiffs_open(const char *name, int flags){
|
int myspiffs_open(const char *name, int flags){
|
||||||
int res = SPIFFS_open(&fs, (char *)name, (spiffs_flags)flags, 0);
|
return (int)SPIFFS_open(&fs, (char *)name, (spiffs_flags)flags, 0);
|
||||||
if (res < 0) {
|
|
||||||
SPIFFS_DBG("open errno %i\n", SPIFFS_errno(&fs));
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int myspiffs_close( int fd ){
|
int myspiffs_close( int fd ){
|
||||||
|
@ -135,17 +130,17 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int res = SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
|
int res = SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, (size_t)len);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
SPIFFS_DBG("write errno %i\n", SPIFFS_errno(&fs));
|
NODE_DBG("write errno %i\n", SPIFFS_errno(&fs));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
size_t myspiffs_read( int fd, void* ptr, size_t len){
|
size_t myspiffs_read( int fd, void* ptr, size_t len){
|
||||||
int res = SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
|
int res = SPIFFS_read(&fs, (spiffs_file)fd, ptr, (size_t)len);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
SPIFFS_DBG("read errno %i\n", SPIFFS_errno(&fs));
|
NODE_DBG("read errno %i\n", SPIFFS_errno(&fs));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -165,7 +160,7 @@ int myspiffs_getc( int fd ){
|
||||||
if(!myspiffs_eof(fd)){
|
if(!myspiffs_eof(fd)){
|
||||||
res = SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
|
res = SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
SPIFFS_DBG("getc errno %i\n", SPIFFS_errno(&fs));
|
NODE_DBG("getc errno %i\n", SPIFFS_errno(&fs));
|
||||||
return (int)EOF;
|
return (int)EOF;
|
||||||
} else {
|
} else {
|
||||||
return (int)c;
|
return (int)c;
|
||||||
|
@ -198,13 +193,13 @@ void test_spiffs() {
|
||||||
// Surely, I've mounted spiffs before entering here
|
// Surely, I've mounted spiffs before entering here
|
||||||
|
|
||||||
spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
|
spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
|
||||||
if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) SPIFFS_DBG("errno %i\n", SPIFFS_errno(&fs));
|
if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
|
||||||
SPIFFS_close(&fs, fd);
|
SPIFFS_close(&fs, fd);
|
||||||
|
|
||||||
fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
|
fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
|
||||||
if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) SPIFFS_DBG("errno %i\n", SPIFFS_errno(&fs));
|
if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
|
||||||
SPIFFS_close(&fs, fd);
|
SPIFFS_close(&fs, fd);
|
||||||
|
|
||||||
SPIFFS_DBG("--> %s <--\n", buf);
|
NODE_DBG("--> %s <--\n", buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#include "eagle_soc.h"
|
|
||||||
#include "c_stdio.h"
|
#include "c_stdio.h"
|
||||||
#include "spiffs_config.h"
|
#include "spiffs_config.h"
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ extern "C" {
|
||||||
|
|
||||||
#define SPIFFS_ERR_TEST -10100
|
#define SPIFFS_ERR_TEST -10100
|
||||||
|
|
||||||
#define SPIFFS_WDT_CLEAR(no_arg) WRITE_PERI_REG(0x60000914, 0x73)
|
|
||||||
|
|
||||||
// spiffs file descriptor index type. must be signed
|
// spiffs file descriptor index type. must be signed
|
||||||
typedef s16_t spiffs_file;
|
typedef s16_t spiffs_file;
|
||||||
|
|
|
@ -124,7 +124,7 @@ typedef uint8_t u8_t;
|
||||||
// not on mount point. If not, SPIFFS_format must be called prior to mounting
|
// not on mount point. If not, SPIFFS_format must be called prior to mounting
|
||||||
// again.
|
// again.
|
||||||
#ifndef SPIFFS_USE_MAGIC
|
#ifndef SPIFFS_USE_MAGIC
|
||||||
#define SPIFFS_USE_MAGIC (1)
|
#define SPIFFS_USE_MAGIC (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
|
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
|
||||||
|
@ -169,7 +169,7 @@ typedef uint8_t u8_t;
|
||||||
|
|
||||||
// Enable this if your target needs aligned data for index tables
|
// Enable this if your target needs aligned data for index tables
|
||||||
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
|
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
|
||||||
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
|
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
|
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
|
||||||
|
|
|
@ -936,7 +936,6 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
||||||
int cur_entry = 0;
|
int cur_entry = 0;
|
||||||
|
|
||||||
while (res == SPIFFS_OK && obj_lookup_page < (int)SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
while (res == SPIFFS_OK && obj_lookup_page < (int)SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
int entry_offset = obj_lookup_page * entries_per_page;
|
int entry_offset = obj_lookup_page * entries_per_page;
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
|
|
|
@ -155,7 +155,6 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
||||||
// check each block
|
// check each block
|
||||||
while (res == SPIFFS_OK && entry_count > 0) {
|
while (res == SPIFFS_OK && entry_count > 0) {
|
||||||
int obj_lookup_page = cur_entry / entries_per_page;
|
int obj_lookup_page = cur_entry / entries_per_page;
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
// check each object lookup page
|
// check each object lookup page
|
||||||
while (res == SPIFFS_OK && obj_lookup_page < (int)SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
while (res == SPIFFS_OK && obj_lookup_page < (int)SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
int entry_offset = obj_lookup_page * entries_per_page;
|
int entry_offset = obj_lookup_page * entries_per_page;
|
||||||
|
@ -166,7 +165,6 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
||||||
cur_entry - entry_offset < entries_per_page && // for non-last obj lookup pages
|
cur_entry - entry_offset < entries_per_page && // for non-last obj lookup pages
|
||||||
cur_entry < (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) // for last obj lookup page
|
cur_entry < (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) // for last obj lookup page
|
||||||
{
|
{
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
if ((flags & SPIFFS_VIS_CHECK_ID) == 0 || obj_lu_buf[cur_entry-entry_offset] == obj_id) {
|
if ((flags & SPIFFS_VIS_CHECK_ID) == 0 || obj_lu_buf[cur_entry-entry_offset] == obj_id) {
|
||||||
if (block_ix) *block_ix = cur_block;
|
if (block_ix) *block_ix = cur_block;
|
||||||
if (lu_entry) *lu_entry = cur_entry;
|
if (lu_entry) *lu_entry = cur_entry;
|
||||||
|
@ -303,7 +301,6 @@ s32_t spiffs_obj_lu_scan(
|
||||||
spiffs_obj_id erase_count_min = SPIFFS_OBJ_ID_FREE;
|
spiffs_obj_id erase_count_min = SPIFFS_OBJ_ID_FREE;
|
||||||
spiffs_obj_id erase_count_max = 0;
|
spiffs_obj_id erase_count_max = 0;
|
||||||
while (bix < fs->block_count) {
|
while (bix < fs->block_count) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
#if SPIFFS_USE_MAGIC
|
#if SPIFFS_USE_MAGIC
|
||||||
spiffs_obj_id magic;
|
spiffs_obj_id magic;
|
||||||
res = _spiffs_rd(fs,
|
res = _spiffs_rd(fs,
|
||||||
|
@ -805,7 +802,6 @@ void spiffs_cb_object_event(
|
||||||
u32_t i;
|
u32_t i;
|
||||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||||
for (i = 0; i < fs->fd_count; i++) {
|
for (i = 0; i < fs->fd_count; i++) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
spiffs_fd *cur_fd = &fds[i];
|
spiffs_fd *cur_fd = &fds[i];
|
||||||
if (cur_fd->file_nbr == 0 || (cur_fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG) != obj_id) continue;
|
if (cur_fd->file_nbr == 0 || (cur_fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG) != obj_id) continue;
|
||||||
if (spix == 0) {
|
if (spix == 0) {
|
||||||
|
@ -922,9 +918,9 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||||
|
|
||||||
// write all data
|
// write all data
|
||||||
while (res == SPIFFS_OK && written < len) {
|
while (res == SPIFFS_OK && written < len) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
// calculate object index page span index
|
// calculate object index page span index
|
||||||
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
||||||
|
|
||||||
// handle storing and loading of object indices
|
// handle storing and loading of object indices
|
||||||
if (cur_objix_spix != prev_objix_spix) {
|
if (cur_objix_spix != prev_objix_spix) {
|
||||||
// new object index page
|
// new object index page
|
||||||
|
@ -1154,7 +1150,6 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||||
|
|
||||||
// write all data
|
// write all data
|
||||||
while (res == SPIFFS_OK && written < len) {
|
while (res == SPIFFS_OK && written < len) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
// calculate object index page span index
|
// calculate object index page span index
|
||||||
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
||||||
|
|
||||||
|
@ -1632,7 +1627,6 @@ s32_t spiffs_object_read(
|
||||||
spiffs_page_object_ix *objix = (spiffs_page_object_ix *)fs->work;
|
spiffs_page_object_ix *objix = (spiffs_page_object_ix *)fs->work;
|
||||||
|
|
||||||
while (cur_offset < offset + len) {
|
while (cur_offset < offset + len) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
||||||
if (prev_objix_spix != cur_objix_spix) {
|
if (prev_objix_spix != cur_objix_spix) {
|
||||||
// load current object index (header) page
|
// load current object index (header) page
|
||||||
|
@ -1781,7 +1775,6 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
|
||||||
state.compaction = 0;
|
state.compaction = 0;
|
||||||
state.conflicting_name = conflicting_name;
|
state.conflicting_name = conflicting_name;
|
||||||
while (res == SPIFFS_OK && free_obj_id == SPIFFS_OBJ_ID_FREE) {
|
while (res == SPIFFS_OK && free_obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
if (state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs)*8) {
|
if (state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs)*8) {
|
||||||
// possible to represent in bitmap
|
// possible to represent in bitmap
|
||||||
u32_t i, j;
|
u32_t i, j;
|
||||||
|
@ -1794,7 +1787,6 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
|
||||||
SPIFFS_CHECK_RES(res);
|
SPIFFS_CHECK_RES(res);
|
||||||
// traverse bitmask until found free obj_id
|
// traverse bitmask until found free obj_id
|
||||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs); i++) {
|
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs); i++) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
u8_t mask = fs->work[i];
|
u8_t mask = fs->work[i];
|
||||||
if (mask == 0xff) {
|
if (mask == 0xff) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1816,7 +1808,6 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
|
||||||
u8_t min_count = 0xff;
|
u8_t min_count = 0xff;
|
||||||
|
|
||||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs)/sizeof(u8_t); i++) {
|
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs)/sizeof(u8_t); i++) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
if (map[i] < min_count) {
|
if (map[i] < min_count) {
|
||||||
min_count = map[i];
|
min_count = map[i];
|
||||||
min_i = i;
|
min_i = i;
|
||||||
|
@ -1869,7 +1860,6 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
|
||||||
u32_t i;
|
u32_t i;
|
||||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||||
for (i = 0; i < fs->fd_count; i++) {
|
for (i = 0; i < fs->fd_count; i++) {
|
||||||
SPIFFS_WDT_CLEAR();
|
|
||||||
spiffs_fd *cur_fd = &fds[i];
|
spiffs_fd *cur_fd = &fds[i];
|
||||||
if (cur_fd->file_nbr == 0) {
|
if (cur_fd->file_nbr == 0) {
|
||||||
cur_fd->file_nbr = i+1;
|
cur_fd->file_nbr = i+1;
|
||||||
|
|
|
@ -61,15 +61,13 @@ void nodemcu_init(void)
|
||||||
|
|
||||||
#if defined(FLASH_SAFE_API)
|
#if defined(FLASH_SAFE_API)
|
||||||
if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
|
if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
|
||||||
NODE_ERR("File system initialization ...\n");
|
NODE_ERR("Self adjust flash size.\n");
|
||||||
NODE_ERR("This will take a minute, don't power off.\n");
|
|
||||||
// Fit hardware real flash size.
|
// Fit hardware real flash size.
|
||||||
flash_rom_set_size_byte(flash_safe_get_size_byte());
|
flash_rom_set_size_byte(flash_safe_get_size_byte());
|
||||||
// Flash init data at FLASHSIZE - 0x04000 Byte.
|
// Flash init data at FLASHSIZE - 0x04000 Byte.
|
||||||
flash_init_data_default();
|
flash_init_data_default();
|
||||||
// Flash blank data at FLASHSIZE - 0x02000 Byte.
|
// Flash blank data at FLASHSIZE - 0x02000 Byte.
|
||||||
flash_init_data_blank();
|
flash_init_data_blank();
|
||||||
|
|
||||||
if( !fs_format() )
|
if( !fs_format() )
|
||||||
{
|
{
|
||||||
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
|
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
|
||||||
|
@ -78,8 +76,7 @@ void nodemcu_init(void)
|
||||||
else{
|
else{
|
||||||
NODE_ERR( "format done.\n" );
|
NODE_ERR( "format done.\n" );
|
||||||
}
|
}
|
||||||
// Unmount filesystem because mounted by format.
|
fs_unmount(); // mounted by format.
|
||||||
fs_unmount();
|
|
||||||
}
|
}
|
||||||
#endif // defined(FLASH_SAFE_API)
|
#endif // defined(FLASH_SAFE_API)
|
||||||
|
|
||||||
|
@ -105,22 +102,6 @@ void nodemcu_init(void)
|
||||||
// test_romfs();
|
// test_romfs();
|
||||||
#elif defined ( BUILD_SPIFFS )
|
#elif defined ( BUILD_SPIFFS )
|
||||||
fs_mount();
|
fs_mount();
|
||||||
if(SPIFFS_mounted == 0)
|
|
||||||
{
|
|
||||||
NODE_ERR("File system broken, formating ...\n");
|
|
||||||
NODE_ERR("This will take a minute, don't power off.\n");
|
|
||||||
if( !fs_format() )
|
|
||||||
{
|
|
||||||
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
|
|
||||||
NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
NODE_ERR( "format done.\n" );
|
|
||||||
}
|
|
||||||
// Ensure filesystem mounted.
|
|
||||||
fs_unmount();
|
|
||||||
fs_mount();
|
|
||||||
}
|
|
||||||
// test_spiffs();
|
// test_spiffs();
|
||||||
#endif
|
#endif
|
||||||
// endpoint_setup();
|
// endpoint_setup();
|
||||||
|
|
Loading…
Reference in New Issue