lfs_fragments.lua 2.6 KB

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