Commit 16ef39e2 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

idf4: overhaul to new build system, part 1 of 3

Yet to come:
  - part 2: dealing with deprecated and removed APIs
  - part 3: making it actually work again
parent 8e0e0cb3
#ifndef __I2C_SW_MASTER_H__
#define __I2C_SW_MASTER_H__
#include "rom/ets_sys.h"
#include "esp32/rom/ets_sys.h"
#define I2C_NUM_MAX 1
......
if (CONFIG_NODEMCU_EMBED_LFS)
# Handle hex size in a shell agnostic manner
math(EXPR lfs_size ${CONFIG_NODEMCU_EMBEDDED_LFS_SIZE})
# The luac.out gets written by tools/embed_lfs.sh, but we need a non-empty
# file for the first build pass
add_custom_command(
OUTPUT ${BUILD_DIR}/luac.out
COMMAND [ -s "${BUILD_DIR}/luac.out" ] || echo "" > "${BUILD_DIR}/luac.out"
VERBATIM
)
add_custom_target(luac_out DEPENDS ${BUILD_DIR}/luac.out)
# We use the automatic file name to symbol generation here, to create the
# expected symbol lua_flash_store_reserved
add_custom_command(
OUTPUT ${BUILD_DIR}/lua.flash.store.reserved
COMMAND truncate --size=${lfs_size} ${BUILD_DIR}/lua.flash.store.reserved && dd if=${BUILD_DIR}/luac.out of=${BUILD_DIR}/lua.flash.store.reserved conv=notrunc status=none
DEPENDS luac_out
VERBATIM
)
add_custom_target(reserved_lfs DEPENDS ${BUILD_DIR}/lua.flash.store.reserved)
idf_component_register(
EMBED_FILES ${BUILD_DIR}/lua.flash.store.reserved
LDFRAGMENTS "embedded_lfs.lf"
)
add_dependencies(${COMPONENT_LIB} reserved_lfs)
else()
idf_component_register()
endif()
SHELL:=/bin/bash
ifeq ($(CONFIG_LUA_EMBED_LFS),y)
COMPONENT_OBJS := $(COMPONENT_BUILD_DIR)/luac_out.o
COMPONENT_EXTRA_CLEAN := $(COMPONENT_OBJS) $(COMPONENT_BUILD_DIR)/luac_out.o.bin
COMPONENT_ADD_LINKER_DEPS := $(COMPONENT_BUILD_DIR)/luac_out.o
EMBEDDED_LFS_DATA:= $(BUILD_DIR_BASE)/luac.out
$(COMPONENT_BUILD_DIR)/luac_out.o: $(EMBEDDED_LFS_DATA)
echo "embedding luac.out into object file $@..."
dd if=/dev/zero bs=1 count=$$(( $(CONFIG_LUA_EMBEDDED_FLASH_STORE) )) of="$@.bin" status=none
dd if="$(EMBEDDED_LFS_DATA)" conv=notrunc of="$@.bin" status=none
cd $(dir $@) && $(OBJCOPY) --input-target binary --output-target elf32-xtensa-le --binary-architecture xtensa --rename-section .data=.lfs.reserved --redefine-sym _binary_luac_out_o_bin_start=lua_flash_store_reserved "$(notdir $@.bin)" "$@"
$(EMBEDDED_LFS_DATA):
touch $@
endif
[sections:rodata_embedded]
entries:
.rodata.embedded
[scheme:embedded_lfs]
entries:
rodata_embedded -> flash_text
[mapping:embedded_lfs]
archive: libembedded_lfs.a
entries:
* (default);
rodata -> flash_rodata KEEP() ALIGN(4096)
idf_component_register(
SRCS "diskio.c" "ff.c" "myfatfs.c" "ffunicode.c" "ffsystem.c"
INCLUDE_DIRS "."
REQUIRES "platform" "sdmmc"
)
target_compile_options(${COMPONENT_LIB} PRIVATE -imacros fatfs_prefix_lib.h)
# TODO: add Kconfig to select code page used?
COMPONENT_SRCDIRS:=.
# TODO: add Kconfig to select code page used?
COMPONENT_OBJS:=diskio.o ff.o myfatfs.o ffunicode.o ffsystem.o
COMPONENT_ADD_INCLUDEDIRS:=.
CFLAGS+=-imacros fatfs_prefix_lib.h
......@@ -100,7 +100,7 @@
#define FF_USE_LFN 3
#define FF_MAX_LFN (CONFIG_FS_OBJ_NAME_LEN+1+1)
#define FF_MAX_LFN (CONFIG_NODEMCU_FS_OBJ_NAME_LEN+1+1)
/* The FF_USE_LFN switches the support for LFN (long file name).
/
/ 0: Disable LFN. FF_MAX_LFN has no effect.
......
......@@ -301,8 +301,8 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf )
memset( buf, 0, sizeof( struct vfs_stat ) );
// fill in supported stat entries
strncpy( buf->name, fno->fname, CONFIG_FS_OBJ_NAME_LEN+1 );
buf->name[CONFIG_FS_OBJ_NAME_LEN] = '\0';
strncpy( buf->name, fno->fname, CONFIG_NODEMCU_FS_OBJ_NAME_LEN+1 );
buf->name[CONFIG_NODEMCU_FS_OBJ_NAME_LEN] = '\0';
buf->size = fno->fsize;
buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0;
buf->is_rdonly = fno->fattrib & AM_RDO ? 1 : 0;
......
idf_component_register(
SRCS "lapi.c" "lauxlib.c" "lbaselib.c" "lcode.c" "ldblib.c" "ldebug.c"
"ldo.c" "ldump.c" "legc.c" "lflash.c" "lfunc.c" "lgc.c" "llex.c" "lmathlib.c"
"lmem.c" "loadlib.c" "lobject.c" "lopcodes.c" "lparser.c" "lrotable.c"
"lstate.c" "lstring.c" "lstrlib.c" "ltable.c" "ltablib.c" "ltm.c"
"lua.c" "lundump.c" "lvm.c" "lzio.c"
INCLUDE_DIRS "."
REQUIRES "platform" "uzlib" "driver_console"
PRIV_REQUIRES "base_nodemcu" "embedded_lfs"
)
target_compile_options(${COMPONENT_LIB} PRIVATE
-Wno-error=misleading-indentation
)
menu "Lua configuration"
config LUA_NUMBER_INTEGRAL
bool "Integer-only build"
default "n"
help
Build Lua without support for floating point numbers.
Not generally recommended, but can save on code size.
menu "Core Lua modules"
config LUA_BUILTIN_STRING
bool "String module"
default "y"
help
Includes the string module (recommended).
config LUA_BUILTIN_TABLE
bool "Table module"
default "y"
help
Includes the table module (recommended).
config LUA_BUILTIN_COROUTINE
bool "Coroutine module"
default "y"
help
Includes the coroutine module (recommended).
config LUA_BUILTIN_MATH
bool "Math module"
default "y"
help
Includes the math module (recommended).
config LUA_BUILTIN_DEBUG
bool "Debug module"
default "n"
help
Includes the debug module.
config LUA_BUILTIN_DEBUG_EXTENDED
depends on LUA_BUILTIN_DEBUG
bool "Extended debug support"
default "n"
help
Includes the full debug module, rather than just getregistry
and traceback.
config LUA_BUILTIN_DEBUG_MINIMAL
depends on LUA_BUILTIN_DEBUG
bool
default !LUA_BUILTIN_DEBUG_EXTENDED
endmenu
menu "Lua compilation"
choice LUA_OPTIMIZE_DEBUG_LEVEL
prompt "Discard debug info in compiled Lua"
default LUA_OPTIMIZE_DEBUG_NONE
help
Discard debug information in compiled Lua code to save memory.
config LUA_OPTIMIZE_DEBUG_NONE
bool "No (keep full debug info)"
config LUA_OPTIMIZE_DEBUG_LOCAL_UPVAL
bool "Some (discard local & upvalue debug info)"
config LUA_OPTIMIZE_DEBUG_LOCAL_UPVAL_LINENO
bool "All (discard local, upvalue & line number info)"
endchoice
config LUA_OPTIMIZE_DEBUG
int
default 1 if LUA_OPTIMIZE_DEBUG_NONE
default 2 if LUA_OPTIMIZE_DEBUG_LOCAL_UPVAL
default 3 if LUA_OPTIMIZE_DEBUG_LOCAL_UPVAL_LINENO
endmenu
endmenu
-include $(PROJECT_PATH)/build/include/config/auto.conf
CFLAGS+=\
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLUA_OPTIMIZE_DEBUG=$(CONFIG_LUA_OPTIMIZE_DEBUG) \
......@@ -12,7 +12,7 @@ extern char _irom0_text_end;
#define RODATA_START_ADDRESS (&_irom0_text_start)
#define RODATA_END_ADDRESS (&_irom0_text_end)
#elif defined(__ESP32__)
#elif defined(__ESP32__) || defined(CONFIG_IDF_TARGET_ESP32)
#define RODATA_START_ADDRESS ((char*)0x3F400000)
#define RODATA_END_ADDRESS ((char*)0x3F800000)
......
COMPONENT_ADD_INCLUDEDIRS:=.
......@@ -81,7 +81,7 @@ struct OUTPUT {
} *out;
#ifdef CONFIG_LUA_EMBEDDED_FLASH_STORE
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
extern const char lua_flash_store_reserved[0];
#endif
......@@ -110,7 +110,7 @@ LUA_API void dumpStrings(lua_State *L) {
}
#endif
#ifndef CONFIG_LUA_EMBEDDED_FLASH_STORE
#ifndef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
/* =====================================================================================
* The next 4 functions: flashPosition, flashSetPosition, flashBlock and flashErase
* wrap writing to flash. The last two are platform dependent. Also note that any
......@@ -155,8 +155,8 @@ static int procFirstPass (void);
* Hook in lstate.c:f_luaopen() to set up ROstrt and ROpvmain if needed
*/
LUAI_FUNC void luaN_init (lua_State *L) {
#ifdef CONFIG_LUA_EMBEDDED_FLASH_STORE
flashSize = CONFIG_LUA_EMBEDDED_FLASH_STORE;
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
flashSize = CONFIG_NODEMCU_EMBEDDED_LFS_SIZE;
flashAddr = lua_flash_store_reserved;
flashAddrPhys = spi_flash_cache2phys(lua_flash_store_reserved);
if (flashAddrPhys == SPI_FLASH_CACHE2PHYS_FAIL) {
......@@ -226,7 +226,7 @@ LUAI_FUNC void luaN_init (lua_State *L) {
* Library function called by node.flashreload(filename).
*/
LUALIB_API int luaN_reload_reboot (lua_State *L) {
#ifdef CONFIG_LUA_EMBEDDED_FLASH_STORE
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
// Updating the LFS section is disabled for now because any changes to the
// image requires updating its checksum to prevent boot failure.
lua_pushstring(L, "Not allowed to write to LFS section");
......@@ -291,7 +291,7 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) {
esp_restart();
return 0;
#endif // CONFIG_LUA_EMBEDDED_FLASH_STORE
#endif // CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
}
......@@ -346,7 +346,7 @@ LUAI_FUNC int luaN_index (lua_State *L) {
return 5;
}
#ifndef CONFIG_LUA_EMBEDDED_FLASH_STORE
#ifndef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
/* =====================================================================================
* The following routines use my uzlib which was based on pfalcon's inflate and
* deflate routines. The standard NodeMCU make also makes two host tools uz_zip
......
......@@ -266,7 +266,7 @@ static int runargs (lua_State *L, char **argv, int n) {
static int handle_luainit (lua_State *L) {
const char *init = LUA_INIT_STRING;
if (init[0] == '@') {
#if CONFIG_LUA_EMBEDDED_FLASH_STORE > 0
#if CONFIG_NODEMCU_EMBEDDED_LFS_SIZE > 0
int status = dolfsfile(L, init+1);
if (status == 0)
return status;
......
foreach(def
"-DLUA_OPTIMIZE_MEMORY=2"
"-DMIN_OPT_LEVEL=2"
"-DLUA_OPTIMIZE_DEBUG=${CONFIG_LUA_OPTIMIZE_DEBUG}"
)
idf_build_set_property(COMPILE_DEFINITIONS ${def} APPEND)
endforeach()
if(CONFIG_LUA_NUMBER_INTEGRAL)
idf_build_set_property(COMPILE_DEFINITIONS -DLUA_NUMBER_INTEGRAL APPEND)
endif()
idf_component_register(luac_cross)
# Not sure why we can't directly depend on ${SDKCONFIG_HEADER} in our
# externalproject_add(), but them's the brakes...
add_custom_command(
OUTPUT sdkconfig.h
COMMAND cp ${SDKCONFIG_HEADER} sdkconfig.h
DEPENDS ${SDKCONFIG_HEADER}
VERBATIM
)
add_custom_target(sdkconfig_h DEPENDS sdkconfig.h)
externalproject_add(luac_cross_build
PREFIX ${BUILD_DIR}/luac_cross
SOURCE_DIR ${COMPONENT_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND make -f ${COMPONENT_DIR}/Makefile BUILD_DIR_BASE=${BUILD_DIR} COMPONENT_PATH=${COMPONENT_DIR} CONFIG_LUA_OPTIMIZE_DEBUG=${CONFIG_LUA_OPTIMIZE_DEBUG} PYTHON=${PYTHON}
INSTALL_COMMAND ""
BUILD_ALWAYS 1
DEPENDS sdkconfig_h
)
all: build
HOSTCC?=$(PYTHON) -m ziglang cc
# zig cc (0.8.0 at least) seems to get itself all confused with its cache
# when we're running a separate path for dependencies, so we skip them for
# now as for most people they're not needed anyway.
ifeq ($(findstring zig,$(HOSTCC)),zig)
WITHOUT_DEPS:=1
endif
ifeq ($V,)
Q:=@
endif
LUAC_CFLAGS:= -I$(COMPONENT_PATH)/../uzlib -I$(COMPONENT_PATH)/../lua -I$(BUILD_DIR_BASE)/include -I$(COMPONENT_PATH)/../base_nodemcu/include -O2 -g -Wall -Wextra
LUAC_CFLAGS:= -I$(COMPONENT_PATH)/../uzlib -I$(COMPONENT_PATH)/../lua -I$(BUILD_DIR_BASE)/config -I$(COMPONENT_PATH)/../base_nodemcu/include -O2 -g -Wall -Wextra
LUAC_LDFLAGS:= -ldl -lm
LUAC_DEFINES += -DLUA_CROSS_COMPILER -DLUA_USE_STDIO
......@@ -41,14 +50,16 @@ LUAC_OBJS+=$(LUAC_UZSRC:$(COMPONENT_PATH)/../uzlib/%.c=$(LUAC_BUILD_DIR)/%.o)
LUAC_OBJS+=$(LUAC_NODEMCUSRC:$(COMPONENT_PATH)/../base_nodemcu/%.c=$(LUAC_BUILD_DIR)/%.o)
ifneq ($(WITHOUT_DEPS),1)
LUAC_DEPS:=$(LUAC_OBJS:%.o=%.d)
endif
LUAC_CROSS:=$(LUAC_BUILD_DIR)/luac.cross
$(LUAC_BUILD_DIR):
@mkdir -p "$@"
$(LUAC_BUILD_DIR)/%.o: | $(LUAC_BUILD_DIR)
$(LUAC_BUILD_DIR)/%.o: %.c | $(LUAC_BUILD_DIR)
@echo '[hostcc] $(notdir $@)'
$Q$(HOSTCC) $(LUAC_DEFINES) $(LUAC_CFLAGS) "$<" -c -o "$@"
......
COMPONENT_OWNBUILDTARGET:=build
COMPONENT_ADD_LDFLAGS:=
build:
$(MAKE) -f $(COMPONENT_PATH)/Makefile HOSTCC=$(HOSTCC) BUILD_DIR_BASE=$(BUILD_DIR_BASE) V=$V COMPONENT_PATH=$(COMPONENT_PATH) CONFIG_LUA_OPTIMIZE_DEBUG=$(CONFIG_LUA_OPTIMIZE_DEBUG)
ar cr lib$(COMPONENT_NAME).a # work around IDF regression
# Globbing isn't recommended, but I dislike it less than having to edit
# this file whenever a new module source file springs into existence.
# Just remember to "idf.py reconfigure" (or do a clean build) to get
# cmake to pick up on the new (or removed) files.
file(
GLOB module_srcs
LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.c
)
idf_component_register(
SRCS ${module_srcs}
PRIV_INCLUDE_DIRS "." "${CMAKE_CURRENT_BINARY_DIR}"
PRIV_REQUIRES
"app_update"
"base_nodemcu"
"bt"
"driver_can"
"esp_http_client"
"libsodium"
"lua"
"mbedtls"
"mqtt"
"platform"
"qrcodegen"
"sdmmc"
"sjson"
"soc"
"u8g2"
"ucg"
)
# Match up all the module source files with their corresponding Kconfig
# option in the form NODEMCU_CMODULE_<modname> and if enabled, add a
# "-u <modname>_module_selected1" option to force the linker to include
# the module. See components/core/include/module.h for further details on
# how this works.
set(modules_enabled)
foreach(module_src ${module_srcs})
string(REPLACE ".c" "" module_name ${module_src})
string(TOUPPER ${module_name} module_ucase)
set(mod_opt "CONFIG_NODEMCU_CMODULE_${module_ucase}")
#message("checking ${mod_opt}")
if (${${mod_opt}})
list(APPEND modules_enabled ${module_ucase})
endif()
endforeach()
message("Including the following modules: ${modules_enabled}")
foreach(mod ${modules_enabled})
target_link_libraries(${COMPONENT_LIB} "-u ${mod}_module_selected1")
endforeach()
# Auto-generation of ucg/u8g2 header files, per
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#source-code-generation
add_custom_command(
OUTPUT ucg_config.h
COMMAND perl -w ${PROJECT_DIR}/tools/ucg_config.pl < ${SDKCONFIG_HEADER} > ucg_config.h
DEPENDS ${SDKCONFIG_HEADER}
VERBATIM
)
add_custom_target(ucg_config DEPENDS ucg_config.h)
add_custom_command(
OUTPUT u8g2_fonts.h
COMMAND perl -w ${PROJECT_DIR}/tools/u8g2_config_fonts.pl < ${SDKCONFIG_HEADER} > u8g2_fonts.h
DEPENDS ${SDKCONFIG_HEADER}
VERBATIM
)
add_custom_target(u8g2_fonts DEPENDS u8g2_fonts.h)
add_custom_command(
OUTPUT u8g2_displays.h
COMMAND perl -w ${PROJECT_DIR}/tools/u8g2_config_displays.pl < ${SDKCONFIG_HEADER} > u8g2_displays.h
)
add_custom_target(u8g2_displays DEPENDS u8g2_displays.h)
add_dependencies(${COMPONENT_LIB} ucg_config u8g2_fonts u8g2_displays)
set_property(
DIRECTORY "${COMPONENT_DIR}" APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ucg_config.h u8g2_fonts.h u8g2_displays.h
)
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