From 9f40fa68347ca6ace7669d7fe6a2ec08a2e41e3d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 14 Jun 2021 16:03:02 +0200 Subject: [PATCH] elf_mem_map: parse D23 output directly --- tools/elf_mem_map | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/elf_mem_map b/tools/elf_mem_map index 2a7e8c308..b0a7db186 100755 --- a/tools/elf_mem_map +++ b/tools/elf_mem_map @@ -4,6 +4,7 @@ import elftools.elf.elffile import elftools.dwarf.descriptions from collections import namedtuple from struct import unpack +import sys import re SRAM_START = 0x200 @@ -264,12 +265,26 @@ def decode_dump(path): buf_addr = None # starting address buf_data = None # data - for line in fd: - tokens = line.split(maxsplit=1) - if len(tokens) == 0 or tokens[0] == 'ok': - break - elif len(tokens) < 2 or tokens[0] == 'D2': + in_dump = False + for line in enumerate(fd): + line = (line[0], line[1].rstrip()) + tokens = line[1].split(maxsplit=1) + if not in_dump: + if len(tokens) > 0 and tokens[0] in ['D2', 'D23']: + in_dump = True continue + else: + if len(tokens) < 1: + print('malformed line {}: {}'.format(*line), file=sys.stderr) + continue + elif tokens[0] == 'ok': + break + elif tokens[0] == 'reason:': + # ignored + continue + elif not re.match(r'[0-9a-fA-F]', tokens[0]): + print('malformed line {}: {}'.format(*line), file=sys.stderr) + continue addr = int.from_bytes(bytes.fromhex(tokens[0]), 'big') data = bytes.fromhex(tokens[1])