From: Benjamin Herrenschmidt Date: Fri, 22 May 2020 07:53:20 +0000 (+1000) Subject: csr: Fix definition(s) of CSR_BASE in generated headers X-Git-Tag: 24jan2021_ls180~270 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c78caeb998156fcb9dc050c60df702cb786e2514;p=litex.git csr: Fix definition(s) of CSR_BASE in generated headers CSR_BASE is currently defined twice. Once in mem.h as the base of the CSR region in the SoC address space, and once in csr.h as the base address for all CSRs. This fixes two issues with those definitions: - The mem.h one is unconditional which prevents an external redefinition (which is useful under some circumstances such as when using an address decoder outside of LiteX with a standalone core). - The csr.h one is actually the origin of the first CSR region rather than the origin of the CSR region in the SoC space. They are usually the same ... unless you don't have CSR bank 0 in which case the csr.h one becomes different. This causes conflicts with the mem.h definition and breaks projects using a standalone cores. The first one is fixed by adding the #ifndef/#endif around the definition of the memory regions, the second one by passing the csr_base to use to get_csr_header() Signed-off-by: Benjamin Herrenschmidt --- diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 2c3044d2..ef7e45e6 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -136,8 +136,11 @@ class Builder: export.get_soc_header(self.soc.constants)) write_to_file( os.path.join(self.generated_dir, "csr.h"), - export.get_csr_header(self.soc.csr_regions, - self.soc.constants) + export.get_csr_header( + regions = self.soc.csr_regions, + constants = self.soc.constants, + csr_base = self.soc.mem_regions['csr'].origin + ) ) write_to_file( os.path.join(self.generated_dir, "git.h"), diff --git a/litex/soc/integration/export.py b/litex/soc/integration/export.py index ed827ed5..ebf12555 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -118,8 +118,10 @@ def get_mem_header(regions): r = generated_banner("//") r += "#ifndef __GENERATED_MEM_H\n#define __GENERATED_MEM_H\n\n" for name, region in regions.items(): + r += "#ifndef {name}\n".format(name=name.upper()) r += "#define {name}_BASE 0x{base:08x}L\n#define {name}_SIZE 0x{size:08x}\n\n".format( name=name.upper(), base=region.origin, size=region.length) + r += "#endif\n" r += "#endif\n" return r