Skip to main content

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 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.h in main.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

leaninit-0.0.7.tar.gz (217.0 kB view details)

Uploaded Source

Built Distribution

leaninit-0.0.7-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file leaninit-0.0.7.tar.gz.

File metadata

  • Download URL: leaninit-0.0.7.tar.gz
  • Upload date:
  • Size: 217.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for leaninit-0.0.7.tar.gz
Algorithm Hash digest
SHA256 566524dab601a591f4e74ba668c08b743080814561bcea315d7201c7e78e07fc
MD5 7a88f16aa3c3b16064ae129c8f48b809
BLAKE2b-256 c1c0a86c0290300ccb2b41e5b8242b58215a2ef5d4a5f73dfaf6f3733056fb0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for leaninit-0.0.7.tar.gz:

Publisher: workflow.yml on sebastien-riou/lean-init

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leaninit-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: leaninit-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for leaninit-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7719e5971e9c877ea9a6fed8bbe0a6172f986595e54f7b16627af68b1994af7f
MD5 03317b29060f2f7a0b4c40dd9e221b82
BLAKE2b-256 07561d70b49447ecda31785322d33cfc52a72ce5ce66fb38afe32f9903f6a457

See more details on using hashes here.

Provenance

The following attestation bundles were made for leaninit-0.0.7-py3-none-any.whl:

Publisher: workflow.yml on sebastien-riou/lean-init

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page