Esempio n. 1
0
    def _generate_includes(self):
        cpu_type = self.soc.cpu_type
        memory_regions = self.soc.get_memory_regions()
        flash_boot_address = getattr(self.soc, "flash_boot_address", None)
        shadow_base = getattr(self.soc, "shadow_base", None)
        csr_regions = self.soc.get_csr_regions()
        constants = self.soc.get_constants()

        buildinc_dir = os.path.join(self.output_dir, "software", "include")
        generated_dir = os.path.join(buildinc_dir, "generated")
        os.makedirs(generated_dir, exist_ok=True)

        if cpu_type is not None:
            variables_contents = []

            def define(k, v):
                variables_contents.append("{}={}\n".format(
                    k, _makefile_escape(v)))

            for k, v in cpu_interface.get_cpu_mak(self.soc.cpu,
                                                  self.compile_software):
                define(k, v)
            # Distinguish between LiteX and MiSoC.
            define("LITEX", "1")
            # Distinguish between applications running from main RAM and
            # flash for user-provided software packages.
            exec_profiles = {"COPY_TO_MAIN_RAM": "0", "EXECUTE_IN_PLACE": "0"}
            if "main_ram" in (m[0] for m in memory_regions):
                exec_profiles["COPY_TO_MAIN_RAM"] = "1"
            else:
                exec_profiles["EXECUTE_IN_PLACE"] = "1"
            for k, v in exec_profiles.items():
                define(k, v)
            define("SOC_DIRECTORY", soc_directory)
            variables_contents.append("export BUILDINC_DIRECTORY\n")
            define("BUILDINC_DIRECTORY", buildinc_dir)
            for name, src_dir in self.software_packages:
                define(name.upper() + "_DIRECTORY", src_dir)
            write_to_file(os.path.join(generated_dir, "variables.mak"),
                          "".join(variables_contents))
            write_to_file(os.path.join(generated_dir, "output_format.ld"),
                          cpu_interface.get_linker_output_format(self.soc.cpu))
            write_to_file(os.path.join(generated_dir, "regions.ld"),
                          cpu_interface.get_linker_regions(memory_regions))
        write_to_file(
            os.path.join(generated_dir, "mem.h"),
            cpu_interface.get_mem_header(memory_regions, flash_boot_address,
                                         shadow_base))
        write_to_file(os.path.join(generated_dir, "csr.h"),
                      cpu_interface.get_csr_header(csr_regions, constants))
        write_to_file(os.path.join(generated_dir, "git.h"),
                      cpu_interface.get_git_header())

        if isinstance(self.soc, soc_sdram.SoCSDRAM):
            if hasattr(self.soc, "sdram"):
                write_to_file(
                    os.path.join(generated_dir, "sdram_phy.h"),
                    get_sdram_phy_c_header(
                        self.soc.sdram.controller.settings.phy,
                        self.soc.sdram.controller.settings.timing))
Esempio n. 2
0
    def _generate_includes(self):
        cpu_type = self.soc.cpu_type
        memory_regions = self.soc.get_memory_regions()
        flash_boot_address = getattr(self.soc, "flash_boot_address", None)
        csr_regions = self.soc.get_csr_regions()
        constants = self.soc.get_constants()

        buildinc_dir = os.path.join(self.output_dir, "software", "include")
        generated_dir = os.path.join(buildinc_dir, "generated")
        os.makedirs(generated_dir, exist_ok=True)

        variables_contents = []
        def define(k, v):
            variables_contents.append("{}={}\n".format(k, _makefile_escape(v)))
        for k, v in cpu_interface.get_cpu_mak(self.soc.cpu):
            define(k, v)
        # Distinguish between LiteX and MiSoC.
        define("LITEX", "1")
        # Distinguish between applications running from main RAM and
        # flash for user-provided software packages.
        exec_profiles = {
            "COPY_TO_MAIN_RAM" : "0",
            "EXECUTE_IN_PLACE" : "0"
        }
        if "main_ram" in (m[0] for m in memory_regions):
            exec_profiles["COPY_TO_MAIN_RAM"] = "1"
        else:
            exec_profiles["EXECUTE_IN_PLACE"] = "1"
        for k, v in exec_profiles.items():
            define(k, v)
        define("SOC_DIRECTORY", soc_directory)
        variables_contents.append("export BUILDINC_DIRECTORY\n")
        define("BUILDINC_DIRECTORY", buildinc_dir)
        for name, src_dir in self.software_packages:
            define(name.upper() + "_DIRECTORY", src_dir)
        write_to_file(
            os.path.join(generated_dir, "variables.mak"),
            "".join(variables_contents))

        write_to_file(
            os.path.join(generated_dir, "output_format.ld"),
            cpu_interface.get_linker_output_format(self.soc.cpu))
        write_to_file(
            os.path.join(generated_dir, "regions.ld"),
            cpu_interface.get_linker_regions(memory_regions))

        write_to_file(
            os.path.join(generated_dir, "mem.h"),
            cpu_interface.get_mem_header(memory_regions, flash_boot_address))
        write_to_file(
            os.path.join(generated_dir, "csr.h"),
            cpu_interface.get_csr_header(csr_regions, constants))

        if isinstance(self.soc, soc_sdram.SoCSDRAM):
            if hasattr(self.soc, "sdram"):
                write_to_file(
                    os.path.join(generated_dir, "sdram_phy.h"),
                    sdram_init.get_sdram_phy_c_header(
                        self.soc.sdram.controller.settings.phy,
                        self.soc.sdram.controller.settings.timing))
Esempio n. 3
0
 def generate_software_header(self):
     csr_header = get_csr_header(self.get_csr_regions(),
                                 self.get_constants(),
                                 with_access_functions=False,
                                 with_shadow_base=False)
     tools.write_to_file(
         os.path.join("software", "pcie", "kernel", "csr.h"), csr_header)
Esempio n. 4
0
    def _generate_includes(self):
        os.makedirs(self.include_dir, exist_ok=True)
        os.makedirs(self.generated_dir, exist_ok=True)

        if self.soc.cpu_type is not None:
            variables_contents = []

            def define(k, v):
                variables_contents.append("{}={}\n".format(
                    k, _makefile_escape(v)))

            for k, v in cpu_interface.get_cpu_mak(self.soc.cpu,
                                                  self.compile_software):
                define(k, v)
            # Distinguish between LiteX and MiSoC.
            define("LITEX", "1")
            # Distinguish between applications running from main RAM and
            # flash for user-provided software packages.
            exec_profiles = {"COPY_TO_MAIN_RAM": "0", "EXECUTE_IN_PLACE": "0"}
            if "main_ram" in self.soc.mem_regions.keys():
                exec_profiles["COPY_TO_MAIN_RAM"] = "1"
            else:
                exec_profiles["EXECUTE_IN_PLACE"] = "1"
            for k, v in exec_profiles.items():
                define(k, v)
            define("SOC_DIRECTORY", soc_directory)
            variables_contents.append("export BUILDINC_DIRECTORY\n")
            define("BUILDINC_DIRECTORY", self.include_dir)
            for name, src_dir in self.software_packages:
                define(name.upper() + "_DIRECTORY", src_dir)

            write_to_file(os.path.join(self.generated_dir, "variables.mak"),
                          "".join(variables_contents))
            write_to_file(os.path.join(self.generated_dir, "output_format.ld"),
                          cpu_interface.get_linker_output_format(self.soc.cpu))
            write_to_file(
                os.path.join(self.generated_dir, "regions.ld"),
                cpu_interface.get_linker_regions(self.soc.mem_regions))

        write_to_file(os.path.join(self.generated_dir, "mem.h"),
                      cpu_interface.get_mem_header(self.soc.mem_regions))
        write_to_file(os.path.join(self.generated_dir, "soc.h"),
                      cpu_interface.get_soc_header(self.soc.constants))
        write_to_file(
            os.path.join(self.generated_dir, "csr.h"),
            cpu_interface.get_csr_header(self.soc.csr_regions,
                                         self.soc.constants))
        write_to_file(os.path.join(self.generated_dir, "git.h"),
                      cpu_interface.get_git_header())

        if hasattr(self.soc, "sdram"):
            from litedram.init import get_sdram_phy_c_header
            write_to_file(
                os.path.join(self.generated_dir, "sdram_phy.h"),
                get_sdram_phy_c_header(
                    self.soc.sdram.controller.settings.phy,
                    self.soc.sdram.controller.settings.timing))
Esempio n. 5
0
    def generate_software_header(self):
        csr_header = get_csr_header(self.get_csr_regions(),
                                    self.get_constants(),
                                    with_access_functions=True)
        tools.write_to_file(os.path.join("software/generated/csr.h"), csr_header)

        phy_header = sdram_init.get_sdram_phy_c_header(
                         self.sdram.controller.settings.phy,
                         self.sdram.controller.settings.timing)
        tools.write_to_file(os.path.join("software/generated/sdram_phy.h"), phy_header)
