add file.format() to rebuild fs system, get more ram back

This commit is contained in:
funshine 2015-01-07 15:57:17 +08:00
parent acd9d0dc97
commit b65fb02cc5
9 changed files with 48 additions and 30 deletions

View File

@ -26,6 +26,12 @@ Tencent QQ group QQ群: 309957875<br />
- add coap module
# Change log
2015-01-07<br />
retrive more ram back.<br />
add api file.format() to rebuild file system.<br />
rename "NodeMcu" to "NodeMCU" in firmware.<br />
add some check for file system op.
2015-01-06<br />
update sdk to 0.9.5.<br />
pre_build bin now compiled by gcc toolchain.<br />
@ -33,13 +39,6 @@ memory/heap usage optimized.<br />
add support for multiple platform and toolchain include eclipse. <br />
combine firmware for 512K, 1M, 2M, 4M flash to one. flash size auto-detected.
2014-12-30<br />
modify uart.on api, when run_input set to 0, uart.on now can read raw data from uart.<br />
serial input now accept non-ascii chars.<br />
fix dev-kit gpio map.<br />
add setip, setmac, sleeptype api to wifi module. <br />
add tmr.time() api to get rtc time and calibration.
[more change log](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#change_log)<br />
[更多变更日志](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_cn#change_log)
@ -147,6 +146,7 @@ eagle.app.v6.irom0text.bin: 0x10000<br />
esp_init_data_default.bin: 0x7c000<br />
blank.bin: 0x7e000<br />
*Better run file.format() after flash*
#Connect the hardware in serial
baudrate:9600

View File

@ -6,7 +6,7 @@
#define NODE_VERSION_REVISION 5U
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMcu 0.9.5"
#define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 20150107"
// #define FLASH_512K

View File

@ -133,7 +133,7 @@ static int docall (lua_State *L, int narg, int clear) {
static void print_version (void) {
// l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
l_message(NULL, NODE_VERSION " " BUILD_DATE " powered by " LUA_RELEASE);
l_message(NULL, "\n" NODE_VERSION " " BUILD_DATE " powered by " LUA_RELEASE);
}

View File

@ -11,7 +11,7 @@
#include "flash_fs.h"
#include "c_string.h"
static int file_fd = FS_OPEN_OK - 1;
static volatile int file_fd = FS_OPEN_OK - 1;
// Lua: open(filename, mode)
static int file_open( lua_State* L )
@ -48,6 +48,22 @@ static int file_close( lua_State* L )
return 0;
}
// Lua: format()
static int file_format( lua_State* L )
{
size_t len;
file_close(L);
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" );
}
return 0;
}
#if defined(BUILD_WOFS)
// Lua: list()
static int file_list( lua_State* L )
@ -63,22 +79,6 @@ static int file_list( lua_State* L )
return 1;
}
// Lua: format()
static int file_format( lua_State* L )
{
size_t len;
file_close(L);
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" );
}
return 0;
}
#elif defined(BUILD_SPIFFS)
extern spiffs fs;
@ -275,8 +275,8 @@ const LUA_REG_TYPE file_map[] =
{ LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
{ LSTRKEY( "read" ), LFUNCVAL( file_read ) },
{ LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
#if defined(BUILD_WOFS)
{ LSTRKEY( "format" ), LFUNCVAL( file_format ) },
#if defined(BUILD_WOFS)
#elif defined(BUILD_SPIFFS)
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },

View File

@ -81,6 +81,7 @@ int myspiffs_format( void )
while( sect_first <= sect_last )
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
return 0;
spiffs_mount();
return 1;
}
@ -107,10 +108,20 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){
return len;
}
#endif
return SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
int res = SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
if (res < 0) {
NODE_DBG("write errno %i\n", SPIFFS_errno(&fs));
return 0;
}
return res;
}
size_t myspiffs_read( int fd, void* ptr, size_t len){
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
int res = SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
if (res < 0) {
NODE_DBG("read errno %i\n", SPIFFS_errno(&fs));
return 0;
}
return res;
}
int myspiffs_lseek( int fd, int off, int whence ){
return SPIFFS_lseek(&fs, (spiffs_file)fd, off, whence);
@ -123,8 +134,13 @@ int myspiffs_tell( int fd ){
}
int myspiffs_getc( int fd ){
char c = EOF;
int res;
if(!myspiffs_eof(fd)){
SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
res = SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
if (res != 1) {
NODE_DBG("getc errno %i\n", SPIFFS_errno(&fs));
return (int)EOF;
}
}
return (int)c;
}

View File

@ -310,3 +310,5 @@ uart.on("data", 5 ,function(input) if input=="quit\r" then uart.on("data") else
uart.on("data", 0 ,function(input) if input=="q" then uart.on("data") else print(input) end end, 0)
uart.on("data","\r",function(input) if input=="quit" then uart.on("data") else print(input) end end, 1)
for k, v in pairs(file.list()) do print('file:'..k..' len:'..v) end

Binary file not shown.

Binary file not shown.