-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add support for compressed ota updates #6614
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
Comments
From #905: The idea was floated at some point to add support for compressed images, i.e.: receive an image that is compressed. The following possibilities for implementation have shown up: Try for full (de)compression, i.e.: deflate, possibly use code from miniz from the flash_stub, which is already known to work on the ESP (because the flash_stub is used by esptool.py). Take the absolute minimum code to deflate and add it to eboot. There is a bit of space left between the end of the eboot bin and the start of the current sketch in the flash. This should be the best solution, because it would allow writing the received image in fully compressed form, then after reboot it could get decompressed on the fly while copying. Also, if the code fits, it would not increase bin size. |
@earlephilhower said: MiniZ inflator alone takes 0x14b2 = 5298 bytes pf code when built with I just patched in a naive version into the bootloader and updated the makefile to
|
@davisonja said: That's a more comprehensive assessment. I commented out the compressor code and built it to get an absolute upper bound, which was about 15k (with eboot, but no optimisations). It seemed like a viable prospect even at that size. |
@earlephilhower said: For eboot, the makefile needs ti go from Then, the problem is that minigz has compress and decompress in one file and the linker will include the entire file even if compression is unused ( Granted, I did not test the resulting ELF, just looked at sizes. The eboot.c might have some code that's busted in a way to require no optimization to work. |
Alright, let's continue the compressed OTA discussion here. |
Is the typical gain in size comparable with the compression levels reported by the flash tool? |
Using the 5.5k miniz would give exactly the same compression as the uploader. The simpler RLE would give about 0 compression on binaries, but close to the same on sparse filesystems. |
While I've certainly encountered obscure optimisation issues with bootloaders in other places, it's been fairly irrelevant for eboot. |
Iirc lzw ends up being fairly small and does better than rle. It's been a while since I built it in C, tho. With only a little thought we should be able to expose inflator code in eboot for use in main code meaning it would save additional space in images. |
Very interesting, lzw |
Just a question/thought I have. Is it only RLE, or is it also using some very basic dictionary and thus able to compress English words/texts by a significant factor? |
@TD-er ... RLE + dictionary ~= LZW. :) I thought zlib was LZW, too, but maybe I'm thinking of original AT&T GNU LD or GCC are not going to do any kind of exe compression like that. The CPU already has variable-length instructions, helping minimize code size vs. a nice, clean, 32b insn word like in the Hennessy and Patterson everyone starts with. There's really no runs of constant values in the executable portion of a binary, so RLE won't affect size there. |
What part of the binary is then compressed/compressible using RLE? |
RLE will compress ~0% of the executable. On a 1MB filesystem with 100k of files, RLE will compress a heck of a lot. zlib/miniz gives maybe 20-30% compression on the binaries, and great #s on a sparse FS (the long runs of 0s will give ~ same as RLE, while the data pages will get whatever miniz can do on them) |
But when I do an OTA of the sketch, I don't have the filesystem included, right? |
esptool uploads a |
eboot currently runs from ram that's how it is able to overwrite itself (which it does as part of every upgrade). I don't have any concerns about adding the inflator to eboot and having everything run as it currently does - unless I've misread something :) |
One issue to keep in mind when doing compressed updates is signed binaries. You have to sign the uncompressed binary and perform the check in Updater.cpp to ensure it's not been tampered with. I suppose it's possible to make signing.py do the actual compression and sign that blob, but then the uploader needs to make sure it doesn't try it again... |
Or you could also sign the compressed one? Another thing to keep in mind is the uncompressed size of the binary, so it may not overwrite the SPIFFS or EEPROM part of the flash layout unintended. |
I'd opt for signing the compressed one. The bootloader should be able to assume the data its dealing with is valid/acceptable. Unless we're looking at making the bootloader a sort of utility library for main code to use we should aim to keep it fairly lightweight and small - so we don't want to be adding signature verification to it. |
What's the status here? can this be closed? |
Yeah, I think this is closed with the commit since OTA is the only way to get a compressed update in flash. |
Forgive me for commenting on a closed issue. I'm trying to get my head around the progress that's been made in the last year that i've been out of the loop. Compression is a brilliant idea but the workflow at the moment seems to be that you have to manually compress it, then sign it if you want that, then upload it. Is there a reason that the uploader (espota.py) cannot support a --compress flag to compress the binary with a menu option in arduino/ flag in pio. There are issues discussing moving to esptool.py which does support compression but having a very superficial look I can't see that, and 1.7.4 just contains esptool no esptool.py. Furthermore would it be possible to have the OTA query the device to see if the updaterClass supports compression eg via the I can open a new issue if desired. |
That is advised. |
A useful improvement to the OTA system would be to transfer the update in a compressed format that is expanded as part of the final flash process.
This issue is to provide a place to discuss, plan and exchange clever ideas.
The very first discussion points appeared initially on #905
The text was updated successfully, but these errors were encountered: