2018-07-20 04:11:41 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2020-04-06 14:25:11 -04:00
|
|
|
import subprocess
|
2020-04-06 20:45:55 -04:00
|
|
|
import shutil
|
2020-05-20 03:04:13 -04:00
|
|
|
import hashlib
|
2018-07-20 04:11:41 -04:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
2020-04-06 19:39:49 -04:00
|
|
|
import urllib.request
|
2018-07-20 04:11:41 -04:00
|
|
|
|
2020-02-23 17:58:45 -05:00
|
|
|
current_path = os.path.abspath(os.curdir)
|
2020-09-10 07:19:34 -04:00
|
|
|
# Check location (is litex_setup.py executed inside a cloned LiteX repository or alongside?)
|
|
|
|
if os.path.exists(".gitignore"):
|
|
|
|
current_path = os.path.join(current_path, "../")
|
2020-02-23 17:58:45 -05:00
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# Repositories -------------------------------------------------------------------------------------
|
|
|
|
|
2020-05-19 04:44:36 -04:00
|
|
|
# name, (url, recursive clone, develop, sha1)
|
2018-07-20 04:11:41 -04:00
|
|
|
repos = [
|
2019-08-26 03:27:19 -04:00
|
|
|
# HDL
|
2020-05-19 04:44:36 -04:00
|
|
|
("migen", ("https://github.com/m-labs/", True, True, None)),
|
|
|
|
("nmigen", ("https://github.com/nmigen/", True, True, None)),
|
2019-08-26 03:27:19 -04:00
|
|
|
|
|
|
|
# LiteX SoC builder
|
2021-07-23 08:30:09 -04:00
|
|
|
("pythondata-software-picolibc", ("https://github.com/antmicro/", True, True, None)),
|
|
|
|
("pythondata-software-compiler_rt", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("litex", ("https://github.com/antmicro/", False, True, 0xba7b7b97)),
|
2019-08-26 03:27:19 -04:00
|
|
|
|
|
|
|
# LiteX cores ecosystem
|
2020-05-19 04:44:36 -04:00
|
|
|
("liteeth", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litedram", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litepcie", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litesata", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litesdcard", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("liteiclink", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litevideo", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litescope", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litejesd204b", ("https://github.com/enjoy-digital/", False, True, None)),
|
|
|
|
("litespi", ("https://github.com/litex-hub/", False, True, None)),
|
2020-05-19 09:49:25 -04:00
|
|
|
("litehyperbus", ("https://github.com/litex-hub/", False, True, None)),
|
2019-08-26 03:27:19 -04:00
|
|
|
|
|
|
|
# LiteX boards support
|
2020-05-19 04:44:36 -04:00
|
|
|
("litex-boards", ("https://github.com/litex-hub/", False, True, None)),
|
2020-02-23 09:54:48 -05:00
|
|
|
|
|
|
|
# Optional LiteX data
|
2020-05-19 04:44:36 -04:00
|
|
|
("pythondata-misc-tapcfg", ("https://github.com/litex-hub/", False, True, None)),
|
2021-08-13 10:27:50 -04:00
|
|
|
("pythondata-misc-opentitan", ("https://github.com/litex-hub/", False, True, 0xe43566c)),
|
2021-06-01 04:29:49 -04:00
|
|
|
("pythondata-misc-usb_ohci", ("https://github.com/litex-hub/", False, True, None)),
|
2020-05-19 04:44:36 -04:00
|
|
|
("pythondata-cpu-lm32", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("pythondata-cpu-mor1kx", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("pythondata-cpu-picorv32", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("pythondata-cpu-serv", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("pythondata-cpu-vexriscv", ("https://github.com/litex-hub/", False, True, None)),
|
2020-07-28 10:56:32 -04:00
|
|
|
("pythondata-cpu-vexriscv-smp",("https://github.com/litex-hub/", True, True, None)),
|
2020-05-19 04:44:36 -04:00
|
|
|
("pythondata-cpu-rocket", ("https://github.com/litex-hub/", False, True, None)),
|
|
|
|
("pythondata-cpu-minerva", ("https://github.com/litex-hub/", False, True, None)),
|
cpu/microwatt: use 0xf9807b6 and fix compilation, working with IRQs :)
Tested with:
/arty.py --cpu-type=microwatt --cpu-variant=standard+irq --integrated-rom-size=0x10000 --build --load
__ _ __ _ __
/ / (_) /____ | |/_/
/ /__/ / __/ -_)> <
/____/_/\__/\__/_/|_|
Build your hardware, easily!
(c) Copyright 2012-2020 Enjoy-Digital
(c) Copyright 2007-2015 M-Labs
BIOS built on Dec 30 2020 15:59:16
BIOS CRC passed (fb76e85d)
Migen git sha1: d42aa6f
LiteX git sha1: 74844db3
--=============== SoC ==================--
CPU: Microwatt @ 100MHz
BUS: WISHBONE 32-bit @ 4GiB
CSR: 32-bit data
ROM: 64KiB
SRAM: 8KiB
L2: 8KiB
SDRAM: 262144KiB 16-bit @ 800MT/s (CL-6 CWL-5)
--========== Initialization ============--
Initializing SDRAM @0x40000000...
Switching SDRAM to software control.
Write latency calibration:
m0:0 m1:0
Read leveling:
m0, b0: |00000000000000000000000000000000| delays: -
m0, b1: |00000000000011111111111111100000| delays: 19+-07
m0, b2: |00000000000000000000000000001111| delays: 30+-02
m0, b3: |00000000000000000000000000000000| delays: -
m0, b4: |00000000000000000000000000000000| delays: -
m0, b5: |00000000000000000000000000000000| delays: -
m0, b6: |00000000000000000000000000000000| delays: -
m0, b7: |00000000000000000000000000000000| delays: -
best: m0, b01 delays: 19+-07
m1, b0: |00000000000000000000000000000000| delays: -
m1, b1: |00000000000011111111111111000000| delays: 19+-07
m1, b2: |00000000000000000000000000001111| delays: 30+-01
m1, b3: |00000000000000000000000000000000| delays: -
m1, b4: |00000000000000000000000000000000| delays: -
m1, b5: |00000000000000000000000000000000| delays: -
m1, b6: |00000000000000000000000000000000| delays: -
m1, b7: |00000000000000000000000000000000| delays: -
best: m1, b01 delays: 19+-06
Switching SDRAM to hardware control.
Memtest at 0x0000000040000000 (2MiB)...
Write: 0x40000000-0x40200000 2MiB
Read: 0x40000000-0x40200000 2MiB
Memtest OK
Memspeed at 0x0000000040000000 (2MiB)...
Write speed: 32MiB/s
Read speed: 54MiB/s
--============== Boot ==================--
Booting from serial...
Press Q or ESC to abort boot completely.
sL5DdSMmkekro
Timeout
No boot medium found
--============= Console ================--
litex>
2020-12-30 10:20:11 -05:00
|
|
|
("pythondata-cpu-microwatt", ("https://github.com/litex-hub/", False, True, 0xf9807b6)),
|
2020-05-19 04:44:36 -04:00
|
|
|
("pythondata-cpu-blackparrot", ("https://github.com/litex-hub/", False, True, None)),
|
2020-05-22 09:43:00 -04:00
|
|
|
("pythondata-cpu-cv32e40p", ("https://github.com/litex-hub/", True, True, None)),
|
2018-07-20 04:11:41 -04:00
|
|
|
]
|
2020-04-28 02:58:26 -04:00
|
|
|
|
2018-07-20 04:11:41 -04:00
|
|
|
repos = OrderedDict(repos)
|
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# RISC-V toolchain download ------------------------------------------------------------------------
|
2020-04-06 19:39:49 -04:00
|
|
|
|
|
|
|
def sifive_riscv_download():
|
2020-04-07 05:05:14 -04:00
|
|
|
base_url = "https://static.dev.sifive.com/dev-tools/"
|
2020-04-06 19:39:49 -04:00
|
|
|
base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
|
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# Windows
|
|
|
|
if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
|
|
|
|
end_file = "w64-mingw32.zip"
|
|
|
|
# Linux
|
|
|
|
elif sys.platform.startswith("linux"):
|
|
|
|
end_file = "linux-ubuntu14.tar.gz"
|
|
|
|
# Mac OS
|
|
|
|
elif sys.platform.startswith("darwin"):
|
|
|
|
end_file = "apple-darwin.tar.gz"
|
2020-04-06 19:39:49 -04:00
|
|
|
else:
|
|
|
|
raise NotImplementedError(sys.platform)
|
|
|
|
fn = base_file + end_file
|
|
|
|
|
|
|
|
if not os.path.exists(fn):
|
2020-04-07 05:05:14 -04:00
|
|
|
url = base_url + fn
|
2020-04-06 19:39:49 -04:00
|
|
|
print("Downloading", url, "to", fn)
|
|
|
|
urllib.request.urlretrieve(url, fn)
|
|
|
|
else:
|
|
|
|
print("Using existing file", fn)
|
|
|
|
|
|
|
|
print("Extracting", fn)
|
2020-04-06 20:45:55 -04:00
|
|
|
shutil.unpack_archive(fn)
|
2020-04-06 19:39:49 -04:00
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# Setup --------------------------------------------------------------------------------------------
|
|
|
|
|
2018-07-20 04:11:41 -04:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Available commands:")
|
|
|
|
print("- init")
|
|
|
|
print("- update")
|
2020-05-19 04:44:36 -04:00
|
|
|
print("- install (add --user to install to user directory)")
|
2020-04-06 19:39:49 -04:00
|
|
|
print("- gcc")
|
2020-05-20 03:04:13 -04:00
|
|
|
print("- dev (dev mode, disable automatic litex_setup.py update)")
|
2018-07-20 04:11:41 -04:00
|
|
|
exit()
|
|
|
|
|
2020-05-20 03:04:13 -04:00
|
|
|
# Check/Update litex_setup.py
|
|
|
|
|
2021-07-23 07:03:43 -04:00
|
|
|
litex_setup_url = "https://raw.githubusercontent.com/antmicro/litex/libbase-replacement/litex_setup.py"
|
2020-05-20 03:04:13 -04:00
|
|
|
current_sha1 = hashlib.sha1(open(os.path.realpath(__file__)).read().encode("utf-8")).hexdigest()
|
|
|
|
print("[checking litex_setup.py]...")
|
|
|
|
try:
|
2020-05-20 05:30:50 -04:00
|
|
|
import requests
|
2020-05-20 03:04:13 -04:00
|
|
|
r = requests.get(litex_setup_url)
|
|
|
|
if r.status_code != 404:
|
|
|
|
upstream_sha1 = hashlib.sha1(r.content).hexdigest()
|
|
|
|
if current_sha1 != upstream_sha1:
|
|
|
|
if "dev" not in sys.argv[1:]:
|
|
|
|
print("[updating litex_setup.py]...")
|
|
|
|
with open(os.path.realpath(__file__), "wb") as f:
|
|
|
|
f.write(r.content)
|
|
|
|
os.execl(sys.executable, sys.executable, *sys.argv)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# Repositories cloning
|
2018-07-20 04:11:41 -04:00
|
|
|
if "init" in sys.argv[1:]:
|
|
|
|
for name in repos.keys():
|
2020-05-19 04:44:36 -04:00
|
|
|
os.chdir(os.path.join(current_path))
|
2020-04-12 13:46:56 -04:00
|
|
|
if not os.path.exists(name):
|
2020-05-19 04:44:36 -04:00
|
|
|
url, need_recursive, need_develop, sha1 = repos[name]
|
2020-04-12 13:46:56 -04:00
|
|
|
# clone repo (recursive if needed)
|
|
|
|
print("[cloning " + name + "]...")
|
|
|
|
full_url = url + name
|
|
|
|
opts = "--recursive" if need_recursive else ""
|
2020-05-19 04:44:36 -04:00
|
|
|
subprocess.check_call("git clone " + full_url + " " + opts, shell=True)
|
|
|
|
if sha1 is not None:
|
|
|
|
os.chdir(os.path.join(current_path, name))
|
|
|
|
os.system("git checkout {:7x}".format(sha1))
|
|
|
|
|
|
|
|
# Repositories update
|
|
|
|
if "update" in sys.argv[1:]:
|
|
|
|
for name in repos.keys():
|
|
|
|
os.chdir(os.path.join(current_path))
|
|
|
|
url, need_recursive, need_develop, sha1 = repos[name]
|
|
|
|
print(url)
|
|
|
|
if not os.path.exists(name):
|
|
|
|
raise Exception("{} not initialized, please (re)-run init and install first.".format(name))
|
|
|
|
# update
|
|
|
|
print("[updating " + name + "]...")
|
|
|
|
os.chdir(os.path.join(current_path, name))
|
2020-05-20 03:04:13 -04:00
|
|
|
subprocess.check_call("git checkout master", shell=True)
|
2020-05-19 04:44:36 -04:00
|
|
|
subprocess.check_call("git pull --ff-only", shell=True)
|
2021-01-27 01:55:09 -05:00
|
|
|
if need_recursive:
|
|
|
|
subprocess.check_call("git submodule update --init --recursive", shell=True)
|
2020-05-19 04:44:36 -04:00
|
|
|
if sha1 is not None:
|
|
|
|
os.chdir(os.path.join(current_path, name))
|
|
|
|
os.system("git checkout {:7x}".format(sha1))
|
2018-07-20 04:11:41 -04:00
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# Repositories installation
|
2018-07-20 04:11:41 -04:00
|
|
|
if "install" in sys.argv[1:]:
|
|
|
|
for name in repos.keys():
|
2020-05-19 04:44:36 -04:00
|
|
|
os.chdir(os.path.join(current_path))
|
|
|
|
url, need_recursive, need_develop, sha1 = repos[name]
|
2018-07-20 04:11:41 -04:00
|
|
|
# develop if needed
|
|
|
|
print("[installing " + name + "]...")
|
|
|
|
if need_develop:
|
|
|
|
os.chdir(os.path.join(current_path, name))
|
2019-04-23 08:53:00 -04:00
|
|
|
if "--user" in sys.argv[1:]:
|
2020-05-19 04:44:36 -04:00
|
|
|
subprocess.check_call("python3 setup.py develop --user", shell=True)
|
2019-04-23 08:53:00 -04:00
|
|
|
else:
|
2020-05-19 04:44:36 -04:00
|
|
|
subprocess.check_call("python3 setup.py develop", shell=True)
|
2020-04-06 19:39:49 -04:00
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
if "--user" in sys.argv[1:]:
|
|
|
|
if ".local/bin" not in os.environ.get("PATH", ""):
|
|
|
|
print("Make sure that ~/.local/bin is in your PATH")
|
|
|
|
print("export PATH=$PATH:~/.local/bin")
|
2018-07-20 04:11:41 -04:00
|
|
|
|
2020-04-07 05:05:14 -04:00
|
|
|
# RISC-V GCC installation
|
|
|
|
if "gcc" in sys.argv[1:]:
|
2020-05-19 04:44:36 -04:00
|
|
|
os.chdir(os.path.join(current_path))
|
2020-04-07 05:05:14 -04:00
|
|
|
sifive_riscv_download()
|
|
|
|
if "riscv64" not in os.environ.get("PATH", ""):
|
|
|
|
print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
|
|
|
|
print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")
|