litex_setup: add nmigen dependency (used to generate Minerva CPU).
[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 ]
50
51 repos = OrderedDict(repos)
52
53 # RISC-V toolchain download ------------------------------------------------------------------------
54
55 def sifive_riscv_download():
56 base_url = "https://static.dev.sifive.com/dev-tools/"
57 base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
58
59 # Windows
60 if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
61 end_file = "w64-mingw32.zip"
62 # Linux
63 elif sys.platform.startswith("linux"):
64 end_file = "linux-ubuntu14.tar.gz"
65 # Mac OS
66 elif sys.platform.startswith("darwin"):
67 end_file = "apple-darwin.tar.gz"
68 else:
69 raise NotImplementedError(sys.platform)
70 fn = base_file + end_file
71
72 if not os.path.exists(fn):
73 url = base_url + fn
74 print("Downloading", url, "to", fn)
75 urllib.request.urlretrieve(url, fn)
76 else:
77 print("Using existing file", fn)
78
79 print("Extracting", fn)
80 shutil.unpack_archive(fn)
81
82 # Setup --------------------------------------------------------------------------------------------
83
84 if os.environ.get("TRAVIS", "") == "true":
85 # Ignore `ssl.SSLCertVerificationError` on CI.
86 import ssl
87 ssl._create_default_https_context = ssl._create_unverified_context
88
89 if len(sys.argv) < 2:
90 print("Available commands:")
91 print("- init")
92 print("- install (add --user to install to user directory)")
93 print("- update")
94 print("- gcc")
95 exit()
96
97 # Repositories cloning
98 if "init" in sys.argv[1:]:
99 os.chdir(os.path.join(current_path))
100 for name in repos.keys():
101 if not os.path.exists(name):
102 url, need_recursive, need_develop = repos[name]
103 # clone repo (recursive if needed)
104 print("[cloning " + name + "]...")
105 full_url = url + name
106 opts = "--recursive" if need_recursive else ""
107 subprocess.check_call(
108 "git clone " + full_url + " " + opts,
109 shell=True)
110
111 # Repositories installation
112 if "install" in sys.argv[1:]:
113 for name in repos.keys():
114 url, need_recursive, need_develop = repos[name]
115 # develop if needed
116 print("[installing " + name + "]...")
117 if need_develop:
118 os.chdir(os.path.join(current_path, name))
119 if "--user" in sys.argv[1:]:
120 subprocess.check_call(
121 "python3 setup.py develop --user",
122 shell=True)
123 else:
124 subprocess.check_call(
125 "python3 setup.py develop",
126 shell=True)
127 os.chdir(os.path.join(current_path))
128
129 if "--user" in sys.argv[1:]:
130 if ".local/bin" not in os.environ.get("PATH", ""):
131 print("Make sure that ~/.local/bin is in your PATH")
132 print("export PATH=$PATH:~/.local/bin")
133
134 # Repositories update
135 if "update" in sys.argv[1:]:
136 for name in repos.keys():
137 if not os.path.exists(name):
138 raise Exception("{} not initialized, please (re)-run init and install first.".format(name))
139 # update
140 print("[updating " + name + "]...")
141 os.chdir(os.path.join(current_path, name))
142 subprocess.check_call(
143 "git pull --ff-only",
144 shell=True)
145 os.chdir(os.path.join(current_path))
146
147 # RISC-V GCC installation
148 if "gcc" in sys.argv[1:]:
149 sifive_riscv_download()
150 if "riscv64" not in os.environ.get("PATH", ""):
151 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
152 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")