Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5304105c61 | ||
|
|
55715492b0 |
Executable
+104
@@ -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
|
||||
Reference in New Issue
Block a user