Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spiff1m #42

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,13 @@ jobs:
key: ${{ runner.os }}
- name: Run install.sh
run: |
source ./.env-vars
cd nodemcu-firmware
if [ "$X_BRANCH" = "dev-esp32" ]; then bash "$GITHUB_WORKSPACE"/ESP32/install.sh; else bash "$GITHUB_WORKSPACE"/ESP8266/install.sh; fi
"${GITHUB_WORKSPACE}"/run.sh -install
- name: Run before-script.sh
run: |
source ./.env-vars
cd nodemcu-firmware
if [ "$X_BRANCH" = "dev-esp32" ]; then bash "$GITHUB_WORKSPACE"/ESP32/before-script.sh; else bash "$GITHUB_WORKSPACE"/ESP8266/before-script.sh; fi
"${GITHUB_WORKSPACE}"/run.sh -before
- name: Run script.sh
run: |
source ./.env-vars
cd nodemcu-firmware
if [ "$X_BRANCH" = "dev-esp32" ]; then bash "$GITHUB_WORKSPACE"/ESP32/script.sh; else bash "$GITHUB_WORKSPACE"/ESP8266/script.sh; fi
"${GITHUB_WORKSPACE}"/run.sh -script
- name: Upload artifacts in 'nodemcu-firmware/bin'
uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@

# Debug files
*.dSYM/

.env-vars
106 changes: 27 additions & 79 deletions ESP32/before-script.sh
Original file line number Diff line number Diff line change
@@ -1,83 +1,31 @@
#!/bin/env bash

set -e

