6 def line_index(lines
, start
):
7 for i
, line
in enumerate(lines
):
8 if line
.startswith(start
):
12 def extract_vars(lines
):
14 lines
= lines
[line_index(lines
, ".data"):line_index(lines
, ".memory")]
19 if line
.startswith("*"):
21 if line
.startswith(" .data.") or line
.startswith(" .bss."):
22 fields
= (line
+ lines
[i
]).split()
25 var
= fields
[0].split(".")[-1]
26 offset
= int(fields
[1], 16)
27 size
= int(fields
[2], 16)
28 result
.append((var
, offset
, size
))
33 parser
= argparse
.ArgumentParser(description
="Extract firmware.map")
34 parser
.add_argument("file", type=argparse
.FileType("r"))
36 args
= parser
.parse_args()
41 vars = extract_vars(lines
)
42 vars.sort(key
=lambda var
: "%08d %s" % (var
[2], var
[0]))
43 for var
, offset
, size
in vars:
44 print("%s\t %d" % (var
, size
))
47 if __name__
== "__main__":