4 releases

0.2.8 Jun 29, 2023
0.2.7 Jun 2, 2023
0.2.6 Jun 2, 2023
0.2.5 Jun 1, 2023

#2 in #ld

30 downloads per month

Apache-2.0 and AGPL-3.0-only

19KB
347 lines

About

This CLI tool allows creating GNU ld linker script memory sections via command line.

Installation

cargo install ld-memory-cli

Usage

ld-memory is supposed to be hooked into your build system. Given the right arguments, it will output a snippet that can be used as part of a GNU ld linker script.

Example:

ld-memory --section rom:0x0:1024K

... outputs

_rom_start = 0x0;
_rom_length = 0x100000;

MEMORY
{
    rom : ORIGIN = 0x0, LENGTH = 0x100000
}

An offset can be specified, which will be added to ORIGIN and subtracted from LENGTH:

❯ ld-memory --section rom:0x0:1024K:128
_rom_start = 0x80;
_rom_length = 0xFFF80;

MEMORY
{
    rom : ORIGIN = 0x80, LENGTH = 0xFFF80
}

Empty field counts as "0". Simple arithmetic is allowed.

❯ ld-memory --section rom:0x0:1024K:128 --section empty:: --section other:0x0+128K:1K+7K
_rom_start = 0x80;
_rom_length = 0xFFF80;
_empty_start = 0x0;
_empty_length = 0x0;
_other_start = 0x20000;
_other_length = 0x2000;

MEMORY
{
    rom : ORIGIN = 0x80, LENGTH = 0xFFF80
    empty : ORIGIN = 0x0, LENGTH = 0x0
    other : ORIGIN = 0x20000, LENGTH = 0x2000
}

Dependencies

~0.8–1.4MB
~28K SLoC