8 from collections
import OrderedDict
12 current_path
= os
.path
.abspath(os
.curdir
)
14 # Repositories -------------------------------------------------------------------------------------
16 # name, (url, recursive clone, develop, sha1)
19 ("migen", ("https://github.com/m-labs/", True, True, None)),
20 ("nmigen", ("https://github.com/nmigen/", True, True, None)),
23 ("pythondata-software-compiler_rt", ("https://github.com/litex-hub/", False, True, None)),
24 ("litex", ("https://github.com/enjoy-digital/", False, True, None)),
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)),
39 # LiteX boards support
40 ("litex-boards", ("https://github.com/litex-hub/", False, True, None)),
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-rocket", ("https://github.com/litex-hub/", False, True, None)),
50 ("pythondata-cpu-minerva", ("https://github.com/litex-hub/", False, True, None)),
51 ("pythondata-cpu-microwatt", ("https://github.com/litex-hub/", False, True, 0xa7859fb)),
52 ("pythondata-cpu-blackparrot", ("https://github.com/litex-hub/", False, True, None)),
55 repos
= OrderedDict(repos
)
57 # RISC-V toolchain download ------------------------------------------------------------------------
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-"
64 if (sys
.platform
.startswith("win") or sys
.platform
.startswith("cygwin")):
65 end_file
= "w64-mingw32.zip"
67 elif sys
.platform
.startswith("linux"):
68 end_file
= "linux-ubuntu14.tar.gz"
70 elif sys
.platform
.startswith("darwin"):
71 end_file
= "apple-darwin.tar.gz"
73 raise NotImplementedError(sys
.platform
)
74 fn
= base_file
+ end_file
76 if not os
.path
.exists(fn
):
78 print("Downloading", url
, "to", fn
)
79 urllib
.request
.urlretrieve(url
, fn
)
81 print("Using existing file", fn
)
83 print("Extracting", fn
)
84 shutil
.unpack_archive(fn
)
86 # Setup --------------------------------------------------------------------------------------------
88 if os
.environ
.get("TRAVIS", "") == "true":
89 # Ignore `ssl.SSLCertVerificationError` on CI.
91 ssl
._create
_default
_https
_context
= ssl
._create
_unverified
_context
94 print("Available commands:")
97 print("- install (add --user to install to user directory)")
99 print("- dev (dev mode, disable automatic litex_setup.py update)")
102 # Check/Update litex_setup.py
104 litex_setup_url
= "https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.py"
105 current_sha1
= hashlib
.sha1(open(os
.path
.realpath(__file__
)).read().encode("utf-8")).hexdigest()
106 print("[checking litex_setup.py]...")
109 r
= requests
.get(litex_setup_url
)
110 if r
.status_code
!= 404:
111 upstream_sha1
= hashlib
.sha1(r
.content
).hexdigest()
112 if current_sha1
!= upstream_sha1
:
113 if "dev" not in sys
.argv
[1:]:
114 print("[updating litex_setup.py]...")
115 with
open(os
.path
.realpath(__file__
), "wb") as f
:
117 os
.execl(sys
.executable
, sys
.executable
, *sys
.argv
)
121 # Repositories cloning
122 if "init" in sys
.argv
[1:]:
123 for name
in repos
.keys():
124 os
.chdir(os
.path
.join(current_path
))
125 if not os
.path
.exists(name
):
126 url
, need_recursive
, need_develop
, sha1
= repos
[name
]
127 # clone repo (recursive if needed)
128 print("[cloning " + name
+ "]...")
129 full_url
= url
+ name
130 opts
= "--recursive" if need_recursive
else ""
131 subprocess
.check_call("git clone " + full_url
+ " " + opts
, shell
=True)
133 os
.chdir(os
.path
.join(current_path
, name
))
134 os
.system("git checkout {:7x}".format(sha1
))
136 # Repositories update
137 if "update" in sys
.argv
[1:]:
138 for name
in repos
.keys():
139 os
.chdir(os
.path
.join(current_path
))
140 url
, need_recursive
, need_develop
, sha1
= repos
[name
]
142 if not os
.path
.exists(name
):
143 raise Exception("{} not initialized, please (re)-run init and install first.".format(name
))
145 print("[updating " + name
+ "]...")
146 os
.chdir(os
.path
.join(current_path
, name
))
147 subprocess
.check_call("git checkout master", shell
=True)
148 subprocess
.check_call("git pull --ff-only", shell
=True)
150 os
.chdir(os
.path
.join(current_path
, name
))
151 os
.system("git checkout {:7x}".format(sha1
))
153 # Repositories installation
154 if "install" in sys
.argv
[1:]:
155 for name
in repos
.keys():
156 os
.chdir(os
.path
.join(current_path
))
157 url
, need_recursive
, need_develop
, sha1
= repos
[name
]
159 print("[installing " + name
+ "]...")
161 os
.chdir(os
.path
.join(current_path
, name
))
162 if "--user" in sys
.argv
[1:]:
163 subprocess
.check_call("python3 setup.py develop --user", shell
=True)
165 subprocess
.check_call("python3 setup.py develop", shell
=True)
167 if "--user" in sys
.argv
[1:]:
168 if ".local/bin" not in os
.environ
.get("PATH", ""):
169 print("Make sure that ~/.local/bin is in your PATH")
170 print("export PATH=$PATH:~/.local/bin")
172 # RISC-V GCC installation
173 if "gcc" in sys
.argv
[1:]:
174 os
.chdir(os
.path
.join(current_path
))
175 sifive_riscv_download()
176 if "riscv64" not in os
.environ
.get("PATH", ""):
177 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
178 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")