aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2019-06-02 21:26:40 +0200
committerMichael Buesch <m@bues.ch>2019-06-02 22:24:11 +0200
commitac2df5c5d236a8a504a9ddff4d0de0b92c4b9baa (patch)
treeaa2fd47d5f657220b761ccdb606c70727f222133
parent7d5df4e64363ded7adcaa356e353e699b9b138f9 (diff)
downloadpyprofibus-ac2df5c5d236a8a504a9ddff4d0de0b92c4b9baa.tar.xz
pyprofibus-ac2df5c5d236a8a504a9ddff4d0de0b92c4b9baa.zip
phy_fpga: Add script to bootstrap toolchain
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--doc/hardware_fpga.md17
-rwxr-xr-xphy_fpga/build_toolchain.sh155
2 files changed, 172 insertions, 0 deletions
diff --git a/doc/hardware_fpga.md b/doc/hardware_fpga.md
index a00cde3..83f5c2c 100644
--- a/doc/hardware_fpga.md
+++ b/doc/hardware_fpga.md
@@ -49,6 +49,23 @@ The [nextpnr FPGA place and route tool](https://github.com/YosysHQ/nextpnr) is r
[GNU make](https://www.gnu.org/software/make/) and various other standard GNU/Linux shell utilities, that are already installed on any Desktop Linux distribution. Building on Windows is not supported.
+#### Downloading and installing all toolchain tools
+
+The script `build_toolchain.sh` that is included in the pyprofibus archive can be used to download, build and install all FPGA toolchain tools to the $HOME directory.
+
+Just run the script as follows. It will download all required packages, build and install everything to `$HOME/fpga-toolchain` by default.
+
+<pre>
+cd phy_fpga
+./build_toolchain.sh
+</pre>
+
+After successful execution of `build_toolchain.sh` please read the information about $PATH that the script prints to the console. The line printed by the script shall be added to your `$HOME/.bashrc`
+
+No changes to the operating system are necessary.<br />
+Do not run `build_toolchain.sh` as root.<br />
+The toolchain can be uninstalled by simply deleting the directory `$HOME/fpga-toolchain`
+
### Building pyprofibus PHY-FPGA
To build the PHY-FPGA sources run the following commands:
diff --git a/phy_fpga/build_toolchain.sh b/phy_fpga/build_toolchain.sh
new file mode 100755
index 0000000..1caacd2
--- /dev/null
+++ b/phy_fpga/build_toolchain.sh
@@ -0,0 +1,155 @@
+#!/bin/sh
+#
+# FPGA toolchain install script.
+# This script installs the full FPGA toolchain into the
+# directory specified as INSTALLDIR.
+#
+
+
+# The toolchain will be installed into this directory:
+INSTALLDIR="$HOME/fpga-toolchain"
+
+# The following directory will be used as temporary build directory:
+BUILDDIR="./toolchain-build"
+
+# Run at most this many build processes in parallel:
+PARALLEL="$(getconf _NPROCESSORS_ONLN)"
+
+# The following tools are needed to build the toolchain:
+# - gcc
+# - clang
+# - python3
+# - cmake
+# - git
+#
+# Please ensure that all these tools are installed in the system.
+
+
+
+#####################################################################
+#####################################################################
+#####################################################################
+
+
+# Source repositories:
+REPO_ICESTORM="https://github.com/cliffordwolf/icestorm.git"
+REPO_NEXTPNR="https://github.com/YosysHQ/nextpnr.git"
+REPO_YOSYS="https://github.com/YosysHQ/yosys.git"
+REPO_TINYPROG="https://github.com/tinyfpga/TinyFPGA-Bootloader.git"
+
+BUILD_ICESTORM=1
+BUILD_NEXTPNR=1
+BUILD_YOSYS=1
+BUILD_TINYPROG=1
+
+die()
+{
+ echo "$*" >&2
+ exit 1
+}
+
+checkprog()
+{
+ local prog="$1"
+ which "$prog" >/dev/null ||\
+ die "$prog is not installed. Please install it by use of the distribution package manager (apt, apt-get, rpm, etc...)"
+}
+
+[ "$(id -u)" = "0" ] && die "Do not run this as root!"
+checkprog gcc
+checkprog clang
+checkprog python3
+checkprog cmake
+checkprog git
+
+BUILDDIR="$(realpath -m -s "$BUILDDIR")"
+INSTALLDIR="$(realpath -m -s "$INSTALLDIR")"
+echo "BUILDDIR=$BUILDDIR"
+echo "INSTALLDIR=$INSTALLDIR"
+echo "PARALLEL=$PARALLEL"
+[ -n "$BUILDDIR" -a -n "$INSTALLDIR" ] || die "Failed to resolve directories"
+echo
+
+
+# Cleanup
+rm -rf "$BUILDDIR" || die "Failed to cleanup BUILDDIR"
+mkdir -p "$BUILDDIR" || die "Failed to create BUILDDIR"
+mkdir -p "$INSTALLDIR" || die "Failed to create INSTALLDIR"
+
+newpath="\$PATH"
+
+
+# Project Icestorm
+if [ $BUILD_ICESTORM -ne 0 ]; then
+ echo "Building icestorm..."
+ cd "$BUILDDIR" || die "Failed to cd to builddir."
+ git clone "$REPO_ICESTORM" "$BUILDDIR/icestorm" || die "Failed to clone icestorm"
+ cd "$BUILDDIR/icestorm" || die "Failed to cd to icestorm."
+ export PREFIX="$INSTALLDIR/icestorm"
+ make -j "$PARALLEL" PREFIX="$PREFIX" || die "Failed to build icestorm"
+ rm -rf "$PREFIX" || die "Failed to clean install icestorm"
+ make install PREFIX="$PREFIX" || die "Failed to install icestorm"
+ newpath="$PREFIX/bin:$newpath"
+fi
+
+
+# nextpnr
+if [ $BUILD_NEXTPNR -ne 0 ]; then
+ echo "Building nextpnr..."
+ cd "$BUILDDIR" || die "Failed to cd to builddir."
+ git clone "$REPO_NEXTPNR" "$BUILDDIR/nextpnr" || die "Failed to clone nextpnr"
+ mkdir "$BUILDDIR/nextpnr/builddir" || die "Failed to create nextpnr builddir"
+ cd "$BUILDDIR/nextpnr/builddir" || die "Failed to cd to nextpnr."
+ export PREFIX="$INSTALLDIR/nextpnr"
+ cmake -DARCH=ice40 -DICEBOX_ROOT="$INSTALLDIR/icestorm/share/icebox" -DCMAKE_INSTALL_PREFIX="$PREFIX" .. || die "Failed to build nextpnr"
+ make -j "$PARALLEL" || die "Failed to build nextpnr"
+ rm -rf "$PREFIX" || die "Failed to clean install nextpnr"
+ make install || die "Failed to install nextpnr"
+ newpath="$PREFIX/bin:$newpath"
+fi
+
+
+# yosys
+if [ $BUILD_YOSYS -ne 0 ]; then
+ echo "Building yosys..."
+ cd "$BUILDDIR" || die "Failed to cd to builddir."
+ git clone "$REPO_YOSYS" "$BUILDDIR/yosys" || die "Failed to clone yosys"
+ cd "$BUILDDIR/yosys" || die "Failed to cd to yosys."
+ export PREFIX="$INSTALLDIR/yosys"
+ make config-clang PREFIX="$PREFIX" || die "Failed to configure yosys"
+ make -j "$PARALLEL" PREFIX="$PREFIX" || die "Failed to build yosys"
+ rm -rf "$PREFIX" || die "Failed to clean install yosys"
+ make install PREFIX="$PREFIX" || die "Failed to install yosys"
+ newpath="$PREFIX/bin:$newpath"
+fi
+
+
+# tinyprog
+if [ $BUILD_TINYPROG -ne 0 ]; then
+ echo "Building tinyprog..."
+ cd "$BUILDDIR" || die "Failed to cd to builddir."
+ git clone "$REPO_TINYPROG" "$BUILDDIR/TinyFPGA-Bootloader" || die "Failed to clone tinyprog"
+ cd "$BUILDDIR/TinyFPGA-Bootloader/programmer" || die "Failed to cd to tinyprog."
+ export PREFIX="$INSTALLDIR/tinyprog"
+ rm -rf "$PREFIX" || die "Failed to clean install tinyprog"
+ mkdir -p "$PREFIX/share" || die "Failed to create tinyprog share"
+ mkdir -p "$PREFIX/bin" || die "Failed to create tinyprog bin"
+ cp -r "$BUILDDIR/TinyFPGA-Bootloader/programmer/tinyprog" "$PREFIX/share/" || die "Failed to install tinyprog"
+ cat > "$PREFIX/bin/tinyprog" <<EOF
+#!/bin/sh
+export PYTHONPATH="$PREFIX/share/"
+exec python3 "$PREFIX/share/tinyprog" "\$@"
+EOF
+ [ -f "$PREFIX/bin/tinyprog" ] || die "Failed to install tinyprog wrapper"
+ chmod 755 "$PREFIX/bin/tinyprog" || die "Failed to chmod tinyprog"
+ newpath="$PREFIX/bin:$newpath"
+fi
+
+echo
+echo
+echo
+echo "Successfully built and installed all FPGA tools to: $INSTALLDIR"
+echo "Please add the following line to your $HOME/.bashrc file:"
+echo
+echo "export PATH=\"$newpath\""
+echo
bues.ch cgit interface