Commit 4ae52c23 authored by TerryE's avatar TerryE
Browse files

Alpha working wersion for third party evaluation

parent e00d927a
......@@ -18,7 +18,7 @@
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "ldo.h"
#include "lfunc.h"
#include "lmem.h"
......@@ -37,6 +37,7 @@ static int flash=0; /* output flash image */
static int lookup=0; /* output lookup-style master combination header */
static char Output[]={ OUTPUT }; /* default output file name */
static const char* output=Output; /* actual output file name */
static const char* execute; /* executed a Lua file */
static const char* progname=PROGNAME; /* actual program name */
static DumpTargetInfo target;
......@@ -66,6 +67,7 @@ static void usage(const char* message)
" - process stdin\n"
" -l list\n"
" -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
" -e name execute a lua source file\n"
" -f output a flash image file\n"
" -i generate lookup combination master (default with option -f)\n"
" -p parse only\n"
......@@ -93,8 +95,14 @@ static int doargs(int argc, char* argv[])
if (version) ++version;
break;
}
else if (IS("-")) /* end of options; use stdin */
else if (IS("-")) /* end of options; use stdin */
break;
else if (IS("-e")) /* execute a lua source file file */
{
execute=argv[++i];
if (execute ==NULL || *execute==0 || *execute=='-' )
usage(LUA_QL("-e") " needs argument");
}
else if (IS("-f")) /* Flash image file */
{
flash=1;
......@@ -242,12 +250,25 @@ static int pmain(lua_State* L)
const Proto* f;
int i;
if (!lua_checkstack(L,argc)) fatal("too many input files");
if (execute)
{
if (luaL_loadfile(L,execute)!=0) fatal(lua_tostring(L,-1));
luaL_openlibs(L);
lua_pushstring(L, execute);
if (lua_pcall(L, 1, 1, 0)) fatal(lua_tostring(L,-1));
if (!lua_isfunction(L, -1))
{
lua_pop(L,1);
if(argc == 0) return 0;
execute = NULL;
}
}
for (i=0; i<argc; i++)
{
const char* filename=IS("-") ? NULL : argv[i];
if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));
}
f=combine(L,argc,lookup);
f=combine(L,argc + (execute ? 1: 0), lookup);
if (listing) luaU_print(f,listing>1);
if (dumping)
{
......@@ -286,7 +307,7 @@ int main(int argc, char* argv[])
int i=doargs(argc,argv);
argc-=i; argv+=i;
if (argc<=0) usage("no input files given");
if (argc<=0 && execute==0) usage("no input files given");
L=lua_open();
if (L==NULL) fatal("not enough memory for state");
s.argc=argc;
......
......@@ -167,7 +167,7 @@
#define LUA_INTEGER ptrdiff_t
#else
#if !defined LUA_INTEGRAL_LONGLONG
#define LUA_INTEGER long
#define LUA_INTEGER int
#else
#define LUA_INTEGER long long
#endif // #if !defined LUA_INTEGRAL_LONGLONG
......@@ -487,7 +487,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
/* 16-bit ints */
#define LUAI_UINT32 unsigned long
#define LUAI_INT32 long
#define LUAI_MAXINT32 LONG_MAX
#define LUAI_MAXINT32 INT_MAX
#define LUAI_UMEM unsigned long
#define LUAI_MEM long
#endif
......@@ -607,8 +607,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
*/
#if defined LUA_NUMBER_INTEGRAL
#if !defined LUA_INTEGRAL_LONGLONG
#define LUA_NUMBER_SCAN "%ld"
#define LUA_NUMBER_FMT "%ld"
#define LUA_NUMBER_SCAN "%d"
#define LUA_NUMBER_FMT "%d"
#else
#define LUA_NUMBER_SCAN "%lld"
#define LUA_NUMBER_FMT "%lld"
......@@ -894,7 +894,7 @@ union luai_Cast { double l_d; long l_l; };
/* If you define the next macro you'll get the ability to set rotables as
metatables for tables/userdata/types (but the VM might run slower)
*/
#if (LUA_OPTIMIZE_MEMORY == 2) && !defined(LUA_CROSS_COMPILER)
#if (LUA_OPTIMIZE_MEMORY == 2)
#define LUA_META_ROTABLES
#endif
......
......@@ -172,7 +172,7 @@ static TString* LoadString(LoadState* S)
} else {
s = (char*)luaZ_get_crt_address(S->Z);
LoadBlock(S,NULL,size);
return luaS_newrolstr(S->L,s,size-1);
return luaS_newlstr(S->L,s,size-1);
}
}
}
......@@ -280,7 +280,7 @@ static Proto* LoadFunction(LoadState* S, TString* p)
Proto* f;
if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
f=luaF_newproto(S->L);
if (luaZ_direct_mode(S->Z)) proto_readonly(f);
if (luaZ_direct_mode(S->Z)) l_setbit((f)->marked, READONLYBIT);
setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
f->source=LoadString(S); if (f->source==NULL) f->source=p;
f->linedefined=LoadInt(S);
......
......@@ -41,7 +41,7 @@ LUA_NUMBER luai_ipow(LUA_NUMBER a, LUA_NUMBER b) {
LUA_NUMBER c = 1;
for (;;) {
if (b & 1)
c *= a;
c *= a;
b = b >> 1;
if (b == 0)
return c;
......
......@@ -50,7 +50,7 @@ INCLUDES += -I ../pcm
INCLUDES += -I ../platform
INCLUDES += -I ../spiffs
INCLUDES += -I ../smart
INCLUDES += -I ../dhtlib
INCLUDES += -I ../dht
INCLUDES += -I ../fatfs
INCLUDES += -I ../http
INCLUDES += -I ../sjson
......
/*
** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
** Initialization of libraries for lua.c
** See Copyright Notice in lua.h
*/
#define linit_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "luaconf.h"
#include "module.h"
BUILTIN_LIB_INIT( BASE, "", luaopen_base);
BUILTIN_LIB_INIT( LOADLIB, LUA_LOADLIBNAME, luaopen_package);
#if defined(LUA_USE_BUILTIN_IO)
BUILTIN_LIB_INIT( IO, LUA_IOLIBNAME, luaopen_io);
#endif
#if defined (LUA_USE_BUILTIN_STRING)
extern const luaR_entry strlib[];
BUILTIN_LIB_INIT( STRING, LUA_STRLIBNAME, luaopen_string);
BUILTIN_LIB( STRING, LUA_STRLIBNAME, strlib);
#endif
#if defined(LUA_USE_BUILTIN_TABLE)
extern const luaR_entry tab_funcs[];
BUILTIN_LIB_INIT( TABLE, LUA_TABLIBNAME, luaopen_table);
BUILTIN_LIB( TABLE, LUA_TABLIBNAME, tab_funcs);
#endif
#if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
extern const luaR_entry dblib[];
BUILTIN_LIB_INIT( DBG, LUA_DBLIBNAME, luaopen_debug);
BUILTIN_LIB( DBG, LUA_DBLIBNAME, dblib);
#endif
#if defined(LUA_USE_BUILTIN_OS)
extern const luaR_entry syslib[];
BUILTIN_LIB( OS, LUA_OSLIBNAME, syslib);
#endif
#if defined(LUA_USE_BUILTIN_COROUTINE)
extern const luaR_entry co_funcs[];
BUILTIN_LIB( CO, LUA_COLIBNAME, co_funcs);
#endif
#if defined(LUA_USE_BUILTIN_MATH)
extern const luaR_entry math_map[];
BUILTIN_LIB( MATH, LUA_MATHLIBNAME, math_map);
#endif
#ifdef LUA_CROSS_COMPILER
const luaL_Reg lua_libs[] = {{NULL, NULL}};
const luaR_table lua_rotable[] = {{NULL, NULL}};
#else
extern const luaL_Reg lua_libs[];
#endif
void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib = lua_libs;
for (; lib->name; lib++) {
if (lib->func)
{
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
}
}
......@@ -17,7 +17,9 @@
#include "platform.h"
#include "lrodefs.h"
#ifdef LUA_FLASH_STORE
#include "lflash.h"
#endif
#include "c_types.h"
#include "c_string.h"
#include "driver/uart.h"
......@@ -134,7 +136,6 @@ static int node_chipid( lua_State* L )
// lua_pushinteger(L, vdd33);
// return 1;
// }
// Lua: flashid()
static int node_flashid( lua_State* L )
{
......@@ -574,6 +575,13 @@ static const LUA_REG_TYPE node_task_map[] = {
{ LSTRKEY( "HIGH_PRIORITY" ), LNUMVAL( TASK_PRIORITY_HIGH ) },
{ LNILKEY, LNILVAL }
};
#ifdef LUA_FLASH_STORE
static const LUA_REG_TYPE node_flash_map[] = {
{ LSTRKEY( "reload" ), LFUNCVAL( luaN_reload_reboot ) },
{ LSTRKEY( "index" ), LFUNCVAL( luaN_index ) },
{ LNILKEY, LNILVAL }
};
#endif
static const LUA_REG_TYPE node_map[] =
{
......@@ -601,6 +609,9 @@ static const LUA_REG_TYPE node_map[] =
{ LSTRKEY( "random" ), LFUNCVAL( node_random) },
#ifdef LUA_OPTIMIZE_DEBUG
{ LSTRKEY( "stripdebug" ), LFUNCVAL( node_stripdebug ) },
#endif
#ifdef LUA_FLASH_STORE
{ LSTRKEY( "flash") , LROVAL( node_flash_map ) },
#endif
{ LSTRKEY( "egc" ), LROVAL( node_egc_map ) },
{ LSTRKEY( "task" ), LROVAL( node_task_map ) },
......
......@@ -12,7 +12,7 @@
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = mqtt.a
GEN_LIBS = libmqtt.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
......
......@@ -12,7 +12,7 @@
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = pcm.a
GEN_LIBS = libpcm.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
......
......@@ -67,22 +67,54 @@ uint32_t platform_flash_get_num_sectors(void)
#endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE
}
static uint32_t allocated = 0;
static uint32_t phys_flash_used_end = 0; //Phyiscal address of last byte in last flash used sector
uint32_t platform_flash_reserve_section( uint32_t regsize, uint32_t *start )
{
// Return Flash sector no (and optional flash mapped address of first allocated byte)
if(phys_flash_used_end == 0)
flashh_find_sector(platform_flash_mapped2phys( (uint32_t)_flash_used_end - 1), NULL, &phys_flash_used_end );
/* find sector and last byte address of previous allocation */
uint32_t end;
uint32_t sect = flashh_find_sector( phys_flash_used_end + allocated, NULL, &end );
if(start)
*start = end + 1;
/* allocated regions are always sector aligned */
flashh_find_sector( phys_flash_used_end + allocated + regsize, NULL, &end );
allocated = end - phys_flash_used_end;
NODE_DBG("Flash base: %08x %08x %08x\n", regsize, allocated, phys_flash_used_end);
return sect + 1;
}
uint32_t platform_flash_get_first_free_block_address( uint32_t *psect )
{
// Round the total used flash size to the closest flash block address
uint32_t start, end, sect;
NODE_DBG("_flash_used_end:%08x\n", (uint32_t)_flash_used_end);
#if 0
if(_flash_used_end>0){ // find the used sector
sect = flashh_find_sector( platform_flash_mapped2phys ( (uint32_t)_flash_used_end - 1), NULL, &end );
if( psect )
*psect = sect + 1;
return end + 1;
sect++;
start = end + 1;
}else{
sect = flashh_find_sector( 0, &start, NULL ); // find the first free sector
if( psect )
*psect = sect;
return start;
}
if(_flash_used_end>0){ // find the used sector
uint32_t sta1, sec1;
sec1 = platform_flash_reserve_section( 0, &sta1 );
NODE_DBG("Flash base: %p %p %p %p\n", sect, start, sec1, sta1);
}
#endif
sect = _flash_used_end ? platform_flash_reserve_section( 0, &start ) :
flashh_find_sector( 0, &start, NULL );
if( psect )
*psect = sect;
return start;
}
uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size )
......
......@@ -879,7 +879,7 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz
if(SPI_FLASH_RESULT_OK == r)
return size;
else{
NODE_ERR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr);
NODE_ERR( "ERROR in flash_write: r=%d at %p\n", ( int )r, ( unsigned )toaddr);
return 0;
}
}
......@@ -917,7 +917,7 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
if(SPI_FLASH_RESULT_OK == r)
return size;
else{
NODE_ERR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr);
NODE_ERR( "ERROR in flash_read: r=%d at %p\n", ( int )r, ( unsigned )fromaddr);
return 0;
}
}
......@@ -928,15 +928,26 @@ int platform_flash_erase_sector( uint32_t sector_id )
return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR;
}
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr)
static uint32_t flash_map_meg_offset ()
{
uint32_t cache_ctrl = READ_PERI_REG(CACHE_FLASH_CTRL_REG);
if (!(cache_ctrl & CACHE_FLASH_ACTIVE))
return -1;
bool b0 = (cache_ctrl & CACHE_FLASH_MAPPED0) ? 1 : 0;
bool b1 = (cache_ctrl & CACHE_FLASH_MAPPED1) ? 1 : 0;
uint32_t meg = (b1 << 1) | b0;
return mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg * 0x100000;
return ((b1 << 1) | b0) * 0x100000;
}
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr)
{
uint32_t meg = flash_map_meg_offset();
return (meg&1) ? -1 : mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg ;
}
uint32_t platform_flash_phys2mapped (uint32_t phys_addr)
{
uint32_t meg = flash_map_meg_offset();
return (meg&1) ? -1 : phys_addr + INTERNAL_FLASH_MAPPED_ADDRESS - meg;
}
void* platform_print_deprecation_note( const char *msg, const char *time_frame)
......
......@@ -268,8 +268,11 @@ uint32_t platform_eth_get_elapsed_time(void);
// *****************************************************************************
// Internal flash erase/write functions
uint32_t platform_flash_reserve_section( uint32_t regsize, uint32_t *start );
uint32_t platform_flash_get_first_free_block_address( uint32_t *psect );
uint32_t platform_flash_get_sector_of_address( uint32_t addr );
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr);
uint32_t platform_flash_phys2mapped (uint32_t phys_addr);
uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size );
uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size );
uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size );
......
......@@ -12,7 +12,7 @@
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = tsl2561lib.a
GEN_LIBS = libtsl2561.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
......
......@@ -12,7 +12,7 @@
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = u8glib.a
GEN_LIBS = libu8glib.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
......
......@@ -12,7 +12,7 @@
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = ucglib.a
GEN_LIBS = libucglib.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
......
......@@ -240,6 +240,7 @@ user_rf_cal_sector_set(void)
return rf_cal_sec;
}
extern void luaN_user_init(void);
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
......@@ -261,5 +262,9 @@ void user_init(void)
system_set_os_print(0);
#endif
#ifdef LUA_FLASH_STORE
luaN_user_init();
#endif
system_init_done_cb(nodemcu_init);
}
......@@ -173,7 +173,7 @@ system heap size left in bytes (number)
## node.info()
Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed.
Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, and Lua File Store (LFS) usage statics.
#### Syntax
`node.info()`
......@@ -496,6 +496,37 @@ provides more detailed information on the EGC.
`node.egc.setmode(node.egc.ALWAYS, 4096) -- This is the default setting at startup.`
`node.egc.setmode(node.egc.ON_ALLOC_FAILURE) -- This is the fastest activeEGC mode.`
# node.flash module
## node.flash.index()
Returns the function reference for a function in the LFS (Lua Flash Store).
#### Syntax
`node.flash.index()`
#### Parameters
None
#### Returns
- In the case where the LFS in not loaded, `node.flash.index` evaluates to `nil`
- If the LFS is loaded, this returns the index function within the LFS which indexes its contents. This index function can itself to called to interrogate or access the LFS contents:
- In that case where the function is called with the name of a valid module in the LFS, the function is returned in the same way the `load()` and the other Lua load functions do.
- Otherwise the function returns a list of module names in the LFS. Note that the first entry in the list is the Unix datetime of he build.
## node.flash.reload()
Reload the LFS (Lua Flash Store) with the flash image provided. Flash images are generated on the host machine using the `luac.cross`commnad.
#### Syntax
`node.flash.rebuild(imageName)`
#### Parameters
`imageName` The of name of a image file in the filesystem to be loaded into the LFS.
#### Returns
_Not applicable_. The ESP will load the LFS image and immediately reboot. Control is not returned to the calling application.
# node.task module
## node.task.post()
......
......@@ -234,11 +234,11 @@ SECTIONS
/* Link-time arrays containing the defs for the included modules */
. = ALIGN(4);
lua_libs = ABSOLUTE(.);
lua_libs_base = ABSOLUTE(.);
/* Allow either empty define or defined-to-1 to include the module */
KEEP(*(.lua_libs))
LONG(0) LONG(0) /* Null-terminate the array */
lua_rotable = ABSOLUTE(.);
lua_rotable_base = ABSOLUTE(.);
KEEP(*(.lua_rotable))
LONG(0) LONG(0) /* Null-terminate the array */
......
......@@ -5,8 +5,8 @@
FSSOURCE ?= ../local/fs/
LUASOURCE ?= ../local/lua/
FLASHSIZE ?= 4mb 32mb 8mb
FLASH_SW = -S
SUBDIRS =
HOSTCC ?= gcc
OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump)
......@@ -20,16 +20,16 @@ SPIFFSFILES ?= $(patsubst $(FSSOURCE)%,%,$(shell find $(FSSOURCE) -name '*' '!'
# Get the filesize of /bin/0x10000.bin and SPIFFS sizing
#
FLASH_USED_END := $$((0x`$(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app.v6.out |grep _flash_used_end |cut -f1 -d" "` - 0x40200000))
FLASH_FS_SIZE := $(shell $(HOSTCC) -E -dM - <../app/include/user_config.h | grep SPIFFS_MAX_FILESYSTEM_SIZE| cut -d ' ' -f 3)
FLASH_FS_LOC := $(shell $(HOSTCC) -E -dM - <../app/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3)
FLASH_FS_SIZE := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_MAX_FILESYSTEM_SIZE| cut -d ' ' -f 3)
ifneq (FLASH_FS_SIZE,'')
ifneq ($(strip $(FLASH_FS_SIZE)),)
FLASHSIZE = $(shell printf "0x%x" $(FLASH_FS_SIZE))
FLASH_SW = -c
endif
ifeq (FLASH_FS_LOC,'')
FLASH_FS_LOC := $(FLASH_USED_END)
FLASH_FS_LOC := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3)
ifeq ($(strip $(FLASH_FS_LOC)),)
FLASH_FS_LOC := $(shell printf "0x%x" $$((0x$(shell $(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app.v6.out |grep " _flash_used_end" |cut -f1 -d" ") - 0x40200000)))
else
FLASH_FS_LOC := $(shell printf "0x%x" $(FLASH_FS_LOC))
endif
......@@ -42,6 +42,16 @@ endif
all: spiffsscript
.PHONY: TEST
TEST:
@echo $(FLASHSIZE)
@echo $(FLASH_FS_SIZE)
@echo $(FLASH_FS_LOC)
@echo $(FLASH_USED_END)
spiffsimg/spiffsimg:
.PHONY: spiffsimg
.PHONY: spiffsimg/spiffsimg
......@@ -56,7 +66,7 @@ spiffsscript: remove-image LFSimage spiffsimg/spiffsimg
rm -f ./spiffsimg/spiffs.lst
@echo "" >> ./spiffsimg/spiffs.lst
@$(foreach f, $(SPIFFSFILES), echo "import $(FSSOURCE)$(f) $(f)" >> ./spiffsimg/spiffs.lst ;)
$(foreach sz, $(FLASHSIZE), spiffsimg/spiffsimg -f ../bin/0x%x-$(sz).img -c $(sz) -U $(FLASH_FS_LOC) -r ./spiffsimg/spiffs.lst -d; )
$(foreach sz, $(FLASHSIZE), spiffsimg/spiffsimg -f ../bin/0x%x-$(sz).img $(FLASH_SW) $(sz) -U $(FLASH_FS_LOC) -r ./spiffsimg/spiffs.lst -d; )
@$(foreach sz, $(FLASHSIZE), if [ -r ../bin/spiffs-$(sz).dat ]; then echo Built $$(cat ../bin/spiffs-$(sz).dat)-$(sz).bin; fi; )
LFSimage: $(LUASOURCE)*.lua
......
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