From: Florent Kermarrec Date: Thu, 25 Apr 2019 21:43:10 +0000 (+0200) Subject: soc/integration/soc_core: fix get_mem_data when not file is not multiple of 4 bytes X-Git-Tag: 24jan2021_ls180~1267 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78c09125beb53a34c6e44b01a9f7da4afd325d24;p=litex.git soc/integration/soc_core: fix get_mem_data when not file is not multiple of 4 bytes --- diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index fba5ada2..6cbd1dff 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("