From f181eabebb6a01b2a171cdcb3abfd18d3232de59 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 2 Apr 2024 09:12:03 +0200 Subject: [PATCH] soc/init_rom: Add SoCError when ROM Size < Contents Size and cosmetic cleanups. --- litex/soc/integration/soc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 8439b97c9..93ae9c297 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -1050,7 +1050,7 @@ class SoC(LiteXModule, SoCCoreCompat): address_width = self.bus.address_width, bursting = self.bus.bursting ) - ram = ram_cls(size, bus=ram_bus, init=contents, read_only=("w" not in mode), name=name) + ram = ram_cls(size, bus=ram_bus, init=contents, read_only=("w" not in mode), name=name) self.bus.add_slave(name=name, slave=ram.bus, region=SoCRegion(origin=origin, size=size, mode=mode)) self.check_if_exists(name) self.logger.info("RAM {} {} {}.".format( @@ -1068,8 +1068,15 @@ class SoC(LiteXModule, SoCCoreCompat): self.logger.info("Initializing ROM {} with contents (Size: {}).".format( colorer(name), colorer(f"0x{4*len(contents):x}"))) + if self.bus.regions[name].size < 4*len(contents): + self.logger.error("Contents Size ({}) {} ROM Size ({}).".format( + colorer(f"0x{4*len(contents):x}"), + colorer("exceeds", color="red"), + colorer(f"0x{self.bus.regions[name].size:x}"), + )) + raise SoCError() getattr(self, name).mem.init = contents - if auto_size and "w" not in self.bus.regions[name].mode: + if auto_size and ("w" not in self.bus.regions[name].mode): self.logger.info("Auto-Resizing ROM {} from {} to {}.".format( colorer(name), colorer(f"0x{self.bus.regions[name].size:x}"),