Skip to content

Instantly share code, notes, and snippets.

@sam210723
Last active April 2, 2021 07:42
Show Gist options
  • Save sam210723/394e4b1d0d0dd834d1f61e3daf0af9dd to your computer and use it in GitHub Desktop.
Save sam210723/394e4b1d0d0dd834d1f61e3daf0af9dd to your computer and use it in GitHub Desktop.
Install IceStorm + Yosys + NextPNR + RISC-V toolchain + TinyFPGA PicoSoC Example
# Install deps
sudo apt-get update
sudo apt-get install autoconf automake autotools-dev build-essential clang bison \
flex libreadline-dev gawk tcl-dev libffi-dev cmake curl git graphviz xdot \
pkg-config python python3 python3-dev mercurial libboost-system-dev \
libboost-python-dev libboost-filesystem-dev libboost-all-dev libeigen3-dev \
zlib1g-dev libmpc-dev libftdi-dev libmpfr-dev libgmp-dev gawk texinfo gperf \
libtool patchutils bc libexpat-dev qt5-default
# Install IceStorm
git clone https://github.com/YosysHQ/icestorm
cd icestorm
make -j$(nproc)
sudo make install
cd ..
# Setup Yosys
git clone https://github.com/YosysHQ/yosys
cd yosys
make
sudo make install
cd ..
# Setup nextpnr
git clone --recurse-submodules https://github.com/YosysHQ/nextpnr
cd nextpnr
mkdir build
cd build
cmake .. -DARCH=ice40
make -j$(nproc)
sudo make install
cd ../..
# Setup RISC-V build toolchain
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain-rv32i
cd riscv-gnu-toolchain-rv32i
./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32
export PATH="$PATH:/opt/riscv/bin"
sudo make
cd ..
# Clone TinyFPGA PicoSoC example
git clone https://github.com/tinyfpga/TinyFPGA-BX
cd TinyFPGA-BX/examples/picosoc
rm Makefile
wget https://gist.githubusercontent.com/sam210723/394e4b1d0d0dd834d1f61e3daf0af9dd/raw/5907f3b06c7fd42c9c61706c76da45ea41c90e08/Makefile
make upload
upload: hardware.bin firmware.bin
tinyprog -p hardware.bin -u firmware.bin
build: hardware.bin firmware.bin
echo "Complete"
hardware.blif: hardware.v spimemio.v simpleuart.v picosoc.v picorv32.v
yosys -ql hardware.log -p 'synth_ice40 -top hardware -json hardware.json' $^
hardware.asc: hardware.pcf hardware.blif
nextpnr-ice40 --lp8k --package cm81 --json hardware.json --asc hardware.asc --pcf hardware.pcf
hardware.bin: hardware.asc
icetime -d lp8k -c 12 -mtr hardware.rpt hardware.asc
icepack hardware.asc hardware.bin
firmware.elf: sections.lds start.S firmware.c
riscv32-unknown-elf-gcc -march=rv32imc -nostartfiles -Wl,-Bstatic,-T,sections.lds,--strip-debug,-Map=firmware.map,--cref -ffreestanding -nostdlib -o firmware.elf start.S firmware.c
firmware.bin: firmware.elf
riscv32-unknown-elf-objcopy -O binary firmware.elf /dev/stdout > firmware.bin
clean:
rm -f firmware.elf firmware.hex firmware.bin firmware.o firmware.map \
hardware.blif hardware.log hardware.asc hardware.rpt hardware.bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment