soc/integration/csr_bridge: use registered version only when SDRAM is present.
[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-vexriscv-smp",("https://github.com/litex-hub/", True, True, None)),
50 ("pythondata-cpu-rocket", ("https://github.com/litex-hub/", False, True, None)),
51 ("pythondata-cpu-minerva", ("https://github.com/litex-hub/", False, True, None)),
52 ("pythondata-cpu-microwatt", ("https://github.com/litex-hub/", False, True, 0xba76652)),
53 ("pythondata-cpu-blackparrot", ("https://github.com/litex-hub/", False, True, None)),
54 ("pythondata-cpu-cv32e40p", ("https://github.com/litex-hub/", True, True, None)),
55 ]
56
57 repos = OrderedDict(repos)
58
59 # RISC-V toolchain download ------------------------------------------------------------------------
60
61 def sifive_riscv_download():
62 base_url = "https://static.dev.sifive.com/dev-tools/"
63 base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
64
65 # Windows
66 if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
67 end_file = "w64-mingw32.zip"
68 # Linux
69 elif sys.platform.startswith("linux"):
70 end_file = "linux-ubuntu14.tar.gz"
71 # Mac OS
72 elif sys.platform.startswith("darwin"):
73 end_file = "apple-darwin.tar.gz"
74 else:
75 raise NotImplementedError(sys.platform)
76 fn = base_file + end_file
77
78 if not os.path.exists(fn):
79 url = base_url + fn
80 print("Downloading", url, "to", fn)
81 urllib.request.urlretrieve(url, fn)
82 else:
83 print("Using existing file", fn)
84
85 print("Extracting", fn)
86 shutil.unpack_archive(fn)
87
88 # Setup --------------------------------------------------------------------------------------------
89
90 if os.environ.get("TRAVIS", "") == "true":
91 # Ignore `ssl.SSLCertVerificationError` on CI.
92 import ssl
93 ssl._create_default_https_context = ssl._create_unverified_context
94
95 if len(sys.argv) < 2:
96 print("Available commands:")
97 print("- init")
98 print("- update")
99 print("- install (add --user to install to user directory)")
100 print("- gcc")
101 print("- dev (dev mode, disable automatic litex_setup.py update)")
102 exit()
103
104 # Check/Update litex_setup.py
105
106 litex_setup_url = "https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.py"
107 current_sha1 = hashlib.sha1(open(os.path.realpath(__file__)).read().encode("utf-8")).hexdigest()
108 print("[checking litex_setup.py]...")
109 try:
110 import requests
111 r = requests.get(litex_setup_url)
112 if r.status_code != 404:
113 upstream_sha1 = hashlib.sha1(r.content).hexdigest()
114 if current_sha1 != upstream_sha1:
115 if "dev" not in sys.argv[1:]:
116 print("[updating litex_setup.py]...")
117 with open(os.path.realpath(__file__), "wb") as f:
118 f.write(r.content)
119 os.execl(sys.executable, sys.executable, *sys.argv)
120 except:
121 pass
122
123 # Repositories cloning
124 if "init" in sys.argv[1:]:
125 for name in repos.keys():
126 os.chdir(os.path.join(current_path))
127 if not os.path.exists(name):
128 url, need_recursive, need_develop, sha1 = repos[name]
129 # clone repo (recursive if needed)
130 print("[cloning " + name + "]...")
131 full_url = url + name
132 opts = "--recursive" if need_recursive else ""
133 subprocess.check_call("git clone " + full_url + " " + opts, shell=True)
134 if sha1 is not None:
135 os.chdir(os.path.join(current_path, name))
136 os.system("git checkout {:7x}".format(sha1))
137
138 # Repositories update
139 if "update" in sys.argv[1:]:
140 for name in repos.keys():
141 os.chdir(os.path.join(current_path))
142 url, need_recursive, need_develop, sha1 = repos[name]
143 print(url)
144 if not os.path.exists(name):
145 raise Exception("{} not initialized, please (re)-run init and install first.".format(name))
146 # update
147 print("[updating " + name + "]...")
148 os.chdir(os.path.join(current_path, name))
149 subprocess.check_call("git checkout master", shell=True)
150 subprocess.check_call("git pull --ff-only", shell=True)
151 if sha1 is not None:
152 os.chdir(os.path.join(current_path, name))
153 os.system("git checkout {:7x}".format(sha1))
154
155 # Repositories installation
156 if "install" in sys.argv[1:]:
157 for name in repos.keys():
158 os.chdir(os.path.join(current_path))
159 url, need_recursive, need_develop, sha1 = repos[name]
160 # develop if needed
161 print("[installing " + name + "]...")
162 if need_develop:
163 os.chdir(os.path.join(current_path, name))
164 if "--user" in sys.argv[1:]:
165 subprocess.check_call("python3 setup.py develop --user", shell=True)
166 else:
167 subprocess.check_call("python3 setup.py develop", shell=True)
168
169 if "--user" in sys.argv[1:]:
170 if ".local/bin" not in os.environ.get("PATH", ""):
171 print("Make sure that ~/.local/bin is in your PATH")
172 print("export PATH=$PATH:~/.local/bin")
173
174 # RISC-V GCC installation
175 if "gcc" in sys.argv[1:]:
176 os.chdir(os.path.join(current_path))
177 sifive_riscv_download()
178 if "riscv64" not in os.environ.get("PATH", ""):
179 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
180 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")