-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execution of Lua out of flash memory #2292
Comments
BTW, guys and gals -- once you've loaded a set of files into flash. you can do: node.flash.index()('init')() to run the init.lua file in the LFS, and this can do stuff life set up a flash table/metatable with an pcall(function()node.flash.index()('init')()end) is probably the simplest. Also add an entry into package.loaders. entry [3] is good one since this is the C loader which isn't used on NodeMCU the function must either return a Lua function or and error message. Using [3] means that SPIFFS is ahead of LFS in the search path. @georeb, you hassled me for long enough to release this. It does everything that you want. I am surprised that you haven't started testing this. All, if I get no feedback in the next few days, then I do a PR to dev with LFS disabled by default. If no objections after a week, then Ill merge it into dev myself. |
I am sorry if you felt hassled! I have just been excited to try it out! |
I built the image, but ... time passes I uploaded the flash.img file and did
It appears to restart whenever I try and find any module..... I wonder if I uploaded a corrupt module or something. |
@pjsg, Phillip can you either link a gist to your test application or email it to me and I will run it through the debugger to see that is going on. Whatever, you shouldn't do a bare I have just put a one-line
So I have about 300 lines of Lua comprising 8 modules and 138 strings in my LFS (the code is a bit denser than RAM, because we don't have all of the So send me the example and I'll have a look. 😄 Alternatively set PS: IIRC, I've moded the spiffs code to be LFS aware and load a base spiffs image above the LFS region, but not your spiffimg algo which still uses As I said this is still Alpha code and I haven't dotted all the i's |
The 'test' app was just this in
I'll do some more digging in. |
@pjsg, Philip this is a big patch, bigger than the original elua mods to the Lua core, and it needs better documentation, and some decent examples. Also in order to get it working I had to sort out quite a lot of other stuff: bringing luac.cross into the core build and supporting LFS generation, sorting out correct spiffsimg sizing and location, getting remote gdb truly usable; making libs like sqlite3 only be built if enabled so my VM would make, .... However, maybe a good way to sync up would be for us to chat offline on Sykpe or WhatsApp when convenient :) |
The latest push fixes this. |
I've just done a PR as per my comment above 5 days ago. Phillip had some fun getting this going -- until I twigged that he uses Integer builds by default, and I hadn't put the extra variant code in the cross-compiler to repack for 32-bit TValues. Once I fixed this then we've both got this working, but not fully stress tested. Using this really merits its own FAQ plus Lua examples for the LFS based init code to add autoloading, etc. but gven that this patch is as large as the original core patch for eLua, it is better to get this version into the hands of developers for evaluation. |
The tl;dr from the review comments is that we've had 3 of our committers (Johny, Phillip and myself) go through this patch and we haven't picked up any show stoppers. There are some fine grain tweaks, that I need to pick up with another incremental push, but the main concern voiced by Johny relates to the overall API. Thinking about his comments, I do think that could easily make life simpler for Lua developers:
So
I also suggest that the two Lastly Marcel has requested that we delay any commit to dev until after the SDK2.2 commit and snapshot to master. Comments? |
All sounds very promising! So if I am understanding correctly, we execute |
@georeb the C libraries like local mq = node.getflash("mqtt")("mqtt") does the same thing directly with using the loader search list.. |
So when you say Lua module; that could be a standalone function that uses the I may be misunderstanding here, sorry - I don't fully understand the underlying code. |
@georeb, Why don't you just read the working paper that wrote that which explains all of this? Instead of asking Qs about stuff that I've already documented. You can use |
@TerryE I have had a chance now to look at this in greater depth. From what I am reading and seeing, it appears to be very reliable!
I have read all the related documention, twice, and I am still struggling with this. As far as I can tell, I need to supply my What am I doing wrong?! Please can you perhaps provide a ' The end goal is to include this |
@jmattsson @pjsg @devsaurus @marcelstoer @djphoenix, I have had to add a couple of options to I haven't changed any of the underlying defaults, but rather just added decent documentary commenting and reordered into a logical order. I can't be bothered to raise a separate PR for this, but just wanted to give you all an early heads-up just in case any of you have any fundamental concerns with this restructuring. See a draft of this new layout at this gist user_config.h. |
Looks great Terry!
Smaller PRs are much easier to reason about and stand a much better change at getting reviewed and merged quickly. I see no reason why this couldn't be fixed independently from the LFS feature (before or after). |
Thank you @TerryE Can someone point me in the right direction to keep the ball rolling at least until the documentation is completed? How can I build these required image files in the interim? |
Because of my lack of competence with git features, mainly, to be honest. I stashed some of the |
@georeb, the source is king; including the make files. |
Sorry @TerryE I'm still not managing to get anywhere :( |
@georeb, Ii've just pushed a new update. Have a look at the lfs subdir in lua_examples. I will also update my whitepaper. In due course, a version of this will be added to our documentation FAQ hierarchy. |
Thanks @TerryE for that. |
Thankyou @TerryE - I have emailed you... |
We now have 4 users (me, @pjsg, @devsaurus, @georeb) who have tried this out to varying degrees, but enough to know that this works and delivers huge benefits. I've got one more push to tweak a couple of parameters, but I feel we are now at a point where we can sensibly commit this to dev. Comment? |
@TerryE - Thank-you for your support with this. |
My 1st thought was: Put FTPd and TELNETd in there and nobody will need ESPLORER again. Edit stuff transparently via FTP ( Maybe even an editor in there might be doable... Testing it is on a high place of my todo list. |
LFS allows the development to load whatever is required into the store. This is entirely up to you. |
Sure everyone knowing how to handle this can do whatever she wants. More space means more ways to help newcomers. If some helpers for access and development would be the default in distributed images, newcomers would have an easier start without looking for 3rd party tools like ESPlorer. That was the direction I was thinking of. If it's too offtopic here, such thoughts may have sense in an own place for discussion. |
@drawkula, I partially agree with you, in that it makes sense to create a set of LFS-complementary lua examples, and even possibly some standard bundles to help the Lua developer fast-start. However, this is all secondary to getting LFS into dev with cloud builder support. When I first got involved with NodeMCU, you had 15Kb of RAM at boot, and you could only run toy applications. Johnny added his patch to my ctext into flash, and I added LCD, which made a huge difference to the size of apps that you can run -- if you were willing to us overlay techniques to break your app into small compilation units. The next big mode shift for me (and when I stopped using ESPlorer) was when I moved to a LuaOTA provisioning model, with all large file compiling done on the host, and this allowed me to develop practical serious Lua applications. I see LFS as just the next step here in this progression. It becomes practical to have Lua applications that are 1,000s line long, or have 40 Kb RAM available for data. |
@cwrseck @devsaurus @dnc40085 @dtran123 @georeb @jmattsson @marcelstoer @NicolSpies @nwf @pjsg
My aim is to add extra commits to cover off (2) - (4) above so that we can do the merge immediately after next |
@TerryE , I am working my way through the LFS Whitepaper and will provide feedback. My comment so far is that the changes clarify a lot and provide context from a Lua developer's perspective to provide understanding how it works and how to use it. Referring to the last bullet item: I also like your preferred approach as indicated to keep the module in test in SPIFFS and move it into LFS once stable. |
@NicolSpies, we intend to extend the cloud build service to build standard LFS firmware images with a similar degree of flexibility offered by the current build service for non-LFS firmware. Using My challenge here is that I haven't used WinX for over a decade, so I can't do this work myself. If we go the docker route then I can do the docker side, but the Lua developer would still need to install Docker for Windows which requires Win10Pro, but a number of other providers also supply standard minimal docker servers which run are there in Hyper-V Virtualbox or VMware. |
@TerryE, I have followed the Windows 10 with WSL procedure detailed in #2315 by @joysfera with a small correction to save the bytecode output. @marcelstoer, A lua application development environment that would work for me as a crazy, lazy Windows lua application developer spoiled by the current cloud build service would be the following:
|
*nix programmers tend to spend time in terminal windows because we find it more productive. Dunno about it being manual. But remember that if you have all of the lua files for the LFS in one directory then you can easily build the entire LFS with a single Your suggested develop in ESPlorer/SPIFFS then use some cloud service to blow the files to an LFS image doesn't scale well as you are constrained by the RAM during developing. I would suggest that you will want to move tested code incrementally into LFS and only use SPIFFS for the one or two modules currently under test. I personally find ESPlorer really slow and clunky, and I hate the editor. It only takes a couple of seconds to remake a 64Kb LFS image in |
Ok, I will stop acting like Garfield the cat resisting a bath. 😜 My inexperience and ignorance of what *nix programmers have mastered shows. I accept the challenge to become more rooted in |
Nicol, In many ways you are an excellent example of the typical Lua developer -- except that you also engage constructively with us core collaborators. I've been working in IT for over 40 years; it's just over 50 since I wrote my first Fortran programs, and in that time I've worked on mainframes, mini's such as PDPs ad VAXes, embedded systems, all sorts of micros and the entire evolution of the PC from the first IBM PC, and I used to be considered an MS guru and I've been to the Redmond campus a few times, but I've also worked with *nix for over 20 years and pretty much exclusively with Linux systems over the last decade. My strengths are also what makes me useless as a test case for the typical ESP developers who have been brought up on WinX and windows GUIs, but now want to build their own IoT apps. They know WinX and want to learn IoT, and they've probably chosen Lua because this way they don't need to get into the bowels of low level C. It's one thing to ask them to familiarize themselves with PuTTY or Openssh for windows to be able to type in a few commands in the CMD window, but they shouldn't have to spend ages learning a Linux ecosystem to do this. |
Thanks Terry, IT for me was always on the fringes as a design tool, means-to-an-end since I started as a young electronic engineer 32 years ago when I graduated. My dream was to one day get closer to embedded development which took place just as the ESP appeared on the scene, so still a lot to learn and so little time. Your description of the WinX/Lua/IoT developer is spot on.:ok_hand: |
That reminds me: with LFS and IMG I'd need to develop a new way of remote upgrading of my ESP devices. Currently I use my own code that downloads new *.lc files using HTTP GET and that has two major drawbacks: first, it does not allow me to update the NodeMCU firmware itself, which is a PITA because every new NodeMCU release fixes some often major issues and I'd love to be able to replace the firmware as well. Second issue, since I have many small lua/lc files (to fit in RAM) the upgrading process needs to download many files and often crashes during that (no idea why, it never happens in my testing, only in the field). |
@joysfera Petr, IMO, the main constraint that drives you towards small files is the RAM limitation during the compilation on ESP, simply because the act of compilation itself takes a lot of memory, and this is also related to the size of the module being compiled, so taking the compilation off the ESP and onto the host makes a big difference, as I discovered with my provisioning system. The second impact is that even though the Lua loader can load large LC files, they still take up memory when the functions are bound to an active Lua variable as a closure. LFS removes both of these constraints in that the compilation must be done on host, and the compiled code get directly loaded into Flash memory, and my LFS enabled OTA upgrade of the firmware itself is another issue and would involve another development sub-project, though IIRC @jmattsson's company DiUS have done some work on this in the past. In the meantime I am intending to release robust and LFS compatible versions of Telnet, FTP and luaOTA soon. PS. Lua OTA uses bare TCP exchange the its own host-based server, and this is stable, so I suspect that your instabilities are from bugs in the HTTP module. |
@TerryE Terry, please note that my upgrade system downloads *.lc files (the compiled ones) already. Perhaps with the latest NodeMCU the crashes are gone because I discovered and you fixed the recursive issue corrupting stack back in winter that could be causing it. But I don't know for sure as I don't have any latest NodeMCU in the field yet simply because there's no way of remote updating the NodeMCU firmware, contrary to the ArduinoOTA, for example. Looking forward to your robust LFS release. I may look into the ESP8266 OTA firmware upgrade in the meantime. I implemented ESP32 OTA year ago in one of my SDK based projects and it worked so great that I'd love to have it for NodeMCU projects as well. |
Requires 2 MB flash. I've got 1 MB only so I'm stuck with non-OTA firmware upgrades, it seems :) |
@TerryE small Typ here. It is item #816 and #806. @joysfera the developers of ESPEasy have a 2 step OTA mechanism which has an intermediate firmware which is small enough to fit in a fraction of 1 MB and can only load a new firmware which then can be larger than 512 KB again. Maybe that would be a way to go. |
Fixed the typo. The toggling memory map approach is simple and robust but doesn't easily facilitate multiple memory mapped partitions which is what we have with the firmware + SPIFFS. More research is needed and a job for another day. Definitely outside the scope of LFS. |
This issue is getting a bit long, and the LFS patch has been merged. I am therefore closing this and we will use #2413 to track any post-merge discussions. |
New Feature
This issue supersedes #2068, which contains all of the historic discussion. My devLFS branch contains a working version of the functionality described in detail in this LFS whitepaper.
This is simply an Alpha cut so I have committed an as-is snapshot of my system (that is with development options still enabled) and so it is not ready for incorporation into dev, hence this isn't a PR at this stage. However, the top level highlights are as follows:
You can use
luac.cross
to compile your Lua project into an overlay image on your host machine. Once copied to the ESPs SPIFFS, you can then load this into Flash memory and execute Lua modules directly out of this Lua Flash Store (LFS) in just the same way as the Lua Firmware executes from flash memory. I need to benchmark this a bit better but it looks like you can compile projects of up to roughly 5,000 lines of Lua into Flash.You will still be limited by the 48Kb RAM available for data and any (typically in development) Lua modules that you want to load directly from SPIFFS, but this in effect at least doubles the size of Lua application that you can run on the ESP.
This patch was a total bitch to debug, so in developing it I have also had to sort out a number of other issues.
luac.cross
is now just built as part of the standard make, and it doesn't require Lua to be installed on the host.luac.cross
has a couple of new options-f
builds a LFS image and-e
executes a Lua file on the host using the NodeMCU firmware version. (Unlike NodeMCU/Linux development started [announcement] #2278, this only supports the core,io
andos
libraries and but doesn't attempt to support anyapp/modules
libraries. It is really there to do first-pass debugging of the Lua core on the host with a full host debugger support.)step
,next
andcontinue
from breakpoints, as well as examining data in your application, as well enabling lua_asserts to throw you into the debugger, even if you haven't started in debug mode.. See Improving debug / development support in our builds #2146 for more details.I'll do some more tidy up and improve the whitepaper in the next few days, but the reason for this new issue
is to enable a dialogue with the other committers and developers based on the actual code rather than a concept, so that I can sort some basic feedback stuff before raising the PR. Enjoy.
The text was updated successfully, but these errors were encountered: