Skip to content

Commit

Permalink
Verify memory sub-regions
Browse files Browse the repository at this point in the history
Validate memory regions parameters before generating
Renode platform.

The script will check if memory regions have acceptable
size and if they are not overlapping.
  • Loading branch information
mateusz-holenko committed Oct 23, 2019
1 parent 2cb6886 commit ad52a03
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions generate-renode-scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def generate_ethmac(peripheral, **kwargs):
"""
buf = kwargs['buffer']()
phy = kwargs['phy']()

# FIXME: Get litex to generate CSR region size into output information
# currently only a base address is present
phy['size'] = 0x800

result = """
Expand Down Expand Up @@ -336,9 +339,12 @@ def generate_repl():
}
}

for mem_region in configuration.mem_regions.values():
if mem_region['name'] not in non_generated_mem_regions:
result += generate_memory_region(mem_region)
# RISC-V CPU in Renode requires memory region size
# to be a multiple of 4KB - this is a known limitation
# (not a bug) and there are no plans to handle smaller
# memory regions for now
for mem_region in filter_memory_regions(list(configuration.mem_regions.values()), alignment=0x1000):
result += generate_memory_region(mem_region)

result += generate_cpu('cpu_timer' if 'cpu' in configuration.peripherals else None)

Expand All @@ -354,6 +360,39 @@ def generate_repl():
return result


def filter_memory_regions(raw_regions, alignment=None):
""" Filters memory regions skipping those from `non_generated_mem_regions`
list and verifying if they have proper size and do not overlap.
Args:
raw_regions (list): list of memory regions parsed from
the configuration file
alignment (int or None): memory size boundary
Returns:
list: reduced, sorted list of memory regions to be generated
in a repl file
"""
previous_region = None

raw_regions.sort(key=lambda x: x['address'])
for r in raw_regions:
if alignment is not None and r['size'] % alignment != 0:
print('Error: `{}` memory region size ({}) is not aligned to {}'.format(r['name'], hex(r['size']), hex(alignment)))
sys.exit(1)

if previous_region is not None and (previous_region['address'] + previous_region['size']) > (r['address'] + r['size']):
print("Error: detected overlaping memory regions: `{}` and `{}`".format(r['name'], previous_region['name']))
sys.exit(1)

if r['name'] in non_generated_mem_regions:
print('Skipping pre-defined memory region: {}'.format(r['name']))
continue

previous_region = r
yield r


def generate_resc(repl_file, host_tap_interface=None, bios_binary=None, firmware_binary=None):
""" Generates platform definition.
Expand Down

0 comments on commit ad52a03

Please sign in to comment.