1#!/bin/bash
2
3# Exit in error if we use an undefined variable (i.e. commit a typo).
4set -u
5
6function getvar {
7	hex=$(nm $1 | grep -v "U" | grep "$2" |awk '{print "16#" $1 }')
8	echo $(($hex))
9}
10
11
12heap_start=$(getvar $1 __heap_start)
13heap_end=$(getvar $1 __heap_end)
14heap_sz=$(($heap_end-$heap_start))
15
16bss_start=$(getvar $1 __bss_start)
17bss_end=$(getvar $1 __bss_end)
18bss_sz=$(($bss_end-$bss_start))
19
20data_start=$(getvar $1 __data_start)
21data_end=$(getvar $1 __data_end)
22data_sz=$(($data_end-$data_start))
23
24stack_start=$(getvar $1 __stack_bottom)
25stack_end=$(getvar $1 __stack_top)
26stack_sz=$(($stack_end-$stack_start))
27
28code_start=$(getvar $1 __code_start)
29code_end=$(getvar $1 __text_end)
30code_sz=$(($code_end-$code_start))
31
32echo
33echo "SIZES:"
34
35printf "  BSS SIZE:         %6d bytes\n" $bss_sz
36printf "  DATA SIZE:        %6d bytes\n" $data_sz
37printf "  STACK SIZE:       %6d bytes\n" $stack_sz
38printf "  HEAP SIZE:        %6d bytes\n" $heap_sz
39printf "  CODE SIZE:        %6d bytes\n" $code_sz
40
41flash_use=$(($code_sz+$data_sz))
42ram_use=$(($heap_sz+$bss_sz+$data_sz+$stack_sz))
43
44echo
45printf "  OS RAM USE:       %6d bytes\n" $ram_use
46printf "  OS FLASH USE:     %6d bytes\n" $flash_use
47