From 1798c6b78c2366fa6a181ce5ef212c882da44249 Mon Sep 17 00:00:00 2001 From: funshine Date: Sat, 14 Feb 2015 16:59:45 +0800 Subject: [PATCH 1/3] minor update --- app/lua/lauxlib.c | 25 +++++-------------------- app/lua/luaconf.h | 2 +- app/spiffs/spiffs.h | 1 + 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index 64618f1b..00e740be 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -652,8 +652,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { typedef struct LoadFSF { int extraline; int f; - char *buff; - int len; + char buff[LUAL_BUFFERSIZE]; } LoadFSF; @@ -666,7 +665,7 @@ static const char *getFSF (lua_State *L, void *ud, size_t *size) { return "\n"; } if (fs_eof(lf->f)) return NULL; - *size = fs_read(lf->f, lf->buff, (lf->len)); + *size = fs_read(lf->f, lf->buff, sizeof(lf->buff)); return (*size > 0) ? lf->buff : NULL; } @@ -685,9 +684,6 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) { int c; int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ lf.extraline = 0; - // lf.len = LUAL_BUFFERSIZE; - lf.len = 0; - lf.buff = NULL; if (filename == NULL) { return luaL_error(L, "filename is NULL"); } @@ -696,10 +692,8 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) { lf.f = fs_open(filename, FS_RDONLY); if (lf.f < FS_OPEN_OK) return errfsfile(L, "open", fnameindex); } - lf.len = fs_size(lf.f) + 32; - lf.buff = c_zalloc(lf.len); - if(!lf.buff) return LUA_ERRMEM; - + // if(fs_size(lf.f)>LUAL_BUFFERSIZE) + // return luaL_error(L, "file is too big"); c = fs_getc(lf.f); if (c == '#') { /* Unix exec. file? */ lf.extraline = 1; @@ -709,13 +703,7 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) { if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ fs_close(lf.f); lf.f = fs_open(filename, FS_RDONLY); /* reopen in binary mode */ - if (lf.f < FS_OPEN_OK){ - if(lf.buff) - c_free(lf.buff); - lf.buff = NULL; - lf.len = 0; - return errfsfile(L, "reopen", fnameindex); - } + if (lf.f < FS_OPEN_OK) return errfsfile(L, "reopen", fnameindex); /* skip eventual `#!...' */ while ((c = fs_getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; lf.extraline = 0; @@ -725,9 +713,6 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) { if (filename) fs_close(lf.f); /* close file (even in case of errors) */ lua_remove(L, fnameindex); - if(lf.buff) - c_free(lf.buff); - lf.buff = NULL; return status; } diff --git a/app/lua/luaconf.h b/app/lua/luaconf.h index d1078468..1a1760c7 100644 --- a/app/lua/luaconf.h +++ b/app/lua/luaconf.h @@ -542,7 +542,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length); /* @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. */ -#define LUAL_BUFFERSIZE BUFSIZ +#define LUAL_BUFFERSIZE ((BUFSIZ)*4) /* }================================================================== */ diff --git a/app/spiffs/spiffs.h b/app/spiffs/spiffs.h index c4077ede..23228446 100644 --- a/app/spiffs/spiffs.h +++ b/app/spiffs/spiffs.h @@ -466,5 +466,6 @@ int myspiffs_error( int fd ); void myspiffs_clearerr( int fd ); int myspiffs_check( void ); int myspiffs_rename( const char *old, const char *newname ); +size_t myspiffs_size( int fd ); #endif /* SPIFFS_H_ */ From f6b1d3a39907ac6529a0a82c3a17c4ed4ea47760 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Sun, 15 Feb 2015 00:02:53 +0800 Subject: [PATCH 2/3] Test what caused flash AUTO_SIZE bug. --- app/platform/flash_api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 3fde416b..3ef15abe 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -24,6 +24,7 @@ SPIFlashInfo flash_get_info(void) { volatile SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR; spi_flash_info = *((SPIFlashInfo *)(FLASH_MAP_START_ADDRESS)); + // spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info)); return spi_flash_info; } @@ -232,13 +233,14 @@ bool flash_self_destruct(void) return true; } -uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index) +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 ) + { NODE_DBG("aligned_array is not 4-byte aligned.\n"); return 0; } - uint32_t v = ((uint32_t *)aligned_array)[ index/4 ]; + uint32_t v = ((uint32_t *)aligned_array)[ index / 4 ]; uint8_t *p = (uint8_t *) (&v); - return p[ (index%4) ]; + return p[ (index % 4) ]; } From 0232c13b83cf4c84c45ab5fc67b6677297e9f24d Mon Sep 17 00:00:00 2001 From: HuangRui Date: Sun, 15 Feb 2015 02:13:58 +0800 Subject: [PATCH 3/3] Emergency update, fix flash size auto detection bug. 64Mbit and 128Mbit supported by hardware, but not supported by this SDK 0.9.5. Waiting SDK update. --- app/platform/flash_api.c | 12 +++++++++++- app/platform/flash_api.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 3ef15abe..c4ce6f57 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -57,9 +57,11 @@ uint32_t flash_get_size_byte(void) case SIZE_32MBIT: // 32Mbit, 4MByte flash_size = 4 * 1024 * 1024; + break; case SIZE_64MBIT: // 64Mbit, 8MByte flash_size = 8 * 1024 * 1024; + break; case SIZE_128MBIT: // 128Mbit, 16MByte flash_size = 16 * 1024 * 1024; @@ -132,7 +134,15 @@ bool flash_set_size_byte(uint32_t size) uint16_t flash_get_sec_num(void) { - return flash_get_size_byte() / SPI_FLASH_SEC_SIZE; + //static uint16_t sec_num = 0; + // return flash_get_size_byte() / (SPI_FLASH_SEC_SIZE); + // c_printf("\nflash_get_size_byte()=%d\n", ( flash_get_size_byte() / (SPI_FLASH_SEC_SIZE) )); + // if( sec_num == 0 ) + //{ + // sec_num = 4 * 1024 * 1024 / (SPI_FLASH_SEC_SIZE); + //} + //return sec_num; + return ( flash_get_size_byte() / (SPI_FLASH_SEC_SIZE) ); } uint8_t flash_get_mode(void) diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 82d681e3..038553a2 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -3,6 +3,7 @@ #include "ets_sys.h" #include "user_config.h" #include "cpu_esp8266.h" + #define FLASH_MAP_START_ADDRESS (INTERNAL_FLASH_START_ADDRESS) /******************************************************************************