Getting Detailed Information of MCU Memory Usage from .map File

.map file, generated from GCC-toolchain, has almost all information needed to find memory usage in details. Symbols, including functions and variables, with memory address, size and memory section name that holds this symbol can be found there and much more.

We can find in .map file for example:

Memory Configuration

Name             Origin             Length             Attributes
FLASH            0x0001f000         0x00055ffc         xr
FIRTRUN          0x00074ffc         0x00000004         r
RAM              0x20002560         0x0000d7a0         xrw
NOINIT           0x2000fd00         0x00000300         xrw
*default*        0x00000000         0xffffffff

    .bss :
    {
        . = ALIGN(4);
        __bss_start__ = .;
        *(.bss*)
        *(COMMON)
        . = ALIGN(4);
        __bss_end__ = .;
    } > RAM

The snippet above means that linker will assign current program counter value to __bss_start__  then fill the section as needed with variables and then supply the end address (PC) to __bss_end__  . We will find that in .map file, but instead of the dot we will find the real start and end address of bss section.
....
0x20002ca4 __bss_start__ = .
....
0x2000e7a8 __bss_end__ = .
....

From the points above, I found .map file has all information needed to find memory usage statistics, so I made a draft for Python script to scan .map file for these useful information mentioned above. The idea started with me while I was debugging my code functions size using nm tool with .out file, but I felt that more information can be obtained from .map file.

This script searches in .map file for information related to memory usage. User has to change settings in the associated file “map_settings.txt” to set:

....
*(.dtors)
*(.rodata*)

KEEP(*(.eh_frame*))
....

that was part from linker script. (.eh_frame) is the unique keyword that makes the map_file_analyzer.py knows where (.rodata) ends.

Script in Action

Download the script form Github repository. Note: More powerful .map file analyzing tools are there like MapViewer and AMAP.

 

Exit mobile version