integration/common/get_mem_data: add support for wider data widths

Currently the code only supports 32/64 bit SoC data width.

Add support for any possible data width that is multiply of 32-bit.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
This commit is contained in:
Icenowy Zheng 2022-11-03 20:20:52 +08:00
parent eb2e9a371d
commit 5ff23066b7
1 changed files with 6 additions and 6 deletions

View File

@ -40,7 +40,7 @@ def get_mem_regions(filename_or_regions, offset):
return regions return regions
def get_mem_data(filename_or_regions, data_width=32, endianness="big", mem_size=None, offset=0): def get_mem_data(filename_or_regions, data_width=32, endianness="big", mem_size=None, offset=0):
assert data_width in [32, 64] assert data_width % 32 == 0
assert endianness in ["big", "little"] assert endianness in ["big", "little"]
# Return empty list if no filename or regions. # Return empty list if no filename or regions.
@ -80,11 +80,11 @@ def get_mem_data(filename_or_regions, data_width=32, endianness="big", mem_size=
"little": "<I", "little": "<I",
"big": ">I" "big": ">I"
}[endianness] }[endianness]
if data_width == 32: data[(base - offset)//bytes_per_data + i] = 0
data[(base - offset)//bytes_per_data + i] = struct.unpack(unpack_order, w)[0] for filled_data_width in range(0, data_width, 32):
if data_width == 64: cur_byte = filled_data_width//8
data[(base - offset)//bytes_per_data + i] = (struct.unpack(unpack_order, w[0:4])[0] << 0) data[(base - offset)//bytes_per_data + i] |= (struct.unpack(unpack_order, w[cur_byte:cur_byte+4])[0] << filled_data_width)
data[(base - offset)//bytes_per_data + i] |= (struct.unpack(unpack_order, w[4:8])[0] << 32) filled_data_width += 32
i += 1 i += 1
return data return data