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