human-readable .elf size report, inspired by @wntrblm's fw_size
This is a shameless rust re-write of the excellent fw_size, written by @wntrblm as part of the wintertools python package.
Here's why:
- I wanted more stuff (I initially contributed to fw_size to get what I wanted)
- A colleague of mine had issues running fw_size because of Python2 / Python3 being a hot mess on their distro
- I wanted an excuse to try out the Rust programming language
A quick and dirty way :
cargo install --git https://github.com/nebularnoise/pretty_size
Here's an example, based on my usage.
pretty_size \
--size-prog ~/dev_tools/arm-none-eabi-size \
--ld STM32H743BITx_FLASH.ld \
-e section_edits.json \
a.elf
Here are the memory regions defined in my linker script.
MEMORY
{
bootloader (rx) : ORIGIN = 0x08000000, LENGTH = 0x20000
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 0x1E0000
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x20000
DMA_RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 0x8000
RAM (xrw) : ORIGIN = 0x24008000, LENGTH = 0x78000
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 0x48000
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 0x10000
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 0x10000
SDRAM (xrw) : ORIGIN = 0xC0000000, LENGTH = 0x2000000
}
This is just to illustrate two things:
Firstly, I had to put all the origin and sizes in hex, as the(EDIT: actually,ldscript-parser
crate seemed to not like the2M
/64k
, etc. syntaxldscript-parser
does not support expressions, so arithmetic in ORIGIN and LENGTH was the culprit.- Secondly, this example will be referenced in the following section.
Section edits allow to groups regions and ignoring sections. They are to be stored in a json file, and passed to pretty-size
with the -e
argument.
Here's an example:
[
{
"GroupRegions": {
"region_to_insert_as_section": "bootloader",
"output_region": "FLASH",
"output_section_name": ".bootloader"
}
},
{
"GroupRegions": {
"region_to_insert_as_section": "DMA_RAM",
"output_region": "RAM",
"output_section_name": ".dma_ram"
}
},
{
"Ignore": {
"region_name": "FLASH",
"section_name_to_ignore": ".padding"
}
}
]
My linker script used a region called bootloader
to define a memory location reserved for the bootloader. In the report, I want to see it in the FLASH
region.
Similarly, I used a region called DMA_RAM
to easily have a range addresses in RAM, on which I could disable caching, which was causing issues with DMA in my project.
Finally, the size
program was showing me the .padding
section I had defined in the linker script, but I don't want to see it in the report.
Distributed under the MIT License. See LICENSE.txt
for more information.