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