From c6791de7282d478e46ba986ee412ecb05dfc8457 Mon Sep 17 00:00:00 2001 From: Jari Date: Tue, 23 Jun 2026 21:22:34 -0400 Subject: [PATCH] Fix uf2 generation in CI --- .github/workflows/build.yml | 6 ++++ .github/workflows/release.yml | 14 ++++++++-- gen_uf2.sh | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100755 gen_uf2.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 93b4be3..84519cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,12 @@ jobs: --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \ OpenPuck + - name: Generate UF2 + # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in + # platform.txt, so arduino-cli only emits .hex/.zip. Convert the .hex to + # a drag-and-drop .uf2 ourselves. + run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2 + - name: List build outputs run: | find build/openpuck -maxdepth 1 -type f -print | sort diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bec7f4a..1a3cf32 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,9 @@ jobs: --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \ OpenPuck + - name: Generate UF2 (standard) + run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2 + - name: Compile recovery build run: | mkdir -p build/openpuck-recovery build/cache/openpuck-recovery @@ -59,6 +62,9 @@ jobs: --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DOPK_FACTORY_RESET=1" \ OpenPuck + - name: Generate UF2 (recovery) + run: ./gen_uf2.sh build/openpuck-recovery/OpenPuck.ino.hex build/openpuck-recovery/OpenPuck.ino.uf2 + - name: Collect artifacts run: | mkdir -p release_assets @@ -71,14 +77,16 @@ jobs: -maxdepth 1 -type f \ \( -name '*.uf2' -o -name '*.zip' \) \ -print | while read -r f; do - base="$(basename "$f")" + # Keep only the extension; the arduino base name (OpenPuck.ino.*) + # is redundant once we prefix with OpenPuck--. + ext="${f##*.}" dir="$(basename "$(dirname "$f")")" if [ "$dir" = "openpuck-recovery" ]; then flavor="factory-reset" else flavor="standard" fi - cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}-${base}" + cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}.${ext}" done test -n "$(find release_assets -maxdepth 1 -type f -print -quit)" ls -la release_assets @@ -100,6 +108,6 @@ jobs: ### Files included: - `.zip` files for Adafruit DFU tool - - `.uf2` files for drag-and-drop flashing, if generated by the board core + - `.uf2` files for drag-and-drop flashing (BOOT/UF2 drive) env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/gen_uf2.sh b/gen_uf2.sh new file mode 100755 index 0000000..bf8b945 --- /dev/null +++ b/gen_uf2.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# gen_uf2.sh -- convert a compiled .hex into a .uf2 for drag-and-drop flashing. +# +# The Adafruit nRF52 core ships uf2conv.py but leaves the UF2 objcopy recipe +# COMMENTED OUT in platform.txt (recipe.objcopy.uf2.pattern), so `arduino-cli +# compile` only ever emits .hex/.zip and never a .uf2. This regenerates the +# .uf2 from the .hex after the compile step. +# +# Usage: ./gen_uf2.sh [family] +set -e + +HEX="$1" +OUT="$2" +# nRF52840 UF2 family id (boards.txt: feather52840.build.uf2_family=0xADA52840). +FAMILY="${3:-0xADA52840}" + +if [ -z "$HEX" ] || [ -z "$OUT" ]; then + echo "usage: $0 [family]" >&2 + exit 2 +fi +if [ ! -f "$HEX" ]; then + echo "gen_uf2.sh: input hex not found: $HEX" >&2 + exit 1 +fi + +# Locate uf2conv.py inside the installed Adafruit nRF52 core. Honor a custom +# Arduino data dir (config get), falling back to the per-OS defaults. +DATA_DIR="$(arduino-cli config get directories.data 2>/dev/null || true)" +if [ -z "$DATA_DIR" ]; then + if [ -d "$HOME/Library/Arduino15" ]; then + DATA_DIR="$HOME/Library/Arduino15" + else + DATA_DIR="$HOME/.arduino15" + fi +fi + +UF2CONV="$(find "$DATA_DIR/packages/adafruit/hardware/nrf52" -name uf2conv.py 2>/dev/null | sort | tail -n1)" +if [ -z "$UF2CONV" ]; then + echo "gen_uf2.sh: could not find uf2conv.py under $DATA_DIR" >&2 + exit 1 +fi + +# Prefer python3; fall back to a bare python (the CI runner's setup-python +# provides `python`, while macOS only ships `python3`). uf2conv.py is py3-safe. +PYTHON="$(command -v python3 || command -v python || true)" +if [ -z "$PYTHON" ]; then + echo "gen_uf2.sh: no python interpreter found" >&2 + exit 1 +fi + +"$PYTHON" "$UF2CONV" -f "$FAMILY" -c -o "$OUT" "$HEX" +echo "gen_uf2.sh: wrote $OUT (family $FAMILY)" -- knotmirror 0.0.1