blob: c5a8478ab69a338fe46a848b7eff0dd72158f740 [file] [log] [blame]
Jens Wiklander29f1a452014-08-29 08:26:57 +02001#
2# Copyright (c) 2014, Linaro Limited
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8# 1. Redistributions of source code must retain the above copyright notice,
9# this list of conditions and the following disclaimer.
10#
11# 2. Redistributions in binary form must reproduce the above copyright notice,
12# this list of conditions and the following disclaimer in the documentation
13# and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28BEGIN {
29 in_shdr = 0;
30 num_sects = 0;
31}
32
33/Section Headers:/ {
34 in_shdr = 1;
35 next;
36}
37
38/Key to Flags:/ {
39 in_shdr = 0;
40 next;
41}
42
43function add_section(_name, _addr, _offs, _size)
44{
45 sects[num_sects]["name"] = _name;
46 sects[num_sects]["addr"] = strtonum("0x" _addr);
47 sects[num_sects]["offs"] = strtonum("0x" _offs);
48 sects[num_sects]["size"] = strtonum("0x" _size);
49 num_sects++;
50}
51
52{
53 if (in_shdr) {
54 if ($1 == "[")
55 name_offs = 3;
56 else
57 name_offs = 2;
58
59 name = $(name_offs);
60 addr = $(name_offs + 2);
61 offs = $(name_offs + 3);
62 size = $(name_offs + 4);
63 flags = $(name_offs + 6);
64
Jens Wiklander923c1f32015-12-06 11:01:54 +010065 if (flags == "AX" || flags == "WA" || flags == "A" ||
66 flags == "AL") {
Jens Wiklander29f1a452014-08-29 08:26:57 +020067 add_section(name, addr, offs, size);
68 }
69 }
70}
71
72function print_sect(_name, _addr, _size, _round_up, _print_num_pages,
73 #local variables
74 _size_kib, _num_pages)
75{
76 if (_size == 0) {
77 _size_kib = 0;
78 _num_pages = 0;
79 } else {
80 if (_round_up) {
81 _size_kib = (_size - 1) / 1024 + 1;
82 } else {
83 _size_kib = _size / 1024;
84 }
85 _num_pages = (_size - 1) / 4096 + 1;
86 }
87
88
89
90 printf "%-16s", _name;
91 printf " %.8X - %.8X", _addr, _addr + _size;
92 printf " size %.8X %3d KiB", _size, _size_kib
93
94 if (_print_num_pages)
95 printf " %d pages", _num_pages;
96 printf "\n";
97}
98
99END {
100 for (i = 0; i < num_sects; i++ ) {
101 addr = sects[i]["addr"];
102
103 if (addr != 0) {
104 first_addr = addr;
105 break;
106 }
107 }
108
109 last_addr = sects[num_sects - 1]["addr"];
110 last_size = sects[num_sects - 1]["size"];
111 ram_usage = last_addr + last_size - first_addr;
112 print_sect("RAM Usage", first_addr, ram_usage, 1, 1);
113
114 last_addr = 0;
115 last_size = 0;
116
117 for (i = 0; i < num_sects; i++ ) {
118 name = sects[i]["name"];
119 addr = sects[i]["addr"];
120 size = sects[i]["size"];
121
122 if (last_addr != 0 && addr != last_addr + last_size)
123 print_sect("*hole*", last_addr + last_size,
124 addr - (last_addr + last_size), 0, 0);
125 print_sect(name, addr, size, 0, 0);
126 last_addr = addr;
127 last_size = size;
128 }
129}