Merge pull request #491 from gsomlo/gls-spisd-clusters
[litex.git] / litex_setup.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 import subprocess
6 import shutil
7 from collections import OrderedDict
8
9 import urllib.request
10
11 current_path = os.path.abspath(os.curdir)
12
13
14 # Repositories -------------------------------------------------------------------------------------
15
16 # name, (url, recursive clone, develop)
17 repos = [
18 # HDL
19 ("migen", ("https://github.com/m-labs/", True, True)),
20 ("nmigen", ("https://github.com/nmigen/", True, True)),
21
22 # LiteX SoC builder
23 ("pythondata-software-compiler_rt", ("https://github.com/litex-hub/", False, True)),
24 ("litex", ("https://github.com/enjoy-digital/", False, True)),
25
26 # LiteX cores ecosystem
27 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
28 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
29 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
30 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
31 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
32 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
33 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
34 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
35 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
36 ("litespi", ("https://github.com/litex-hub/", False, True)),
37
38 # LiteX boards support
39 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
40
41 # Optional LiteX data
42 ("pythondata-misc-tapcfg", ("https://github.com/litex-hub/", False, True)),
43 ("pythondata-cpu-lm32", ("https://github.com/litex-hub/", False, True)),
44 ("pythondata-cpu-mor1kx", ("https://github.com/litex-hub/", False, True)),
45 ("pythondata-cpu-picorv32", ("https://github.com/litex-hub/", False, True)),
46 ("pythondata-cpu-serv", ("https://github.com/litex-hub/", False, True)),
47 ("pythondata-cpu-vexriscv", ("https://github.com/litex-hub/", False, True)),
48 ("pythondata-cpu-rocket", ("https://github.com/litex-hub/", False, True)),
49 ("pythondata-cpu-minerva", ("https://github.com/litex-hub/", False, True)),
50 ]
51
52 repos = OrderedDict(repos)
53
54 # RISC-V toolchain download ------------------------------------------------------------------------
55
56 def sifive_riscv_download():
57 base_url = "https://static.dev.sifive.com/dev-tools/"
58 base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
59
60 # Windows
61 if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
62 end_file = "w64-mingw32.zip"
63 # Linux
64 elif sys.platform.startswith("linux"):
65 end_file = "linux-ubuntu14.tar.gz"
66 # Mac OS
67 elif sys.platform.startswith("darwin"):
68 end_file = "apple-darwin.tar.gz"
69 else:
70 raise NotImplementedError(sys.platform)
71 fn = base_file + end_file
72
73 if not os.path.exists(fn):
74 url = base_url + fn
75 print("Downloading", url, "to", fn)
76 urllib.request.urlretrieve(url, fn)
77 else:
78 print("Using existing file", fn)
79
80 print("Extracting", fn)
81 shutil.unpack_archive(fn)
82
83 # Setup --------------------------------------------------------------------------------------------
84
85 if os.environ.get("TRAVIS", "") == "true":
86 # Ignore `ssl.SSLCertVerificationError` on CI.
87 import ssl
88 ssl._create_default_https_context = ssl._create_unverified_context
89
90 if len(sys.argv) < 2:
91 print("Available commands:")
92 print("- init")
93 print("- install (add --user to install to user directory)")
94 print("- update")
95 print("- gcc")
96 exit()
97
98 # Repositories cloning
99 if "init" in sys.argv[1:]:
100 os.chdir(os.path.join(current_path))
101 for name in repos.keys():
102 if not os.path.exists(name):
103 url, need_recursive, need_develop = repos[name]
104 # clone repo (recursive if needed)
105 print("[cloning " + name + "]...")
106 full_url = url + name
107 opts = "--recursive" if need_recursive else ""
108 subprocess.check_call(
109 "git clone " + full_url + " " + opts,
110 shell=True)
111
112 # Repositories installation
113 if "install" in sys.argv[1:]:
114 for name in repos.keys():
115 url, need_recursive, need_develop = repos[name]
116 # develop if needed
117 print("[installing " + name + "]...")
118 if need_develop:
119 os.chdir(os.path.join(current_path, name))
120 if "--user" in sys.argv[1:]:
121 subprocess.check_call(
122 "python3 setup.py develop --user",
123 shell=True)
124 else:
125 subprocess.check_call(
126 "python3 setup.py develop",
127 shell=True)
128 os.chdir(os.path.join(current_path))
129
130 if "--user" in sys.argv[1:]:
131 if ".local/bin" not in os.environ.get("PATH", ""):
132 print("Make sure that ~/.local/bin is in your PATH")
133 print("export PATH=$PATH:~/.local/bin")
134
135 # Repositories update
136 if "update" in sys.argv[1:]:
137 for name in repos.keys():
138 if not os.path.exists(name):
139 raise Exception("{} not initialized, please (re)-run init and install first.".format(name))
140 # update
141 print("[updating " + name + "]...")
142 os.chdir(os.path.join(current_path, name))
143 subprocess.check_call(
144 "git pull --ff-only",
145 shell=True)
146 os.chdir(os.path.join(current_path))
147
148 # RISC-V GCC installation
149 if "gcc" in sys.argv[1:]:
150 sifive_riscv_download()
151 if "riscv64" not in os.environ.get("PATH", ""):
152 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
153 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")