diff --git a/components/base_nodemcu/CMakeLists.txt b/components/base_nodemcu/CMakeLists.txt index ffb07017..ae355564 100644 --- a/components/base_nodemcu/CMakeLists.txt +++ b/components/base_nodemcu/CMakeLists.txt @@ -5,3 +5,11 @@ idf_component_register( PRIV_REQUIRES "nvs_flash" LDFRAGMENTS "nodemcu.lf" ) + +target_compile_options(${COMPONENT_LIB} PRIVATE -DCONFIG_NODEMCU_CMODULE_UART) +target_link_libraries(${COMPONENT_LIB} + "-u UART_module_selected1" + "-u lua_rotables_part_map" + "-Wl,-defsym=lua_rotables_map=_lua_rotables_map_start" + "-Wl,-defsym=lua_libs_map=_lua_libs_map_start" +) diff --git a/components/base_nodemcu/ld/nodemcu_rodata.ld b/components/base_nodemcu/ld/nodemcu_rodata.ld deleted file mode 100644 index e63f75a2..00000000 --- a/components/base_nodemcu/ld/nodemcu_rodata.ld +++ /dev/null @@ -1,29 +0,0 @@ - - /* ----- Begin NodeMCU link-time arrays ------- */ - - /* Don't change the alignment here without also updating the _Static_assert - * over in linit.c! */ - . = ALIGN(8); - /* Link-time arrays containing the defs for the included modules */ - lua_libs_map = ABSOLUTE(.); - KEEP(*(.lua_libs)) - /* Null-terminate the array, 24 bytes */ - LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) - - /* Don't change the alignment here without also updating the _Static_assert - * over in linit.c! */ - . = ALIGN(8); - lua_rotables_map = ABSOLUTE(.); - KEEP(*(.lua_rotable)) - /* Null-terminate the array, 24 bytes */ - LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) - - /* Don't change the alignment here without also updating the _Static_assert - * over in nodemcu_esp_event.h! */ - . = ALIGN(4); - esp_event_cb_table = ABSOLUTE(.); - KEEP(*(.lua_esp_event_cb_table)) - LONG(0) LONG(0) /* Null-terminate the array, 8 bytes */ - - /* ----- End NodeMCU link-time arrays ------- */ - diff --git a/components/base_nodemcu/ld/nodemcu_rodata_lfs.ld b/components/base_nodemcu/ld/nodemcu_rodata_lfs.ld deleted file mode 100644 index 3420fa6a..00000000 --- a/components/base_nodemcu/ld/nodemcu_rodata_lfs.ld +++ /dev/null @@ -1,37 +0,0 @@ - - /* ----- Begin NodeMCU link-time arrays ------- */ - - /* Don't change the alignment here without also updating the _Static_assert - * over in linit.c! */ - . = ALIGN(8); - /* Link-time arrays containing the defs for the included modules */ - lua_libs_map = ABSOLUTE(.); - KEEP(*(.lua_libs)) - /* Null-terminate the array, 24 bytes */ - LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) - - /* Don't change the alignment here without also updating the _Static_assert - * over in linit.c! */ - . = ALIGN(8); - lua_rotables_map = ABSOLUTE(.); - KEEP(*(.lua_rotable)) - /* Null-terminate the array, 24 bytes */ - LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) LONG(0) - - /* Don't change the alignment here without also updating the _Static_assert - * over in nodemcu_esp_event.h! */ - . = ALIGN(4); - esp_event_cb_table = ABSOLUTE(.); - KEEP(*(.lua_esp_event_cb_table)) - LONG(0) LONG(0) /* Null-terminate the array, 8 bytes */ - - /* ----- End NodeMCU link-time arrays ------- */ - - /* ----- NodeMCU embedded LFS reserved area --------- */ - - . = ALIGN(4096); /* flash page alignment needed */ - lua_flash_store_reserved = ABSOLUTE(.); - KEEP(*(.lfs.reserved)) - - /* ----- End NodeMCU embedded LFS reserved area ----- */ - diff --git a/components/base_nodemcu/linit.c b/components/base_nodemcu/linit.c index c3bd6e3d..1149467e 100644 --- a/components/base_nodemcu/linit.c +++ b/components/base_nodemcu/linit.c @@ -16,6 +16,7 @@ #include "luaconf.h" #include "module.h" #include "lstate.h" +#include "lrotable.h" #include #include @@ -62,7 +63,27 @@ const LOCK_IN_SECTION(A) char _ro_start[1] = {0}; const LOCK_IN_SECTION(zzzzzzzz) char _ro_end[1] = {0}; #endif +#if defined(LUA_CROSS_COMPILER) + LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables) + LROT_TABENTRY( string, strlib ) + LROT_TABENTRY( table, tab_funcs ) + LROT_TABENTRY( coroutine, co_funcs ) + LROT_TABENTRY( debug, dblib) + LROT_TABENTRY( math, math ) + LROT_TABENTRY( ROM, lua_rotables ) + LROT_TABENTRY( os, oslib ) + //LROT_TABENTRY( io, iolib ) +LROT_END(lua_rotables, NULL, 0) + +#else + +// Due to limitations in the IDF linker fragment generation, we have to +// play with link-time symbol generation/aliasing to set up the rotables +// properly. As part of that, we need to use a different name for the +// table here. + +LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables_part) #ifdef CONFIG_LUA_BUILTIN_STRING LROT_TABENTRY( string, strlib ) #endif @@ -78,15 +99,12 @@ LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables) #ifdef CONFIG_LUA_BUILTIN_MATH LROT_TABENTRY( math, math ) #endif - LROT_TABENTRY( ROM, lua_rotables ) -#ifdef LUA_CROSS_COMPILER - LROT_TABENTRY( os, oslib ) - //LROT_TABENTRY( io, iolib ) -LROT_END(lua_rotables, NULL, 0) -#else -LROT_BREAK(lua_rotables) + LROT_TABENTRY( ROM, lua_rotables_part ) +LROT_BREAK(lua_rotables_part) + #endif + LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs) LROT_FUNCENTRY( _, luaopen_base ) LROT_FUNCENTRY( package, luaopen_package ) @@ -100,7 +118,7 @@ LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs) LROT_FUNCENTRY( debug, luaopen_debug ) #endif #ifndef LUA_CROSS_COMPILER -LROT_BREAK(lua_rotables) +LROT_BREAK(lua_libs) #else LROT_FUNCENTRY( io, luaopen_io ) LROT_END( lua_libs, NULL, 0) @@ -110,8 +128,16 @@ LROT_END( lua_libs, NULL, 0) extern void luaL_dbgbreak(void); #endif -void luaL_openlibs (lua_State *L) { +/* Historically the linker script took care of zero terminating both the + * lua_libs and lua_rotable arrays, but the IDF currently does not + * support injecting LONG(0) entries. To compensate, we have explicit + * end markers here which the linker fragment then place appropriately + * to terminate aforementioned arrays. + */ +const luaR_entry LOCK_IN_SECTION(libs_end_marker) libs_end_marker= { 0, }; +const luaR_entry LOCK_IN_SECTION(rotable_end_marker) rotable_end_marker = { 0, }; +void luaL_openlibs (lua_State *L) { lua_pushrotable(L, LROT_TABLEREF(lua_libs)); lua_pushnil(L); /* first key */ /* loop round and open libraries */ diff --git a/components/base_nodemcu/nodemcu.lf b/components/base_nodemcu/nodemcu.lf index 61084954..1756aa32 100644 --- a/components/base_nodemcu/nodemcu.lf +++ b/components/base_nodemcu/nodemcu.lf @@ -2,19 +2,29 @@ entries: .lua_libs +[sections:lua_libs_end_marker] +entries: + .lua_libs_end_marker + [sections:lua_rotable] entries: .lua_rotable +[sections:lua_rotable_end_marker] +entries: + .lua_rotable_end_marker + [sections:lua_esp_event_cb_table] entries: .lua_esp_event_cb_table [scheme:nodemcu_arrays] entries: - lua_libs -> flash_text - lua_rotable -> flash_text - lua_esp_event_cb_table -> flash_text + lua_libs -> flash_rodata + lua_libs_end_marker -> flash_rodata + lua_rotable -> flash_rodata + lua_rotable_end_marker -> flash_rodata + lua_esp_event_cb_table -> flash_rodata # Important: don't change the alignments below without also updating the @@ -24,6 +34,8 @@ entries: archive: * entries: * (nodemcu_arrays); - lua_libs -> flash_text KEEP() ALIGN(8) SURROUND(lua_libs_map), - lua_rotable -> flash_text KEEP() ALIGN(8) SURROUND(lua_rotables_map), - lua_esp_event_cb_table -> flash_text KEEP() ALIGN(4) SURROUND(esp_event_cb_table) + lua_libs -> flash_rodata KEEP() ALIGN(8) SURROUND(lua_libs_map), + lua_libs_end_marker -> flash_rodata KEEP(), + lua_rotable -> flash_rodata ALIGN(8) SURROUND(lua_rotables_map), + lua_rotable_end_marker -> flash_rodata KEEP(), + lua_esp_event_cb_table -> flash_rodata KEEP() ALIGN(4) SURROUND(esp_event_cb_table) diff --git a/docs/build.md b/docs/build.md index 28bf047c..2b75f6cd 100644 --- a/docs/build.md +++ b/docs/build.md @@ -20,7 +20,7 @@ NodeMCU firmware developers commit or contribute to the project on GitHub and mi #### Ubuntu: ```bash -sudo apt-get install -y gperf python-pip python-dev flex bison build-essential libssl-dev libffi-dev libncurses5-dev libncursesw5-dev libreadline-dev +sudo apt-get install -y gperf python-pip python-dev flex bison build-essential libssl-dev libffi-dev libncurses5-dev libncursesw5-dev libreadline-dev cmake ``` #### Setting up the repository