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