From 2802fd1b481f3563c4c0f76bfc671d1dee6711a0 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Mon, 12 Oct 2026 14:27:50 +0800 Subject: [PATCH] FPGA: Added workflow for PM5 fpga build. --- .github/workflows/fpga-pm5.yml | 87 ++++++++++++++++++++++++++++++++++ fpga/proxmark5_fpga.mk | 7 ++- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fpga-pm5.yml diff --git a/.github/workflows/fpga-pm5.yml b/.github/workflows/fpga-pm5.yml new file mode 100644 index 000000000..1a0f88b5f --- /dev/null +++ b/.github/workflows/fpga-pm5.yml @@ -0,0 +1,87 @@ +name: FPGA PM5 Build + +on: + push: + paths: + - 'fpga/**' + - '.github/workflows/fpga-pm5.yml' + pull_request: + paths: + - 'fpga/**' + - '.github/workflows/fpga-pm5.yml' + workflow_dispatch: + +env: + # oss-cad-suite is released daily; bump the date to move to a newer one. + OSS_CAD_SUITE_VERSION: '2026-10-11' + +permissions: + contents: read + +jobs: + pm5: + name: Build PM5 bitstream + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Install oss-cad-suite + run: | + set -euo pipefail + url="https://github.com/YosysHQ/oss-cad-suite-build/releases/download/${OSS_CAD_SUITE_VERSION}/oss-cad-suite-linux-x64-${OSS_CAD_SUITE_VERSION//-/}.tgz" + echo "Fetching $url" + curl -sSL "$url" | tar -xz -C "$RUNNER_TEMP" + # the makefile puts the suite's bin/, lib/ and bundled python3 in + # front of PATH itself, so nothing else needs to be exported + echo "OSS_CAD_SUITE=$RUNNER_TEMP/oss-cad-suite" >> "$GITHUB_ENV" + + - name: Show the toolchain + run: | + set -euo pipefail + # the same resolution the build uses, then the versions for the log + make -C fpga -f proxmark5_fpga.mk check-tools + set +u + source "$OSS_CAD_SUITE/environment" + set -u + yosys -V + nextpnr-himbaechel --version + python3 -c "import apycula; print('apycula:', apycula.__file__)" + + # Place and route fails the job on a timing violation, so this does not + # only prove the design still elaborates. + - name: Build the PM5 bitstream + run: make -C fpga pm5 + + - name: Check the bitstream + run: | + set -euo pipefail + bin_size=$(stat -c%s fpga/fpga_pm5.bin) + fs_size=$(stat -c%s fpga/fpga_pm5.fs) + echo "fpga_pm5.bin ${bin_size} bytes" + echo "fpga_pm5.fs ${fs_size} bytes" + # the .bin is the bitstream the ARM JTAG loader shifts out, the .fs is + # its ASCII form: 8 characters plus a newline per byte + test "$bin_size" -gt 100000 + test "$fs_size" -gt $((bin_size * 6)) + test "$fs_size" -lt $((bin_size * 10)) + + # A rebuild from scratch has to produce the same bytes; the tools carry no + # timestamp, so a difference means something started leaking one in, and + # a released bitstream could no longer be checked against the sources. + - name: Check the build is reproducible + run: | + set -euo pipefail + md5sum fpga/fpga_pm5.fs fpga/fpga_pm5.bin > "$RUNNER_TEMP/bitstream.md5" + make -C fpga -f proxmark5_fpga.mk clean + make -C fpga pm5 + md5sum -c "$RUNNER_TEMP/bitstream.md5" + + - name: Upload the bitstream + uses: actions/upload-artifact@v6 + with: + name: fpga-pm5-bitstream + path: | + fpga/fpga_pm5.fs + fpga/fpga_pm5.bin + if-no-files-found: error diff --git a/fpga/proxmark5_fpga.mk b/fpga/proxmark5_fpga.mk index 6b62c17da..909a99a87 100644 --- a/fpga/proxmark5_fpga.mk +++ b/fpga/proxmark5_fpga.mk @@ -43,9 +43,12 @@ PM5_OUT = $(PREFIX)build_$(PM5_NAME) # The oss-cad-suite launchers need their root, and both bin/ and lib/ on PATH # (lib/ carries the shared libraries), otherwise they exit without a message. +# The suite bundles its own python, named per platform. With OSS_CAD_SUITE +# unset everything comes from PATH instead, which is what sourcing the suite's +# environment script gives you. ifneq ($(OSS_CAD_SUITE),) -OC_ENV = YOSYSHQ_ROOT="$(OSS_CAD_SUITE)/" PATH="$(OSS_CAD_SUITE)/bin:$(OSS_CAD_SUITE)/lib:$$PATH" PYTHON_EXECUTABLE="$(OSS_CAD_SUITE)/lib/python3.exe" -OC_PYTHON = $(OSS_CAD_SUITE)/lib/python3.exe +OC_PYTHON = $(firstword $(wildcard $(OSS_CAD_SUITE)/lib/python3.exe $(OSS_CAD_SUITE)/py3bin/python3 $(OSS_CAD_SUITE)/lib/python3 $(OSS_CAD_SUITE)/bin/python3) python3) +OC_ENV = YOSYSHQ_ROOT="$(OSS_CAD_SUITE)/" PATH="$(OSS_CAD_SUITE)/bin:$(OSS_CAD_SUITE)/lib:$$PATH" LD_LIBRARY_PATH="$(OSS_CAD_SUITE)/lib:$$LD_LIBRARY_PATH" PYTHON_EXECUTABLE="$(OC_PYTHON)" else OC_ENV = OC_PYTHON = python3