lean-init
Compression of initialized data and/or code for embedded systems.
This is tested against:
- arm-none-eabi-gcc-13.2.1-1.1 (ARM Cortex-M33)
- riscv-none-elf-gcc-13.2.0-2 (RISC-V RV32IC)
Features
- Use a fast decompressor (lz4)
- Produce a fully debuggable elf file
- User has full control over what is compressed
Installation
Python package
pipenv shell
pip install leaninit
Native dependencies
The python package relies on lz4 to perform the compression and binutils to parse/edit elf files. Binutils package need to match the target CPU.
How to integrate
LD file
- User add a new section
.leaninit:- It shall be the last section in the load memory.
- Use
ASCIZstatement to specify the name of each section to compress. - Add
BYTE(0)to mark the end of the list. - Add a
LONGwith the total size of the load memory. - Consume the remaining space of the load memory (optional).
- Remove
ATstatement for sections to compress.
Example of .leaninit section:
/* .leaninit: shall be the last section in FLASH */
.leaninit (READONLY): ALIGN(4)
{
__leaninit_table = .;
/*
The tool will replace this with the compressed content.
*/
/* Here we list the sections to compress. You can add more.*/
ASCIZ ".rodata"
ASCIZ ".preinit_array?" /* the final ? mark this section as optional, i.e. the tool won't complain if it is not in the elf file */
ASCIZ ".init_array?"
ASCIZ ".fini_array?"
ASCIZ ".text"
ASCIZ ".data"
/* end of list marker, don't change */
BYTE(0)
/* indicates the total size to the tool for reporting purposes */
LONG(LENGTH(FLASH))
/* Optional: 'footer data', i.e. data to place after compressed section */
LONG(4) /* size of the data: set to 0 if no use */
LONG(4) /* alignement of the data: set to 0 if no use */
LONG(0x12345678) /* Optional: the data */
/* Take all the remaining flash, hoping it is enough */
. = ORIGIN(FLASH)+LENGTH(FLASH);
} > FLASH
Start up file
- Replace uncompressed initialization loop by a call to the compressed initialization function.
C code
- Include
leaninit.hinmain.c.
Build system
- Invoke
leansys.cliat the end of the build to generate the final elf file.
How to test
Native dependencies
The test use Renode.
Launching a test
The testit_env scripts build the python package in an isolated environment and then test the basic example for a particular build preset.
cd examples/basic
./testit_env minSizeRel
Examples overview
basic example
It is a bare metal application which outputs the full text of Saint Exupery's novel "Le petit prince" on a UART.
In this example, we compress the .data section. It contains all initialized variables including the array petitprince.
whole_fw example
It is a bare metal application which outputs the full text of Saint Exupery's novel "Le petit prince" on a UART.
In this example, we compress the whole firmware. Everything is compressed except the startup file and the decompressor. At startup the firmware is decompressed into RAM and executed from there.
Release files for leaninit 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| leaninit-0.0.9.tar.gz | 217.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| leaninit-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 229.2 kB
Release files / leaninit-0.0.9.tar.gz
| Download URL | leaninit-0.0.9.tar.gz |
|---|---|
| Size | 217.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
da2eb3505d4c178dd0c1f58c4141eba1f689829d6594176c38046e77c6623271
|
|
BLAKE2b-256 checksum How to use checksums |
46993d04ababc4ded02ab52fe45bf701e4f8deda3f4b2b84a0976f4afa4d198e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2025.
Transparency logRelease files / leaninit-0.0.9-py3-none-any.whl
| Download URL | leaninit-0.0.9-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1638d8defd474987b6a087ea060e3c7a7a94668b65fa7ff4a7cad0f199c642b1
|
|
BLAKE2b-256 checksum How to use checksums |
86922b4e1306ed152672c69c23df515e4d70c981e2f9e55fb83d713291930c8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2025.
Transparency log