This CLI tool allows creating GNU ld linker script memory sections via command line.
cargo install ld-memory-cli
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
``` romstart = 0x0; romlength = 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 romstart = 0x80; romlength = 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 romstart = 0x80; romlength = 0xFFF80; emptystart = 0x0; emptylength = 0x0; otherstart = 0x20000; otherlength = 0x2000;
MEMORY { rom : ORIGIN = 0x80, LENGTH = 0xFFF80 empty : ORIGIN = 0x0, LENGTH = 0x0 other : ORIGIN = 0x20000, LENGTH = 0x2000 } ```