X9D+ 2019 Bootloader: wait needed before detecting trims are pressed
[opentx.git] / tools / extract-map.py
blob95e87ebce092f1db632befc7faa3fd55fce5154e
1 #!/usr/bin/python3
3 import argparse
6 def line_index(lines, start):
7 for i, line in enumerate(lines):
8 if line.startswith(start):
9 return i
12 def extract_vars(lines):
13 result = []
14 lines = lines[line_index(lines, ".data"):line_index(lines, ".memory")]
15 i = 0
16 while i < len(lines):
17 line = lines[i]
18 i += 1
19 if line.startswith("*"):
20 continue
21 if line.startswith(" .data.") or line.startswith(" .bss."):
22 fields = (line + lines[i]).split()
23 # print(fields)
24 i += 1
25 var = fields[0].split(".")[-1]
26 offset = int(fields[1], 16)
27 size = int(fields[2], 16)
28 result.append((var, offset, size))
29 return result
32 def main():
33 parser = argparse.ArgumentParser(description="Extract firmware.map")
34 parser.add_argument("file", type=argparse.FileType("r"))
36 args = parser.parse_args()
38 f = args.file
39 lines = f.readlines()
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__":
48 main()