From d045f95b5c366e58d94a5f4b475155e7fc1a4c1c Mon Sep 17 00:00:00 2001 From: someone2639 Date: Sat, 18 Sep 2021 23:56:00 -0400 Subject: [PATCH] import map packer script; remove debug print --- tools/mapPacker.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/mapPacker.py diff --git a/tools/mapPacker.py b/tools/mapPacker.py new file mode 100644 index 00000000..d9954522 --- /dev/null +++ b/tools/mapPacker.py @@ -0,0 +1,42 @@ +import sys, struct + +class MapEntry(): + def __init__(self, nm, addr): + self.name = nm + self.addr = addr + self.strlen = (len(nm) + 4) & (~3) + def __str__(self): + return "%s %s %d" % (self.addr, self.name, self.strlen) + def __repr__(self): + return "%s %s %d" % (self.addr, self.name, self.strlen) + + +structDef = ">LLLL" + +symNames = [] + +with open(sys.argv[1]) as f: + for line in f: + if "0x000000008" in line and "=" not in line and "." not in line and "*" not in line and "load address" not in line: + tokens = line.split() + symNames.append(MapEntry(tokens[1], int(tokens[0], 16))) + + + +f1 = open(sys.argv[2], "wb+") +f2 = open(sys.argv[3], "wb+") + +symNames.sort(key=lambda x: x.addr) + +off = 0 +for x in symNames: + f1.write(struct.pack(structDef, x.addr, off, len(x.name), 0)) + f2.write(struct.pack(">%ds" % x.strlen, bytes(x.name, encoding="ascii"))) + off += x.strlen + + +f1.close() +f2.close() + +# print('\n'.join([str(hex(x.addr)) + " " + x.name for x in symNames])) +