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
...@@ -9,11 +9,13 @@ addons: ...@@ -9,11 +9,13 @@ addons:
# we can use the system python and python-serial, rather than messing around # we can use the system python and python-serial, rather than messing around
# with pip all over the place # with pip all over the place
install: install:
- export PATH=$PWD/tools/toolchains/esp8266/bin:$PWD/tools/toolchains/esp32/bin:/bin:/usr/bin:/sbin:/usr/sbin - export PATH=/bin:/usr/bin:/sbin:/usr/sbin
- /usr/bin/python -m pip install --user -r $PWD/sdk/esp32-esp-idf/requirements.txt - ./install.sh
script: script:
- export BUILD_DATE=$(date +%Y%m%d) - export BUILD_DATE=$(date +%Y%m%d)
- env BUILD_DIR_BASE=`pwd`/build/float make MORE_CFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" defconfig all - cp sdkconfig.defaults sdkconfig
- env BUILD_DIR_BASE=`pwd`/build/integer make MORE_CFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'" defconfig all - make IDFPY_ARGS="-B build/float"
- echo CONFIG_LUA_NUMBER_INTEGRAL=y >> sdkconfig
- make IDFPY_ARGS="-B build/integer"
# http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables # http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
#- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/pr-build.sh; fi #- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/pr-build.sh; fi
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(nodemcu)
# -*- coding: utf-8, tab-width: 2 -*-
# If we haven't got IDF_PATH set already, reinvoke with IDF_PATH in the environ
.NOTPARALLEL:
ifeq ($(IDF_PATH),) ifeq ($(IDF_PATH),)
THIS_MK_FILE:=$(notdir $(lastword $(MAKEFILE_LIST))) THIS_MK_FILE:=$(notdir $(lastword $(MAKEFILE_LIST)))
THIS_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) THIS_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
IDF_PATH=$(THIS_DIR)/sdk/esp32-esp-idf IDF_PATH=$(THIS_DIR)/sdk/esp32-esp-idf
TOOLCHAIN_RELEASES_BASEURL:=https://github.com/jmattsson/esp-toolchains/releases/ all:
TOOLCHAIN_VERSION:=20181106.1 . $(IDF_PATH)/export.sh && $(MAKE) "$@"
PLATFORM:=linux-$(shell uname --machine)
## Directory to place external modules:
export EXTRA_COMPONENT_DIRS:=$(THIS_DIR)/components/modules/external
ESP32_BIN:=$(THIS_DIR)/tools/toolchains/esp32-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin
ESP32_GCC:=$(ESP32_BIN)/xtensa-esp32-elf-gcc
ESP32_TOOLCHAIN_DL:=$(THIS_DIR)/cache/toolchain-esp32-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz
all: | $(ESP32_GCC)
%: | $(ESP32_GCC)
@echo Setting IDF_PATH and re-invoking...
@env IDF_PATH=$(IDF_PATH) PATH="$(PATH):$(ESP32_BIN)" $(MAKE) -f $(THIS_MK_FILE) $@
@if test "$@" = "clean"; then rm -rf $(THIS_DIR)/tools/toolchains/esp32-*; fi
install_toolchain: $(ESP32_GCC)
$(ESP32_GCC): $(ESP32_TOOLCHAIN_DL) %:
@echo Uncompressing toolchain . $(IDF_PATH)/export.sh && $(MAKE) "$@"
@mkdir -p $(THIS_DIR)/tools/toolchains/
@tar -xJf $< -C $(THIS_DIR)/tools/toolchains/
# the archive contains ro files
@chmod -R u+w $(THIS_DIR)/tools/toolchains/esp32-*
@touch $@
download_toolchain: $(ESP32_TOOLCHAIN_DL)
$(ESP32_TOOLCHAIN_DL):
@mkdir -p $(THIS_DIR)/cache
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused ${TOOLCHAIN_RELEASES_BASEURL}download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp32-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ || { rm -f -- "$@"; echo "W: Download failed. Please check ${TOOLCHAIN_RELEASES_BASEURL} for an appropriate version. If there is none for $(PLATFORM), you might need to compile it yourself."; exit 1; }
else else
PROJECT_NAME:=NodeMCU all:
$(IDF_PATH)/tools/idf.py $(IDFPY_ARGS) "$@"
# This is, sadly, the cleanest way to resolve the different non-standard
# conventions for sized integers across the various components.
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
$(IDF_PATH)/make/project.mk: %:
@echo "ESP-IDF isn't properly installed, will try to re-install and then re-run make:" $(IDF_PATH)/tools/idf.py $(IDFPY_ARGS) "$@"
git submodule init
git submodule update --recursive
python -m pip install --user --requirement $(IDF_PATH)/requirements.txt || echo "W: pip failed, but this might be harmless. Let's just try whether it works anyway." >&2
# If we'd just continue, make would fake-succeed albeit with a warning
# "make[1]: *** No rule to make target `menuconfig'. Stop."
# $(MAKE) -f $(THIS_MK_FILE) $@ || exit $?
include $(IDF_PATH)/make/project.mk
# Ensure these overrides are always used
CC:=$(CC) $(BASIC_TYPES) -D__ESP32__ $(MORE_CFLAGS)
endif endif
extmod-update: # FIXME - needs updating to work in IDF4
@tools/extmod/extmod.sh update #
#extmod-update:
extmod-clean: # @tools/extmod/extmod.sh update
@tools/extmod/extmod.sh clean #
#extmod-clean:
## @tools/extmod/extmod.sh clean
idf_component_register(
SRCS "ip_fmt.c" "lextra.c" "linit.c" "lnodeaux.c" "uart.c" "user_main.c"
INCLUDE_DIRS "include"
REQUIRES "lua"
PRIV_REQUIRES "nvs_flash"
LDFRAGMENTS "nodemcu.lf"
)
menu "NodeMCU miscellaneous"
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
BASE_NODEMCU_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
BASE_NODEMCU_BUILD_DIR:=$(BUILD_DIR_BASE)/base_nodemcu
ifeq ($(CONFIG_LUA_EMBED_LFS),y)
NODEMCU_LD_SCRIPT:= nodemcu_rodata_lfs.ld
else
NODEMCU_LD_SCRIPT:= nodemcu_rodata.ld
endif
$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf: $(BASE_NODEMCU_BUILD_DIR)/ld_patched
$(BASE_NODEMCU_BUILD_DIR)/ld_patched: $(BUILD_DIR_BASE)/esp32/esp32.project.ld
"$(BASE_NODEMCU_DIR)/add_rodata_ld.sh" "$<" "$(BASE_NODEMCU_DIR)/ld/$(NODEMCU_LD_SCRIPT)"
touch $@
#!/bin/bash
# syntax: add_rodata_ld.sh /path/to/esp32.project.ld /path/to/snippet_file
set -eu
ldfile="$1"
partial="$2"
out="${ldfile}.new"
IFS='
'
msg="/* NodeMCU patched */"
if [[ $(head -n 1 "$ldfile") =~ "$msg" ]]
then
echo "NodeMCU rodata already patched into $(basename $ldfile)"
exit 0
else
echo "Patching in NodeMCU rodata into $(basename $ldfile)"
echo "$msg" > "$out"
fi
cat "$ldfile" | while read line
do
if [[ $line =~ "drom0_0_seg" ]]
then
cat "$partial" >> "$out"
fi
echo $line >> "$out"
done
mv "$out" "$ldfile"
...@@ -65,7 +65,8 @@ typedef struct { ...@@ -65,7 +65,8 @@ typedef struct {
nodemcu_esp_event_cb callback; nodemcu_esp_event_cb callback;
} nodemcu_esp_event_reg_t; } nodemcu_esp_event_reg_t;
extern nodemcu_esp_event_reg_t esp_event_cb_table; extern nodemcu_esp_event_reg_t _esp_event_cb_table_start;
extern nodemcu_esp_event_reg_t _esp_event_cb_table_end;
#define NODEMCU_ESP_EVENT(evcode, func) \ #define NODEMCU_ESP_EVENT(evcode, func) \
static const LOCK_IN_SECTION(esp_event_cb_table) \ static const LOCK_IN_SECTION(esp_event_cb_table) \
......
...@@ -63,11 +63,21 @@ const LOCK_IN_SECTION(zzzzzzzz) char _ro_end[1] = {0}; ...@@ -63,11 +63,21 @@ const LOCK_IN_SECTION(zzzzzzzz) char _ro_end[1] = {0};
#endif #endif
LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables) LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables)
#ifdef CONFIG_LUA_BUILTIN_STRING
LROT_TABENTRY( string, strlib ) LROT_TABENTRY( string, strlib )
#endif
#ifdef CONFIG_LUA_BUILTIN_TABLE
LROT_TABENTRY( table, tab_funcs ) LROT_TABENTRY( table, tab_funcs )
LROT_TABENTRY( debug, dblib) #endif
#ifdef CONFIG_LUA_BUILTIN_COROUTINE
LROT_TABENTRY( coroutine, co_funcs ) LROT_TABENTRY( coroutine, co_funcs )
#endif
#ifdef CONFIG_LUA_BUILTIN_DEBUG
LROT_TABENTRY( debug, dblib)
#endif
#ifdef CONFIG_LUA_BUILTIN_MATH
LROT_TABENTRY( math, math ) LROT_TABENTRY( math, math )
#endif
LROT_TABENTRY( ROM, lua_rotables ) LROT_TABENTRY( ROM, lua_rotables )
#ifdef LUA_CROSS_COMPILER #ifdef LUA_CROSS_COMPILER
LROT_TABENTRY( os, oslib ) LROT_TABENTRY( os, oslib )
...@@ -80,9 +90,15 @@ LROT_BREAK(lua_rotables) ...@@ -80,9 +90,15 @@ LROT_BREAK(lua_rotables)
LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs) LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs)
LROT_FUNCENTRY( _, luaopen_base ) LROT_FUNCENTRY( _, luaopen_base )
LROT_FUNCENTRY( package, luaopen_package ) LROT_FUNCENTRY( package, luaopen_package )
#ifdef CONFIG_LUA_BUILTIN_STRING
LROT_FUNCENTRY( string, luaopen_string ) LROT_FUNCENTRY( string, luaopen_string )
#endif
#ifdef CONFIG_LUA_BUILTIN_TABLE
LROT_FUNCENTRY( table, luaopen_table ) LROT_FUNCENTRY( table, luaopen_table )
#endif
#ifdef CONFIG_LUA_BUILTIN_DEBUG
LROT_FUNCENTRY( debug, luaopen_debug ) LROT_FUNCENTRY( debug, luaopen_debug )
#endif
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
LROT_BREAK(lua_rotables) LROT_BREAK(lua_rotables)
#else #else
......
[sections:lua_libs]
entries:
.lua_libs
[sections:lua_rotable]
entries:
.lua_rotable
[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
# Important: don't change the alignments below without also updating the
# _Static_assert over in linit.c and/or nodemcu_esp_event.h!
[mapping:nodemcu]
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)
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_system.h" #include "esp_system.h"
#include "esp_event.h" #include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "flash_api.h" #include "flash_api.h"
...@@ -70,8 +69,8 @@ static void handle_esp_event (task_param_t param, task_prio_t prio) ...@@ -70,8 +69,8 @@ static void handle_esp_event (task_param_t param, task_prio_t prio)
system_event_t evt; system_event_t evt;
while (xQueueReceive (esp_event_queue, &evt, 0) == pdPASS) while (xQueueReceive (esp_event_queue, &evt, 0) == pdPASS)
{ {
nodemcu_esp_event_reg_t *evregs; nodemcu_esp_event_reg_t *evregs = &_esp_event_cb_table_start;
for (evregs = &esp_event_cb_table; evregs->callback; ++evregs) for (; evregs < &_esp_event_cb_table_end; ++evregs)
{ {
if (evregs->event_id == evt.event_id) if (evregs->event_id == evt.event_id)
evregs->callback (&evt); evregs->callback (&evt);
...@@ -126,7 +125,7 @@ void nodemcu_init(void) ...@@ -126,7 +125,7 @@ void nodemcu_init(void)
return; return;
} }
#if defined ( CONFIG_BUILD_SPIFFS ) #if defined ( CONFIG_NODEMCU_BUILD_SPIFFS )
// This can take a while, so be nice and provide some feedback while waiting // This can take a while, so be nice and provide some feedback while waiting
printf ("Mounting flash filesystem...\n"); printf ("Mounting flash filesystem...\n");
if (!vfs_mount("/FLASH", 0)) { if (!vfs_mount("/FLASH", 0)) {
...@@ -155,12 +154,12 @@ void app_main (void) ...@@ -155,12 +154,12 @@ void app_main (void)
esp_event_loop_init(bounce_events, NULL); esp_event_loop_init(bounce_events, NULL);
ConsoleSetup_t cfg; ConsoleSetup_t cfg;
cfg.bit_rate = CONFIG_CONSOLE_BIT_RATE; cfg.bit_rate = CONFIG_NODEMCU_CONSOLE_BIT_RATE;
cfg.data_bits = CONSOLE_NUM_BITS_8; cfg.data_bits = CONSOLE_NUM_BITS_8;
cfg.parity = CONSOLE_PARITY_NONE; cfg.parity = CONSOLE_PARITY_NONE;
cfg.stop_bits = CONSOLE_STOP_BITS_1; cfg.stop_bits = CONSOLE_STOP_BITS_1;
cfg.auto_baud = cfg.auto_baud =
#ifdef CONFIG_CONSOLE_BIT_RATE_AUTO #ifdef CONFIG_NODEMCU_CONSOLE_BIT_RATE_AUTO
true; true;
#else #else
false; false;
...@@ -172,7 +171,7 @@ void app_main (void) ...@@ -172,7 +171,7 @@ void app_main (void)
nodemcu_init (); nodemcu_init ();
nvs_flash_init (); nvs_flash_init ();
tcpip_adapter_init (); esp_netif_init ();
start_lua (); start_lua ();
task_pump_messages (); task_pump_messages ();
......
idf_component_register(
SRCS "CAN.c"
INCLUDE_DIRS "include"
)
#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the
# src/ directory, compile them and link them into lib(subdirectory_name).a
# in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
idf_component_register(
SRCS "console.c"
INCLUDE_DIRS "include"
REQUIRES "task" "esp32"
)
COMPONENT_ADD_INCLUDEDIRS:=include
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
*/ */
#include "driver/console.h" #include "driver/console.h"
#include "esp_intr.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
#include "freertos/queue.h" #include "freertos/queue.h"
#include <unistd.h> #include <unistd.h>
#include "rom/libc_stubs.h" #include "esp32/rom/libc_stubs.h"
#include "sys/reent.h" #include "sys/reent.h"
#define UART_INPUT_QUEUE_SZ 0x100 #define UART_INPUT_QUEUE_SZ 0x100
......
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
* @author Johny Mattsson <jmattsson@dius.com.au> * @author Johny Mattsson <jmattsson@dius.com.au>
*/ */
#include "rom/uart.h" #include "esp32/rom/uart.h"
#include "task/task.h" #include "task/task.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define CONSOLE_UART CONFIG_CONSOLE_UART_NUM #define CONSOLE_UART CONFIG_ESP_CONSOLE_UART_NUM
typedef enum typedef enum
{ {
......
idf_component_register(
SRCS "i2c_sw_master.c"
INCLUDE_DIRS "include"
REQUIRES "esp32"
)
COMPONENT_ADD_INCLUDEDIRS:=include
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