ScratchABit: action_goto: Update for picotui 1.1.
[ScratchABit.git] / tools / map2scratchabit.py
blob8c8f8007681a605de1531074ecdf29d859834c8a
2 # Parse mapfile and dump all information collected.
3 # Requires https://github.com/pfalcon/pymapfile .
5 import sys
6 import logging
7 from pprint import pprint
9 from mapfile import GnuMapFile
12 logging.basicConfig(level=logging.DEBUG)
14 f = open(sys.argv[1])
15 m = GnuMapFile(f)
16 m.skip_till_memmap()
17 m.skip_while_lead_space()
18 m.parse_sections()
19 m.validate()
21 basename = sys.argv[1].replace("-", "_").replace(".", "_")
23 with open(basename + ".subareas", "w") as f:
24 print("[subareas]", file=f)
25 for k, addr, sz in m.section_order:
26 #print("%08x %08x %s" % (addr, sz, k))
27 for sec, addr, sz, obj, symbols in m.sections[k]["objects"]:
28 if sec.endswith(".literal"):
29 obj += ".literal"
30 obj = obj.replace(" ", "_")
31 print("%s 0x%08x(0x%08x)" % (obj, addr, sz), file=f)
32 print(file=f)
34 with open(basename + "_script.py", "w") as f:
35 print("""\
36 from idc import *
38 """, file=f)
39 for k, addr, sz in m.section_order:
40 #print("%08x %08x %s" % (addr, sz, k))
41 for sec, addr, sz, obj, symbols in m.sections[k]["objects"]:
42 if obj.endswith(".fill"):
43 print("# %s 0x%08x(0x%08x)" % (obj, addr, sz), file=f)
44 print("MakeAlign(0x%08x, 0x%08x, 0)" % (addr, sz), file=f)
45 print(file=f)