Skip to content

Compress firmware and self-extract on boot#604

Open
danngreen wants to merge 46 commits into
mainfrom
self-extracting-lz4
Open

Compress firmware and self-extract on boot#604
danngreen wants to merge 46 commits into
mainfrom
self-extracting-lz4

Conversation

@danngreen

Copy link
Copy Markdown
Member

Firmware uimg file is built normally, and then a separate project compresses it with LZ4 and tacks on a small stub that decompresses it. The whole package is then given a uimg header so the mp1-boot bootloader recognizes it and loads it as an executable. At that point the startup stub decompresses the image to a high address in RAM, and then walks the uimg headers just as mp1-boot would do, copying the images to the right place.
While the MMU is used, the state of the MMU and caches is restored after it's done, but before it jumps to the actual firmware entry point.

This is required now because the internal NOR flash chip only has 9.5MB allocated for firmware. We have been > 9.0MB for several versions now.

danngreen added 30 commits July 8, 2026 23:02
- newlib wrapper functions for free/free_r/realloc/realloc_r that check ptr and route
…a instead

TLSF cannot easily be forced to align to > sizeof(void*), so instead we
just force alignment in plugin arena
Catches OOM in plugin's init() and also in loading the metadata.
OOM in allocating space for the assets and/or the .so code are caught elsewhere
They are just printed to console, so a fatal error could cause a crash.
Because the preview buffer is shared between pages
-AbortRescue holds the jmp_buf, activates it when a context calls "arm()"
-One AbortRescue can be active per context (previous one is swapped back in when one is destructed)
-Disabled if malloc or tslf arena lock is held (hard crash if exception throws inside malloc/tslf alloc)
-
If the module crashes/oom in its constructor, then we'll catch the abort()
danngreen added 16 commits July 21, 2026 06:43
Firmware uiimg is built normally, and then compressed with l4z. Then a
small stub is prepended which contains the basic start code to launch a
decompressor. This whole package is then given a uimg header and
released.
MP1-boot will load the compressed uimg to 0xCC000040 and run the stub,
which decompressed to 0xD0000000. Then the uimg headers are walked and
copied to the right places
Prevents blanking the splash image out when proper firmware starts up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant