Skip to content

Instantly share code, notes, and snippets.

@cr1901
Last active August 27, 2022 22:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr1901/e870ac71283c792a20f6d4a0ee23cb37 to your computer and use it in GitHub Desktop.
Save cr1901/e870ac71283c792a20f6d4a0ee23cb37 to your computer and use it in GitHub Desktop.
FOSS FPGA Toolchain Build Script
PREFIX=/path/to/install
FPGA_ROOT=/root/of/repos
NUM_JOBS=4
# If non-zero, enable sscache optimizations. Need to set CC and CXX as well.
SCCACHE=0
CC=gcc
CXX=g++
# If non-zero, use chipdbs built on another machine.
NEXTPNR_EXTERN_CHIPDB=0
# Server plus root to SSH to to find .bbas
EXTERN_CHIPDB_REMOTE=""
# Extra NextPNR Options
NEXTPNR_OPTS=""
# Set if build machine has 2GB of RAM or less.
NEXTPNR_LO_MEM=0
# `*_JOBS`, `*_REMOTE`, and `*_BRANCH` environment variables also exist with the
# following prefixes: `TRELLIS`, `ICESTORM`, `ICE40`, `ECP5`, `NEXTPNR`,
# `YOSYS`, `SYMBIYOSYS`, `IVERILOG`, `VERILATOR`, `GHDL`, `GHDL_YOSYS_PLUGIN`,
# `OPENOCD`, `DFU`, `OFL`, and `GENERIC`:
# * `*_JOBS` overrides the number of compile jobs (defaults to `NUM_JOBS`).
# `SYMBIYOSYS_JOBS`, `GHDL_YOSYS_PLUGIN_JOBS` are ignored, as well as jobs
# for chipdb generation.
#
# `NEXTPNR_JOBS` is also ignored, use `ICE40_JOBS`, `ECP5_JOBS`,
# `GENERIC_JOBS`, etc instead.
# * `*_REMOTE` specifies the git remote to use (defaults to `origin`).
# (`ICE40_REMOTE`, `ECP5_REMOTE`, and `GENERIC_REMOTE` are ignored. Use)
# `NEXTPNR_REMOTE` instead.
# * `*_BRANCH` specifies the git branch to use (defaults to `master`).
# (`ICE40_BRANCH`, `ECP5_BRANCH`, and `GENERIC_BRANCH` are ignored. Use)
# `NEXTPNR_BRANCH` instead.

FOSS Toolchain Build Script

To run:

  • Symlink to the Justfile at your FPGA_ROOT (see .env.sample).
    • Does not work for now. Alternate strategy- checkout this repo in a directory under FPGA_ROOT (see .env.sample). We'll call this directory foss-build in the below instructions.
  • Copy .env.sample to .env at your FPGA_ROOT and fill out accordingly. The Justfile will find .env as long as its the first one in a parent directory.
  • just foss-build/rebuild-toolchains for fully-automated build of below tools.
  • just foss-build/rebuild-toolchain {ice40, ecp5, iverilog, ghdl, yosys, generic} to pull/build one at a time.
  • just --list foss-build for help.
    • DRY enables --dry-run to make.

    • SKIP_CHECK allows you to build on dirty repos and branches besides the ones specific in .env (defaults to origin remote, master branch).

    • CLEAN in build-chipdbs will clean build-chipdb-{{FAMILY}} before rebuilding them (default is to leave them alone), while CLEAN in prepare will clean all repos.

    • PULL in build-chipdbs will pull from the remotes and branches specified in .env for prjtrellis, icestorm, and nextpnr (defaults to origin remote, master branch).

    • Hidden recipes like _rebuild-{ecp5, ice40} also exist. The CHIPDB parameter controls how/whether chipdbs are built or downloaded as part of rebuilding nextpnr:

      • only- Rebuild only chipdbs, don't clean chipdbs beforehand.
      • only-full- Rebuild only chipdbs, clean chipdbs beforehand.
      • full- Rebuild everything, clean chipdbs beforehand.
      • quick- Rebuild everything, don't clean chipdbs beforehand.
      • none- Only rebuild nextpnr, don't rebuild chipdbs.

      Use these recipes with caution; nextpnr does not appear to keep track of whether the inputs to create chipdbs at ICESTORM_INSTALL_PREFIX, TRELLIS_INSTALL_PREFIX, etc have changed.

Prerequisites

  • cmake
  • ninja
  • rsync
  • sh (Could in principle work with PowerShell)
  • make
  • just
  • autotools
  • flex
  • bison

Built tools

  • yosys
  • nextpnr-ice40
  • nextpnr-ecp5
  • nextpnr-generic
  • iverilog
  • SymbiYosys (as part of yosys toolchain)
  • ghdl and ghdl-yosys-plugin
  • openocd
  • dfu-util
  • openFPGALoader
  • verilator

Directory layout (required at FPGA_ROOT)

  • yosys
  • nextpnr
  • nextpnr/build-{ice40, ecp5, generic, chipdb-ice40, chipdb-ecp5}
  • iverilog
  • build-iverilog
  • SymbiYosys
  • ghdl
  • build-ghdl
  • ghdl-yosys-plugin
  • openocd
  • build-openocd
  • dfu-util
  • build-dfu
  • openFPGALoader
  • openFPGALoader/build
  • verilator

Additional requirements if building chipdbs

  • icestorm
  • prjtrellis
#!/bin/sh
# Common shell functions for Justfile recipes.
# git helpers
# $1- Skip check, $2- remote, $3- branch
check_branch() {
if [ $# -ne 3 ]; then
echo "check_branch didn't get 3 input params."
exit 1
fi
if [ $1 -ne 0 ]; then
return 0;
fi
CURR_BR=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
if [ $CURR_BR != $3 ]; then
echo "Branch not set to $3. Not continuing."
exit 2
fi
if ! git diff --quiet --ignore-submodules; then
echo "Branch has local changes. Not continuing."
exit 3
fi
# Update submodules?
git pull $2 $3
}
# sccache helpers
make_clean_if_sccache() {
if [ $SCCACHE -ne 0 ]; then
make $MKDRY clean
fi
}
ninja_clean_if_sccache() {
if [ $SCCACHE -ne 0 ]; then
ninja $MKDRY clean
fi
}
make_begin_if_sccache() {
autoconf_begin_if_sccache
}
make_end_if_sccache() {
autoconf_end_if_sccache
}
autoconf_begin_if_sccache() {
if [ $SCCACHE -ne 0 ]; then
ORIG_CC=$CC
ORIG_CXX=$CXX
export CC="sccache $CC"
export CXX="sccache $CXX"
fi
}
autoconf_end_if_sccache() {
if [ $SCCACHE -ne 0 ]; then
export CC=$ORIG_CC
export CXX=$ORIG_CXX
fi
}
set_cmake_vars_if_sccache() {
if [ $SCCACHE -ne 0 ]; then
CMAKE_SCCACHE_OPTS="-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
fi
}
# misc helpers
set_dry() {
if [ $1 -ne 0 ]; then
MKDRY="-n"
fi
}
# full recipe wrappers
# $1- family, $2- "full", "only-full", "quick", "only", "none", $3-$5- inputs to check_branch
# TODO: Number of ninja jobs is not manually set here.
build_nextpnr_chipdbs() {
if [ $# -ne 5 ]; then
echo "build_nextpnr_chipdbs didn't get 5 input params."
exit 1
fi
cd $FPGA_ROOT/nextpnr/build-chipdb-$1
check_branch $3 $4 $5
case $2 in
"only-full"|"full")
ninja $MKDRY clean
;;
"quick"|"only"|"none")
;;
*)
echo "build_nextpnr_chipdbs input arg 2 was $2, not \"full\", \"only-full\", \"quick\", \"only\" or \"none\""
exit 2
;;
esac
cmake -G"Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX -DSERIALIZE_CHIPDBS=NO ../$1
ninja $MKDRY
}
# $1- family
# Set RSYNC_SSH var for dbclient
get_remote_chipdbs() {
mkdir -p $FPGA_ROOT/nextpnr/build-chipdb-$1
cd $FPGA_ROOT/nextpnr/build-chipdb-$1
rsync -zaHphiv $EXTERN_CHIPDB_REMOTE/nextpnr/build-chipdb-$1/chipdb .
}
# $1- family, $2- number of jobs, $3- low mem, $4-$6- inputs to check_branch
build_nextpnr() {
if [ $# -ne 6 ]; then
echo "build_nextpnr didn't get 6 input params."
exit 1
fi
cd $FPGA_ROOT/nextpnr/build-$1
check_branch $4 $5 $6
case $1 in
"ice40")
cmake -G"Ninja" -DARCH=ice40 -DCMAKE_INSTALL_PREFIX=$PREFIX -DICE40_CHIPDB=$FPGA_ROOT/nextpnr/build-chipdb-ice40/chipdb $CMAKE_SCCACHE_OPTS $NEXTPNR_OPTS ..
if [ $3 -ne 0 ]; then
ninja -j$2 $MKDRY CMakeFiles/chipdb-ice40.dir/ice40/chipdb/chipdb-8k.cc.o
ninja -j$2 $MKDRY CMakeFiles/chipdb-ice40.dir/ice40/chipdb/chipdb-5k.cc.o
fi
;;
"ecp5")
cmake -G"Ninja" -DARCH=ecp5 -DCMAKE_INSTALL_PREFIX=$PREFIX -DECP5_CHIPDB=$FPGA_ROOT/nextpnr/build-chipdb-ecp5/chipdb $CMAKE_SCCACHE_OPTS $NEXTPNR_OPTS ..
if [ $3 -ne 0 ]; then
ninja -j$2 $MKDRY CMakeFiles/nextpnr-ecp5.dir/ecp5/baseconfigs.cc.o
fi
;;
"generic")
cmake -G"Ninja" -DARCH=generic -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_SCCACHE_OPTS $NEXTPNR_OPTS -DBUILD_GUI=OFF ..
;;
esac
ninja -j$2 $MKDRY
ninja $MKDRY install
ninja_clean_if_sccache
}
set dotenv-load := true
alias r := rebuild-toolchain
# TODO:
# * mkdir -p for all build directories (via init recipe?).
# * Recipes to split out ghdl-yosys-plugin and SymbiYosys again?
# * Use more consistent line breaks.
# * openocd, litex, and amaranth recipes?
# Rebuild order shouldn't matter, but GHDL needs to be built before yosys on
# Windows and I haven't bothered making the dep order match the recipes in this
# file.
# Rebuild all toolchains.
rebuild-toolchains: (rebuild-toolchain "ecp5") (rebuild-toolchain "ice40") (rebuild-toolchain "ghdl") (rebuild-toolchain "iverilog") (rebuild-toolchain "verilator") (rebuild-toolchain "openocd") (rebuild-toolchain "dfu") (rebuild-toolchain "ofl") (rebuild-toolchain "yosys") (rebuild-toolchain "generic")
# Rebuild a given FOSS FPGA toolchain.
rebuild-toolchain FAMILY DRY="0" SKIP_CHECK="0":
#!/bin/sh
case {{FAMILY}} in
"ice40")
just -f "{{justfile()}}" _rebuild-ice40 {{DRY}} {{SKIP_CHECK}}
;;
"ecp5")
just -f "{{justfile()}}" _rebuild-ecp5 {{DRY}} {{SKIP_CHECK}}
;;
"yosys")
just -f "{{justfile()}}" _rebuild-yosys {{DRY}} {{SKIP_CHECK}}
;;
"iverilog")
just -f "{{justfile()}}" _rebuild-iverilog {{DRY}} {{SKIP_CHECK}}
;;
"ghdl")
just -f "{{justfile()}}" _rebuild-ghdl {{DRY}} {{SKIP_CHECK}}
;;
"generic")
just -f "{{justfile()}}" _rebuild-generic {{DRY}} {{SKIP_CHECK}}
;;
"openocd")
just -f "{{justfile()}}" _rebuild-openocd {{DRY}} {{SKIP_CHECK}}
;;
"dfu-util" | "dfu")
just -f "{{justfile()}}" _rebuild-dfu {{DRY}} {{SKIP_CHECK}}
;;
"openfpgaloader" | "ofl")
just -f "{{justfile()}}" _rebuild-ofl {{DRY}} {{SKIP_CHECK}}
;;
"verilator")
just -f "{{justfile()}}" _rebuild-verilator {{DRY}} {{SKIP_CHECK}}
;;
*)
echo "Unrecognized toolchain {{FAMILY}}"
exit 1
;;
esac
# Rebuild the ECP5 toolchain
_rebuild-ecp5 DRY="0" SKIP_CHECK="0" CHIPDB="quick":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
set_cmake_vars_if_sccache
if [ {{CHIPDB}} != "none" ]; then
if [ $NEXTPNR_EXTERN_CHIPDB -eq 0 ]; then
cd $FPGA_ROOT/prjtrellis/libtrellis
check_branch {{SKIP_CHECK}} ${TRELLIS_REMOTE-origin} ${TRELLIS_BRANCH-master}
cmake -G"Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_SCCACHE_OPTS .
ninja -j${TRELLIS_JOBS-$NUM_JOBS} $MKDRY
ninja $MKDRY install
ninja_clean_if_sccache
build_nextpnr_chipdbs ecp5 {{CHIPDB}} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master}
else
get_remote_chipdbs ecp5
fi
fi
# build_nextpnr_chipdbs will also make sure remote is up-to-date for you.
if [ {{CHIPDB}} != "only" ] && [ {{CHIPDB}} != "only-full" ]; then
build_nextpnr ecp5 ${ECP5_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master}
fi
# Rebuild the iCE40 toolchain
_rebuild-ice40 DRY="0" SKIP_CHECK="0" CHIPDB="quick":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
set_cmake_vars_if_sccache
if [ {{CHIPDB}} != "none" ]; then
if [ $NEXTPNR_EXTERN_CHIPDB -eq 0 ]; then
cd $FPGA_ROOT/icestorm
check_branch {{SKIP_CHECK}} ${ICESTORM_REMOTE-origin} ${ICESTORM_BRANCH-master}
make_begin_if_sccache
make -j${ICESTORM_JOBS-$NUM_JOBS} $MKDRY PREFIX=$PREFIX
make_end_if_sccache
make $MKDRY PREFIX=$PREFIX install
make_clean_if_sccache
build_nextpnr_chipdbs ice40 {{CHIPDB}} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master}
else
get_remote_chipdbs ice40
fi
fi
# build_nextpnr_chipdbs will also make sure remote is up-to-date for you.
if [ {{CHIPDB}} != "only" ] && [ {{CHIPDB}} != "only-full" ]; then
build_nextpnr ice40 ${ICE40_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master}
fi
# Rebuild the yosys toolchain
_rebuild-yosys DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/yosys
check_branch {{SKIP_CHECK}} ${YOSYS_REMOTE-origin} ${YOSYS_BRANCH-master}
if [ "{{os()}}" = "windows" ]; then
# Invoking just will mess with the environment variable path
# pkg-config- restore it.
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
fi
# ENABLE_GHDL not handled here- must be added manually to Makefile.conf.
# Eventually Windows will load it like a plugin.
make -j${YOSYS_JOBS-$NUM_JOBS} $MKDRY PREFIX=$PREFIX ENABLE_SCCACHE=${SCCACHE:-0}
make $MKDRY PREFIX=$PREFIX install
make_clean_if_sccache
cd $FPGA_ROOT/SymbiYosys
check_branch {{SKIP_CHECK}} ${SYMBIYOSYS_REMOTE-origin} ${SYMBIYOSYS_BRANCH-master}
make $MKDRY PREFIX=$PREFIX install
# Rebuild the iverilog toolchain
_rebuild-iverilog DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/iverilog
check_branch {{SKIP_CHECK}} ${IVERILOG_REMOTE-origin} ${IVERILOG_BRANCH-master}
cd $FPGA_ROOT/build-iverilog
autoconf_begin_if_sccache
../iverilog/configure --prefix=$PREFIX # --no-create --no-recursion
autoconf_end_if_sccache
make -j${IVERILOG_JOBS-$NUM_JOBS} $MKDRY
make $MKDRY install
make_clean_if_sccache
# Rebuild the verilator simulator
_rebuild-verilator DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/verilator
check_branch {{SKIP_CHECK}} ${VERILATOR_REMOTE-origin} ${VERILATOR_BRANCH-master}
if [ "{{os()}}" = "windows" ]; then
# Known issue w/ MinGW:
cp /usr/include/FlexLexer.h $PREFIX/include
fi
autoconf
autoconf_begin_if_sccache
./configure --prefix=$PREFIX
autoconf_end_if_sccache
make -j${VERILATOR_JOBS-$NUM_JOBS} $MKDRY
make $MKDRY install
make_clean_if_sccache
# Rebuild the GHDL toolchain
_rebuild-ghdl DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/ghdl
check_branch {{SKIP_CHECK}} ${GHDL_REMOTE-origin} ${GHDL_BRANCH-master}
cd $FPGA_ROOT/build-ghdl
# if [ "{{os()}}" = "windows" ]; then
GHDL_BACKEND="--with-llvm-config"
# fi
# autoconf_begin_if_sccache
../ghdl/configure --prefix=$PREFIX --enable-libghdl $GHDL_BACKEND
# autoconf_end_if_sccache
make -j${GHDL_JOBS-$NUM_JOBS} $MKDRY
make $MKDRY install
# make_clean_if_sccache # If sccache support ever added, uncomment.
cd $FPGA_ROOT/ghdl-yosys-plugin
check_branch {{SKIP_CHECK}} ${GHDL_PLUGIN_REMOTE-origin} ${GHDL_PLUGIN_BRANCH-master}
if [ "{{os()}}" = "windows" ]; then
mkdir -p $FPGA_ROOT/yosys/frontends/ghdl
cp src/* $FPGA_ROOT/yosys/frontends/ghdl
else
# Number of ninja jobs is not manually set here.
make $MKDRY
make $MKDRY install
fi
# Rebuild the generic toolchain
_rebuild-generic DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
set_cmake_vars_if_sccache
build_nextpnr generic ${GENERIC_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master}
# Rebuild openocd
_rebuild-openocd DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/openocd
check_branch {{SKIP_CHECK}} ${OPENOCD_REMOTE-origin} ${OPENOCD_BRANCH-master}
if [ "{{os()}}" = "windows" ]; then
# Invoking just will mess with the paths aclocal looks at- restore it.
export ACLOCAL_PATH="/usr/share/aclocal/"
fi
./bootstrap
cd $FPGA_ROOT/build-openocd
autoconf_begin_if_sccache
# jimtcl's autosetup consults CCACHE, and won't play nicely w/ sccache.
CCACHE=none ../openocd/configure --prefix=$PREFIX # --no-create --no-recursion
autoconf_end_if_sccache
make -j${OPENOCD_JOBS-$NUM_JOBS} $MKDRY
make $MKDRY install
make_clean_if_sccache
# Rebuild dfu-util
_rebuild-dfu DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
cd $FPGA_ROOT/dfu-util
check_branch {{SKIP_CHECK}} ${DFU_REMOTE-origin} ${DFU_BRANCH-master}
if [ "{{os()}}" = "windows" ]; then
# Invoking just will mess with the paths aclocal looks at- restore it.
export ACLOCAL_PATH="/usr/share/aclocal/"
fi
./autogen.sh
cd $FPGA_ROOT/build-dfu
autoconf_begin_if_sccache
../dfu-util/configure --prefix=$PREFIX
autoconf_end_if_sccache
make -j${DFU_JOBS-$NUM_JOBS} $MKDRY
make $MKDRY install
make_clean_if_sccache
# Rebuild openFPGALoader
_rebuild-ofl DRY="0" SKIP_CHECK="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
set_dry {{DRY}}
set_cmake_vars_if_sccache
cd $FPGA_ROOT/openFPGALoader
check_branch {{SKIP_CHECK}} ${OFL_REMOTE-origin} ${OFL_BRANCH-master}
cd $FPGA_ROOT/openFPGALoader/build
cmake -G"Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_SCCACHE_OPTS ..
ninja -j${OFL_JOBS-$NUM_JOBS} $MKDRY
ninja $MKDRY install
ninja_clean_if_sccache
# Change all branches to master for the duration of this script (fail if not possible).
prepare CLEAN="0":
#!/bin/sh
set -e
# $1- Desired branch
switch_if_not_desired_branch() {
CURR_BR=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
if [ $CURR_BR = $1 ]; then
echo "Branch set to $1 on `pwd` already"
else
git checkout $1
fi
}
# $1- Directory to change to.
make_clean_if_clean() {
if [ {{CLEAN}} -ne 0 ]; then
cd $1
make clean
fi
}
# $1- Directory to change to.
ninja_clean_if_clean() {
if [ {{CLEAN}} -ne 0 ]; then
cd $1
ninja clean
fi
}
cd $FPGA_ROOT/icestorm
switch_if_not_desired_branch ${ICESTORM_BRANCH-master}
make_clean_if_clean `pwd`
cd $FPGA_ROOT/prjtrellis/libtrellis
switch_if_not_desired_branch ${TRELLIS_BRANCH-master}
ninja_clean_if_clean `pwd`
cd $FPGA_ROOT/nextpnr
switch_if_not_desired_branch ${NEXTPNR_BRANCH-master}
ninja_clean_if_clean $FPGA_ROOT/nextpnr/build-ice40
ninja_clean_if_clean $FPGA_ROOT/nextpnr/build-ecp5
cd $FPGA_ROOT/yosys
switch_if_not_desired_branch ${YOSYS_BRANCH-master}
if [ {{CLEAN}} -ne 0 ] && [ "{{os()}}" = "windows" ]; then
# Invoking just will mess with the environment variable path
# pkg-config- restore it.
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
fi
make_clean_if_clean `pwd`
cd $FPGA_ROOT/SymbiYosys
switch_if_not_desired_branch ${SYMBIYOSYS_BRANCH-master}
make_clean_if_clean `pwd`
cd $FPGA_ROOT/iverilog
switch_if_not_desired_branch ${IVERILOG_BRANCH-master}
make_clean_if_clean $FPGA_ROOT/build-iverilog
cd $FPGA_ROOT/verilator
switch_if_not_desired_branch ${VERILATOR_BRANCH-master}
make_clean_if_clean `pwd`
cd $FPGA_ROOT/ghdl
switch_if_not_desired_branch ${GHDL_BRANCH-master}
make_clean_if_clean $FPGA_ROOT/build-ghdl
cd $FPGA_ROOT/ghdl-yosys-plugin
switch_if_not_desired_branch ${GHDL_YOSYS_PLUGIN_BRANCH-master}
make_clean_if_clean `pwd`
cd $FPGA_ROOT/dfu-util
switch_if_not_desired_branch ${DFU_BRANCH-master}
make_clean_if_clean $FPGA_ROOT/build-dfu
cd $FPGA_ROOT/openFPGALoader
switch_if_not_desired_branch ${OFL_BRANCH-master}
ninja_clean_if_clean `pwd`/build
# Use with caution/not ready yet- need a mechanism to determine whether branch
# was actually changed in prepare. Might be removed completely.
# Change branches back to previous branches after running prepare.
_restore:
#!/bin/sh
set -e
# $1- Current branch
switch_to_previous_branch() {
set +e
PREV_REV=`git rev-parse @{-1} 2> /dev/null`
RET=$?
set -e
if [ $RET -ne 0 ]; then
PREV_BR=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
else
PREV_BR=`git name-rev $PREV_REV --name-only`
fi
if [ $PREV_BR=$1 ]; then
echo "Branch was set to $1 (or same commit as $1) on `pwd` previously"
else
git checkout -
fi
}
cd $FPGA_ROOT/icestorm
switch_to_previous_branch ${ICESTORM_BRANCH-master}
cd $FPGA_ROOT/prjtrellis
switch_to_previous_branch ${TRELLIS_BRANCH-master}
cd $FPGA_ROOT/nextpnr
switch_to_previous_branch ${NEXTPNR_BRANCH-master}
cd $FPGA_ROOT/yosys
switch_to_previous_branch ${YOSYS_BRANCH-master}
cd $FPGA_ROOT/SymbiYosys
switch_to_previous_branch ${SYMBIYOSYS_BRANCH-master}
cd $FPGA_ROOT/iverilog
switch_to_previous_branch ${IVERILOG_BRANCH-master}
cd $FPGA_ROOT/verilator
switch_to_previous_branch ${VERILATOR_BRANCH-master}
cd $FPGA_ROOT/ghdl
switch_to_previous_branch ${GHDL_BRANCH-master}
cd $FPGA_ROOT/ghdl-yosys-plugin
switch_to_previous_branch ${GHDL_YOSYS_PLUGIN_BRANCH-master}
cd $FPGA_ROOT/dfu-util
switch_to_previous_branch ${DFU_BRANCH-master}
cd $FPGA_ROOT/openFPGALoader
switch_to_previous_branch ${OFL_BRANCH-master}
# Create pre-built nextpnr chipdbs for a family.
build-chipdbs FAMILY CLEAN="0" PULL="0":
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
if [ {{PULL}} -ne 0 ]; then SKIP_CHECK=0; fi
if [ {{CLEAN}} -ne 0 ]; then CHIPDB="only-full"; fi
case {{FAMILY}} in
"ice40")
just -f "{{justfile()}}" _rebuild-ice40 "0" "${SKIP_CHECK=1}" "${CHIPDB=\"only\"}"
;;
"ecp5")
just -f "{{justfile()}}" _rebuild-ecp5 "0" "${SKIP_CHECK=1}" "${CHIPDB=\"only\"}"
;;
*)
echo "Unrecognized chipdb family {{FAMILY}}"
exit 1
;;
esac
# Grab pre-built nextpnr chipdbs on a machine that previously ran build-chipdbs.
get-chipdbs FAMILY:
#!/bin/sh
set -e
. "{{justfile_directory()}}/common.sh"
get_remote_chipdbs {{FAMILY}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment