From cbe91bcd418fac2b3a82b2f4f3e565c360750784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Thu, 21 May 2020 16:18:34 +0200 Subject: [PATCH] modules: add function for parsing SPD EEPROM dumps from BIOS firmware --- litedram/modules.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/litedram/modules.py b/litedram/modules.py index dbc63f4..9f02df5 100644 --- a/litedram/modules.py +++ b/litedram/modules.py @@ -158,6 +158,27 @@ class DDR3SPDData: raise ValueError("Transfer rate = {:.2f} does not correspond to any DDR3 speedgrade" .format(freq_mhz)) +def parse_spd_hexdump(filename): + """Parse data dumped using the `spdread` command in LiteX BIOS + + This will read files in format: + Memory dump: + 0x00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................ + 0x00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................ + """ + data = [] + last_addr = -1 + with open(filename) as f: + for line in f: + if line.startswith("0x"): + tokens = line.strip().split() + addr = int(tokens[0], 16) + assert addr > last_addr + values = [int(v, 16) for v in tokens[1:17]] + data.extend(values) + last_addr = addr + return data + # SDRAMModule -------------------------------------------------------------------------------------- class SDRAMModule: