-
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
SPIFFS and LFS-free Fast Lua Source Loader #3117
Comments
@TerryE Terry, why not to store directly the compiled Lua code in |
From my point view of this looks incredible useful feature for something like OTA (or startup failure recovery) implementation where you could do full format of spiffs, download init.lua (or whatever startup type you use), download lfs.img, do restart and reload *.img. |
@vsky279, Funny you should mention that, as I was going through the same thoughts myself. There are two advantages of using the source:
However, the disadvantage of the source is that it needs to be compiled on the ESP to load, and compilation has quite a RAM overhead, limiting the maximum source file that I can load. The current FTP server was really optimised for LFS use, and so is a single 500 line file. It will load and run from RAM but only if it has been first compiled using I've been going through the code looking to see the simplest way to partition it, but at moment it looks as if this is doable and I'll update my gist later today. |
I've also been thinking about something like this. |
@HHHartmann see my last comments. Also the dump format is not the same as the internal binary format. The file format is byte encoded and a lot more dense. Yes there is nothing stopping you putting the binary format into a byte array and directly loading it, but as you say the module would also need the 3 different variants (5.1-float, 5.1-int and 5.3) for the module to be runnable across al 3 platforms. Whatever happens the executing code will still run out of RAM, and so will eat into the ~44kB heap space. If you need a large app then LFS is the only way to achieve this. I am thinking of a different sweet-spot: someone has just download a bare cloudbuilder image and flashed it to an ESP8266 module with no SPIFFS or LFS set up and they want to start FTP'ing or a terminal session into it, etc. In practice this would be in a <restart>, <do something> cycle so as long each "something" fits in RAM it is doable. |
Something like https://github.com/moononournation/nodemcu-webide might be a good candidate -- I haven't tried it, but it would be amazing to bootstrap into it. |
@TerryE Terry, why do you need all different variants. For one specific firmware you need one matching variant which can be built on the fly using luac.cross. No need to embed all three variants in a specific firmware. A bit tricky to convert a binary file in a byte array but its not impossible. I also haven't gotten the part about the different internal byte format. luac.cross can build it as LFS image, so why not as single file format. Or just LFS images for each module. The resulting string might need to be aligned around some word boundaries then. |
Why way the Lua C API works is that there is a high commonality between the APIs if you stick as per the guidelines to
Not really. That's what
I changed the LFS format for Lua 5.3, partly because the LC format itself changed between versions but also to facilitate in-ESP LFS building which I still plan to roll out for 5.3 versions, so LC byte-stream code is 5.1-int, 5.1-float and 5.3 specific. If we changed the make process to build this one module during the make, then maybe we could get away with this, but I for one am not going to make my life difficult by attempting this. Perhaps you can take a look at my implementation and try your own variant. For the avoidance of doubt, there is no readily feasible way that we could include executable Proto + TValue + TString + strt data in a module. Achieving this would be more complex than a fresh LFS implementation.
I am not sure why you say this. The LC format is just a btye stream that Extending the make process to dynamically build modules is a risky path to go down and this increases the complexity of makes for every developer. Bad idea, IMO. |
Terry, thanks for your answer. I will try and understand why this is not going to be an easy task. I seem to have a quite incomplete view of the LFS implementation. I think adding the complexity to dynamically build such modules might well be worth it and not every developer has to deal with it. For the time to be (which might be rather longer or infinite than shorter if I want to get this fixed) your approach seems perfectly fitting and would allow for a startup system which is not dependent on LFS OTA success. |
The ideal of this is that if you have the |
A quick progress update. See my gists fast.c and the conversion utility lua-to-c-include.lua. The conversion utility is documented in code, and the overhead of running it is quite good. This version of the FTP server includes the if FAST then
return setmetatable(FTP,{__index=function(self, name) return fast[name] end})
end Note that the local FAST is set to 1 on all fast loaded source, so the module omits the
A few more i's to dot, and testing shake down before I make the PR. |
If you want to try this out, then my gists include the updated version of
So in my case restarting the ESP and doing this works fine
@nwf @HHHartmann , I would appreciate you guys taking another look and giving me your reactions. Anyone else welcome :) |
It also struck me that most new developers aren't familiar with the more esoteric features such as using |
I've been playing with this a bit more, and I realise that this
|
I am inclined to generate a PR for this one simply because it is such a bloody useful bootstrap for provisioning the ESP: include the module and build the firmware. You can enable ftp with a single typed line, and do all of the provisioning drag and drop from the PC. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
leave open |
NewFeature / Technique
I am not sure whether is an application note or an example of an add-on project but I thought that I should raise this issue to get feedback from the other contributors
Justification
At them moment we need a filesystem in place and some files downloaded to be able to bootstrap up and provision a new module. Whilst this can be done using esptool and other downloaders, these are not project maintained and so for many developers who are tooled up with python, spiffsimg, etc. getting your project bootstrapped can involve some hurdles.
I have been experimenting with an alternative bootstrapping approach that might have some merit (I am actually using it on my automated test harness.) In essence I have taken a set of modules, run them through LuaSrcDiet and then convert the output compressed Lua source a C string and included them into a C module, so that
fast.load('name')
returns an albeit RAM-based modulename
:My current fast module adds about 4Kb to the image. So:
node.startupcommand()
to do this automatically after boot. Sofast.load'telnet'(ssid,pwd)
will start up a telnet server, for example.Squashed Lua is incredibly dense (the C string containing the telnet server is under 1Kb Flash).
At this moment my ideas are very much in a formative stage, but I have floated this for feedback and comment. See my gist Fash Lua module loader.
I am also going to look at adding an FTP implementation, but the current version is really designed to run out of LFS, I need to tweak this to do some lazy loading to reduce the RAM footprint for RAM only running.
The text was updated successfully, but these errors were encountered: