]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_ctfws/commitdiff
Rework for LFS
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 12 Aug 2018 01:09:08 +0000 (02:09 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sat, 27 Oct 2018 19:03:31 +0000 (20:03 +0100)
ctfws-lfs-strings.lua [new file with mode: 0644]
ctfws.lua
init2.lua
init3.lua
mklfs.sh [new file with mode: 0755]
pushall.sh

diff --git a/ctfws-lfs-strings.lua b/ctfws-lfs-strings.lua
new file mode 100644 (file)
index 0000000..847f4e7
--- /dev/null
@@ -0,0 +1,46 @@
+local modload = "cron", "cron.entry", "schedule", "unschedule",
+  "gpio", "HIGH", "LOW", "ALARM_AUTO",
+  "mqtt.socket",
+  "math", "floor", "unregister",
+  "error", "self"
+
+local ctfws = "ctfws", "ctfws_lcd", "ctfws_tmr",
+  "setupD", "roundD", "rounds", "startT", "endT", "flagsN", "flagsR", "flagsY",
+  "times", "config", "deconfig", "setFlags", "setEndTime",
+  "GAME NOT CONFIGURED!",
+  "GAME OVER @ %02d:%02d",
+  "START TIME IN FUTURE",
+  "TIME IS UP"
+
+local lcdpreload =
+  "define_char",
+  "lcd", "mtmr", "ftmr", "dl_elapsed", "dl_elapsed", "dl_remain", "dl_round",
+  "attnState", "reset", "drawTimes", "drawFlags", "drawMessage", "drawFlagsMessage",
+  "%02d:%02d.%d", "%02d.%d", "%d", "%-20s", "%d\000: R=%s Y=%s",
+  " CMUKGB CTFWS TIMER ", "                    ",
+  "GAME      :",
+  "SETUP     :",
+  "START IN  :",
+  "GAME END  :",
+  "JAILBREAK :",
+  "JB#   %d/%d :",
+  "JB# %2d/%2d :"
+
+local init3load =
+  "flg_tmr", "lastMsgTime", "mqttUser", "msg_tmr", "dprint", "mqc",
+  "nwfmqtt.conf",
+  "* * * * *",
+  "ctfws/game/config",
+  "ctfws/game/endtime",
+  "ctfws/game/flags",
+  "ctfws/game/message",
+  "ctfws/game/message/jail",
+  "none",
+  "^%s*(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+).*$",
+  "^%s*(%d+)%s+(%d+).*$",
+  "^%s*(%d+)%s*(.*)$",
+  "^%s*%?.*$",
+  "^ctfws/game/message",
+  "CONNECTING...", "MQTT", "MQTT CONNECTED", "MQTT Disconnected", "DHCP %s",
+  "WIFI %s", "NET", "Trying reconn...",
+  "alive", "beat %d %s"
index f9393778b14b2a2eed910c86c9167cbd6d295aee..3b76625c1d01fcd1c26b86d4f40fade70d2f7fef 100644 (file)
--- a/ctfws.lua
+++ b/ctfws.lua
@@ -77,12 +77,10 @@ local function setEndTime(self,t)
   self.endT = t
 end
 
-return function() 
-  local self = {}
-  self.times = times
-  self.config = config
-  self.deconfig = deconfig
-  self.setFlags = setFlags
-  self.setEndTime = setEndTime
-  return self
-end
+local self = {}
+self.times = times
+self.config = config
+self.deconfig = deconfig
+self.setFlags = setFlags
+self.setEndTime = setEndTime
+return self
index ed70cace0a38b3477b86b7043c853ba8fde9b0f7..5c5687b69f02e555bc7ea0b000e7b0efe53c56a2 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -1,6 +1,22 @@
+if node.flashindex() == nil then
+  -- no LFS image.  Perhaps it failed to flash?
+  if file.exists("luac.out.stage") and not file.exists("luac.out") then
+    -- Looks like we tried once before, indeed.  Try again.
+    node.flashreload("luac.out.stage")
+  end
+end
+file.remove("luac.out.stage") -- remove stage file from last attempt
+-- Do we have a new LFS blob?  If so, install it.
+if file.exists("luac.out") then
+  print("Updating LFS image.  Will reboot if things go well.")
+  file.rename("luac.out", "luac.out.stage")
+  node.flashreload("luac.out.stage")
+  error("Failed to update LFS!")
+end
+
 -- It's early in boot, so we have plenty of RAM.  Compile
 -- the rest of the firmware from source if it's there.
-dofile("compileall.lc")
+OVL.compileall()
 
 -- Grab some configuration parameters we might need,
 -- notably, the LCD address
@@ -18,7 +34,7 @@ print("init2 hw")
 wifi.sta.sleeptype(wifi.NONE_SLEEP) -- don't power down radio
 gpio.mode(5,gpio.OUTPUT)   -- beeper on GPIO14
 i2c.setup(0,2,1,i2c.SLOW)  -- init i2c on GPIO4 and GPIO5
-lcd = dofile("lcd1602.lc")(ctfwshw.lcd or 0x27)
+lcd = OVL.lcd1602()(ctfwshw.lcd or 0x27)
 
 -- give the LCD time to initialize properly
-tmr.create():alarm(125, tmr.ALARM_SINGLE, function() print("init2 go3") dofile("init3.lc") end)
+tmr.create():alarm(125, tmr.ALARM_SINGLE, function() print("init2 go3") OVL.init3() end)
index 8902a942bb2e7e8d3b94326b19f521ab7625e38f..f6bdd81d2f35fc644ac2d6b1da56f81a414e39e2 100644 (file)
--- a/init3.lua
+++ b/init3.lua
@@ -3,16 +3,16 @@
 dprint = function(...) print(...) end -- ON
 
 -- common module initialization
-cron.schedule("*/5 * * * *", function(e) dofile("nwfnet-sntp.lc").dosntp(nil) end)
+cron.schedule("*/5 * * * *", function(e) OVL["nwfnet-sntp"]().dosntp(nil) end)
 nwfnet = require "nwfnet"
 
 -- Game logic modules
-ctfws = dofile("ctfws.lc")()
+ctfws = OVL.ctfws()
 ctfws:setFlags(0,0)
 
 msg_tmr = tmr.create()
 flg_tmr = tmr.create()
-ctfws_lcd = dofile("ctfws-lcd.lc")(ctfws, lcd, msg_tmr, flg_tmr)
+ctfws_lcd = OVL["ctfws-lcd"]()(ctfws, lcd, msg_tmr, flg_tmr)
 ctfws_tmr = tmr.create()
 
 -- Draw the default display
@@ -20,7 +20,7 @@ ctfws_lcd:drawTimes()
 ctfws_lcd:drawFlagsMessage("BOOT...")
 
 -- MQTT plumbing
-mqc, mqttUser = dofile("nwfmqtt.lc").mkclient("nwfmqtt.conf")
+mqc, mqttUser = OVL.nwfmqtt().mkclient("nwfmqtt.conf")
 local mqttBootTopic  = string.format("ctfws/dev/%s/beat",mqttUser)
 mqc:lwt(mqttBootTopic,"dead",1,1)
 
@@ -36,9 +36,9 @@ local mqtt_reconn_cronentry
 local function mqtt_reconn()
   dprint("Trying reconn...")
   mqtt_reconn_cronentry = cron.schedule("* * * * *", function(e)
-    mqc:close(); dofile("nwfmqtt.lc").connect(mqc,"nwfmqtt.conf")
+    mqc:close(); OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf")
   end)
-  dofile("nwfmqtt.lc").connect(mqc,"nwfmqtt.conf")
+  OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf")
 end
 
 local mqtt_beat_cronentry
@@ -163,5 +163,5 @@ end
 
 -- hook us up to the network!
 ctfws_lcd:drawFlagsMessage("CONNECTING...")
--- dofile("nwfnet-diag.lc")(true)
-dofile("nwfnet-go.lc")
+-- OVL["nwfnet-diag"]()(true)
+OVL["nwfnet-go"]()
diff --git a/mklfs.sh b/mklfs.sh
new file mode 100755 (executable)
index 0000000..6ca1faf
--- /dev/null
+++ b/mklfs.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+set -e -u
+
+SOURCES=(
+  ctfws-lfs-strings.lua
+  core/_external/lcd1602.lua
+  core/fifo/fifo.lua
+  core/net/{fifosock,nwfmqtt,nwfnet*}.lua
+  core/telnetd/telnetd{,-{diag,file}}.lua
+  core/util/compileall.lua
+  core/util/diag.lua
+  core/util/lfs-strings.lua
+)
+
+rm -rf _lfs_build
+mkdir _lfs_build
+
+# for i in ${SOURCES[@]}; do
+#   lua5.1 -e "package.path=package.path..';core/_external/luasrcdiet/?.lua'" \
+#     core/_external/luasrcdiet/bin/luasrcdiet $i -o _lfs_build/`basename $i` --quiet
+# done
+cp ${SOURCES[@]} _lfs_build/
+
+if [ -z "${LUACROSS:-}" ]; then
+  LUACROSS=$(readlink -f $(dirname $0)/luac.cross)
+fi
+
+if ! [ -x "${LUACROSS}" ]; then
+  echo "Need cross compiler!  Tried non-existant ${LUACROSS}."
+  exit 1
+fi
+
+(cd _lfs_build; $LUACROSS -f *.lua)
+ls -l _lfs_build/luac.out
index e123a2d1b2c53914adbe9a91f7724091cb5a8af2..5720b14c25e8687f5bbfd15bdfdf65b1d1ebae61 100755 (executable)
@@ -5,9 +5,6 @@ set -e -u
 . ./core/host/pushcommon.sh
 
 pushsrc() {
-  dopushcompile core/util/compileall.lua
-  dopushlua     core/net/nwfmqtt.lua
-  dopushlua     core/_external/lcd1602.lua
   dopushlua     ctfws.lua
   dopushlua     ctfws-lcd.lua
   dopushlua     init3.lua
@@ -31,11 +28,20 @@ pushconf() {
   done
 }
 
+pushlfs() {
+    if [ -z ${LUACROSS:-} ]; then
+      ./core/host/pushinit.sh
+    else
+      ./mklfs.sh
+      dopushtext _lfs_build/luac.out
+    fi
+}
+
 case "${1:-}" in
   all)
     pushconf
     pushsrc
-    ./core/host/pushinit.sh
+    pushlfs
     ;;
   both)
     pushconf
@@ -44,11 +50,15 @@ case "${1:-}" in
   src)
     pushsrc
     ;;
+  srcmore)
+    pushsrc
+    pushlfs
+    ;;
   conf)
     pushconf
     ;;
   *)
-    echo "Please specify push mode: {conf,src,both,all}"
+    echo "Please specify push mode: {conf,src,srcmore,both,all}"
     exit 1
     ;;
 esac