#!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later # Fetch lvd2's AY-3-8910 die model at its pin into upstream/ (git-ignored), give its trireg # nets keepers (patches/trireg-keepers.patch, applied to a copy in build/) and compile the # Icarus Verilog testbench into build/ay_ref (git-ignored). Writes build/build-info.json. # # ./build.sh fetch what is missing, patch, build # OSS_CAD_SUITE=DIR ./build.sh take iverilog from DIR/bin (else the PATH) # # Only rtl/ and the top-level files (LICENSE) are checked out; the schematics and PDFs are not # fetched. Never deletes anything: a checkout at another commit with local changes stops the # script. set -eu HERE=$(cd "$(dirname "$0")" && pwd) UP=$HERE/upstream/ay-3-8910_reverse_engineered OUT=$HERE/build URL=https://github.com/lvd2/ay-3-8910_reverse_engineered PIN=cf8d14db0aec5ae86ed4f4e6e67bf14c40a42d77 [ -n "${OSS_CAD_SUITE:-}" ] && PATH="$OSS_CAD_SUITE/bin:$PATH" command -v iverilog > /dev/null || { echo "build.sh: iverilog not found (PATH or OSS_CAD_SUITE)" >&2; exit 3; } mkdir -p "$HERE/upstream" "$OUT" if [ ! -d "$UP/.git" ]; then git clone --quiet --filter=blob:none --no-checkout "$URL" "$UP" git -C "$UP" sparse-checkout set rtl git -C "$UP" -c advice.detachedHead=false checkout --quiet "$PIN" fi if [ "$(git -C "$UP" rev-parse HEAD)" != "$PIN" ]; then if [ -n "$(git -C "$UP" status --porcelain)" ]; then echo "build.sh: $UP has local changes and is not at $PIN; move it aside first" >&2 exit 1 fi git -C "$UP" fetch --quiet origin git -C "$UP" -c advice.detachedHead=false checkout --quiet "$PIN" fi if [ -n "$(git -C "$UP" status --porcelain)" ]; then echo "build.sh: $UP has local changes; move it aside first" >&2 exit 1 fi model=$OUT/ay_model_icarus.v patch --quiet --no-backup-if-mismatch -r - -o "$model" "$UP/rtl/ay_model.v" \ < "$HERE/patches/trireg-keepers.patch" left=$(grep -c '^[[:space:]]*trireg' "$model" || true) kept=$(grep -c 'ay_tb_keeper' "$model" || true) [ "$left" = 0 ] && [ "$kept" = 6 ] || { echo "build.sh: expected 0 trireg nets left and 6 keepers, got $left and $kept" >&2; exit 1; } vvp -V 2>&1 | head -n 1 # The model's begin/end blocks draw one warning each under -g2012; it says nothing about us. iverilog -g2012 -o "$OUT/ay_ref" "$HERE/ay_tb.v" "$model" 2>&1 | grep -v "Anachronistic use of begin/end" || true [ -f "$OUT/ay_ref" ] || { echo "build.sh: iverilog wrote no $OUT/ay_ref" >&2; exit 1; } echo "built $OUT/ay_ref (ay-3-8910_reverse_engineered @ ${PIN%"${PIN#???????}"}, trireg-keepers.patch)" printf '{"compiler": "%s", "flags": "-g2012", "built": "%s", "upstream": "%s", "patches": ["trireg-keepers.patch"]}\n' \ "$(vvp -V 2>&1 | head -n 1)" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ "$(git -C "$UP" rev-parse HEAD)" > "$OUT/build-info.json"