Compression of initialized data and/or code for embedded systems.
Project description
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
ASCIZ
statement to specify the name of each section to compress. - Add
BYTE(0)
to mark the end of the list. - Add a
LONG
with the total size of the load memory. - Consume the remaining space of the load memory (optional).
- Remove
AT
statement 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 table marker, don't change */
BYTE(0)
/* indicates the total size to the tool for reporting purposes */
LONG(LENGTH(FLASH))
/* 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.h
inmain.c
.
Build system
- Invoke
leansys.cli
at 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file leaninit-0.0.5.tar.gz
.
File metadata
- Download URL: leaninit-0.0.5.tar.gz
- Upload date:
- Size: 216.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da82533e4fa00c46aebb3e8e49d63c49adad5cca611c8da780b741dd71c5440f |
|
MD5 | 0563e8feba47e09ba3c002a904f7ee7d |
|
BLAKE2b-256 | fc7d9a975c0c0cba2ab62adcfb5ac38358025785f2fc823fd7290120e06946e5 |
Provenance
The following attestation bundles were made for leaninit-0.0.5.tar.gz
:
Publisher:
workflow.yml
on sebastien-riou/lean-init
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
leaninit-0.0.5.tar.gz
- Subject digest:
da82533e4fa00c46aebb3e8e49d63c49adad5cca611c8da780b741dd71c5440f
- Sigstore transparency entry: 160341716
- Sigstore integration time:
- Permalink:
sebastien-riou/lean-init@e72c6124b77d025c426439209e83815a3502987c
- Branch / Tag:
refs/tags/v0.0.5
- Owner: https://github.com/sebastien-riou
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
workflow.yml@e72c6124b77d025c426439209e83815a3502987c
- Trigger Event:
release
- Statement type:
File details
Details for the file leaninit-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: leaninit-0.0.5-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a223f41a773f1ebbe41573e5e133cf54db63a211e37a04fc7403e2a873eb3436 |
|
MD5 | d1d2d5616eeffc58e807cbfd67b3d2e2 |
|
BLAKE2b-256 | 5fbf5b625f4bbf0bbebe75bac5bed456ff316fd051a958fab834ce7a29ddf44f |
Provenance
The following attestation bundles were made for leaninit-0.0.5-py3-none-any.whl
:
Publisher:
workflow.yml
on sebastien-riou/lean-init
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
leaninit-0.0.5-py3-none-any.whl
- Subject digest:
a223f41a773f1ebbe41573e5e133cf54db63a211e37a04fc7403e2a873eb3436
- Sigstore transparency entry: 160341717
- Sigstore integration time:
- Permalink:
sebastien-riou/lean-init@e72c6124b77d025c426439209e83815a3502987c
- Branch / Tag:
refs/tags/v0.0.5
- Owner: https://github.com/sebastien-riou
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
workflow.yml@e72c6124b77d025c426439209e83815a3502987c
- Trigger Event:
release
- Statement type: