Compare commits

...
Author SHA1 Message Date
noahandClaude Opus 4.8 5304105c61 fix(a113d): start the console with --serve in /init
The A113D image boots a custom /init (not BusyBox rcS, so the init.d overlay is
not run). That /init launched the console binary with no args, which only
prints usage -- so the board came up on SSH + network but served no web UI/API.
Patch /init during the build to launch 'alkane-os --serve', bringing up the
web console on :80 and the HTTP API that fleet discovery/install-verify need.
Caught by the full GUI-flow test (board installed + reachable but absent from
the post-install scan).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
2026-11-17 15:23:21 -06:00
noahandClaude Opus 4.8 55715492b0 build: make-a113d-afw.sh -- A113D afw with the alkane web console/API
Mirrors make-zynq-afw.sh for the Amlogic A113D (arm64): cross-compiles the
alkane-os console/API binary for aarch64 (static musl), replaces the SDK
rootfs placeholder binary with it, drops the image overlay (S60alkane-web,
which serves /api/identity + the console on :80), wraps the ramdisk as a
uImage, and packages the .afw. Gives A113D images the HTTP API/UI that fleet
discovery and the toolkit's install-verify rely on (the earlier bench image
served only SSH).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
2026-11-17 14:36:59 -06:00
noahandClaude Opus 5.5 2d3417b7d3 web: public read-only GET /api/identity for fleet discovery
source-pr / source (pull_request) Successful in 3m26s
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
noah cc14543ced Merge pull request 'main: afw OS-bundle line (web console, .afw producer, zynq image, review fixes)' (#15) from feature/afw-os-bundle into main
main-release-gate / verify-and-release (push) Failing after 9m34s
2026-11-12 14:13:16 -07:00
3 changed files with 198 additions and 5 deletions
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
# Build an Amlogic A113D (arm64) .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 aarch64 (static musl, so it
# runs on the SDK rootfs regardless of its libc), drops it and the image overlay
# (image/overlay) into the SDK's rootfs in place of the placeholder binary,
# wraps the repacked ramdisk as a legacy uImage (the format the A113D boot chain
# loads), 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-a113d-afw.sh [--sdk-out DIR] [--version X.Y.Z] [--skip-build]
# defaults: --sdk-out ../alkane-sdk/build/out/a113d --version 0.1.1
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SDK_OUT="$ROOT/../alkane-sdk/build/out/a113d"
SDK_DIR="$ROOT/../alkane-sdk"
VERSION=0.1.1
TARGET=aarch64-unknown-linux-musl
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; }
command -v mkimage >/dev/null 2>&1 || { echo "mkimage (u-boot-tools) is required" >&2; exit 1; }
SDK_OUT="$(cd "$SDK_OUT" && pwd)"
# The A113D SDK out names the kernel "Image" and the dtb "meson-axg-alkane.dtb";
# the .afw payload names them vmlinux.bin / devicetree.dtb.
[ -f "$SDK_OUT/Image" ] || { echo "missing SDK kernel: $SDK_OUT/Image (build it in alkane-sdk first)" >&2; exit 1; }
[ -f "$SDK_OUT/meson-axg-alkane.dtb" ] || { echo "missing SDK dtb: $SDK_OUT/meson-axg-alkane.dtb" >&2; exit 1; }
[ -f "$SDK_OUT/rootfs.cpio.gz" ] || { echo "missing SDK rootfs: $SDK_OUT/rootfs.cpio.gz" >&2; exit 1; }
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)"
rustup target add "$TARGET" >/dev/null 2>&1 || true
# Only the aarch64 linker driver is used; musl crt + libs come from rustup's
# self-contained target.
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="${AARCH64_LINKER:-aarch64-linux-gnu-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}/a113d-afw.XXXXXX")
trap 'rm -rf "$WORK"' EXIT
mkdir -p "$WORK/in"
echo "staging the console binary"
cp "$BIN" "$WORK/alkane-os"
command -v aarch64-linux-gnu-strip >/dev/null 2>&1 && aarch64-linux-gnu-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 )
# Replace the placeholder binary with the real console/API server.
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"
# This board boots a custom /init (not BusyBox rcS, so the init.d overlay is not
# run). That /init launches the console binary with no args -- which only prints
# usage and exits. The real binary needs `--serve` to bring up the web console +
# HTTP API, so patch the launch line. Idempotent.
if [ -f "$RFS/init" ] && ! grep -q 'alkane-os --serve' "$RFS/init"; then
sed -i 's#\(/usr/bin/alkane-os\)\( >/dev/null\)#\1 --serve\2#' "$RFS/init"
fi
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/rootfs.cpio.gz" )
PACK
fakeroot -- bash "$WORK/pack.sh" "$WORK/rootfs" "$SDK_OUT" "$WORK" "$ROOT/image/overlay" "$VERSION"
echo "wrapping the ramdisk as a uImage"
mkimage -A arm64 -O linux -T ramdisk -C gzip -a 0 -e 0 -n "Alkane a113d initramfs" \
-d "$WORK/rootfs.cpio.gz" "$WORK/in/uramdisk.image.gz" >/dev/null
cp "$SDK_OUT/Image" "$WORK/in/vmlinux.bin"
cp "$SDK_OUT/meson-axg-alkane.dtb" "$WORK/in/devicetree.dtb"
echo "packaging the .afw"
"$ROOT/ci/make-afw.sh" \
--board a113d \
--version "$VERSION" \
--input "$WORK/in" \
--sdk-dir "$SDK_DIR" \
--os-revision "$(git -C "$ROOT" rev-parse HEAD)" \
--output "$ROOT/dist" \
--allow-unsigned
+4 -2
View File
@@ -58,10 +58,12 @@ command -v arm-linux-gnueabihf-strip >/dev/null 2>&1 && arm-linux-gnueabihf-stri
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
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#./}"
@@ -69,7 +71,7 @@ if [ -d "$OVERLAY" ]; then
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"
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"
+90 -3
View File
@@ -221,8 +221,11 @@ fn route(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io::Res
// The read-only miner-state JSON stays open (it is the interface of record
// and is already exposed on the cgminer socket). Everything else - the HTML
// console, host reads, and every mutation - needs a live session.
let open_api =
method == "GET" && matches!(path, "/api/hardware" | "/api/summary" | "/api/control");
let open_api = method == "GET"
&& matches!(
path,
"/api/hardware" | "/api/summary" | "/api/control" | "/api/identity"
);
let authed = request.wsid.as_deref().is_some_and(|w| ctx.auth.valid(w));
if !authed && !open_api {
if method == "GET" && !path.starts_with("/api/") {
@@ -252,6 +255,7 @@ fn route(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io::Res
("GET", "/api/summary") => {
json_response(stream, &bus.read_state_or(topics::SUMMARY, json!({})))
}
("GET", "/api/identity") => json_response(stream, &identity(Path::new("/"))),
("GET", "/api/control") => json_response(
stream,
&bus.read_state_or(
@@ -519,6 +523,39 @@ fn auth_local(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io
}
}
/// Read-only identity for network discovery (alkane-toolkit's fleet scan finds
/// Alkane boards by it: they have no cgminer socket or vendor web UI for a
/// generic scanner to recognise). Public like the other read-only state. It
/// carries no secret, only what a stock miner also exposes: OS and version, the
/// board family, SDK revision, hostname, MAC and kernel. `root` is the
/// filesystem root (the real one on a board; a temp dir in tests).
fn identity(root: &Path) -> Value {
let read = |rel: &str| {
fs::read_to_string(root.join(rel))
.ok()
.map(|text| text.trim().to_string())
.filter(|text| !text.is_empty())
};
let os_release = read("etc/os-release").unwrap_or_default();
let release_field = |key: &str| {
os_release.lines().find_map(|line| {
line.strip_prefix(key)
.and_then(|rest| rest.strip_prefix('='))
.map(|value| value.trim_matches('"').to_string())
})
};
json!({
"os": "alkane-os",
"os_version": read("etc/alkane-os-version")
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()),
"board": release_field("VARIANT_ID"),
"sdk_revision": release_field("VERSION_ID"),
"hostname": read("proc/sys/kernel/hostname"),
"mac": read("sys/class/net/eth0/address"),
"kernel": read("proc/sys/kernel/osrelease"),
})
}
fn json_response(stream: &mut TcpStream, value: &Value) -> io::Result<()> {
respond(
stream,
@@ -1019,13 +1056,63 @@ mod tests {
#[test]
fn the_api_serves_state_from_the_bus() {
for path in ["/api/hardware", "/api/summary", "/api/control"] {
for path in [
"/api/hardware",
"/api/summary",
"/api/control",
"/api/identity",
] {
let reply = client(&format!("GET {path} HTTP/1.1\r\nHost: x\r\n\r\n"));
assert!(reply.starts_with("HTTP/1.1 200 OK"), "{path}");
assert!(reply.contains("application/json"));
}
}
#[test]
fn the_identity_api_is_public_and_names_alkane() {
// No session cookie: discovery must work before anyone signs in.
let reply = client("GET /api/identity HTTP/1.1\r\nHost: x\r\n\r\n");
assert!(reply.starts_with("HTTP/1.1 200 OK"), "{reply}");
let body = reply.split("\r\n\r\n").nth(1).unwrap_or("");
let doc: Value = serde_json::from_str(body).unwrap_or_else(|_| json!({}));
assert_eq!(doc["os"], "alkane-os");
assert!(doc["os_version"].as_str().is_some_and(|v| !v.is_empty()));
}
#[test]
fn identity_reads_the_board_files() {
let root = std::env::temp_dir().join(format!("alkane-identity-{}", std::process::id()));
for dir in ["etc", "proc/sys/kernel", "sys/class/net/eth0"] {
fs::create_dir_all(root.join(dir)).unwrap();
}
fs::write(
root.join("etc/os-release"),
"NAME=\"Alkane OS\"\nID=alkane\nVERSION_ID=6a9080ac82c1\nVARIANT_ID=zynq-7010\n",
)
.unwrap();
fs::write(root.join("etc/alkane-os-version"), "0.1.2\n").unwrap();
fs::write(root.join("proc/sys/kernel/hostname"), "alkane-zynq\n").unwrap();
fs::write(root.join("proc/sys/kernel/osrelease"), "6.18.48\n").unwrap();
fs::write(
root.join("sys/class/net/eth0/address"),
"26:4e:52:8b:e2:48\n",
)
.unwrap();
let doc = identity(&root);
let _ = fs::remove_dir_all(&root);
assert_eq!(doc["os"], "alkane-os");
assert_eq!(doc["os_version"], "0.1.2");
assert_eq!(doc["board"], "zynq-7010");
assert_eq!(doc["sdk_revision"], "6a9080ac82c1");
assert_eq!(doc["hostname"], "alkane-zynq");
assert_eq!(doc["mac"], "26:4e:52:8b:e2:48");
assert_eq!(doc["kernel"], "6.18.48");
// Absent files read as null, never a panic.
let bare = identity(Path::new("/nonexistent-alkane-root"));
assert_eq!(bare["os"], "alkane-os");
assert!(bare["board"].is_null() && bare["mac"].is_null());
}
#[test]
fn the_control_api_reports_operator_state() {
let reply = client("GET /api/control HTTP/1.1\r\nHost: x\r\n\r\n");