Files
noahandClaude Opus 5.5 2d3417b7d3
source-pr / source (pull_request) Successful in 3m26s
web: public read-only GET /api/identity for fleet discovery
alkane-toolkit's fleet scan (asic-rs) recognises miners by their cgminer
socket or vendor web UI; an Alkane board has neither exposed, so it never
appeared and could not be right-clicked to flash. Add an open, read-only
identity endpoint beside /api/summary: os, os_version, board, sdk_revision,
hostname, mac, kernel - nothing a stock miner does not already expose, no
secret. The .afw packager stamps the bundle version into
/etc/alkane-os-version for it. Tests: served without a session; every field
read from the board files; absent files read as null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
2026-11-12 15:40:02 -06:00

88 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a zynq-7010 .afw carrying the current alkane-os console.
#
# The SDK builds the base OS (kernel, dtb, rootfs) for the board; this script
# cross-compiles the current alkane-os binary for armv7 (static musl, matching
# the SDK rootfs), drops it and the image overlay (image/overlay) into the SDK's
# rootfs, repacks the ramdisk, and packages the three images into a .afw with
# ci/make-afw.sh. The rootfs is repacked under fakeroot so device nodes and root
# ownership survive. Unsigned is bench-only.
#
# usage:
# image/make-zynq-afw.sh [--sdk-out DIR] [--version X.Y.Z] [--skip-build]
# defaults: --sdk-out ../alkane-sdk/build/out/zynq-7010 --version 0.1.0
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SDK_OUT="$ROOT/../alkane-sdk/build/out/zynq-7010"
SDK_DIR="$ROOT/../alkane-sdk"
VERSION=0.1.0
TARGET=armv7-unknown-linux-musleabihf
SKIP_BUILD=0
while [ "$#" -gt 0 ]; do
case "$1" in
--sdk-out) SDK_OUT=$2; shift 2 ;;
--sdk-dir) SDK_DIR=$2; shift 2 ;;
--version) VERSION=$2; shift 2 ;;
--skip-build) SKIP_BUILD=1; shift ;;
*) echo "unknown argument: $1" >&2; exit 2 ;;
esac
done
command -v fakeroot >/dev/null 2>&1 || { echo "fakeroot is required" >&2; exit 1; }
SDK_OUT="$(cd "$SDK_OUT" && pwd)"
for f in zImage zynq-alkane.dtb rootfs.cpio.gz; do
[ -f "$SDK_OUT/$f" ] || { echo "missing SDK image: $SDK_OUT/$f (build it in alkane-sdk first)" >&2; exit 1; }
done
TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}"
BIN="$TARGET_DIR/$TARGET/release/alkane-os"
if [ "$SKIP_BUILD" -eq 0 ]; then
echo "cross-compiling alkane-os for $TARGET (static)"
# rustc drives the final link through a C compiler; the host cc cannot link
# ARM objects, so use the ARM cross-gcc as the linker (musl crt + libs come
# from rustup's self-contained target, so only the ARM linker driver is used).
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER="${ARMV7_LINKER:-arm-linux-gnueabihf-gcc}"
( cd "$ROOT" && cargo build --release --offline --target "$TARGET" --bin alkane-os )
fi
[ -f "$BIN" ] || { echo "cross-compiled binary not found: $BIN" >&2; exit 1; }
WORK=$(mktemp -d "${TMPDIR:-/tmp}/zynq-afw.XXXXXX")
trap 'rm -rf "$WORK"' EXIT
mkdir -p "$WORK/in"
echo "staging the console binary"
cp "$BIN" "$WORK/alkane-os"
command -v arm-linux-gnueabihf-strip >/dev/null 2>&1 && arm-linux-gnueabihf-strip "$WORK/alkane-os" || true
echo "repacking the SDK rootfs with the console + overlay (under fakeroot)"
cat > "$WORK/pack.sh" <<'PACK'
set -e
RFS=$1; SDK_OUT=$2; WORK=$3; OVERLAY=$4; VERSION=$5
mkdir -p "$RFS"
( cd "$RFS" && zcat "$SDK_OUT/rootfs.cpio.gz" | cpio -idm --quiet )
install -D -m 0755 "$WORK/alkane-os" "$RFS/usr/bin/alkane-os"
# The .afw version, reported by GET /api/identity (fleet discovery).
printf '%s\n' "$VERSION" > "$RFS/etc/alkane-os-version"
if [ -d "$OVERLAY" ]; then
( cd "$OVERLAY" && find . -type f ) | while IFS= read -r f; do
install -D -m 0755 "$OVERLAY/${f#./}" "$RFS/${f#./}"
done
fi
( cd "$RFS" && find . | cpio -o -H newc --owner=0:0 --quiet | gzip -9 > "$WORK/in/rootfs.cpio.gz" )
PACK
fakeroot -- bash "$WORK/pack.sh" "$WORK/rootfs" "$SDK_OUT" "$WORK" "$ROOT/image/overlay" "$VERSION"
cp "$SDK_OUT/zImage" "$WORK/in/zImage"
cp "$SDK_OUT/zynq-alkane.dtb" "$WORK/in/zynq-alkane.dtb"
echo "packaging the .afw"
"$ROOT/ci/make-afw.sh" \
--board zynq-7010 \
--version "$VERSION" \
--input "$WORK/in" \
--sdk-dir "$SDK_DIR" \
--os-revision "$(git -C "$ROOT" rev-parse HEAD)" \
--output "$ROOT/dist" \
--allow-unsigned