Skip to content

nebularnoise/pretty_size

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


pretty-size

human-readable .elf size report, inspired by @wntrblm's fw_size

About The Project

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:

  1. I wanted more stuff (I initially contributed to fw_size to get what I wanted)
  2. A colleague of mine had issues running fw_size because of Python2 / Python3 being a hot mess on their distro
  3. I wanted an excuse to try out the Rust programming language

Built With

Installation

A quick and dirty way :

 cargo install --git https://github.com/nebularnoise/pretty_size

Usage

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

Linker script parsing

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 ldscript-parser crate seemed to not like the 2M/ 64k, etc. syntax (EDIT: actually, ldscript-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

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.

Output example

output.png

License

Distributed under the MIT License. See LICENSE.txt for more information.

About

human-readable .elf size report, inspired by @wntrblm's fw_size

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages