litex/litex_setup.py

148 lines
5.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
import subprocess
2020-04-06 20:45:55 -04:00
import shutil
from collections import OrderedDict
import urllib.request
current_path = os.path.dirname(os.path.realpath(__file__))
# Repositories -------------------------------------------------------------------------------------
# name, (url, recursive clone, develop)
repos = [
2019-08-26 03:27:19 -04:00
# HDL
2020-04-06 19:49:52 -04:00
("migen", ("https://github.com/m-labs/", True, True)),
2019-08-26 03:27:19 -04:00
# LiteX SoC builder
2020-02-23 17:19:12 -05:00
('litex-data-software-compiler_rt', ("https://github.com/litex-hub/", False, True)),
("litex", ("https://github.com/enjoy-digital/", False, True)),
2019-08-26 03:27:19 -04:00
# LiteX cores ecosystem
2019-10-04 04:00:45 -04:00
("liteeth", ("https://github.com/enjoy-digital/", False, True)),
("litedram", ("https://github.com/enjoy-digital/", False, True)),
("litepcie", ("https://github.com/enjoy-digital/", False, True)),
("litesata", ("https://github.com/enjoy-digital/", False, True)),
("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
("litevideo", ("https://github.com/enjoy-digital/", False, True)),
("litescope", ("https://github.com/enjoy-digital/", False, True)),
("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
2020-03-30 07:37:34 -04:00
("litespi", ("https://github.com/litex-hub/", False, True)),
2019-08-26 03:27:19 -04:00
# LiteX boards support
2020-04-06 19:49:52 -04:00
("litex-boards", ("https://github.com/litex-hub/", False, True)),
# Optional LiteX data
2020-02-23 17:19:12 -05:00
("litex-data-cpu-blackparrot", ("https://github.com/litex-hub/", False, True)),
("litex-data-cpu-mor1kx", ("https://github.com/litex-hub/", False, True)),
("litex-data-cpu-lm32", ("https://github.com/litex-hub/", False, True)),
("litex-data-cpu-microwatt", ("https://github.com/litex-hub/", False, True)),
("litex-data-cpu-picorv32", ("https://github.com/litex-hub/", False, True)),
("litex-data-cpu-rocket", ("https://github.com/litex-hub/", False, True)),
2020-02-23 17:54:07 -05:00
("litex-data-cpu-vexriscv", ("https://github.com/litex-hub/", False, True)),
2020-02-23 17:19:12 -05:00
("litex-data-misc-tapcfg", ("https://github.com/litex-hub/", False, True)),
]
repos = OrderedDict(repos)
# RISC-V toolchain download ------------------------------------------------------------------------
def sifive_riscv_download():
base_url = "https://static.dev.sifive.com/dev-tools/"
base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
# Windows
if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
end_file = "w64-mingw32.zip"
# Linux
elif sys.platform.startswith("linux"):
end_file = "linux-ubuntu14.tar.gz"
# Mac OS
elif sys.platform.startswith("darwin"):
end_file = "apple-darwin.tar.gz"
else:
raise NotImplementedError(sys.platform)
fn = base_file + end_file
if not os.path.exists(fn):
url = base_url + fn
print("Downloading", url, "to", fn)
urllib.request.urlretrieve(url, fn)
else:
print("Using existing file", fn)
print("Extracting", fn)
2020-04-06 20:45:55 -04:00
shutil.unpack_archive(fn)
# Setup --------------------------------------------------------------------------------------------
if os.environ.get("TRAVIS", "") == "true":
2020-04-06 20:36:09 -04:00
# Ignore `ssl.SSLCertVerificationError` on CI.
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
if len(sys.argv) < 2:
print("Available commands:")
print("- init")
print("- install (add --user to install to user directory)")
print("- update")
print("- gcc")
exit()
# Repositories cloning
if "init" in sys.argv[1:]:
os.chdir(os.path.join(current_path))
for name in repos.keys():
url, need_recursive, need_develop = repos[name]
# clone repo (recursive if needed)
print("[cloning " + name + "]...")
full_url = url + name
opts = "--recursive" if need_recursive else ""
subprocess.check_call(
"git clone " + full_url + " " + opts,
shell=True)
# Repositories installation
if "install" in sys.argv[1:]:
for name in repos.keys():
url, need_recursive, need_develop = repos[name]
# develop if needed
print("[installing " + name + "]...")
if need_develop:
os.chdir(os.path.join(current_path, name))
if "--user" in sys.argv[1:]:
subprocess.check_call(
"python3 setup.py develop --user",
shell=True)
else:
subprocess.check_call(
"python3 setup.py develop",
shell=True)
os.chdir(os.path.join(current_path))
if "--user" in sys.argv[1:]:
if ".local/bin" not in os.environ.get("PATH", ""):
print("Make sure that ~/.local/bin is in your PATH")
print("export PATH=$PATH:~/.local/bin")
# Repositories update
if "update" in sys.argv[1:]:
for name in repos.keys():
# update
print("[updating " + name + "]...")
os.chdir(os.path.join(current_path, name))
subprocess.check_call(
"git pull",
shell=True)
os.chdir(os.path.join(current_path))
# RISC-V GCC installation
if "gcc" in sys.argv[1:]:
sifive_riscv_download()
if "riscv64" not in os.environ.get("PATH", ""):
print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")