From c78caeb998156fcb9dc050c60df702cb786e2514 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Fri, 22 May 2020 17:53:20 +1000 Subject: [PATCH] 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 --- litex/soc/integration/builder.py | 7 +++++-- litex/soc/integration/export.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 2c3044d27..ef7e45e6a 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 ed827ed5a..ebf125550 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