lfs_fragments.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 _,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 dealy if your reactions can't
  48. -- meet this.
  49. --
  50. -- You also want to do autoload the LFS, for example by adding the following:
  51. --
  52. if node.flashindex() == nil then
  53. node.flashreload('flash.img')
  54. end
  55. tmr.alarm(0, 1000, tmr.ALARM_SINGLE,
  56. function()
  57. local fi=node.flashindex; return pcall(fi and fi'_init')
  58. end)