diff --git a/litex/soc/integration/common.py b/litex/soc/integration/common.py index dcc18fdc1..15acc31a0 100644 --- a/litex/soc/integration/common.py +++ b/litex/soc/integration/common.py @@ -20,11 +20,13 @@ def get_version(with_time=True): return datetime.datetime.fromtimestamp(time.time()).strftime(fmt) def get_mem_data(filename_or_regions, endianness="big", mem_size=None): - # create memory regions + # Create memory regions. if isinstance(filename_or_regions, dict): regions = filename_or_regions else: filename = filename_or_regions + if not os.path.isfile(filename): + raise OSError(f"Unable to find {filename} memory content file.") _, ext = os.path.splitext(filename) if ext == ".json": f = open(filename, "r") @@ -33,9 +35,11 @@ def get_mem_data(filename_or_regions, endianness="big", mem_size=None): else: regions = {filename: "0x00000000"} - # determine data_size + # Determine data_size. data_size = 0 for filename, base in regions.items(): + if not os.path.isfile(filename): + raise OSError(f"Unable to find {filename} memory content file.") data_size = max(int(base, 16) + os.path.getsize(filename), data_size) assert data_size > 0 if mem_size is not None: @@ -43,7 +47,7 @@ def get_mem_data(filename_or_regions, endianness="big", mem_size=None): "file is too big: {}/{} bytes".format( data_size, mem_size)) - # fill data + # Fill data. data = [0]*math.ceil(data_size/4) for filename, base in regions.items(): with open(filename, "rb") as f: