diff --git a/image/make-zynq-afw.sh b/image/make-zynq-afw.sh new file mode 100755 index 0000000..892b418 --- /dev/null +++ b/image/make-zynq-afw.sh @@ -0,0 +1,85 @@ +#!/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 +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" +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" + +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 diff --git a/image/overlay/etc/init.d/S60alkane-web b/image/overlay/etc/init.d/S60alkane-web new file mode 100755 index 0000000..75289c2 --- /dev/null +++ b/image/overlay/etc/init.d/S60alkane-web @@ -0,0 +1,34 @@ +#!/bin/sh +# S60alkane-web: serve the Alkane console and HTTP API. +# +# Starts after the network (S40). `alkane-os --serve` brings up the web console +# (gated on a login) and the read-only JSON API on port 80, falling back to 8080 +# without privilege. The board HAL/mining backend is started separately; this +# only needs the box to be reachable and observable, so every page renders and +# the console works before any hashboard is driven. +# +# This file is part of the alkane-os image overlay (image/overlay), dropped into +# the SDK rootfs at build time. It is intentionally not in the SDK's own init, +# which owns board-detect / network / ssh and leaves the console to alkane-os. + +PIDFILE=/run/alkane-web.pid +BIN=/usr/bin/alkane-os + +start() { + [ -x "$BIN" ] || { echo "alkane-web: $BIN missing"; exit 1; } + echo "alkane-web: starting console on :80 (falls back to :8080)" + start-stop-daemon -S -b -m -p "$PIDFILE" -x "$BIN" -- --serve +} + +stop() { + echo "alkane-web: stopping console" + start-stop-daemon -K -q -p "$PIDFILE" 2>/dev/null + rm -f "$PIDFILE" +} + +case "$1" in + start) start ;; + stop) stop ;; + restart) stop; start ;; + *) echo "usage: $0 {start|stop|restart}"; exit 1 ;; +esac diff --git a/src/main.rs b/src/main.rs index 6c02768..e10a688 100644 --- a/src/main.rs +++ b/src/main.rs @@ -455,7 +455,9 @@ fn serve_only() -> Result<(), Box> { .ok() .map(|bind| bind.parse()) .transpose()?; - let api = api.or(Some("0.0.0.0:4028".parse()?)); + // The cgminer-style API is loopback-only (reach it through SSH); default to + // loopback so `--serve` starts even when ALKANE_API_LISTEN is unset. + let api = api.or(Some("127.0.0.1:4028".parse()?)); let control = Arc::new(Control::default()); let bus = Bus::new(); service::register(&bus, Arc::clone(&status), Arc::clone(&control));