Tang Nano Dev w/ OpenSourcePosted: April 15, 2025 Introduction This is a page explaining how I got the open source yosys / nextpnr compiled for the Sipeed Tang Nano 20K FPGA. Compiling yosys was pretty easy but nextpnr (or nextpnr-himbaechel) wouldn't straight compile on Ubuntu for me. It unfortunately needs some Python modules that aren't in the Ubuntu apt so it takes forcing the install from PIP. To not break my main Linux system I did the compile under Docker. To make sure I didn't forget how to do this I'm writing it all down here. Hopefully this can help some others too. This document also assumes basic knowledge of Docker. Related Projects @mikekohn.net
Steps If docker isn't installed, on Ubuntu it should be:
sudo apt install docker.io
After it installs, it might be good to add your username to the docker group so it doesn't have to be run with sudo. First step after docker is installed is to pull the lastest debian image with docker:
docker pull debian:latest
Next the docker container can be started:
docker run --rm -it debian:latest /bin/bash
Next a bunch of software needs to be installed:
apt update
apt install git g++ cmake \
build-essential clang lld 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
Next need to clone and build yosys:
cd
git clone https://github.com/YosysHQ/yosys.git
cd yosys
git submodule update --init --recursive
make
Need to install some prerequisites for nextpnr-himbaechel:
apt install \
libboost-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-program-options-dev \
libboost-iostreams-dev \
libboost-dev
apt install libeigen3-dev
apt install pip
pip install --break-system-packages apycula
Next need to clone and build nextpnr-himbaechel:
cd
git clone https://github.com/YosysHQ/nextpnr.git
cd nextpnr
git submodule update --init --recursive
mkdir build
cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gowin"
make
Now all the dev tools should be built. The last thing missing is openFPGAloader. That didn't appear to be a part of Ubuntu either so it seems it needs to be built from source. This one is probably better though to build on the host and not in the container. Before doing that, it would probably be a good idea to "commit" the container so instances of it can be started later without rebuilding the devkits. To save the container first the container id needs to be found. That can be done with:
docker ps
In my case, the container id is d20cae9d3ad2 so to save a new image based on a snapshot of this container with the image name gowin-devkit:
docker commit d20cae9d3ad2 gowin-devkit
This can take some time. After it finishes, this container can be exited. To start a new container based on the new gowin-devkit image:
docker run --rm -it -v /code/fpga/gowin_blink:/fpga gowin-devkit /bin/bash
The -v part is used to mount a directory from the host system /code/fpga/gowin_blink to /fpga inside the container. This will allow the Verilog project to be built in the container leaving the resulting binary on the host system. Also all files can be edited on the host rather than inside the container. Inside the container some environment variables should be set:
export PATH=$PATH:/root/yosys:/root/nextpnr/build
A test program for the Tang Nano that blinks an LED with a Makefile can be downloaded here: The Makefile for the blink program looks like this:
PROGRAM=blink
default:
yosys -q \
-p "synth_gowin -top $(PROGRAM) -json $(PROGRAM).json -family gw2a" \
src/$(PROGRAM).v
nextpnr-himbaechel -r \
--json $(PROGRAM).json \
--write $(PROGRAM)_pnr.json \
--freq 27 \
--vopt family=GW2A-18C \
--vopt cst=tangnano20k.cst \
--device GW2AR-LV18QN88C8/I7
gowin_pack -d GW2A-18C -o $(PROGRAM).fs $(PROGRAM)_pnr.json
To flash the board with the blink.fs file, build openFPGALoader on the host and do:
sudo build/openFPGALoader --scan-usb
sudo build/openFPGALoader --ftdi-serial 2023030621 ~/source/fpga/gowin_blink/blink.fs
Replace 2023030621 with the serial number for the specific Tang Nano board.
Copyright 1997-2025 - Michael Kohn
|