Skip to content
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

Evaluate compressing the wifi firmware #4

Open
peterharperuk opened this issue Jul 7, 2022 · 3 comments
Open

Evaluate compressing the wifi firmware #4

peterharperuk opened this issue Jul 7, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@peterharperuk
Copy link
Collaborator

It looks like we could save ~85KB of flash memory if we compressed the wifi firmware binary. Evaluate if the code size, run time overhead is worth it.

@peterharperuk peterharperuk added the enhancement New feature or request label Jul 7, 2022
@peterharperuk peterharperuk self-assigned this Jul 7, 2022
@dpgeorge
Copy link

dpgeorge commented Jul 7, 2022

It would be great if a compressed version of the firmware could be sent over SPI to the 43439, so it's faster to copy. But I don't think that's possible, the base firmware on that chip doesn't support any compression. So the benefit would just be smaller firmware (which is still a good benefit).

As for runtime overhead, I don't think it will be much. The time for downloading the firmware is dominated by the SPI transfer.

@dpgeorge
Copy link

dpgeorge commented Jul 7, 2022

MicroPython includes a decent gunzip implementation, but for good compression it requires a lot of RAM for the decompression dictionary. One would need to tune the dictionary window size to trade off compression size and RAM usage.

@kripton
Copy link

kripton commented Jul 7, 2022

I think @peterharperuk meant to pre-compress the firmware files before including them into the build and then de-compressing them on-the-fly directly buffer-by-buffer before sending them via SPI to the cyw-chip (instead of doing the compression on the uC before sending. That would also not reduce the firmware size). So the RAM usage needed for compression doesn't matter much since it's on a PC, not the uC.

Here are some compression numbers (file size in byte - file name):

225240  43439A0-7.95.49.00.combined
139024  43439A0-7.95.49.00.combined.br
140996  43439A0-7.95.49.00.combined.gz
164856  43439A0-7.95.49.00.combined.lz4
122820  43439A0-7.95.49.00.combined.xz
137444  43439A0-7.95.49.00.combined.zopfli
146782  43439A0-7.95.49.00.combined.zst
426094  4343WA1-7.45.98.50.combined
282192  4343WA1-7.45.98.50.combined.br
286309  4343WA1-7.45.98.50.combined.gz
330717  4343WA1-7.45.98.50.combined.lz4
249680  4343WA1-7.45.98.50.combined.xz
279263  4343WA1-7.45.98.50.combined.zopfli
304148  4343WA1-7.45.98.50.combined.zst

with .br being Brotli (https://github.com/google/brotli)
.gz being gzip -9
.lz4 being LZ4 -9
.xz being XZ (you don't want to decompress that on a RP2040, just for comparison)
.zopfli (https://github.com/google/zopfli) generates a data stream that can be decompressed using gzip/zlib/deflate but is smaller and much slower to compress. Paramter --i1000 was used and it took some time to compress ;)
.zst being ZStandard

Most of the formats can be decompressed on the rp2040 (excluding xz, see https://github.com/kripton/rp2040-compressiontest), however I would personally chose zopfli for the offline/pre-compression and the existing gunzip to decompress on the rp2040 right before sending the file over SPI

peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Oct 17, 2022
The driver calls cyw43_wifi_firmware_details to get details of the
firware binary. This is defined in wifi_firmware_43439.h which could
in theory be replaced at build time.

If CYW43_STREAM_FIRMWARE is true, cyw43_stream_wifi_firmware_start is
called to start streaming firmware. cyw43_stream_wifi_firmware_next is
called repeatedly to load 64 byte blocks of firmware data to be sent
to the wifi chip.
cyw43_stream_wifi_firmware_end is called at the end of the process.

Firmware is now decompressed from a gzip file using these methods.
See cyw43_decompress_wifi_firmware_start etc.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Oct 17, 2022
The driver calls cyw43_wifi_firmware_details to get details of the
firware binary. This is defined in wifi_firmware_43439.h which could
in theory be replaced at build time.

If CYW43_STREAM_FIRMWARE is true, cyw43_stream_wifi_firmware_start is
called to start streaming firmware. cyw43_stream_wifi_firmware_next is
called repeatedly to load 64 byte blocks of firmware data to be sent
to the wifi chip.
cyw43_stream_wifi_firmware_end is called at the end of the process.

Firmware is now decompressed from a gzip file using these methods.
See cyw43_decompress_wifi_firmware_start etc.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Nov 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Nov 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Nov 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Nov 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Nov 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Dec 22, 2022
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Jan 5, 2023
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Feb 16, 2023
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
peterharperuk added a commit to peterharperuk/cyw43-driver that referenced this issue Mar 14, 2023
Refactor the driver to call wifi_fw_funcs to get functions to load
firmware data. If CYW43_DECOMPRESS_FIRMWARE is true it will load
gzip compressed firmware using uzlib.

The driver calls cyw43_wifi_firmware_details to get details of the
firmware.

Fixes georgerobotics#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants