Beispiel #1
0
 def find_flash_proxy(self):
     # Search in installed flash_proxy_directories
     for d in self.flash_proxy_dirs:
         fulldir = os.path.abspath(os.path.expanduser(d))
         fullname = tools.cygpath(
             os.path.join(fulldir, self.flash_proxy_basename))
         if os.path.exists(fullname):
             return fullname
     # Search in local flash_proxy directory
     fullname = tools.cygpath(
         os.path.join(self.flash_proxy_local, self.flash_proxy_basename))
     if os.path.exists(fullname):
         return fullname
     # Search in repositories and download it
     import requests
     os.makedirs(self.flash_proxy_local, exist_ok=True)
     for d in self.flash_proxy_repos:
         fullname = tools.cygpath(
             os.path.join(self.flash_proxy_local,
                          self.flash_proxy_basename))
         try:
             r = requests.get(d + self.flash_proxy_basename)
             with open(fullname, "wb") as f:
                 f.write(r.content)
             return fullname
         except:
             pass
     raise OSError("Failed to find flash proxy bitstream")
Beispiel #2
0
 def find_flash_proxy(self):
     for d in self.flash_proxy_dirs:
         fulldir = os.path.abspath(os.path.expanduser(d))
         fullname = tools.cygpath(os.path.join(fulldir, self.flash_proxy_basename))
         if os.path.exists(fullname):
             return fullname
     raise OSError("Failed to find flash proxy bitstream")
Beispiel #3
0
def _build_xst_files(device, sources, vincpaths, build_name, xst_opt):
    prj_contents = ""
    for filename, language, library in sources:
        prj_contents += language + " " + library + " " + tools.cygpath(filename) + "\n"
    tools.write_to_file(build_name + ".prj", prj_contents)

    xst_contents = """run
-ifn {build_name}.prj
-top {build_name}
{xst_opt}
-ofn {build_name}.ngc
-p {device}
""".format(build_name=build_name, xst_opt=xst_opt, device=device)
    for path in vincpaths:
        xst_contents += "-vlgincdir " + tools.cygpath(path) + "\n"
    tools.write_to_file(build_name + ".xst", xst_contents)
Beispiel #4
0
 def find_flash_proxy(self):
     for d in self.flash_proxy_dirs:
         fulldir = os.path.abspath(os.path.expanduser(d))
         fullname = tools.cygpath(
             os.path.join(fulldir, self.flash_proxy_basename))
         if os.path.exists(fullname):
             return fullname
     raise OSError("Failed to find flash proxy bitstream")
Beispiel #5
0
def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
        toolchain, platform, ver=None):
    if sys.platform == "win32" or sys.platform == "cygwin":
        source_cmd = "call "
        script_ext = ".bat"
        shell = ["cmd", "/c"]
        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
        fail_stmt = " || exit /b"
    else:
        source_cmd = "source "
        script_ext = ".sh"
        shell = ["bash"]
        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
        fail_stmt = ""
    if source:
        settings = common.settings(ise_path, ver, "ISE_DS")
        build_script_contents += source_cmd + tools.cygpath(settings) + "\n"
    if mode == "edif":
        ext = "edif"
    else:
        ext = "ngc"
        build_script_contents += """
xst -ifn {build_name}.xst{fail_stmt}
"""

    # This generates a .v file for post synthesis simulation
    build_script_contents += """
netgen -ofmt verilog -w -sim {build_name}.{ext} {build_name}_synth.v
"""

    build_script_contents += """
ngdbuild {ngdbuild_opt} -uc {build_name}.ucf {build_name}.{ext} {build_name}.ngd{fail_stmt}
"""
    if mode == "cpld":
        build_script_contents += """
cpldfit -ofmt verilog {par_opt} -p {device} {build_name}.ngd{fail_stmt}
taengine -f {build_name}.vm6 -detail -iopath -l {build_name}.tim{fail_stmt}
hprep6 -s IEEE1532 -i {build_name}.vm6{fail_stmt}
"""
    else:
        build_script_contents += """
map {map_opt} -o {build_name}_map.ncd {build_name}.ngd {build_name}.pcf{fail_stmt}
par {par_opt} {build_name}_map.ncd {build_name}.ncd {build_name}.pcf{fail_stmt}
bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit{fail_stmt}
"""
    build_script_contents = build_script_contents.format(build_name=build_name,
            ngdbuild_opt=ngdbuild_opt, bitgen_opt=toolchain.bitgen_opt, ext=ext,
            par_opt=toolchain.par_opt, map_opt=toolchain.map_opt,
            device=platform.device, fail_stmt=fail_stmt)
    build_script_contents += toolchain.ise_commands.format(build_name=build_name)
    build_script_file = "build_" + build_name + script_ext
    tools.write_to_file(build_script_file, build_script_contents, force_unix=False)
    command = shell + [build_script_file]
    r = tools.subprocess_call_filtered(command, common.colors)
    if r != 0:
        raise OSError("Subprocess failed")
