Skip to content

Instantly share code, notes, and snippets.

@rafaelcorsi
Created July 10, 2023 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcorsi/51060fa0dd039a2df783f458cc271f20 to your computer and use it in GitHub Desktop.
Save rafaelcorsi/51060fa0dd039a2df783f458cc271f20 to your computer and use it in GitHub Desktop.
Dockerfile - opensource toolchain for Intel/Altera Cyclone V FPGAs
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y curl build-essential git 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 \
wget unzip make g++ libftdi1-dev libhidapi-dev libudev-dev cmake \
gzip libboost-all-dev libeigen3-dev liblzma-dev
RUN git clone https://github.com/YosysHQ/yosys yosys
WORKDIR /yosys
RUN make config-gcc; make -j$(nproc); make install
WORKDIR /
RUN git clone https://github.com/Ravenslofty/mistral mistral
WORKDIR /mistral
ENV MISTRAL_ROOT=/mistral
WORKDIR /
RUN git clone https://github.com/YosysHQ/nextpnr nextpnr
WORKDIR /nextpnr
RUN cmake . -DARCH=mistral -DMISTRAL_ROOT=$MISTRAL_ROOT; make -j$(nproc)
RUN make install
WORKDIR /
RUN git clone https://github.com/trabucayre/openFPGALoader openfpgaloader
WORKDIR /openfpgaloader
RUN cmake .; make -j$(nproc)
RUN make install
WORKDIR /
@rafaelcorsi
Copy link
Author

Supposing you have a toplevel.v and a de0cv_pins.qsf file, you can:

  1. make toplevel.rbf : generate the fpga program file
  2. make toplevel.prog: programs the FPGA

On this makefile we are using the OpenFPGALoader installed native on the OS, but you can modify to program it from the docker, for this you need to route the USB device to the docker:

DOCKER_RUN=docker run -v ${PWD}:${PWD} -w ${PWD} -device=/dev/bus/usb/003/002 yosys /bin/bash -c -

Please use the lsusb to get the device number 003/002 (that will change from pc/pc)

Makefile:

DEVICE?=5CEBA4F23C7
QSF=de0cv_pins.qsf
DOCKER_RUN=docker run -v ${PWD}:${PWD} -w ${PWD} yosys /bin/bash -c

%.v: %.py *.py
	python $^

%.json: %.v
	${DOCKER_RUN} "yosys -p \"synth_intel_alm -nobram -nolutram -top toplevel -nodsp; write_json $@\" $^"

%.rbf: %.json ${QSF}
	${DOCKER_RUN} "nextpnr-mistral --parallel-refine --device ${DEVICE} --json $< --qsf ${QSF} --router router2 --rbf $@"

%.prog: %.rbf
	sudo openFPGALoader -b de0 toplevel.rbf

clean:
	rm -f *.json *.rbf *.v

.PRECIOUS: %.json %.rbf %.v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment