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