Skip to content

Instantly share code, notes, and snippets.

@gojimmypi
Last active March 25, 2019 12:06
Show Gist options
  • Save gojimmypi/243fc3a6eead72ae3db8fd32f2567c96 to your computer and use it in GitHub Desktop.
Save gojimmypi/243fc3a6eead72ae3db8fd32f2567c96 to your computer and use it in GitHub Desktop.
TinyFPGA Verilog icestorm toolchain installer
#!/bin/bash
WORKSPACE=~/workspace
export TinyFPGA_COM=/dev/ttyS8
sudo ls # pause if copy/paste password prompt
# This WSL Ubuntu bash script will update the system, fetch all dependencies, and git clone
# all of the libraries for creating a picosoc RISC-V on the TinyFPGA with riscv-gnu-toolchain-rv32i toolchain,
# including icestorm, nextpnr (or arachne-pnr), yosys
#
# See also: https://gojimmypi.blogspot.com/2019/01/tinyfpga-bx-using-tinyprog-in-wsl.html
#
# A WSL-specific Makefile will also be fetched. See https://gist.github.com/gojimmypi/fc29d4fc575a30567536bece094e5585
#
# wget https://gist.githubusercontent.com/gojimmypi/fc29d4fc575a30567536bece094e5585/raw/Makefile -O Makefile
#
# or if you prefer the older arachne-pnr:
#
# wget https://gist.githubusercontent.com/gojimmypi/b85315b4f1786ffced390a1c051f59c8/raw/Makefile -O Makefile
#
# Works bext with Ubuntu 18.04 or later
#***************************************************************************************************
# To fetch and use this file:
#
# wget https://gist.githubusercontent.com/gojimmypi/243fc3a6eead72ae3db8fd32f2567c96/raw/TinyFPGA_WSL_Toolchain.sh -O TinyFPGA_WSL_Toolchain.sh
# chmod +x ./TinyFPGA_WSL_Toolchain.sh
# ./TinyFPGA_WSL_Toolchain.sh
#***************************************************************************************************
date
mkdir -p "$WORKSPACE"
echo ***************************************************************************************************
echo update/upgrade current system
echo ***************************************************************************************************
sudo apt-get update --assume-yes
sudo apt-get upgrade --assume-yes
echo ***************************************************************************************************
echo git config
echo ***************************************************************************************************
# These git .insteadOf options may not be needed if your firewall does not blocks the git ports,
# but we set anyhow.
#
# it is unlikely to cause harm for these repositories, unless for some reason your firewall is blocking HTTPS
sudo apt-get install git --assume-yes
git config --global url.https://git.qemu.org/git/.insteadOf git://git.qemu-project.org/
git config --global url.https://anongit.freedesktop.org/git/.insteadOf git://anongit.freedesktop.org/
git config --global url.https://github.com/riscv.insteadOf git://github.com/riscv
# also consider somerthing like this for everything on GitHub:
# git config --global url.https://github.com/.insteadOf git://github.com/
#
# and to clear:
# git config --global --unset url.https://github.com/.insteadOf
cd "$WORKSPACE"
echo ***************************************************************************************************
echo install icestorm dependencies
echo ***************************************************************************************************
# this next install needs a bit of disk space:
# 0 upgraded, 205 newly installed, 0 to remove and 3 not upgraded.
# Need to get 130 MB of archives.
# After this operation, 652 MB of additional disk space will be used.
#
sudo apt-get install build-essential clang bison flex libreadline-dev \
gawk tcl-dev libffi-dev git mercurial graphviz \
xdot pkg-config python python3 libftdi-dev --assume-yes
echo ***************************************************************************************************
echo install nextpnr dependencies
echo ***************************************************************************************************
# this next line is about another half gig of files!
# 0 upgraded, 249 newly installed, 0 to remove and 3 not upgraded.
# Need to get 132 MB of archives.
# After this operation, 623 MB of additional disk space will be used.
#
sudo apt-get install libboost-all-dev python3-dev qt5-default clang-format --assume-yes
sudo apt-get install cmake --assume-yes
echo ***************************************************************************************************
echo install picorv32 RISC-V dependencies
echo ***************************************************************************************************
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev \
libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo \
gperf libtool patchutils bc zlib1g-dev git libexpat1-dev --assume-yes
echo ***************************************************************************************************
echo install TinyFPGA dependencies
echo ***************************************************************************************************
sudo apt-get install python-pip python3-pip --assume-yes
# sudo pip install apio==0.4.0b5 tinyprog
sudo pip install apio tinyprog
apio install system scons icestorm iverilog
echo ***************************************************************************************************
echo update/upgrade current system again
echo ***************************************************************************************************
sudo apt-get update --assume-yes
sudo apt-get upgrade --assume-yes
cd "$WORKSPACE"
echo ***************************************************************************************************
echo tinyFPGA BX
echo ***************************************************************************************************
if [ ! -d "$WORKSPACE"/TinyFPGA-BX ]; then
git clone --recursive https://github.com/tinyfpga/TinyFPGA-BX.git
cd TinyFPGA-BX
else
cd TinyFPGA-BX
git fetch
git pull
fi
sudo apio drivers --serial-enable
sudo usermod -a -G dialout $USER
cd "$WORKSPACE"
echo ***************************************************************************************************
echo icestorm
echo ***************************************************************************************************
# see http://www.clifford.at/icestorm/
if [ ! -d "$WORKSPACE"/icestorm ]; then
git clone https://github.com/cliffordwolf/icestorm.git icestorm
cd icestorm
else
cd icestorm
git fetch
git pull
make clean
fi
make -j$(nproc)
sudo make install
cd "$WORKSPACE"
cho ***************************************************************************************************
echo arachne-pnr
echo ***************************************************************************************************
if [ ! -d "$WORKSPACE"/arachne-pnr ]; then
git clone https://github.com/cseed/arachne-pnr.git arachne-pnr
cd arachne-pnr
else
cd arachne-pnr
git fetch
git pull
make clean
fi
make -j$(nproc)
sudo make install
cd "$WORKSPACE"
echo ***************************************************************************************************
echo nextpnr
echo ***************************************************************************************************
# See https://github.com/YosysHQ/nextpnr#nextpnr-ice40
if [ ! -d "$WORKSPACE"/nextpnr ]; then
git clone https://github.com/YosysHQ/nextpnr.git
cd nextpnr
else
cd nextpnr
git fetch
git pull
make clean
fi
cmake -DARCH=ice40 .
make -j$(nproc)
sudo make install
cd "$WORKSPACE"
echo ***************************************************************************************************
echo yosys
echo ***************************************************************************************************
# see http://www.clifford.at/yosys/
if [ ! -d "$WORKSPACE"/yosys ]; then
git clone https://github.com/cliffordwolf/yosys.git yosys
cd yosys
else
cd yosys
git fetch
git pull
make clean
fi
make -j$(nproc)
sudo make install
cd "$WORKSPACE"
echo ***************************************************************************************************
echo picorv32 RISC-V
echo ***************************************************************************************************
if [ ! -d "$WORKSPACE"/picorv32 ]; then
git clone https://github.com/cliffordwolf/picorv32.git
cd picorv32
else
cd picorv32
git fetch
git pull
fi
sudo mkdir -p /opt/riscv32i
sudo chown $USER /opt/riscv32i
cd "$WORKSPACE"
echo ***************************************************************************************************
echo riscv-gnu-toolchain-rv32i
echo ***************************************************************************************************
# See https://github.com/cliffordwolf/picorv32/blob/master/README.md#building-a-pure-rv32i-toolchain#
if [ ! -d "$WORKSPACE"/riscv-gnu-toolchain-rv32i ]; then
git clone https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain-rv32i
fi
cd riscv-gnu-toolchain-rv32i
git checkout c3ad555
git submodule update --init --recursive
mkdir -p build; cd build
../configure --with-arch=rv32i --prefix=/opt/riscv32i
make -j$(nproc)
cd "$WORKSPACE"
echo ***************************************************************************************************
echo show versions installed
echo ***************************************************************************************************
lsb_release -a
python --version
python3.5 --version
cmake --version
clang --version
echo qtf_default $(apt-cache show qt5-default | grep -m1 Version)
echo libboost-all-dev $(apt-cache show libboost-all-dev | grep -m1 Version)
for pk in build-essential clang bison flex libreadline-dev \
gawk tcl-dev libffi-dev git mercurial graphviz \
xdot pkg-config python python3 libftdi-dev \
qt5-default python3-dev libboost-dev; \
do echo "$pk" $(apt-cache show "$pk" | grep -m1 Version); done
nextpnr-ice40 --version
yosys -V
/opt/riscv32ic/bin/riscv32-unknown-elf-gcc -v
pip --version
echo apio [pip] $(pip list | grep apio)
echo apio [pip3] $(pip3 list | grep apio)
echo tinyprog [pip] $(pip list | grep tinyprog)
echo tinyprog [pip3] $(pip3 list | grep tinyprog)
cd "$WORKSPACE"
echo ***************************************************************************************************
echo build the TinyFPGA RISC-V
echo ***************************************************************************************************
# See https://discourse.tinyfpga.com/t/riscv-example-project-on-tinyfpga-bx/451
cd TinyFPGA-BX/examples/picosoc
# Get our WSL-specific Makefile
wget https://gist.githubusercontent.com/gojimmypi/fc29d4fc575a30567536bece094e5585/raw/Makefile -O Makefile
make clean
make hardware.bin
make firmware.bin
read -p "Ensure TinyFPGA Makefile has proper tty port and device is in bootloader mode; Press [Enter] to program TinyFPGA"
# WSL seems to regularly forget permissions. Note this line is also in Makefile:
sudo chmod 0666 $(tinyFPGA_COM)
make
date
echo Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment