From: Nathaniel Wesley Filardo Date: Sat, 29 Jun 2019 13:00:28 +0000 (+0100) Subject: Improve firmware construction, add docs X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=41364b8d9dbf6248272a81fd8a78eacd1ae95ee4;p=acmetensortoys-esp-lua_ctfws Improve firmware construction, add docs --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b43dcd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +_lfs_build +firm +spiffs-* diff --git a/README-flashing.rst b/README-flashing.rst new file mode 100644 index 0000000..b6d9aeb --- /dev/null +++ b/README-flashing.rst @@ -0,0 +1,65 @@ +Prepare the Firmware +#################### + +Not yet really documented; build a NodeMCU firmware with the modules listed in +``README.rst``. Ensure that ``./firm`` points to your firmware build directory, +as we're going to pull ``luac.cross`` and the firmware ``.bin`` therefrom. + +Flashing +######## + +Clone this: https://github.com/espressif/esptool + +For each of the three timers (clear, yellow, and red), hook them to USB and run +one of :: + + export BOARDNAME=red + export BOARDNAME=yel + export BOARDNAME=clr + +and then :: + + ./mkspiffs.sh + + ./esptool/esptool.py write_flash \ + --flash_size 4MB --flash_mode dio --verify \ + 0x0 ./firm/bin/nodemcu_integer_test.bin \ + 0x3fc000 ./firm/sdk/esp_iot_sdk_v3.0/bin/esp_init_data_default_v05.bin + + ./firm/tools/nodemcu-partition.py \ + --flash_size 4MB \ + --lfs_size 65536 --lfs_file _lfs_build/luac.out \ + --spiffs_size 262144 --spiffs_file spiffs-${BOARDNAME}.img + +After flashing, the device will reboot, apply some internal changes, and reboot +again. By default, it hangs out for a minute after the second reboot before +rebooting again into the CtFwS logic. This is less than ideal but is (at least +partly) due to an upstream issue; for the less patient, after flashing, count +15, and then hit the RST button and the device should come up into its CtFwS +logic. + +Serial Console +############## + +You may want to get a serial console on the device for a little more visibility +into what's going on. While nwf prefers the use of kermit for this, one can +also just use screen, as in :: + + screen /dev/ttyUSB0 115200 + +Disconnect with the screen attention chord, ``ctrl+a``, followed by the command +``:quit``. + +At the Lua prompt, many things are possible. By default, the device provides +some visibility into internal events by emitting log messages like so:: + + NET wstaconn + NET wstagoip + CTFWS Trying reconn... + NET sntpsync + NET mqttconn + MQTT ctfws/game/endtime 1540688900 + +The function ``OVL.diag()`` will provide a summary of much of the device's +internal state. + diff --git a/mklfs.sh b/mklfs.sh index 6ca1faf..94977c7 100755 --- a/mklfs.sh +++ b/mklfs.sh @@ -2,11 +2,22 @@ set -e -u +[ -d firm ] || { + echo "./firm should be a symbolic link to the nodemcu firmware" + exit 1 +} + +[ -d core ] || { + echo "./core should be a checkout of nwf's core modules" + exit 1 +} + SOURCES=( ctfws-lfs-strings.lua core/_external/lcd1602.lua - core/fifo/fifo.lua - core/net/{fifosock,nwfmqtt,nwfnet*}.lua + firm/lua_modules/fifo/fifo.lua + firm/lua_modules/fifo/fifosock.lua + core/net/{nwfmqtt,nwfnet*}.lua core/telnetd/telnetd{,-{diag,file}}.lua core/util/compileall.lua core/util/diag.lua @@ -32,4 +43,4 @@ if ! [ -x "${LUACROSS}" ]; then fi (cd _lfs_build; $LUACROSS -f *.lua) -ls -l _lfs_build/luac.out +# ls -l _lfs_build/luac.out diff --git a/mkspiffs.sh b/mkspiffs.sh index d940ccc..13cfc65 100755 --- a/mkspiffs.sh +++ b/mkspiffs.sh @@ -1,36 +1,45 @@ #!/bin/bash -FWDIR=${FWDIR:-/home/nwf/ee/esp/nodemcu-firmware} -FWIMG=${FWIMG:-${FWDIR}/bin/nodemcu_integer_test.bin} -CONFNAME=${CONFNAME:-home} +FWIMG=${FWIMG:-firm/bin/nodemcu_integer_test.bin} +BOARDNAME=${BOARDNAME:-home} + +[ -r firm ] || { + echo "./firm should be a symlink to a built firmware repo" + exit 1 +} + +[ -r ${FWIMG} ] || { + echo "No firmware image ${FWIMG}" + exit 1 +} FWSZ=$(stat --printf="%s" ${FWIMG}) -LUACROSS=${FWDIR}/luac.cross ./mklfs.sh +# Now made external +# LUACROSS=$(readlink -f ./firm/luac.cross) ./mklfs.sh ( # Init is the only core Lua that does not live in LFS echo import core/init.lua init.lua # Grab our configuration - if [ -r conf/${CONFNAME}/rewrites.sed ]; then + if [ -r conf/${BOARDNAME}/rewrites.sed ]; then for i in conf/_common/*.conf.in; do - sed -f conf/${CONFNAME}/rewrites.sed < $i \ + sed -f conf/${BOARDNAME}/rewrites.sed < $i \ > `dirname $i`/`basename $i .in` done - elif [ ! -r conf/${CONFNAME}/nwfmqtt.conf ]; then + elif [ ! -r conf/${BOARDNAME}/nwfmqtt.conf ]; then echo 'NO MQTT CONFIGURATION KNOWN; THIS IS UNLIKELY TO WORK!' fi - for i in conf/${CONFNAME}/*.conf; do echo import $i `basename $i`; done + for i in conf/${BOARDNAME}/*.conf; do echo import $i `basename $i`; done # And all our Lua files for i in *.lua; do echo import $i $i; done # And the LFS image with the rest of everything - echo import _lfs_build/luac.out luac.out -) | ${FWDIR}/tools/spiffsimg/spiffsimg \ - -f spiffs-${CONFNAME}.img \ - -S 32m -U ${FWSZ} \ - -o /dev/fd/1 -r /dev/fd/0 - -echo + # We could, and used to, but we now go via the nodemcu partition tool + # echo import _lfs_build/luac.out luac.out +) | ./firm/tools/spiffsimg/spiffsimg \ + -f spiffs-${BOARDNAME}.img \ + -c 262144 \ + -r /dev/fd/0