From bb18d5b9e9507008efcfef6b6e8a7a5c97abdf2b Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Wed, 29 Jan 2025 14:13:11 +0100 Subject: [PATCH] toolchain: Introduce buildtools.sh script Instead of repeated RUNs in Dockerfile, move the entire build of specific tools to a script. - Make commands more shell script-like. - icestorm: Make sure we checkout the right commit. - Add checks for the right digest for all git clones, so no history has been changed. - Add digest file and check for the downloaded tarball. --- contrib/Dockerfile | 104 ++------------------------------ contrib/buildtools.sh | 134 +++++++++++++++++++++++++++++++++++++++++ contrib/verible.sha512 | 1 + 3 files changed, 139 insertions(+), 100 deletions(-) create mode 100755 contrib/buildtools.sh create mode 100644 contrib/verible.sha512 diff --git a/contrib/Dockerfile b/contrib/Dockerfile index 37ed248..7616eab 100644 --- a/contrib/Dockerfile +++ b/contrib/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get -qq update -y \ clang-format \ clang-tidy \ cmake \ + curl \ flex \ g++ \ gawk \ @@ -57,109 +58,12 @@ RUN apt-get -qq update -y \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* -# Enable bash completion -RUN sed -i '/#if ! shopt -oq posix; then/ s/^#//' /etc/bash.bashrc -RUN sed -i '/# if \[ -f \/usr\/share\/bash-completion\/bash_completion \]; then/ s/^#//' /etc/bash.bashrc -RUN sed -i '/# . \/usr\/share\/bash-completion\/bash_completion/ s/^#//' /etc/bash.bashrc -RUN sed -i '/# elif \[ -f \/etc\/bash_completion \]; then/ s/^#//' /etc/bash.bashrc -RUN sed -i '/# . \/etc\/bash_completion/ s/^#//' /etc/bash.bashrc -RUN sed -i '/# fi/ s/^#//' /etc/bash.bashrc -RUN sed -i '/#fi/ s/^#//' /etc/bash.bashrc - FROM base as toolsbuilder -RUN git clone --depth=1 https://github.com/YosysHQ/icestorm /src -WORKDIR /src -RUN git checkout 738af822905fdcf0466e9dd784b9ae4b0b34987f \ - && make -j$(nproc --ignore=2) \ - && make install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-icestorm -WORKDIR / -RUN rm -rf /src +COPY buildtools.sh /buildtools.sh +COPY verible.sha512 /verible.sha512 -# Custom iceprog for the RPi 2040-based programmer (will be upstreamed). -RUN git clone -b interfaces --depth=1 https://github.com/tillitis/icestorm /src -WORKDIR /src/iceprog -RUN make -j$(nproc --ignore=2) \ - && make PROGRAM_PREFIX=tillitis- install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-tillitis--icestorm -WORKDIR / -RUN rm -rf /src - -RUN git clone -b 0.45 --depth=1 https://github.com/YosysHQ/yosys /src -WORKDIR /src -RUN git submodule update --init \ - && make -j$(nproc --ignore=2) \ - && make install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-yosys -WORKDIR / -RUN rm -rf /src - -RUN git clone -b nextpnr-0.7 https://github.com/YosysHQ/nextpnr /src -WORKDIR /src -# Add "Fix handling of RNG seed" #1369 -RUN git cherry-pick --no-commit 6ca64526bb18ace8690872b09ca1251567c116de -# Add early exit if place fails on timing -RUN sed -i \ - '345i \ \ \ \ general.add_options()("exit-on-failed-target-frequency",' \ - common/kernel/command.cc -RUN sed -i \ - '346i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "exit if target frequency is not achieved (use together with "' \ - common/kernel/command.cc -RUN sed -i \ - '347i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "--randomize-seed option)");' \ - common/kernel/command.cc -RUN sed -i \ - '348i \\' \ - common/kernel/command.cc -RUN sed -i \ - '662s/if (do_route) {/if (do_route \&\& (vm.count("exit-on-failed-target-frequency") ? !had_nonfatal_error : true)) {/' \ - common/kernel/command.cc -RUN sed -i \ - '244s/bool warn_on_failure = false/bool warn_on_failure = true/' \ - common/kernel/timing.h -RUN cmake -DARCH=ice40 . \ - && make -j$(nproc --ignore=2) \ - && make install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-nextpnr -WORKDIR / -RUN rm -rf /src - -RUN git clone -b v12_0 --depth=1 https://github.com/steveicarus/iverilog /src -WORKDIR /src -RUN sh autoconf.sh \ - && ./configure \ - && make -j$(nproc --ignore=2) \ - && make install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-iverilog -WORKDIR / -RUN rm -rf /src - -RUN git clone -b v5.028 --depth=1 https://github.com/verilator/verilator /src -WORKDIR /src -RUN autoconf \ - && ./configure \ - && make -j$(nproc --ignore=2) \ - && make test \ - && make install \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-verilator -WORKDIR / -RUN rm -rf /src - -ADD https://github.com/chipsalliance/verible/releases/download/v0.0-3795-gf4d72375/verible-v0.0-3795-gf4d72375-linux-static-x86_64.tar.gz /src/verible.tar.gz -WORKDIR /src -RUN tar xvf verible.tar.gz -RUN mv -v verible*/bin/* /usr/local/bin -RUN verible-verilog-format --version | head -1 > /usr/local/repo-commit-verible -WORKDIR / -RUN rm -rf /src - -RUN git clone -b v1.9.1 https://github.com/cocotb/cocotb.git /src -WORKDIR /src -RUN pip install . --break-system-packages \ - && git describe --all --always --long --dirty > /usr/local/repo-commit-cocotb -WORKDIR / -RUN rm -rf /src +RUN /buildtools.sh FROM base LABEL org.opencontainers.image.description="Toolchain for building TKey FPGA bitstream" diff --git a/contrib/buildtools.sh b/contrib/buildtools.sh new file mode 100755 index 0000000..11e9f74 --- /dev/null +++ b/contrib/buildtools.sh @@ -0,0 +1,134 @@ +#! /bin/sh -e + +# Copyright (C) 2025 Tillitis AB +# SPDX-License-Identifier: GPL-2.0-only + +## Build the specific versions of the tools we need to build the TKey +## FPGA bitstream and apps. + +cd / +mkdir src + +# ---------------------------------------------------------------------- +# Project icestorm +# ---------------------------------------------------------------------- +git clone https://github.com/YosysHQ/icestorm /src/icestorm +cd /src/icestorm + +# No tags or releases yet. Pin down to a specific commit. +git checkout 738af822905fdcf0466e9dd784b9ae4b0b34987f +make -j$(nproc --ignore=2) +make install +git describe --all --always --long --dirty > /usr/local/repo-commit-icestorm + +# ---------------------------------------------------------------------- +# Our own custom iceprog for the RPi 2040-based programmer. Will be +# upstreamed. +# ---------------------------------------------------------------------- +git clone -b interfaces --depth=1 https://github.com/tillitis/icestorm /src/icestorm-tillitis +cd /src/icestorm-tillitis/iceprog +make -j$(nproc --ignore=2) +make PROGRAM_PREFIX=tillitis- install +git describe --all --always --long --dirty > /usr/local/repo-commit-tillitis--icestorm + +# ---------------------------------------------------------------------- +# yosys +# ---------------------------------------------------------------------- +git clone -b 0.45 --depth=1 https://github.com/YosysHQ/yosys /src/yosys +cd /src/yosys + +# Make sure the digest is correct and no history has changed +git checkout 9ed031ddd588442f22be13ce608547a5809b62f0 + +git submodule update --init +make -j$(nproc --ignore=2) +make install +git describe --all --always --long --dirty > /usr/local/repo-commit-yosys + +# ---------------------------------------------------------------------- +# nextpnr +# ---------------------------------------------------------------------- +git clone -b nextpnr-0.7 https://github.com/YosysHQ/nextpnr /src/nextpnr +cd /src/nextpnr +# Make sure the digest is correct and no history has changed +git checkout 73b7de74a5769095acb96eb6c6333ffe161452f2 + +# Add "Fix handling of RNG seed" #1369 +git cherry-pick --no-commit 6ca64526bb18ace8690872b09ca1251567c116de + +# Add early exit if place fails on timing +sed -i \ + '345i \ \ \ \ general.add_options()("exit-on-failed-target-frequency",' \ + common/kernel/command.cc +sed -i \ + '346i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "exit if target frequency is not achieved (use together with "' \ + common/kernel/command.cc +sed -i \ + '347i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "--randomize-seed option)");' \ + common/kernel/command.cc +sed -i \ + '348i \\' \ + common/kernel/command.cc +sed -i \ + '662s/if (do_route) {/if (do_route \&\& (vm.count("exit-on-failed-target-frequency") ? !had_nonfatal_error : true)) {/' \ + common/kernel/command.cc +sed -i \ + '244s/bool warn_on_failure = false/bool warn_on_failure = true/' \ + common/kernel/timing.h + +cmake -DARCH=ice40 . +make -j$(nproc --ignore=2) +make install +git describe --all --always --long --dirty > /usr/local/repo-commit-nextpnr + +# ---------------------------------------------------------------------- +# icarus verilog +# ---------------------------------------------------------------------- +git clone -b v12_0 --depth=1 https://github.com/steveicarus/iverilog /src/iverilog +cd /src/iverilog + +# Make sure the digest is correct and no history has changed +git checkout 4fd5291632232fbe1ba49b2c26bb6b2bf1c6c9cf +sh autoconf.sh +./configure +make -j$(nproc --ignore=2) +make install +git describe --all --always --long --dirty > /usr/local/repo-commit-iverilog + +# ---------------------------------------------------------------------- +# verilator +# ---------------------------------------------------------------------- +git clone -b v5.028 --depth=1 https://github.com/verilator/verilator /src/verilator +cd /src/verilator + +# Make sure the digest is correct and no history has changed +git checkout 8ca45df9c75c611989ae5bfc4112a32212c3dacf + +autoconf +./configure +make -j$(nproc --ignore=2) +make test +make install +git describe --all --always --long --dirty > /usr/local/repo-commit-verilator + +# ---------------------------------------------------------------------- +# verible +# ---------------------------------------------------------------------- +curl --output /src/verible.tar.gz -L https://github.com/chipsalliance/verible/releases/download/v0.0-3795-gf4d72375/verible-v0.0-3795-gf4d72375-linux-static-x86_64.tar.gz + +# Check against the expected digest +sha512sum -c /verible.sha512 + +cd /src + +tar xvf verible.tar.gz +mv -v verible*/bin/* /usr/local/bin +verible-verilog-format --version | head -1 > /usr/local/repo-commit-verible + +# ---------------------------------------------------------------------- +# cocotb +# ---------------------------------------------------------------------- +git clone -b v1.9.1 https://github.com/cocotb/cocotb.git /src/cocotb +cd /src/cocotb +pip install . --break-system-packages +git describe --all --always --long --dirty > /usr/local/repo-commit-cocotb diff --git a/contrib/verible.sha512 b/contrib/verible.sha512 new file mode 100644 index 0000000..9c8fb74 --- /dev/null +++ b/contrib/verible.sha512 @@ -0,0 +1 @@ +3e997b8cd494556fa107b96a6daa4e51133208a85b3c0250c0223d7194aedbc98b3f5213fedaee083edd96c317e50057aa9cdc0517197f4638be3834133e2c9f /src/verible.tar.gz