Esempio n. 6
0
    def _generate_includes(self):
        cpu_type = self.soc.cpu_type
        cpu_variant = self.soc.cpu_variant
        memory_regions = self.soc.get_memory_regions()
        flash_boot_address = getattr(self.soc, "flash_boot_address", None)
        csr_regions = self.soc.get_csr_regions()
        constants = self.soc.get_constants()

        buildinc_dir = os.path.join(self.output_dir, "software", "include")
        generated_dir = os.path.join(buildinc_dir, "generated")
        os.makedirs(generated_dir, exist_ok=True)

        variables_contents = []

        def define(k, v):
            variables_contents.append("{}={}\n".format(k, _makefile_escape(v)))

        for k, v in cpu_interface.get_cpu_mak(cpu_type, cpu_variant):
            define(k, v)
        # Distinguish between applications running from main RAM and
        # flash for user-provided software packages.
        if "main_ram" in (m[0] for m in memory_regions):
            define("COPY_TO_MAIN_RAM", "1")
        else:
            define("COPY_TO_MAIN_RAM", "0")
        define("SOC_DIRECTORY", soc_directory)
        variables_contents.append("export BUILDINC_DIRECTORY\n")
        define("BUILDINC_DIRECTORY", buildinc_dir)
        for name, src_dir in self.software_packages:
            define(name.upper() + "_DIRECTORY", src_dir)
        write_to_file(os.path.join(generated_dir, "variables.mak"),
                      "".join(variables_contents))

        write_to_file(os.path.join(generated_dir, "output_format.ld"),
                      cpu_interface.get_linker_output_format(cpu_type))
        write_to_file(os.path.join(generated_dir, "regions.ld"),
                      cpu_interface.get_linker_regions(memory_regions))

        write_to_file(
            os.path.join(generated_dir, "mem.h"),
            cpu_interface.get_mem_header(memory_regions, flash_boot_address))
        write_to_file(os.path.join(generated_dir, "csr.h"),
                      cpu_interface.get_csr_header(csr_regions, constants))

        if isinstance(self.soc, soc_sdram.SoCSDRAM):
            if hasattr(self.soc, "sdram"):
                write_to_file(
                    os.path.join(generated_dir, "sdram_phy.h"),
                    sdram_init.get_sdram_phy_c_header(
                        self.soc.sdram.controller.settings.phy,
                        self.soc.sdram.controller.settings.timing))
Esempio n. 7
0
    def _generate_includes(self):
        cpu_type = self.soc.cpu_type
        memory_regions = self.soc.get_memory_regions()
        flash_boot_address = getattr(self.soc, "flash_boot_address", None)
        csr_regions = self.soc.get_csr_regions()
        constants = self.soc.get_constants()
        if isinstance(self.soc, soc_sdram.SoCSDRAM) and self.soc._sdram_phy:
            sdram_phy_settings = self.soc._sdram_phy[0].settings
        else:
            sdram_phy_settings = None

        buildinc_dir = os.path.join(self.output_dir, "software", "include")
        generated_dir = os.path.join(buildinc_dir, "generated")
        os.makedirs(generated_dir, exist_ok=True)

        variables_contents = []
        def define(k, v):
            variables_contents.append("{}={}\n".format(k, _makefile_escape(v)))
        for k, v in cpu_interface.get_cpu_mak(cpu_type):
            define(k, v)
        define("SOC_DIRECTORY", soc_directory)
        variables_contents.append("export BUILDINC_DIRECTORY\n")
        define("BUILDINC_DIRECTORY", buildinc_dir)
        for name, src_dir in self.software_packages:
            define(name.upper() + "_DIRECTORY", src_dir)
        write_to_file(
            os.path.join(generated_dir, "variables.mak"),
            "".join(variables_contents))

        write_to_file(
            os.path.join(generated_dir, "output_format.ld"),
            cpu_interface.get_linker_output_format(cpu_type))
        write_to_file(
            os.path.join(generated_dir, "regions.ld"),
            cpu_interface.get_linker_regions(memory_regions))

        write_to_file(
            os.path.join(generated_dir, "mem.h"),
            cpu_interface.get_mem_header(memory_regions, flash_boot_address))
        write_to_file(
            os.path.join(generated_dir, "csr.h"),
            cpu_interface.get_csr_header(csr_regions, constants))

        if sdram_phy_settings is not None:
            write_to_file(
                os.path.join(generated_dir, "sdram_phy.h"),
                sdram_init.get_sdram_phy_header(sdram_phy_settings))
