image: build the console into a zynq-7010 .afw + fix serve_only API bind
Produce a flashable zynq-7010 image carrying the current console, and make the image serve it on boot. - image/make-zynq-afw.sh: cross-compiles alkane-os for armv7 (static musl, matching the SDK rootfs; the ARM cross-gcc is the linker since the host cc cannot link ARM objects), drops the binary and the image overlay into the SDK's zynq rootfs, repacks the ramdisk under fakeroot (device nodes + root ownership preserved), and packages zImage + dtb + rootfs into a .afw via ci/make-afw.sh. - image/overlay/etc/init.d/S60alkane-web: starts `alkane-os --serve` after the network, so the booted image serves the console (login + read-only API) on :80. The SDK init owns board-detect/network/ssh and leaves the console to this. - main.rs: fix serve_only to default the cgminer API to loopback (127.0.0.1:4028) instead of 0.0.0.0, which bind_local (loopback-only) rejected - so plain `--serve` now starts instead of failing to bind. Verified: the build produces dist/alkane-os-0.1.0-zynq-7010-armv7.afw (check-afw OK: kernel 4.3MB, dtb 11KB, rootfs 3.26MB), the rootfs carries the new binary + the web-init overlay, and the static armv7 binary runs under qemu-arm and serves the console end to end (login page renders, admin/admin -> 303 session, /api/hardware open). dist/ is gitignored, so the artifact is not committed. clippy -D warnings clean, no emojis. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdKQBPjAXpCwmigUov5eQk
This commit is contained in:
Executable
+85
@@ -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
|
||||
Executable
+34
@@ -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
|
||||
+3
-1
@@ -455,7 +455,9 @@ fn serve_only() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.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));
|
||||
|
||||
Reference in New Issue
Block a user