Beispiel #6
0
def _build_xst_files(device, sources, vincpaths, build_name, xst_opt):
    prj_contents = ""
    for filename, language, library in sources:
        prj_contents += language + " " + library + " " + tools.cygpath(filename) + "\n"
    tools.write_to_file(build_name + ".prj", prj_contents)

    xst_contents = """run
-ifn {build_name}.prj
-top {build_name}
{xst_opt}
-ofn {build_name}.ngc
-p {device}
""".format(build_name=build_name, xst_opt=xst_opt, device=device)
    if vincpaths:
        xst_contents += "-vlgincdir {"
        for path in vincpaths:
            xst_contents += tools.cygpath(path) + " "
        xst_contents += "}"
    tools.write_to_file(build_name + ".xst", xst_contents)
Beispiel #7
0
def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
        toolchain, platform, ver=None):
    if sys.platform == "win32" or sys.platform == "cygwin":
        source_cmd = "call "
        script_ext = ".bat"
        shell = ["cmd", "/c"]
        build_script_contents = "@echo off\nrem Autogenerated by Migen\n"
        fail_stmt = " || exit /b"
    else:
        source_cmd = "source "
        script_ext = ".sh"
        shell = ["bash"]
        build_script_contents = "# Autogenerated by Migen\nset -e\n"
        fail_stmt = ""
    if source:
        settings = common.settings(ise_path, ver, "ISE_DS")
        build_script_contents += source_cmd + tools.cygpath(settings) + "\n"
    if mode == "edif":
        ext = "edif"
    else:
        ext = "ngc"
        build_script_contents += """
xst -ifn {build_name}.xst{fail_stmt}
"""

    build_script_contents += """
ngdbuild {ngdbuild_opt} -uc {build_name}.ucf {build_name}.{ext} {build_name}.ngd{fail_stmt}
"""
    if mode == "cpld":
        build_script_contents += """
cpldfit -ofmt verilog {par_opt} -p {device} {build_name}.ngd{fail_stmt}
taengine -f {build_name}.vm6 -detail -iopath -l {build_name}.tim{fail_stmt}
hprep6 -s IEEE1532 -i {build_name}.vm6{fail_stmt}
"""
    else:
        build_script_contents += """
map {map_opt} -o {build_name}_map.ncd {build_name}.ngd {build_name}.pcf{fail_stmt}
par {par_opt} {build_name}_map.ncd {build_name}.ncd {build_name}.pcf{fail_stmt}
bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit{fail_stmt}
"""
    build_script_contents = build_script_contents.format(build_name=build_name,
            ngdbuild_opt=ngdbuild_opt, bitgen_opt=toolchain.bitgen_opt, ext=ext,
            par_opt=toolchain.par_opt, map_opt=toolchain.map_opt,
            device=platform.device, fail_stmt=fail_stmt)
    build_script_contents += toolchain.ise_commands.format(build_name=build_name)
    build_script_file = "build_" + build_name + script_ext
    tools.write_to_file(build_script_file, build_script_contents, force_unix=False)
    command = shell + [build_script_file]
    r = tools.subprocess_call_filtered(command, common.colors)
    if r != 0:
        raise OSError("Subprocess failed")
Beispiel #8
0
 def find_config(self):
     # Search in local directory
     fullname = tools.cygpath(self.config)
     if os.path.exists(fullname):
         return self.config
     # Search in local config directory
     fullname = tools.cygpath(os.path.join(self.prog_local, self.config))
     if os.path.exists(fullname):
         return fullname
     # Search in repositories and download it
     import requests
     os.makedirs(self.prog_local, exist_ok=True)
     for d in self.config_repos:
         fullname = tools.cygpath(os.path.join(self.prog_local, self.config))
         try:
             r = requests.get(d + self.config)
             if r.status_code != 404:
                 with open(fullname, "wb") as f:
                     f.write(r.content)
                 return fullname
         except:
             pass
     raise OSError("Failed to find config file")
Beispiel #9
0
    def build_project(self):
        if self._mode not in ["xst", "cpld"]:
            return ("", "")
        prj_contents = ""
        for filename, language, library, *copy in self.platform.sources:
            prj_contents += language + " " + library + " " + tools.cygpath(
                filename) + "\n"
        tools.write_to_file(self._build_name + ".prj", prj_contents)

        xst_contents = """run
-ifn {build_name}.prj
-top {build_name}
{xst_opt}
-ofn {build_name}.ngc
-p {device}
""".format(build_name=self._build_name,
           xst_opt=self.xst_opt,
           device=self.platform.device)
        if self.platform.verilog_include_paths:
            xst_contents += "-vlgincdir {"
            for path in self.platform.verilog_include_paths:
                xst_contents += tools.cygpath(path) + " "
            xst_contents += "}"
        tools.write_to_file(self._build_name + ".xst", xst_contents)