2018-04-19 17:27:47 +02:00
|
|
|
-- First time image boot to discover the confuration
|
|
|
|
--
|
|
|
|
-- If you want to use absolute address LFS load or SPIFFS imaging, then boot the
|
|
|
|
-- image for the first time bare, that is without either LFS or SPIFFS preloaded
|
|
|
|
-- then enter the following commands interactively through the UART:
|
|
|
|
--
|
2018-06-22 23:29:16 +02:00
|
|
|
do
|
2019-12-31 00:53:54 +01:00
|
|
|
local sa, ma, fa = node.flashindex()
|
|
|
|
for n,v in pairs{LFS_MAPPED = ma, LFS_BASE = fa, SPIFFS_BASE = sa} do
|
2018-07-16 07:48:47 +02:00
|
|
|
print(('export %s=""0x%x"'):format(n, v))
|
2018-06-22 23:29:16 +02:00
|
|
|
end
|
|
|
|
end
|
2018-04-19 17:27:47 +02:00
|
|
|
--
|
2019-02-17 19:26:29 +01:00
|
|
|
-- This will print out 3 hex constants: the absolute address used in the
|
2018-04-19 17:27:47 +02:00
|
|
|
-- 'luac.cross -a' options and the flash adresses of the LFS and SPIFFS.
|
|
|
|
--
|
|
|
|
--[[ So you would need these commands to image your ESP module:
|
|
|
|
USB=/dev/ttyUSB0 # or whatever the device of your USB is
|
|
|
|
NODEMCU=~/nodemcu # The root of your NodeMCU file hierarchy
|
|
|
|
SRC=$NODEMCU/local/lua # your source directory for your LFS Lua files.
|
|
|
|
BIN=$NODEMCU/bin
|
|
|
|
ESPTOOL=$NODEMCU/tools/esptool.py
|
|
|
|
|
|
|
|
$ESPTOOL --port $USB erase_flash # Do this is you are having load funnies
|
|
|
|
$ESPTOOL --port $USB --baud 460800 write_flash -fm dio 0x00000 \
|
|
|
|
$BIN/0x00000.bin 0x10000 $BIN/0x10000.bin
|
|
|
|
#
|
2019-02-17 19:26:29 +01:00
|
|
|
# Now restart your module and use whatever your intective tool is to do the above
|
2018-04-19 17:27:47 +02:00
|
|
|
# cmds, so if this outputs 0x4027b000, -0x7b000, 0x100000 then you can do
|
|
|
|
#
|
|
|
|
$NODEMCU/luac.cross -a 0x4027b000 -o $BIN/0x7b000-flash.img $SRC/*.lua
|
|
|
|
$ESPTOOL --port $USB --baud 460800 write_flash -fm dio 0x7b000 \
|
|
|
|
$BIN/0x7b000-flash.img
|
|
|
|
# and if you've setup a SPIFFS then
|
|
|
|
$ESPTOOL --port $USB --baud 460800 write_flash -fm dio 0x100000 \
|
|
|
|
$BIN/0x100000-0x10000.img
|
|
|
|
# and now you are good to go
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- File: init.lua
|
|
|
|
--
|
2019-02-17 19:26:29 +01:00
|
|
|
-- With the previous example you still need an init.lua to bootstrap the _init
|
|
|
|
-- module in LFS. Here is an example. It's a good idea either to use a timer
|
|
|
|
-- delay or a GPIO pin during development, so that you as developer can break into
|
2018-04-19 17:27:47 +02:00
|
|
|
-- the boot sequence if there is a problem with the _init bootstrap that is causing
|
2018-06-22 23:29:16 +02:00
|
|
|
-- a panic loop. Here is one example of how you might do this. You have a second
|
2018-08-11 13:48:46 +02:00
|
|
|
-- to inject tmr.stop(0) into UART0. Extend this delay if needed.
|
2018-04-19 17:27:47 +02:00
|
|
|
--
|
2018-08-11 13:48:46 +02:00
|
|
|
-- This example will also attempt to automatically load the LFS block from a SPIFFS
|
|
|
|
-- file named 'flash.img'.
|
2018-04-19 17:27:47 +02:00
|
|
|
--
|
2019-02-17 19:26:29 +01:00
|
|
|
if node.flashindex() == nil then
|
|
|
|
node.flashreload('flash.img')
|
2018-04-19 17:27:47 +02:00
|
|
|
end
|
|
|
|
|
2019-05-22 14:03:06 +02:00
|
|
|
local initTimer = tmr.create()
|
|
|
|
initTimer:register(1000, tmr.ALARM_SINGLE,
|
|
|
|
function()
|
|
|
|
local fi=node.flashindex; return pcall(fi and fi'_init')
|
2019-12-31 00:53:54 +01:00
|
|
|
end)
|
2019-05-22 14:03:06 +02:00
|
|
|
initTimer:start()
|