From 88d302d4db4c61890654a0bd12e64b903c0410f3 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 14 Sep 2021 18:08:07 +0200 Subject: [PATCH] soc/alloc_region: Ensure allocated Region is aligned on size. --- litex/soc/integration/soc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 6e8202f20..cc8173522 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -233,13 +233,17 @@ class SoCBusHandler(Module): for _, search_region in search_regions.items(): origin = search_region.origin while (origin + size) < (search_region.origin + search_region.size_pow2): + # Align Origin on Size. + if (origin%size): + origin += (origin - origin%size) + continue # Create a Candidate. candidate = SoCRegion(origin=origin, size=size, cached=cached) overlap = False # Check Candidate does not overlap with allocated existing regions. for _, allocated in self.regions.items(): if self.check_regions_overlap({"0": allocated, "1": candidate}) is not None: - origin = allocated.origin + allocated.size_pow2 + origin += size overlap = True break if not overlap: