Files
ESP32-S3-Touch-LCD-5B/.gitea/workflows/firmware.yml
T
julian effa949429 OTA updates for Controller A: dual-slot partitions, signed Gitea releases
- partition table: two 7.9 MB OTA slots, SPIFFS dropped, nvs/otadata offsets
  unchanged (tunables survived the one-time USB flash)
- ota_update.cpp: manual `ota status|check|install|rollback` console; HTTPS
  pull from the public repo's latest release, ECDSA P-256 signature over
  "patrol-a|version|sha256" checked before download, streamed image must match,
  parked gate before download and before the slot switch, 30 s
  confirm-or-rollback (verifyRollbackLater override)
- ota_config.h: server/repo, ISRG Root X1 + Root YR, signing public key
- .gitea/workflows/firmware.yml: main -> rolling unsigned pre-release
  main-latest; v* tag -> signed release (needs secret FIRMWARE_SIGNING_KEY)
- wiki: pages/ota-updates.md (design, decisions, B-over-ESP-NOW plan);
  CLAUDE.md, index, log, open-questions #12 updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 21:59:46 +02:00

140 lines
6.2 KiB
YAML

name: Firmware
# Controller A firmware, built by PlatformIO on every push. Two outputs:
#
# - push to main -> rolling PRE-release `main-latest` (firmware.bin + .elf),
# unsigned, no manifest. For bench testing / USB flashing.
# The device never installs it: it only reads
# /releases/latest, which skips pre-releases, and it
# needs a signed manifest.txt anyway.
# - push tag v* -> the OTA release: firmware.bin + firmware.elf +
# manifest.txt (size, sha256, ECDSA P-256 signature over
# "patrol-a|<tag>|<sha256>"). This is what `ota install`
# on the controller pulls.
#
# Signing key: repo secret FIRMWARE_SIGNING_KEY (PEM, EC P-256). Its public
# half is compiled into the firmware (include/config/ota_config.h) and kept in
# tools/ota/firmware_signing_pub.pem, which this job uses to self-check the
# signature before publishing. See wiki/pages/ota-updates.md.
#
# Releases go through the Gitea API with plain curl (actions/upload-artifact
# is unreliable on this runner - same pattern as parking_solution).
on:
push:
branches: [main]
tags: ['v*']
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: |
if [ "${GITHUB_REF#refs/tags/}" != "${GITHUB_REF}" ]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="main-${GITHUB_SHA:0:7}"
fi
case "$VERSION" in *[!A-Za-z0-9._-]*) echo "::error::bad version '$VERSION'"; exit 1;; esac
[ ${#VERSION} -lt 32 ] || { echo "::error::version too long"; exit 1; }
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "version: ${VERSION}"
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: |
~/.platformio/packages
~/.platformio/platforms
.pio/libdeps
key: pio-${{ hashFiles('platformio.ini') }}
- name: Install PlatformIO
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
uv tool install platformio
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Build
run: |
export PLATFORMIO_BUILD_FLAGS="-DFW_VERSION=\\\"${VERSION}\\\""
pio run
mkdir -p dist
cp .pio/build/waveshare_esp32_s3_lcd_5b/firmware.bin dist/
cp .pio/build/waveshare_esp32_s3_lcd_5b/firmware.elf dist/
grep -q "${VERSION}" dist/firmware.bin || { echo "::error::FW_VERSION not baked into the image"; exit 1; }
ls -la dist/
- name: Sign + manifest (tags only)
if: startsWith(github.ref, 'refs/tags/')
env:
FIRMWARE_SIGNING_KEY: ${{ secrets.FIRMWARE_SIGNING_KEY }}
run: |
set -e
[ -n "$FIRMWARE_SIGNING_KEY" ] || { echo "::error::secret FIRMWARE_SIGNING_KEY is not set"; exit 1; }
SHA=$(sha256sum dist/firmware.bin | cut -d' ' -f1)
SIZE=$(stat -c%s dist/firmware.bin)
printf '%s' "patrol-a|${VERSION}|${SHA}" > stmt.txt
umask 077
printf '%s\n' "$FIRMWARE_SIGNING_KEY" > key.pem
openssl dgst -sha256 -sign key.pem -out sig.der stmt.txt
rm -f key.pem
# Self-check against the public key the firmware carries.
openssl dgst -sha256 -verify tools/ota/firmware_signing_pub.pem -signature sig.der stmt.txt
SIG=$(od -An -v -tx1 sig.der | tr -d ' \n')
printf 'target=patrol-a\nversion=%s\nsize=%s\nsha256=%s\nsig=%s\n' \
"$VERSION" "$SIZE" "$SHA" "$SIG" > dist/manifest.txt
cat dist/manifest.txt
- name: Publish release
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
API: ${{ github.api_url }}
REPO: ${{ github.repository }}
run: |
set -e
auth="Authorization: token ${TOKEN}"
if [ "${GITHUB_REF#refs/tags/}" != "${GITHUB_REF}" ]; then
TAG="${GITHUB_REF_NAME}"
PRE=false
NAME="Controller A ${TAG}"
BODY="Signed OTA release. Install on the controller with \`ota install\` (parked, Wi-Fi joined)."
else
TAG="main-latest"
PRE=true
NAME="Controller A main build"
BODY="Unsigned build of main @ ${GITHUB_SHA}. Rolling - overwritten each push. Not installable over OTA; flash over USB for bench tests."
# Rolling: drop the previous release and its tag, recreate at this commit.
OLD=$(curl -sS -H "$auth" "${API}/repos/${REPO}/releases/tags/${TAG}" \
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
if [ -n "$OLD" ]; then
curl -sS -X DELETE -H "$auth" "${API}/repos/${REPO}/releases/${OLD}" || true
curl -sS -X DELETE -H "$auth" "${API}/repos/${REPO}/git/refs/tags/${TAG}" || true
fi
fi
REL=$(curl -sS -X POST -H "$auth" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${NAME}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":${PRE}}" \
"${API}/repos/${REPO}/releases" || true)
REL_ID=$(printf '%s' "$REL" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
if [ -z "$REL_ID" ]; then
REL_ID=$(curl -sS -H "$auth" "${API}/repos/${REPO}/releases/tags/${TAG}" \
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
fi
[ -n "$REL_ID" ] || { echo "::error::could not create release: $REL"; exit 1; }
echo "release id: ${REL_ID}"
for f in dist/*; do
name=$(basename "$f")
echo "uploading ${name}"
code=$(curl -sS -o /tmp/up.json -w '%{http_code}' -X POST -H "$auth" \
-H "Content-Type: application/octet-stream" --data-binary @"${f}" \
"${API}/repos/${REPO}/releases/${REL_ID}/assets?name=${name}")
[ "$code" = "201" ] || { echo "::error::upload ${name} failed (HTTP ${code}): $(cat /tmp/up.json)"; exit 1; }
done
echo "published ${TAG}"