From 78c09125beb53a34c6e44b01a9f7da4afd325d24 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 25 Apr 2019 23:43:10 +0200 Subject: [PATCH] soc/integration/soc_core: fix get_mem_data when not file is not multiple of 4 bytes --- litex/soc/integration/soc_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index fba5ada2c..6cbd1dff4 100644 --- a/litex/soc/integration/soc_core.py +++ b/litex/soc/integration/soc_core.py @@ -2,6 +2,7 @@ import os import struct import inspect import json +import math from operator import itemgetter from migen import * @@ -58,7 +59,7 @@ def get_mem_data(filename, endianness="big", mem_size=None): data_size, mem_size)) # fill data - data = [0]*(data_size//4) + data = [0]*math.ceil(data_size/4) for filename, base in regions.items(): with open(filename, "rb") as f: i = 0 @@ -67,7 +68,7 @@ def get_mem_data(filename, endianness="big", mem_size=None): if not w: break if len(w) != 4: - for i in range(len(w), 4): + for _ in range(len(w), 4): w += b'\x00' if endianness == "little": data[int(base, 16)//4 + i] = struct.unpack("