echo "Running 'before_script' for ESP32"
(
make defconfig # -> will also download and uncompress the toolchain

# ---------------------------------------------------------------------------
# select modules
# ---------------------------------------------------------------------------
# disable all modules
sed -ri 's/(CONFIG_NODEMCU_CMODULE_.*=).{0,1}/\1/' sdkconfig
# enable the selected ones
echo "Enabling modules $X_MODULES"
mapfile -t modules < <(echo "$X_MODULES" | tr , '\n' | tr '[:lower:]' '[:upper:]')
for m in "${modules[@]}"; do
sed -ri "s/(CONFIG_NODEMCU_CMODULE_$m=)/\1y/" sdkconfig
done

# ---------------------------------------------------------------------------
# set SSL/TLS
# ---------------------------------------------------------------------------
if [ "${X_SSL_ENABLED}" == "true" ]; then
echo "Enabling SSL/TLS for mbed TLS and MQTT"
sed -ri 's/(CONFIG_MBEDTLS_TLS_ENABLED=).{0,1}/\1y/' sdkconfig
sed -ri 's/(CONFIG_MQTT_TRANSPORT_SSL=).{0,1}/\1y/' sdkconfig
else
echo "Disabling SSL/TLS for mbed TLS and MQTT"
sed -ri 's/(CONFIG_MBEDTLS_TLS_ENABLED=).{0,1}/\1/' sdkconfig
sed -ri 's/(CONFIG_MQTT_TRANSPORT_SSL=).{0,1}/\1/' sdkconfig
fi

# ---------------------------------------------------------------------------
# set FatFS and also enable the SDMMC module in case the user forgot
# ---------------------------------------------------------------------------
if [ "${X_FATFS_ENABLED}" == "true" ]; then
echo "Enabling FatFS/SDMMC"
sed -ri "s/(CONFIG_BUILD_FATFS=).{0,1}/\1y/" sdkconfig
sed -ri "s/(CONFIG_NODEMCU_CMODULE_SDMMC=).{0,1}/\1y/" sdkconfig
fi

# ---------------------------------------------------------------------------
# set debug mode/level
# ---------------------------------------------------------------------------
if [ "${X_DEBUG_ENABLED}" == "true" ]; then
echo "Enabling debug mode"
sed -ri "s/(CONFIG_LOG_DEFAULT_LEVEL_INFO=).{0,1}/\1/" sdkconfig
sed -ri "s/(CONFIG_LOG_DEFAULT_LEVEL_DEBUG=).{0,1}/\1y/" sdkconfig
sed -ri "s/(CONFIG_LOG_DEFAULT_LEVEL=).{0,1}/\14/" sdkconfig
fi
# current script dir
declare -r SCRIPT_DIR="$( cd $( dirname $0 ) && pwd )"

cat sdkconfig

# below inspired by https://github.com/marcelstoer/docker-nodemcu-build/blob/master/build-esp32

# ---------------------------------------------------------------------------
# set version(s)
# ---------------------------------------------------------------------------
version_file=components/platform/include/user_version.h
lua_header_file=components/lua/lua.h

export BUILD_DATE COMMIT_ID BRANCH SSL MODULES SDK_VERSION
BUILD_DATE="$(date "+%Y-%m-%d %H:%M")"
COMMIT_ID="$(git rev-parse HEAD)"
BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')"
# 'git submodule status' -> 7313e39fde0eb0a47a60f31adccd602c82a8d5ad sdk/esp32-esp-idf (v3.2-dev-1239-g7313e39)
# -> get text between ()
SDK_VERSION="$(git submodule status|grep esp32|sed -r 's/.*\((.+)\)/\1/')"
# If the submodule isn't linked to a released/tagged version the above commands would set SDK_VERSION to
# "7313e39fde0eb0a47a60f31adccd602c82a8d5ad sdk/esp32-esp-idf" (w/o the quotes).
# -> check and get the short Git revion hash instead
if [ ${#SDK_VERSION} -ge 40 ]; then SDK_VERSION=${SDK_VERSION:0:7}; fi
# If it's still empty then set it to a dummy to ensure further operations don't fail.
if [ -z "$SDK_VERSION" ]; then SDK_VERSION="n/a"; fi

sed -i '/#define NODE_VERSION[[:space:]]/ s/$/ " '"$USER_PROLOG"'\\n\\tbranch: '"$BRANCH"'\\n\\tcommit: '"$COMMIT_ID"'\\n\\tSSL: '"$X_SSL_ENABLED"'\\n\\tmodules: '"$X_MODULES"'\\n"/g' "$version_file"
sed -i 's/"unspecified"/"created on '"$BUILD_DATE"'\\n"/g' "$version_file"
sed -i '/#define LUA_RELEASE[[:space:]]/ s/$/ " on ESP-IDF '"$SDK_VERSION"'"/g' "$lua_header_file"
set -e

cat "$version_file"
grep LUA_RELEASE "$lua_header_file"
)
_set_headers() {
# replace modules in user_modules.h by the selected ones
"${SCRIPT_DIR}"/set-modules.sh
# set defines in user_config.h according to X_* variables
"${SCRIPT_DIR}"/set-config.sh
}

_main() {
echo "Running 'before_script' for ESP32"

( _set_headers ) || return 1

# prepare local/{lua,fs} folders out of lua_modules
"${SCRIPT_DIR}"/set-lua-modules.sh

# cat user_modules.h
# cat user_config.h
# cat u8g*.h
# cat ucg_config.h
# cat user_version.h
}

# subshell due to "cd" command inside
_main
99 changes: 99 additions & 0 deletions ESP32/set-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
set -e

function _set {
local key="$1" ; shift
local val="$1" ; shift
echo "${key} = ${val}"
sed -ri "s!^[# ]*${key}[= ].*\$!${key}=${val}!" sdkconfig || return 1
}

function _set_if_str {
if [ -v ${2} ]; then
_set "${1}" "\x22$(echo ${!2})\x22"
fi
}

function _set_if_else {
if [ -v ${2} ]; then
_set "${1}" "${3}"
else
_set "${1}" "${4}"
fi
}

function _set_yes_no {
_set_if_else "$1" "$2" y n
}

function _set_info {
# below inspired by https://github.com/marcelstoer/docker-nodemcu-build/blob/master/build-esp32

# ---------------------------------------------------------------------------
# set version(s)
# ---------------------------------------------------------------------------
version_file=components/platform/include/user_version.h
lua_header_file=components/lua/lua-5.$( [ "x${X_BRANCH_NATURE}x" == "xesp8266x" ] && echo 1 || echo 3 )/lua.h

local -r BUILD_DATE="$(date "+%Y-%m-%d %H:%M")"
local -r COMMIT_ID="$(git rev-parse HEAD)"
local -r BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')"
# 'git submodule status' -> 7313e39fde0eb0a47a60f31adccd602c82a8d5ad sdk/esp32-esp-idf (v3.2-dev-1239-g7313e39)
# -> get text between ()
local SDK_VERSION="$(git submodule status|grep esp32|sed -r 's/.*\((.+)\)/\1/')"
# If the submodule isn't linked to a released/tagged version the above commands would set SDK_VERSION to
# "7313e39fde0eb0a47a60f31adccd602c82a8d5ad sdk/esp32-esp-idf" (w/o the quotes).
# -> check and get the short Git revion hash instead
if [ ${#SDK_VERSION} -ge 40 ]; then SDK_VERSION=${SDK_VERSION:0:7}; fi
# If it's still empty then set it to a dummy to ensure further operations don't fail.
if [ -z "$SDK_VERSION" ]; then SDK_VERSION="n/a"; fi

sed -i '/#define NODE_VERSION[[:space:]]/ s/$/ " '"$USER_PROLOG"'\\n\\tbranch: '"$BRANCH"'\\n\\tcommit: '"$COMMIT_ID"'\\n\\tSSL: '"$X_SSL_ENABLED"'\\n\\tmodules: '"$X_MODULES"'\\n"/g' "${version_file}"
sed -i 's/"unspecified"/"created on '"$BUILD_DATE"'\\n"/g' "${version_file}"
sed -i '/#define LUA_RELEASE[[:space:]]/ s/$/ " on ESP-IDF '"$SDK_VERSION"'"/g' "${lua_header_file}"

#cat "${version_file}"
#grep LUA_RELEASE "${lua_header_file}"
}

function _set_partitions {
local -r part_csv=components/platform/partitions.csv
[ -f "${part_csv}" ] || { echo "[ERR] : expected but missing $(pwd)${part_csv}" && return 1 ; }
if [ -v X_LUA_FLASH_STORE ] ; then
sed -ri "s!lfs,.*!lfs,0xC2, 0x01, ,${X_LUA_FLASH_STORE}!" ${part_csv}
fi
if [ -v X_SPIFFS_MAX_FILESYSTEM_SIZE ] ; then
sed -ri "s!storage,.*!storage, data, spiffs, ,${X_SPIFFS_MAX_FILESYSTEM_SIZE}!" ${part_csv}
fi
}

function _set_lua_ver {
# clear defaults
sed -ri 's/(CONFIG_LUA_VERSION_.*)=.{0,1}/# \1 is not set/' sdkconfig || return 1
_set_yes_no CONFIG_LUA_VERSION_${X_LUA} X_LUA || return 1
}

function _main {
# Lua related
_set_lua_ver || return 1
_set_if_str CONFIG_LUA_INIT_STRING X_LUA_INIT_STRING || return 1

# SSL on/off
_set_yes_no CONFIG_MBEDTLS_TLS_SERVER X_SSL_ENABLED || return 1
_set_yes_no CONFIG_MBEDTLS_TLS_CLIENT X_SSL_ENABLED || return 1
_set_yes_no CONFIG_MBEDTLS_TLS_ENABLED X_SSL_ENABLED || return 1
_set_yes_no CONFIG_MQTT_TRANSPORT_SSL X_SSL_ENABLED || return 1

# set SDMMC module in case the user forgot
_set_yes_no CONFIG_NODEMCU_CMODULE_SDMMC X_FATFS_ENABLED || return 1

_set_yes_no CONFIG_LOG_DEFAULT_LEVEL_INFO X_DEBUG_ENABLED || return 1
_set_yes_no CONFIG_LOG_DEFAULT_LEVEL_DEBUG X_DEBUG_ENABLED || return 1
_set_if_else CONFIG_LOG_DEFAULT_LEVEL X_DEBUG_ENABLED 3 4 || return 1

_set_info || return 1

_set_partitions || return 1
}

_main
54 changes: 54 additions & 0 deletions ESP32/set-lua-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# assuming PWD = "nodemcu-firmware" dir
declare -r tgtPath="${PWD}/local"

# lua_modules is currently located in the parent-of-parent of "nodemcu-firmware"
## this can change once firmware contains all lua_modules
declare -r srcPath="$( cd ${PWD}/../../lua_modules && pwd )"

_copy_file() {
local -r tgtF="$1" ; shift
local -r srcF="$1" ; shift
[ -f "${tgtF}" ] && { echo "[ERR] : duplicate named file detected : ${tgtF}" ; return 1 ; }
[ -f "${srcF}" ] && cp "${srcF}" "${tgtF}"
return 0
}

_copy_all_files() {
local -r tgtDir="$1" ; shift
for i in "$@" ; do
_copy_file "${tgtDir}/$(basename ${i})" "${i}" || return 1
done
}

_copy_module() {
local -r srcDir="${srcPath}/$1" ; shift
_copy_all_files ${tgtPath}/lua ${srcDir}/lua/* || return 1
_copy_all_files ${tgtPath}/fs ${srcDir}/fs/* || return 1
}

_copy_all_modules() {
for i in "$@" ; do
_copy_module "${i}" || return 1
done
}

_clean() {
for i in "${tgtPath}/lua" "${tgtPath}/fs" ; do
rm -rf ${i}/* || { echo "[ERR] : failed cleaning ${i}/* dir" ; return 1 ; }
done
}

_main() {
if [ -n "${X_LUA_MODULES}" ] ; then
[ ! -d "${tgtPath}" ] && { echo "[ERR] : missing ${tgtPath}" ; return 1 ; }
[ ! -d "${srcPath}" ] && { echo "[ERR] : missing ${srcPath}" ; return 1 ; }

_clean || return 1

_copy_all_modules $( echo ${X_LUA_MODULES} | sed 's/,/ /g' )
fi
}

_main
15 changes: 15 additions & 0 deletions ESP32/set-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# disable all modules
sed -ri 's/[# ]*(CONFIG_NODEMCU_CMODULE_.*)[= ].*/#\1/' sdkconfig
sed -ri 's/[# ]*(CONFIG_NODEMCU_CMODULE_.*)$/#\1/' sdkconfig

# enable the selected ones
echo "Enabling modules ${X_MODULES}"
mapfile -t modules < <( echo "${X_MODULES}" | tr , '\n' | tr '[:lower:]' '[:upper:]' )

for m in "${modules[@]}"; do
sed -ri "s/^#(CONFIG_NODEMCU_CMODULE_${m})$/\1=y/" sdkconfig
done
49 changes: 30 additions & 19 deletions ESP8266/before-script.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
#!/bin/env bash
#!/bin/bash

set -e
# current script dir
declare -r SCRIPT_DIR="$( cd $( dirname $0 ) && pwd )"

echo "Running 'before_script' for ESP8266"
(
SCRIPT_DIR=$GITHUB_WORKSPACE/ESP8266
set -e

_set_headers() {
# dig in and modify those config files
cd app/include || exit
cd app/include || { echo "[ERR] : expected but missing $(pwd)/app/include" && return 1 ; }

# replace modules in user_modules.h by the selected ones
"$SCRIPT_DIR"/set-modules.sh
"${SCRIPT_DIR}"/set-modules.sh
# set defines in user_config.h according to X_* variables
"$SCRIPT_DIR"/set-config.sh
"${SCRIPT_DIR}"/set-config.sh
# replace fonts in u8g_config.h by the selected ones
"$SCRIPT_DIR"/set-fonts.sh
"${SCRIPT_DIR}"/set-fonts.sh
# set I2C/SPI displays in u8g_config.h and ucg_config.h
"$SCRIPT_DIR"/set-displays.sh
"${SCRIPT_DIR}"/set-displays.sh
# replace version strings in user_version.h
"$SCRIPT_DIR"/set-version.sh
"${SCRIPT_DIR}"/set-version.sh
# replace LWIP settings in lwipopts.h
"${SCRIPT_DIR}"/set-lwip.sh
}

_main() {
echo "Running 'before_script' for ESP8266"

( _set_headers ) || return 1

# prepare local/{lua,fs} folders out of lua_modules
"${SCRIPT_DIR}"/set-lua-modules.sh

cat user_modules.h
cat user_config.h
cat u8g*.h
cat ucg_config.h
cat user_version.h
# cat user_modules.h
# cat user_config.h
# cat u8g*.h
# cat ucg_config.h
# cat user_version.h
}

# back to where we came from
cd "$GITHUB_WORKSPACE" || exit
)
# subshell due to "cd" command inside
_main
4 changes: 2 additions & 2 deletions ESP8266/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ echo "Running 'script' for ESP8266"
# will always depend on it
if [ -f tools/esp-open-sdk.tar.xz ]; then tar -Jxf tools/esp-open-sdk.tar.xz; elif [ -f tools/esp-open-sdk.tar.gz ]; then tar -zxf tools/esp-open-sdk.tar.gz; fi
export PATH=$PATH:$PWD/esp-open-sdk/sdk:$PWD/esp-open-sdk/xtensa-lx106-elf/bin
make all
make LUA="${X_LUA}" all
cd bin/
timestamp=$(date "+%Y-%m-%d-%H-%M-%S")
base_file_name="nodemcu-$X_BRANCH-$X_NUMBER_OF_MODULES-modules-"$timestamp
file_name_float=$base_file_name"-float.bin"
srec_cat -output "${file_name_float}" -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
cd ../
make clean
make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL"
make LUA="${X_LUA}" EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL"
cd bin/
file_name_integer=$base_file_name"-integer.bin"
srec_cat -output "${file_name_integer}" -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
Expand Down
Loading