soc: improve log colors on error reporting

This commit is contained in:
Florent Kermarrec 2020-02-11 16:24:57 +01:00
parent b22d2ca02b
commit 5f9946085b
1 changed files with 100 additions and 66 deletions

View File

@ -109,23 +109,26 @@ class SoCBusHandler(Module):
# Check Standard # Check Standard
if standard not in self.supported_standard: if standard not in self.supported_standard:
self.logger.error("Unsupported Standard: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {}, supporteds: {:s}".format(
colorer(standard, color="red"), colorer("Bus standard", color="red"),
colorer(", ".join(self.supported_standard), color="green"))) colorer(standard),
colorer(", ".join(self.supported_standard))))
raise raise
# Check Data Width # Check Data Width
if data_width not in self.supported_data_width: if data_width not in self.supported_data_width:
self.logger.error("Unsupported Data_Width: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {}, supporteds: {:s}".format(
colorer(data_width, color="red"), colorer("Data Width", color="red"),
colorer(", ".join(str(x) for x in self.supported_data_width), color="green"))) colorer(data_width),
colorer(", ".join(str(x) for x in self.supported_data_width))))
raise raise
# Check Address Width # Check Address Width
if address_width not in self.supported_address_width: if address_width not in self.supported_address_width:
self.logger.error("Unsupported Address Width: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {}, supporteds: {:s}".format(
colorer(data_width, color="red"), colorer("Address Width", color="red"),
colorer(", ".join(str(x) for x in self.supported_address_width), color="green"))) colorer(data_width),
colorer(", ".join(str(x) for x in self.supported_address_width))))
raise raise
# Create Bus # Create Bus
@ -161,11 +164,12 @@ class SoCBusHandler(Module):
self.io_regions[name] = region self.io_regions[name] = region
overlap = self.check_regions_overlap(self.io_regions) overlap = self.check_regions_overlap(self.io_regions)
if overlap is not None: if overlap is not None:
self.logger.error("IO Region overlap between {} and {}:".format( self.logger.error("IO Region {} between {} and {}:".format(
colorer(overlap[0], color="red"), colorer("overlap", color="red"),
colorer(overlap[1], color="red"))) colorer(overlap[0]),
self.logger.error(str(self.regions[overlap[0]])) colorer(overlap[1])))
self.logger.error(str(self.regions[overlap[1]])) self.logger.error(str(self.io_regions[overlap[0]]))
self.logger.error(str(self.io_regions[overlap[1]]))
raise raise
self.logger.info("{} Region {} {}.".format( self.logger.info("{} Region {} {}.".format(
colorer(name, color="underline"), colorer(name, color="underline"),
@ -182,18 +186,19 @@ class SoCBusHandler(Module):
else: else:
if not region.cached: if not region.cached:
if not self.check_region_is_io(region): if not self.check_region_is_io(region):
self.logger.error("{} Region {}: {}".format( self.logger.error("{} Region {}: {}.".format(
colorer(name, color="red"), colorer(name),
colorer("not cached but not in IO region", color="red"), colorer("not in IO region", color="red"),
str(region))) str(region)))
self.logger.error(self) self.logger.error(self)
raise raise
self.regions[name] = region self.regions[name] = region
overlap = self.check_regions_overlap(self.regions) overlap = self.check_regions_overlap(self.regions)
if overlap is not None: if overlap is not None:
self.logger.error("Region overlap between {} and {}:".format( self.logger.error("Region {} between {} and {}:".format(
colorer(overlap[0], color="red"), colorer("overlap", color="red"),
colorer(overlap[1], color="red"))) colorer(overlap[0]),
colorer(overlap[1])))
self.logger.error(str(self.regions[overlap[0]])) self.logger.error(str(self.regions[overlap[0]]))
self.logger.error(str(self.regions[overlap[1]])) self.logger.error(str(self.regions[overlap[1]]))
raise raise
@ -202,7 +207,7 @@ class SoCBusHandler(Module):
colorer("allocated" if allocated else "added", color="cyan" if allocated else "green"), colorer("allocated" if allocated else "added", color="cyan" if allocated else "green"),
str(region))) str(region)))
else: else:
self.logger.error("{} is not a supported Region".format(colorer(name, color="red"))) self.logger.error("{} is not a supported Region.".format(colorer(name, color="red")))
raise raise
def alloc_region(self, name, size, cached=True): def alloc_region(self, name, size, cached=True):
@ -233,7 +238,7 @@ class SoCBusHandler(Module):
# If no overlap, the Candidate is selected # If no overlap, the Candidate is selected
return candidate return candidate
self.logger.error("Not enough Address Space to allocate Region") self.logger.error("Not enough Address Space to allocate Region.")
raise raise
def check_regions_overlap(self, regions, check_linker=False): def check_regions_overlap(self, regions, check_linker=False):
@ -287,7 +292,9 @@ class SoCBusHandler(Module):
if name is None: if name is None:
name = "master{:d}".format(len(self.masters)) name = "master{:d}".format(len(self.masters))
if name in self.masters.keys(): if name in self.masters.keys():
self.logger.error("{} already declared as Bus Master:".format(colorer(name, color="red"))) self.logger.error("{} {} as Bus Master:".format(
colorer(name),
colorer("already declared", color="red")))
self.logger.error(self) self.logger.error(self)
raise raise
master = self.add_adapter(name, master) master = self.add_adapter(name, master)
@ -300,21 +307,26 @@ class SoCBusHandler(Module):
no_name = name is None no_name = name is None
no_region = region is None no_region = region is None
if no_name and no_region: if no_name and no_region:
self.logger.error("Please specify at least {} or {} of Bus Slave".format( self.logger.error("Please {} {} or/and {} of Bus Slave.".format(
colorer("name", color="red"), colorer("specify", color="red"),
colorer("region", color="red"))) colorer("name"),
colorer("region")))
raise raise
if no_name: if no_name:
name = "slave{:d}".format(len(self.slaves)) name = "slave{:d}".format(len(self.slaves))
if no_region: if no_region:
region = self.regions.get(name, None) region = self.regions.get(name, None)
if region is None: if region is None:
self.logger.error("Unable to find Region {}".format(colorer(name, color="red"))) self.logger.error("{} Region {}.".format(
colorer(name),
colorer("not found", color="red")))
raise raise
else: else:
self.add_region(name, region) self.add_region(name, region)
if name in self.slaves.keys(): if name in self.slaves.keys():
self.logger.error("{} already declared as Bus Slave:".format(colorer(name, color="red"))) self.logger.error("{} {} as Bus Slave:".format(
colorer(name),
colorer("already declared", color="red")))
self.logger.error(self) self.logger.error(self)
raise raise
slave = self.add_adapter(name, slave) slave = self.add_adapter(name, slave)
@ -358,11 +370,13 @@ class SoCLocHandler(Module):
allocated = False allocated = False
if not (use_loc_if_exists and name in self.locs.keys()): if not (use_loc_if_exists and name in self.locs.keys()):
if name in self.locs.keys(): if name in self.locs.keys():
self.logger.error("{} {} name already used.".format(colorer(name, "red"), self.name)) self.logger.error("{} {} name {}.".format(
colorer(name), self.name, colorer("already used", color="red")))
self.logger.error(self) self.logger.error(self)
raise raise
if n in self.locs.values(): if n in self.locs.values():
self.logger.error("{} {} Location already used.".format(colorer(n, "red"), self.name)) self.logger.error("{} {} Location {}.".format(
colorer(n), self.name, colorer("already used", color="red")))
self.logger.error(self) self.logger.error(self)
raise raise
if n is None: if n is None:
@ -370,15 +384,17 @@ class SoCLocHandler(Module):
n = self.alloc(name) n = self.alloc(name)
else: else:
if n < 0: if n < 0:
self.logger.error("{} {} Location should be positive.".format( self.logger.error("{} {} Location should be {}.".format(
colorer(n, color="red"), colorer(n),
self.name)) self.name,
colorer("positive", color="red")))
raise raise
if n > self.n_locs: if n > self.n_locs:
self.logger.error("{} {} Location too high (Up to {}).".format( self.logger.error("{} {} Location {} than maximum: {}.".format(
colorer(n, color="red"), colorer(n),
self.name, self.name,
colorer(self.n_csrs, color="green"))) colorer("higher", color="red"),
colorer(self.n_locs)))
raise raise
self.locs[name] = n self.locs[name] = n
else: else:
@ -422,35 +438,40 @@ class SoCCSRHandler(SoCLocHandler):
# Check Data Width # Check Data Width
if data_width not in self.supported_data_width: if data_width not in self.supported_data_width:
self.logger.error("Unsupported data_width: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {}, supporteds: {:s}".format(
colorer(data_width, color="red"), colorer("Data Width", color="red"),
colorer(", ".join(str(x) for x in self.supported_data_width), color="green"))) colorer(data_width),
colorer(", ".join(str(x) for x in self.supported_data_width))))
raise raise
# Check Address Width # Check Address Width
if address_width not in self.supported_address_width: if address_width not in self.supported_address_width:
self.logger.error("Unsupported address_width: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {} supporteds: {:s}".format(
colorer(address_width, color="red"), colorer("Address Width", color="red"),
colorer(", ".join(str(x) for x in self.supported_address_width), color="green"))) colorer(address_width),
colorer(", ".join(str(x) for x in self.supported_address_width))))
raise raise
# Check Alignment # Check Alignment
if alignment not in self.supported_alignment: if alignment not in self.supported_alignment:
self.logger.error("Unsupported alignment: {} supporteds: {:s}".format( self.logger.error("Unsupported {}: {} supporteds: {:s}".format(
colorer(alignment, color="red"), colorer("Alignment", color="red"),
colorer(", ".join(str(x) for x in self.supported_alignment), color="green"))) colorer(alignment),
colorer(", ".join(str(x) for x in self.supported_alignment))))
raise raise
if data_width > alignment: if data_width > alignment:
self.logger.error("Alignment ({}) should be >= data_width ({})".format( self.logger.error("Alignment ({}) {} Data Width ({})".format(
colorer(alignment, color="red"), colorer(alignment),
colorer(data_width, color="red"))) colorer("should be >=", color="red"),
colorer(data_width)))
raise raise
# Check Paging # Check Paging
if paging not in self.supported_paging: if paging not in self.supported_paging:
self.logger.error("Unsupported paging: {} supporteds: {:s}".format( self.logger.error("Unsupported {} {}, supporteds: {:s}".format(
colorer(paging, color="red"), colorer("Paging", color="red"),
colorer(", ".join(str(x) for x in self.supported_paging), color="green"))) colorer(paging),
colorer(", ".join(str(x) for x in self.supported_paging))))
raise raise
# Create CSR Handler # Create CSR Handler
@ -478,15 +499,17 @@ class SoCCSRHandler(SoCLocHandler):
if name is None: if name is None:
name = "master{:d}".format(len(self.masters)) name = "master{:d}".format(len(self.masters))
if name in self.masters.keys(): if name in self.masters.keys():
self.logger.error("{} already declared as CSR Master:".format(colorer(name, color="red"))) self.logger.error("{} {} as CSR Master:".format(
colorer(name),
colorer("already declared", color="red")))
self.logger.error(self) self.logger.error(self)
raise raise
if master.data_width != self.data_width: if master.data_width != self.data_width:
self.logger.error("{} Master/Handler data_width {} ({} vs {}).".format( self.logger.error("{} Master/Handler Data Width {} ({} vs {}).".format(
colorer(name), colorer(name),
colorer("missmatch"), colorer("missmatch", color="red"),
colorer(master.data_width, color="red"), colorer(master.data_width),
colorer(self.data_width, color="red"))) colorer(self.data_width)))
raise raise
self.masters[name] = master self.masters[name] = master
self.logger.info("{} {} as CSR Master.".format( self.logger.info("{} {} as CSR Master.".format(
@ -503,7 +526,10 @@ class SoCCSRHandler(SoCLocHandler):
if memory is not None: if memory is not None:
name = name + "_" + memory.name_override name = name + "_" + memory.name_override
if self.locs.get(name, None) is None: if self.locs.get(name, None) is None:
self.logger.error("Undefined {} CSR.".format(colorer(name, color="red"))) self.logger.error("CSR {} {}.".format(
colorer(name),
colorer("not found", color="red")))
self.logger.error(self)
raise raise
return self.locs[name] return self.locs[name]
@ -653,13 +679,17 @@ class SoC(Module):
# SoC Helpers ---------------------------------------------------------------------------------- # SoC Helpers ----------------------------------------------------------------------------------
def check_if_exists(self, name): def check_if_exists(self, name):
if hasattr(self, name): if hasattr(self, name):
self.logger.error("{} SubModule already declared.".format(colorer(name, "red"))) self.logger.error("{} SubModule already {}.".format(
colorer(name),
colorer("declared", color="red")))
raise raise
def add_constant(self, name, value=None): def add_constant(self, name, value=None):
name = name.upper() name = name.upper()
if name in self.constants.keys(): if name in self.constants.keys():
self.logger.error("{} Constant already declared.".format(colorer(name, "red"))) self.logger.error("{} Constant already {}.".format(
colorer(name),
colorer("declared", color="red")))
raise raise
self.constants[name] = SoCConstant(value) self.constants[name] = SoCConstant(value)
@ -704,9 +734,10 @@ class SoC(Module):
def add_cpu(self, name="vexriscv", variant="standard", reset_address=None): def add_cpu(self, name="vexriscv", variant="standard", reset_address=None):
if name not in cpu.CPUS.keys(): if name not in cpu.CPUS.keys():
self.logger.error("{} CPU not supported, supporteds: {}".format( self.logger.error("{} CPU {}, supporteds: {}".format(
colorer(name, color="red"), colorer(name),
colorer(", ".join(cpu.CPUS.keys()), color="green"))) colorer("not supported", color="red"),
colorer(", ".join(cpu.CPUS.keys()))))
raise raise
# Add CPU # Add CPU
self.submodules.cpu = cpu.CPUS[name](self.platform, variant) self.submodules.cpu = cpu.CPUS[name](self.platform, variant)
@ -796,8 +827,9 @@ class SoC(Module):
if not isinstance(self.cpu, cpu.CPUNone): if not isinstance(self.cpu, cpu.CPUNone):
for name in ["rom", "sram"]: for name in ["rom", "sram"]:
if name not in self.bus.regions.keys(): if name not in self.bus.regions.keys():
self.logger.error("CPU needs {} Region to be defined as Bus or Linker Region.".format( self.logger.error("CPU needs {} Region to be {} as Bus or Linker Region.".format(
colorer(name, color="red"))) colorer(name),
colorer("defined", color="red")))
self.logger.error(self.bus) self.logger.error(self.bus)
raise raise
@ -810,8 +842,10 @@ class SoC(Module):
if hasattr(self, name): if hasattr(self, name):
module = getattr(self, name) module = getattr(self, name)
if not hasattr(module, "ev"): if not hasattr(module, "ev"):
self.logger.error("No EventManager found on {} SubModule".format( self.logger.error("EventManager {} in {} SubModule.".format(
colorer(name, color="red"))) colorer("not found", color="red"),
colorer(name)))
raise
self.comb += self.cpu.interrupt[loc].eq(module.ev.irq) self.comb += self.cpu.interrupt[loc].eq(module.ev.irq)
self.add_constant(name + "_INTERRUPT", loc) self.add_constant(name + "_INTERRUPT", loc)