Commit b65fb02c authored by funshine's avatar funshine
Browse files

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

parent acd9d0dc
...@@ -26,6 +26,12 @@ Tencent QQ group QQ群: 309957875<br /> ...@@ -26,6 +26,12 @@ Tencent QQ group QQ群: 309957875<br />
- add coap module - add coap module
# Change log # 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 /> 2015-01-06<br />
update sdk to 0.9.5.<br /> update sdk to 0.9.5.<br />
pre_build bin now compiled by gcc toolchain.<br /> pre_build bin now compiled by gcc toolchain.<br />
...@@ -33,13 +39,6 @@ memory/heap usage optimized.<br /> ...@@ -33,13 +39,6 @@ memory/heap usage optimized.<br />
add support for multiple platform and toolchain include eclipse. <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. 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 /> [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) [更多变更日志](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_cn#change_log)
...@@ -147,6 +146,7 @@ eagle.app.v6.irom0text.bin: 0x10000<br /> ...@@ -147,6 +146,7 @@ eagle.app.v6.irom0text.bin: 0x10000<br />
esp_init_data_default.bin: 0x7c000<br /> esp_init_data_default.bin: 0x7c000<br />
blank.bin: 0x7e000<br /> blank.bin: 0x7e000<br />
*Better run file.format() after flash*
#Connect the hardware in serial #Connect the hardware in serial
baudrate:9600 baudrate:9600
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define NODE_VERSION_REVISION 5U #define NODE_VERSION_REVISION 5U
#define NODE_VERSION_INTERNAL 0U #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 BUILD_DATE "build 20150107"
// #define FLASH_512K // #define FLASH_512K
......
...@@ -133,7 +133,7 @@ static int docall (lua_State *L, int narg, int clear) { ...@@ -133,7 +133,7 @@ static int docall (lua_State *L, int narg, int clear) {
static void print_version (void) { static void print_version (void) {
// l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); // 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);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "flash_fs.h" #include "flash_fs.h"
#include "c_string.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) // Lua: open(filename, mode)
static int file_open( lua_State* L ) static int file_open( lua_State* L )
...@@ -48,21 +48,6 @@ static int file_close( lua_State* L ) ...@@ -48,21 +48,6 @@ static int file_close( lua_State* L )
return 0; return 0;
} }
#if defined(BUILD_WOFS)
// Lua: list()
static int file_list( lua_State* L )
{
uint32_t start = 0;
size_t act_len = 0;
char fsname[ FS_NAME_MAX_LENGTH + 1 ];
lua_newtable( L );
while( FS_FILE_OK == wofs_next(&start, fsname, FS_NAME_MAX_LENGTH, &act_len) ){
lua_pushinteger(L, act_len);
lua_setfield( L, -2, fsname );
}
return 1;
}
// Lua: format() // Lua: format()
static int file_format( lua_State* L ) static int file_format( lua_State* L )
{ {
...@@ -71,7 +56,7 @@ static int file_format( lua_State* L ) ...@@ -71,7 +56,7 @@ static int file_format( lua_State* L )
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" );
NODE_ERR( "It is advised to re-flash the nodeMcu image.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
} }
else{ else{
NODE_ERR( "format done.\n" ); NODE_ERR( "format done.\n" );
...@@ -79,6 +64,21 @@ static int file_format( lua_State* L ) ...@@ -79,6 +64,21 @@ static int file_format( lua_State* L )
return 0; return 0;
} }
#if defined(BUILD_WOFS)
// Lua: list()
static int file_list( lua_State* L )
{
uint32_t start = 0;
size_t act_len = 0;
char fsname[ FS_NAME_MAX_LENGTH + 1 ];
lua_newtable( L );
while( FS_FILE_OK == wofs_next(&start, fsname, FS_NAME_MAX_LENGTH, &act_len) ){
lua_pushinteger(L, act_len);
lua_setfield( L, -2, fsname );
}
return 1;
}
#elif defined(BUILD_SPIFFS) #elif defined(BUILD_SPIFFS)
extern spiffs fs; extern spiffs fs;
...@@ -275,8 +275,8 @@ const LUA_REG_TYPE file_map[] = ...@@ -275,8 +275,8 @@ const LUA_REG_TYPE file_map[] =
{ LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) }, { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
{ LSTRKEY( "read" ), LFUNCVAL( file_read ) }, { LSTRKEY( "read" ), LFUNCVAL( file_read ) },
{ LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
#if defined(BUILD_WOFS)
{ LSTRKEY( "format" ), LFUNCVAL( file_format ) }, { LSTRKEY( "format" ), LFUNCVAL( file_format ) },
#if defined(BUILD_WOFS)
#elif defined(BUILD_SPIFFS) #elif defined(BUILD_SPIFFS)
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
......
...@@ -81,6 +81,7 @@ int myspiffs_format( void ) ...@@ -81,6 +81,7 @@ int myspiffs_format( void )
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;
spiffs_mount();
return 1; return 1;
} }
...@@ -107,10 +108,20 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){ ...@@ -107,10 +108,20 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){
return len; return len;
} }
#endif #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){ 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 ){ int myspiffs_lseek( int fd, int off, int whence ){
return SPIFFS_lseek(&fs, (spiffs_file)fd, off, whence); return SPIFFS_lseek(&fs, (spiffs_file)fd, off, whence);
...@@ -123,8 +134,13 @@ int myspiffs_tell( int fd ){ ...@@ -123,8 +134,13 @@ int myspiffs_tell( int fd ){
} }
int myspiffs_getc( int fd ){ int myspiffs_getc( int fd ){
char c = EOF; char c = EOF;
int res;
if(!myspiffs_eof(fd)){ 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; return (int)c;
} }
......
...@@ -310,3 +310,5 @@ uart.on("data", 5 ,function(input) if input=="quit\r" then uart.on("data") else ...@@ -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", 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) 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
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