-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker: Add bitstream synthesis capability (requires yosys and nextpn…
…r present in container). (#56)
- Loading branch information
Showing
3 changed files
with
107 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,39 +5,61 @@ LABEL org.opencontainers.image.description='{{ readme }}' | |
LABEL org.opencontainers.image.vendor='{{ author }}' | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
ENV WORKDIR=/toolchain | ||
WORKDIR /toolchain | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Normal update | ||
RUN apt-get update -y | ||
|
||
RUN apt-get -y install curl git pip | ||
RUN apt-get -y install curl git pip file cmake | ||
|
||
# Install proper nodejs version. | ||
ENV NVM_DIR=/toolchain | ||
ENV NVM_SH=/root/.nvm/nvm.sh | ||
# Install nvm, node and xpm. | ||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh > install.sh | ||
RUN echo "69da4f89f430cd5d6e591c2ccfa2e9e3ad55564ba60f651f00da85e04010c640 install.sh" > checksum.txt | ||
RUN sha256sum -c checksum.txt | ||
RUN bash ./install.sh | ||
RUN source "$NVM_DIR/nvm.sh" && nvm install v16.20.0 && nvm use v16.20.0 | ||
|
||
# Install XPM | ||
RUN source "$NVM_DIR/nvm.sh" && npm install --global [email protected] | ||
RUN source $NVM_SH | ||
RUN source $NVM_SH && nvm install v16.20.0 && nvm use v16.20.0 | ||
RUN source $NVM_SH && npm install --global [email protected] | ||
|
||
# Install gcc toolchain | ||
RUN source "$NVM_DIR/nvm.sh" && xpm install --global @xpack-dev-tools/[email protected] --verbose | ||
RUN source $NVM_SH && xpm install --global @xpack-dev-tools/[email protected] --verbose | ||
ENV PATH="/root/.local/xPacks/@xpack-dev-tools/riscv-none-elf-gcc/13.2.0-1.2/.content/bin:$PATH" | ||
|
||
|
||
RUN pip3 install --upgrade pip | ||
RUN pip3 install poetry | ||
|
||
# Install Poetry dependencies | ||
ADD pyproject.toml . | ||
ADD poetry.lock . | ||
|
||
RUN poetry install --no-interaction | ||
|
||
# Install mtkcpu. | ||
# RUN poetry install --no-interaction | ||
ADD mtkcpu ./mtkcpu | ||
RUN poetry install --no-interaction | ||
|
||
ENV PATH=$HOME/.poetry/bin/:$PATH | ||
|
||
# Install 'iceprog' dependencies. | ||
RUN apt-get install -y libftdi-dev | ||
|
||
# Install 'yosys' dependencies. | ||
RUN apt-get install -y build-essential clang bison flex \ | ||
libreadline-dev gawk tcl-dev libffi-dev git \ | ||
graphviz xdot pkg-config python3 libboost-system-dev \ | ||
libboost-python-dev libboost-filesystem-dev zlib1g-dev | ||
|
||
# Install 'nextpnr' dependencies. | ||
RUN apt-get install -y libboost-all-dev libeigen3-dev | ||
|
||
# By default yosys and iceprog are installed in /usr/local/bin/, and for nextpnr we specify it explicitly. | ||
|
||
RUN git clone https://github.com/YosysHQ/icestorm && cd icestorm && make -j15 && make install | ||
RUN git clone https://github.com/YosysHQ/yosys && cd yosys && make -j15 && make install | ||
RUN git clone https://github.com/YosysHQ/nextpnr && cd nextpnr && cmake . -DARCH=ice40 -DICESTORM_INSTALL_PREFIX=/usr/local/ && make -j15 && make install | ||
|
||
# Make sure all synthesis binaries are in PATH. | ||
RUN which iceprog yosys nextpnr-ice40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from typing import Optional | ||
from pathlib import Path | ||
import sys | ||
import grp | ||
import subprocess | ||
import argparse | ||
|
||
class Color: | ||
yellow = "\x1b[33m" | ||
green = "\x1b[32m" | ||
red = "\x1b[21m" | ||
bold_red = "\x1b[31;1m" | ||
bold = "\033[1m" | ||
uline = "\033[4m" | ||
reset = "\x1b[0m" | ||
|
||
def warn(msg: str): | ||
sys.stderr.write(f"{Color.bold}WARNING{Color.reset}: {msg}\n") | ||
|
||
def get_group_id(group_name: str) -> Optional[int]: | ||
try: | ||
group_info = grp.getgrnam(group_name) | ||
except Exception: | ||
return None | ||
return group_info.gr_gid | ||
|
||
def get_group_members(group_name: str) -> list[str]: | ||
if get_group_id(group_name) is None: | ||
return [] | ||
return grp.getgrnam(group_name).gr_mem | ||
|
||
def construct_groups_params(groups: list[str] = ["dialout", "plugdev"]): | ||
res = " " | ||
for name in groups: | ||
id = get_group_id(name) | ||
if id is None: | ||
warn(f"Could not find group '{name}' in /etc/group! In order to avoid UART/JTAG connection issues, please add the group manually, set your user as a member and refresh (As a result command 'groups' should print it)") | ||
continue | ||
res += f"--group-add {id} " | ||
|
||
return res | ||
|
||
def main(cmd : Optional[str]): | ||
container_name = "docker.io/library/mtkcpu:1.0.0" | ||
interactive = "" if cmd else "-it" | ||
if not cmd: | ||
cmd = "" | ||
else: | ||
if ';' in cmd: | ||
warn("\n\nYour command contain ';' - probably it won't work as you might expect. Use && instead.\n\n") | ||
if (not cmd.startswith("sh")) and (not cmd.startswith("bash")): | ||
cmd = f"sh -c '{cmd}'" | ||
|
||
command = f""" | ||
docker run \ | ||
--net host \ | ||
{construct_groups_params()} \ | ||
-v {Path(__file__).parent}/sw:/toolchain/sw \ | ||
{interactive} {container_name} {cmd} | ||
""" | ||
print(command) | ||
|
||
subprocess.run(command, shell=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(usage="Runs interactive bash session inside Plumerai-Demo docker container.") | ||
parser.add_argument("--cmd", type=str) | ||
main(**vars(parser.parse_args())) |