nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.63k stars 3.12k forks source link

Added node API to allow in place firmware uprade #2606

Closed TerryE closed 2 years ago

TerryE commented 5 years ago

Missing feature

(This FR replaces #1496.) At the moment there is no facility for remote upgrade of the Lua Firmware.

Justification

Currently Lua applications can be field upgraded by updating the SPIFFS and LFS. However there is no functionality on the ESP8266 to similarly upgrade the firmware, so we can't update libraries or introduce new firmware functionality. We should provide Lua developers with the ability to remotely upgrade firmware on ESP8266 devices.

There are broadly two approaches to implementing this functionality.

Workarounds

Devices must be upgraded by a field visit.

Proposed Approach

My suggested functionally the same approach as with LFS reload, only by moving the code into a pre_load stub, there is nothing preventing this also being used to load the firmware itself.

If we go to this approach then I suggest that we move the LFS reflash into this pre-init and unify the two lots of code. The main reason that I would like to do this is that the LFS deflate format is differs from RFC 1951 in one annoying aspect: The RFC stipulates a 32Kb dictionary and on top of this I need another 3 × 2Kb buffers and I can't guarantee that I can map these at our current entry point so I have dropped the dictionary size back down to a non-standard 16Kb. This means that whilst you can use the standard inflate (gzip) library and utilities host-side to inflate LFS images, I can't use the same standard deflate libraries as these will use a 32Kb dictionary which craters as runtime.

I have though of using alternative approaches such as switching to a 16Kb ICACHE for the LFS unpack as this would release another 16Kb of RAM buffers for the dictionary. But more though on this is needed.

marcelstoer commented 5 years ago

This FR replaces #1496.

I'd rather not keep around both then, no?

djphoenix commented 5 years ago

What happens when power fails during unpack? Some fallback? Or stuck in-the-middle with required repair with PC?

marcelstoer commented 5 years ago

Hint for anyone interested in OTA... A Mongoose architect wrote an eye-opening (for me) article about things to consider if you want to do OTA reliably: https://www.embedded.com/design/prototyping-and-development/4443082/Updating-firmware-reliably

TerryE commented 5 years ago

What happens when power fails during unpack? Some fallback? Or stuck in-the-middle with required repair with PC?

Yuri,I have been doing this crap for decades, so I am not about to start making beginners mistakes :smile:

Have a review of the LFS code, for example. Your Qs are entirely valid, but I have also already discussed and addressed most of these points. The one failure mode that we would be vulnerable to using is that the new firmware image isn't functional, and this could be mitigated in a number of ways and we should certainly discuss and agree which is the most appropriate.

TerryE commented 5 years ago

A Mongoose architect wrote an eye-opening (for me) article.

Thanks Marcel, this is a good into for the sort of issues that you need to address, but nothing new for me in this case.

Yes, this sort of stuff is complicated but it is not new to IoT devices. Just remember that the guys who wrote the S/W for the Apollo programme computers had less total processing capacity on the Command Module and LEM than in a single ESP826, but they still faced the same sorts of issues.

I would ask all reviewers to focus on specific functional issues at this stage, and accept that the implementers are competent at the basic technologies. An example of a functional issue here is the implementation of reversion images, do we:

Also even if we do facilitate image automated image reversion, establishing a simple and robust algo for triggering this isn't easy.

marcelstoer commented 5 years ago

nothing new for me in this case

I know 😉

dtran123 commented 5 years ago

Having a rollback scenario would be nice indeed but beggers are not choosers. If we have the ability to upgrade forward reliably, I'd be happy with that. Support for rollback could be a subsequent enhancement. Presumably the "new" build has been tested at length before being deployed. Though, there will be unforseen obscure edge cases where a device could end up bricked under the specific conditions despite all the code reviews and QA testing.

TerryE commented 5 years ago

Done in SDK 3.0 tranche 2 update.

TerryE commented 4 years ago

Not sure why I closed this one. It wasn't part of SDK 3.0 tranche 2

stale[bot] commented 3 years ago

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.

KT819GM commented 3 years ago

Don't even think about that, 'stale bot'

TerryE commented 2 years ago

@KT819GM Modestas, in the current environment and developer resourcing, I can't see us getting around to this so I don't think it sensible to leave an aspirational issue open. Feel free to reopen it if you can identify a realistic development resource.