Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update us symbol addrs #1138

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions tools/update_symbol_addrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import sys
import tqdm
from mapfile_parser import MapFile, Symbol

script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = script_dir + "/../"
Expand Down Expand Up @@ -38,42 +39,22 @@ def read_ignores():


def scan_map():
ram_offset = None
cur_file = "<no file>"
prev_line = ""
with open(map_path) as f:
for line in f:
if "load address" in line:
ram = int(line[16 : 16 + 18], 0)
rom = int(line[59 : 59 + 18], 0)
ram_offset = ram - rom
continue

prev_line = line

if ram_offset is None or "=" in line or "*fill*" in line or " 0x" not in line:
continue

ram = int(line[16 : 16 + 18], 0)
rom = ram - ram_offset
sym = line.split()[-1]

if "0x" in sym:
ram_offset = None
continue
elif "/" in sym:
cur_file = sym
continue
mapfile = MapFile()
mapfile.readMapFile(map_path)

map_symbols[sym] = (rom, cur_file, ram)
for segment in mapfile._segmentsList:
for file in segment._filesList:
for symbol in file._symbols:
map_symbols[symbol.name] = (symbol.vrom, file.getName(), symbol.vram)


def read_symbol_addrs():
unique_lines = set()

with open(symbol_addrs_path, "r") as f:
for line in f.readlines():
unique_lines.add(line)
if line != "\n":
unique_lines.add(line)

for line in unique_lines:
if "_ROM_START" in line or "_ROM_END" in line:
Expand Down Expand Up @@ -154,7 +135,10 @@ def read_elf():
if name in map_symbols:
rom = map_symbols[name][0]
elif re.match(".*_[0-9A-F]{8}_[0-9A-F]{6}", name):
rom = int(name.split("_")[-1], 16)
try:
rom = int(name.split("_")[-1], 16)
except ValueError:
pass

elf_symbols.append((name, addr, type, rom))

Expand Down Expand Up @@ -215,7 +199,7 @@ def write_new_symbol_addrs():
with open(symbol_addrs_path, "w", newline="\n") as f:
for symbol in sorted(symbol_addrs, key=lambda x: (x[3] == -1, x[3], x[1], x[0])):
line = f"{symbol[0]} = 0x{symbol[1]:X}; //"
if symbol[2] and len(symbol[2]) > 0:
if symbol[2] and len(symbol[2]) > 0 and symbol[2] != "data":
line += f" type:{symbol[2]}"
if symbol[3] >= 0:
line += f" rom:0x{symbol[3]:X}"
Expand All @@ -225,7 +209,7 @@ def write_new_symbol_addrs():
f.write(line + "\n")
for symbol in sorted(dead_symbols, key=lambda x: (x[3] == -1, x[3], x[1], x[0])):
line = f"{symbol[0]} = 0x{symbol[1]:X}; //"
if symbol[2] and len(symbol[2]) > 0:
if symbol[2] and len(symbol[2]) > 0 and symbol[2] != "data":
line += f" type:{symbol[2]}"
if symbol[3] >= 0:
line += f" rom:0x{symbol[3]:X}"
Expand Down
Loading
Loading