Esempio n. 8
0
    def _generate_includes(self):
        cpu_type = self.soc.cpu_type
        memory_regions = self.soc.get_memory_regions()
        flash_boot_address = getattr(self.soc, "flash_boot_address", None)
        csr_regions = self.soc.get_csr_regions()
        constants = self.soc.get_constants()
        if isinstance(self.soc, soc_sdram.SoCSDRAM) and self.soc._sdram_phy:
            sdram_phy_settings = self.soc._sdram_phy[0].settings
        else:
            sdram_phy_settings = None

        buildinc_dir = os.path.join(self.output_dir, "software", "include")
        generated_dir = os.path.join(buildinc_dir, "generated")
        os.makedirs(generated_dir, exist_ok=True)

        variables_contents = []
        def define(k, v):
            variables_contents.append("{}={}\n".format(k, _makefile_escape(v)))
        for k, v in cpu_interface.get_cpu_mak(cpu_type):
            define(k, v)
        define("SOC_DIRECTORY", soc_directory)
        define("BUILDINC_DIRECTORY", buildinc_dir)
        for name, src_dir in self.software_packages:
            define(name.upper() + "_DIRECTORY", src_dir)
        write_to_file(
            os.path.join(generated_dir, "variables.mak"),
            "".join(variables_contents))

        write_to_file(
            os.path.join(generated_dir, "output_format.ld"),
            cpu_interface.get_linker_output_format(cpu_type))
        write_to_file(
            os.path.join(generated_dir, "regions.ld"),
            cpu_interface.get_linker_regions(memory_regions))

        write_to_file(
            os.path.join(generated_dir, "mem.h"),
            cpu_interface.get_mem_header(memory_regions, flash_boot_address))
        write_to_file(
            os.path.join(generated_dir, "csr.h"),
            cpu_interface.get_csr_header(csr_regions, constants))

        if sdram_phy_settings is not None:
            write_to_file(
                os.path.join(generated_dir, "sdram_phy.h"),
                sdram_init.get_sdram_phy_header(sdram_phy_settings))
Esempio n. 9
0
 def generate_software_header(self, filename):
     csr_header = get_csr_header(self.csr_regions,
                                 self.constants,
                                 with_access_functions=False)
     tools.write_to_file(filename, csr_header)
Esempio n. 10
0
 def generate_software_header(self, filename):
     csr_header = get_csr_header(self.get_csr_regions(),
                                 self.get_constants(),
                                 with_access_functions=False,
                                 with_shadow_base=False)
     tools.write_to_file(filename, csr_header)
Esempio n. 11
0
        actions["build-bitstream"] = True
        actions["load-bitstream"] = True

    if actions["build-bitstream"]:
        actions["build-csr-csv"] = True
        actions["build-csr-header"] = True

    if actions["clean"]:
        subprocess.call(["rm", "-rf", "build/*"])

    if actions["build-csr-csv"]:
        csr_csv = cpu_interface.get_csr_csv(csr_regions)
        write_to_file(args.csr_csv, csr_csv)

    if actions["build-csr-header"]:
        csr_header = cpu_interface.get_csr_header(csr_regions,
                                                  soc.get_constants(),
                                                  with_access_functions=False)
        write_to_file(args.csr_header, csr_header)

    if actions["build-bitstream"]:
        build_kwargs = dict((k, autotype(v)) for k, v in args.build_option)
        vns = platform.build(soc, build_name=build_name, **build_kwargs)
        if hasattr(soc, "do_exit") and vns is not None:
            if hasattr(soc.do_exit, '__call__'):
                soc.do_exit(vns)

    if actions["load-bitstream"]:
        prog = platform.create_programmer()
        prog.load_bitstream("build/" + build_name + platform.bitstream_ext)
Esempio n. 12
0
        actions["build-csr-csv"] = True
        actions["build-csr-header"] = True
        actions["build-bitstream"] = True
        actions["load-bitstream"] = True

    if actions["build-bitstream"]:
        actions["build-csr-csv"] = True
        actions["build-csr-header"] = True

    if actions["clean"]:
        subprocess.call(["rm", "-rf", "build/*"])

    if actions["build-csr-csv"]:
        csr_csv = cpu_interface.get_csr_csv(csr_regions)
        write_to_file(args.csr_csv, csr_csv)

    if actions["build-csr-header"]:
        csr_header = cpu_interface.get_csr_header(csr_regions, soc.get_constants(), with_access_functions=False)
        write_to_file(args.csr_header, csr_header)

    if actions["build-bitstream"]:
        build_kwargs = dict((k, autotype(v)) for k, v in args.build_option)
        vns = platform.build(soc, build_name=build_name, **build_kwargs)
        if hasattr(soc, "do_exit") and vns is not None:
            if hasattr(soc.do_exit, "__call__"):
                soc.do_exit(vns)

    if actions["load-bitstream"]:
        prog = platform.create_programmer()
        prog.load_bitstream("build/" + build_name + platform.bitstream_ext)