idf4: part 3.1 - sorting out the linker specifics

Now boots to the Lua prompt, and modules are included and findable.
This commit is contained in:
Johny Mattsson 2021-07-21 20:46:42 +10:00
parent bcaf98f8f0
commit 54a41149ea
6 changed files with 62 additions and 82 deletions

View File

@ -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"
)

View File

@ -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 ------- */

View File

@ -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 ----- */

View File

@ -16,6 +16,7 @@
#include "luaconf.h"
#include "module.h"
#include "lstate.h"
#include "lrotable.h"
#include <assert.h>
#include <stdalign.h>
@ -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 */

View File

@ -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)

View File

@ -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