From c149f3e4ddfd36410be9807ced73876e41adfa60 Mon Sep 17 00:00:00 2001 From: Piotr Wojnarowski Date: Mon, 13 Jun 2022 15:57:40 +0200 Subject: [PATCH] tools/litex_json2renode: Add find_memory_region helper --- litex/tools/litex_json2renode.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/litex/tools/litex_json2renode.py b/litex/tools/litex_json2renode.py index eb4a3b80c..1008366ef 100755 --- a/litex/tools/litex_json2renode.py +++ b/litex/tools/litex_json2renode.py @@ -667,6 +667,28 @@ def filter_memory_regions(raw_regions, alignment=None, autoalign=[]): yield r +def find_memory_region(memory_regions, address): + """ Finds the memory region containing the specified address. + + Args: + memory_regions (list): list of memory regions filtered + with filter_memory_regions + address (int): the address to find + + Returns: + dict or None: the region from `memory_regions` that contains + `address` or None if none of them do + """ + for r in memory_regions: + base, size = r['base'], r['size'] + end = base + size + + if base <= address < end: + return r + + return None + + def generate_resc(csr, args, flash_binaries={}, tftp_binaries={}): """ Generates platform definition.