soc/integration/soc_core: fix get_mem_data when not file is not multiple of 4 bytes
This commit is contained in:
parent
0175f86cb2
commit
78c09125be
|
@ -2,6 +2,7 @@ import os
|
||||||
import struct
|
import struct
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
from migen import *
|
from migen import *
|
||||||
|
@ -58,7 +59,7 @@ def get_mem_data(filename, endianness="big", mem_size=None):
|
||||||
data_size, mem_size))
|
data_size, mem_size))
|
||||||
|
|
||||||
# fill data
|
# fill data
|
||||||
data = [0]*(data_size//4)
|
data = [0]*math.ceil(data_size/4)
|
||||||
for filename, base in regions.items():
|
for filename, base in regions.items():
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -67,7 +68,7 @@ def get_mem_data(filename, endianness="big", mem_size=None):
|
||||||
if not w:
|
if not w:
|
||||||
break
|
break
|
||||||
if len(w) != 4:
|
if len(w) != 4:
|
||||||
for i in range(len(w), 4):
|
for _ in range(len(w), 4):
|
||||||
w += b'\x00'
|
w += b'\x00'
|
||||||
if endianness == "little":
|
if endianness == "little":
|
||||||
data[int(base, 16)//4 + i] = struct.unpack("<I", w)[0]
|
data[int(base, 16)//4 + i] = struct.unpack("<I", w)[0]
|
||||||
|
|
Loading…
Reference in New Issue