Initial commit: Geminux 0.1.0 (helio) for Planet Computers Gemini PDA (MT6797X)
This commit is contained in:
commit
034c1f61b1
816 files changed
+223435
No files matched your search
Executable
+178
@@ -0,0 +1,178 @@
|
||||
#!/bin/sh
|
||||
# Apply Geminux local signed @geminux APKs, overlay configs, firmware blobs,
|
||||
# BusyBox links, SSH keys, OpenRC runlevels, and permissions to a target rootfs.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
TARGET_ROOTFS="${1:-${ROOTFS_DIR:-$BASE_DIR/rootfs}}"
|
||||
DEVICE="${2:-gemini-x27}"
|
||||
|
||||
if [ ! -d "$TARGET_ROOTFS" ]; then
|
||||
echo "Error: Target rootfs directory does not exist: $TARGET_ROOTFS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$DEVICE" in
|
||||
gemini-x27|gemini|geminux)
|
||||
DEVICE="gemini-x27"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unsupported device '$DEVICE'." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
VER="$("$BASE_DIR/scripts/version.sh" --print)"
|
||||
|
||||
echo "[1/4] Configuring @geminux + pure Alpine Edge repositories..."
|
||||
mkdir -p "$TARGET_ROOTFS/etc/apk/keys" "$TARGET_ROOTFS/var/lib/geminux/apk-repo"
|
||||
if [ -f "$BASE_DIR/keys/geminux-local.rsa.pub" ]; then
|
||||
cp -f "$BASE_DIR/keys/geminux-local.rsa.pub" "$TARGET_ROOTFS/etc/apk/keys/geminux-local.rsa.pub"
|
||||
fi
|
||||
cat > "$TARGET_ROOTFS/etc/apk/repositories" <<EOF
|
||||
@geminux /var/lib/geminux/apk-repo
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
|
||||
if [ -d "$BASE_DIR/prebuilt/apk-repo" ] && \
|
||||
[ -f "$BASE_DIR/prebuilt/apk-repo/aarch64/APKINDEX.tar.gz" ]; then
|
||||
rm -rf "$TARGET_ROOTFS/var/lib/geminux/apk-repo"
|
||||
mkdir -p "$TARGET_ROOTFS/var/lib/geminux/apk-repo"
|
||||
cp -af "$BASE_DIR/prebuilt/apk-repo/." "$TARGET_ROOTFS/var/lib/geminux/apk-repo/"
|
||||
fi
|
||||
|
||||
echo "[2/4] Installing Geminux packages and overlay into $TARGET_ROOTFS..."
|
||||
if command -v apk >/dev/null 2>&1 && \
|
||||
[ -f "$TARGET_ROOTFS/var/lib/geminux/apk-repo/aarch64/APKINDEX.tar.gz" ] && \
|
||||
[ -f "$TARGET_ROOTFS/etc/apk/keys/geminux-local.rsa.pub" ]; then
|
||||
if [ "$TARGET_ROOTFS" != "/" ]; then
|
||||
mkdir -p /var/lib/geminux
|
||||
ln -sfn "$TARGET_ROOTFS/var/lib/geminux/apk-repo" /var/lib/geminux/apk-repo
|
||||
cp -f "$TARGET_ROOTFS/etc/apk/keys/geminux-local.rsa.pub" /etc/apk/keys/geminux-local.rsa.pub 2>/dev/null || true
|
||||
fi
|
||||
|
||||
apk --root "$TARGET_ROOTFS" --arch aarch64 update --force-refresh >/dev/null
|
||||
|
||||
# Clear any older @geminux world pins and installed hashes so rebuilt local
|
||||
# packages with unchanged -r0 version strings always extract updated payloads.
|
||||
if [ -f "$TARGET_ROOTFS/etc/apk/world" ]; then
|
||||
grep -v -E '^geminux-(kernel-modules|xlibre|suckless|dunst|ui|config)(@|=|$)' \
|
||||
"$TARGET_ROOTFS/etc/apk/world" > "$TARGET_ROOTFS/etc/apk/world.tmp" || true
|
||||
mv "$TARGET_ROOTFS/etc/apk/world.tmp" "$TARGET_ROOTFS/etc/apk/world"
|
||||
fi
|
||||
apk --root "$TARGET_ROOTFS" --arch aarch64 del --no-scripts --purge=yes \
|
||||
geminux-config geminux-ui geminux-dunst geminux-suckless \
|
||||
geminux-xlibre geminux-kernel-modules 2>/dev/null || true
|
||||
|
||||
apk --root "$TARGET_ROOTFS" --arch aarch64 add --no-scripts --clean-protected=no \
|
||||
"geminux-kernel-modules@geminux=7.3.5-r0" \
|
||||
"geminux-xlibre@geminux=25.2.0-r0" \
|
||||
"geminux-suckless@geminux=${VER}-r0" \
|
||||
"geminux-dunst@geminux=1.12.2-r0" \
|
||||
"geminux-ui@geminux=${VER}-r0" \
|
||||
"geminux-config@geminux=${VER}-r0"
|
||||
else
|
||||
# Fallback direct copy when running on host without apk-tools
|
||||
if [ -d "$BASE_DIR/overlay/rootfs" ]; then
|
||||
cp -af "$BASE_DIR/overlay/rootfs/." "$TARGET_ROOTFS/"
|
||||
fi
|
||||
for subdir in xlibre suckless dunst geminux; do
|
||||
if [ -d "$BASE_DIR/prebuilt/$subdir" ]; then
|
||||
cp -af "$BASE_DIR/prebuilt/$subdir/." "$TARGET_ROOTFS/"
|
||||
fi
|
||||
done
|
||||
if [ -d "$BASE_DIR/prebuilt/kernel/lib/modules" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/lib/modules"
|
||||
cp -af "$BASE_DIR/prebuilt/kernel/lib/modules/." "$TARGET_ROOTFS/lib/modules/"
|
||||
fi
|
||||
if [ -d "$BASE_DIR/prebuilt/kernel/boot" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/boot"
|
||||
cp -af "$BASE_DIR/prebuilt/kernel/boot/." "$TARGET_ROOTFS/boot/"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Inject device-owned firmware extracted from stock Gemini system image (gitignored).
|
||||
if [ -d "$BASE_DIR/firmware-cache/mt6797" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/lib/firmware/mediatek/mt6797"
|
||||
cp -af "$BASE_DIR/firmware-cache/mt6797/." "$TARGET_ROOTFS/lib/firmware/mediatek/mt6797/"
|
||||
fi
|
||||
|
||||
echo "[3/4] Ensuring BusyBox symlinks, SSH keys, OpenRC services, and skel..."
|
||||
mkdir -p "$TARGET_ROOTFS/bin" "$TARGET_ROOTFS/sbin" "$TARGET_ROOTFS/usr/bin" "$TARGET_ROOTFS/usr/sbin"
|
||||
if [ -e "$TARGET_ROOTFS/bin/busybox" ]; then
|
||||
ln -sfn /bin/busybox "$TARGET_ROOTFS/sbin/init"
|
||||
for spec in \
|
||||
"busybox-applets.txt:$TARGET_ROOTFS/bin" \
|
||||
"busybox-sbin-applets.txt:$TARGET_ROOTFS/sbin" \
|
||||
"busybox-usr-bin-applets.txt:$TARGET_ROOTFS/usr/bin" \
|
||||
"busybox-usr-sbin-applets.txt:$TARGET_ROOTFS/usr/sbin"; do
|
||||
list_file="$BASE_DIR/scripts/${spec%%:*}"
|
||||
dest_dir="${spec#*:}"
|
||||
[ -f "$list_file" ] || continue
|
||||
while IFS= read -r applet; do
|
||||
[ -n "$applet" ] || continue
|
||||
if [ ! -e "$dest_dir/$applet" ]; then
|
||||
[ ! -L "$dest_dir/$applet" ] || rm -f "$dest_dir/$applet"
|
||||
ln -s /bin/busybox "$dest_dir/$applet"
|
||||
fi
|
||||
done < "$list_file"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -f "$BASE_DIR/keys/geminux_id_ed25519.pub" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/root/.ssh" "$TARGET_ROOTFS/home/user/.ssh"
|
||||
cp "$BASE_DIR/keys/geminux_id_ed25519.pub" "$TARGET_ROOTFS/root/.ssh/authorized_keys"
|
||||
cp "$BASE_DIR/keys/geminux_id_ed25519.pub" "$TARGET_ROOTFS/home/user/.ssh/authorized_keys"
|
||||
chmod 0700 "$TARGET_ROOTFS/root/.ssh" "$TARGET_ROOTFS/home/user/.ssh"
|
||||
chmod 0600 "$TARGET_ROOTFS/root/.ssh/authorized_keys" "$TARGET_ROOTFS/home/user/.ssh/authorized_keys"
|
||||
fi
|
||||
|
||||
if command -v glib-compile-schemas >/dev/null 2>&1 && \
|
||||
[ -d "$TARGET_ROOTFS/usr/share/glib-2.0/schemas" ]; then
|
||||
glib-compile-schemas "$TARGET_ROOTFS/usr/share/glib-2.0/schemas" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
rm -f "$TARGET_ROOTFS/etc/runlevels/sysinit/hwdrivers"
|
||||
|
||||
if [ -e "$TARGET_ROOTFS/usr/lib/dri/libdril_dri.so" ]; then
|
||||
ln -sfn libdril_dri.so "$TARGET_ROOTFS/usr/lib/dri/simpledrm_dri.so"
|
||||
fi
|
||||
|
||||
if command -v ssh-keygen >/dev/null 2>&1; then
|
||||
mkdir -p "$TARGET_ROOTFS/etc/ssh"
|
||||
ssh-keygen -A -f "$TARGET_ROOTFS" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if [ -e "$TARGET_ROOTFS/etc/init.d/geminux-usb-gadget" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/etc/runlevels/boot"
|
||||
ln -sf "/etc/init.d/geminux-usb-gadget" "$TARGET_ROOTFS/etc/runlevels/boot/geminux-usb-gadget"
|
||||
fi
|
||||
rm -f "$TARGET_ROOTFS/etc/runlevels/default/geminux-usb-gadget"
|
||||
|
||||
for svc in geminux-hwinit geminux-ccci geminux-powerd geminux-leds; do
|
||||
if [ -e "$TARGET_ROOTFS/etc/init.d/$svc" ]; then
|
||||
mkdir -p "$TARGET_ROOTFS/etc/runlevels/default"
|
||||
ln -sf "/etc/init.d/$svc" "$TARGET_ROOTFS/etc/runlevels/default/$svc"
|
||||
fi
|
||||
done
|
||||
rm -f "$TARGET_ROOTFS/etc/runlevels/default/bluetooth"
|
||||
|
||||
if [ -x "$BASE_DIR/scripts/version.sh" ]; then
|
||||
"$BASE_DIR/scripts/version.sh" "$TARGET_ROOTFS"
|
||||
fi
|
||||
"$BASE_DIR/scripts/set-geminux-hostname.sh" "$TARGET_ROOTFS" "$DEVICE"
|
||||
|
||||
echo "[4/4] Populating /home/user skel and setting permissions..."
|
||||
mkdir -p "$TARGET_ROOTFS/home/user/.config" "$TARGET_ROOTFS/home/user/.local/share/geminux" \
|
||||
"$TARGET_ROOTFS/home/user/Pictures" "$TARGET_ROOTFS/home/user/Videos" \
|
||||
"$TARGET_ROOTFS/home/user/Downloads"
|
||||
if [ -d "$TARGET_ROOTFS/etc/skel" ]; then
|
||||
cp -af "$TARGET_ROOTFS/etc/skel/." "$TARGET_ROOTFS/home/user/"
|
||||
fi
|
||||
chown -R 10000:10000 "$TARGET_ROOTFS/home/user" 2>/dev/null || true
|
||||
chmod 0600 "$TARGET_ROOTFS/etc/NetworkManager/system-connections/"*.nmconnection \
|
||||
"$TARGET_ROOTFS/usr/lib/NetworkManager/system-connections/"*.nmconnection 2>/dev/null || true
|
||||
chmod 0640 "$TARGET_ROOTFS/etc/doas.d/"* 2>/dev/null || true
|
||||
echo "Applied Geminux overlay and @geminux APKs for $DEVICE."
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Install host Python dependencies needed by flash-mtk.py into .flash-deps/.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
||||
TARGET="$BASE_DIR/.flash-deps"
|
||||
|
||||
if "$PYTHON_BIN" -c 'import usb.core, serial, Crypto, colorama' >/dev/null 2>&1; then
|
||||
echo "[flash-deps] pyusb, pyserial, pycryptodome, and colorama are already available."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -d "$TARGET" ] && PYTHONPATH="$TARGET${PYTHONPATH:+:$PYTHONPATH}" \
|
||||
"$PYTHON_BIN" -c 'import usb.core, serial, Crypto, colorama' >/dev/null 2>&1; then
|
||||
echo "[flash-deps] Using existing dependencies in $TARGET."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! "$PYTHON_BIN" -m pip --version >/dev/null 2>&1; then
|
||||
echo "Error: python3 pip is required to install flashing dependencies (pyusb, pyserial, pycryptodome, colorama)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[flash-deps] Installing pyusb, pyserial, pycryptodome, colorama into $TARGET..."
|
||||
mkdir -p "$TARGET"
|
||||
"$PYTHON_BIN" -m pip install --disable-pip-version-check --no-input \
|
||||
--target "$TARGET" pyusb pyserial pycryptodome colorama
|
||||
echo "[flash-deps] Done."
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
#!/bin/sh
|
||||
# Geminux rootfs bootstrap, container side.
|
||||
# Runs inside alpine:3.24 with /rootfs mounted and /geminux read-only.
|
||||
set -eu
|
||||
|
||||
ROOTFS="/rootfs"
|
||||
REPO="/geminux"
|
||||
PKGS_FILE="$REPO/scripts/rootfs-packages.txt"
|
||||
DEVICE="${TARGET_DEVICE:-gemini-x27}"
|
||||
PASSWORD="${GEMINUX_USER_PASSWORD:-geminux}"
|
||||
HOST_UID="${HOST_UID:-0}"
|
||||
HOST_GID="${HOST_GID:-0}"
|
||||
BOOTSTRAP_VERSION="${BOOTSTRAP_VERSION:-1}"
|
||||
PKG_HASH="${PKG_HASH:-unknown}"
|
||||
|
||||
echo "============================================================"
|
||||
echo "Bootstrapping Geminux aarch64 rootfs for $DEVICE"
|
||||
echo "============================================================"
|
||||
|
||||
echo "[1/8] Configuring pure Alpine Edge apk repositories and trusted keys..."
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
mkdir -p /etc/apk/keys
|
||||
cp "$REPO"/keys/alpine-devel@*.rsa.pub /etc/apk/keys/
|
||||
if [ -f "$REPO/keys/geminux-local.rsa.pub" ]; then
|
||||
cp "$REPO/keys/geminux-local.rsa.pub" /etc/apk/keys/
|
||||
fi
|
||||
|
||||
mkdir -p "$ROOTFS/etc/apk/keys" "$ROOTFS/lib/apk/db" "$ROOTFS/var/cache/apk"
|
||||
cp /etc/apk/repositories "$ROOTFS/etc/apk/repositories"
|
||||
rm -f "$ROOTFS/etc/apk/keys/"*.rsa.pub
|
||||
cp "$REPO"/keys/alpine-devel@*.rsa.pub "$ROOTFS/etc/apk/keys/"
|
||||
if [ -f "$REPO/keys/geminux-local.rsa.pub" ]; then
|
||||
cp "$REPO/keys/geminux-local.rsa.pub" "$ROOTFS/etc/apk/keys/"
|
||||
fi
|
||||
|
||||
echo "[2/8] Installing host helper tools..."
|
||||
apk add --no-cache python3 kmod openssl glib >/dev/null
|
||||
|
||||
echo "[3/8] Installing the Geminux aarch64 package set..."
|
||||
PKGS="$(grep -v '^[[:space:]]*#' "$PKGS_FILE" | grep -v '^[[:space:]]*$' | tr '\n' ' ')"
|
||||
"$REPO/scripts/prune-rootfs-packages.sh" "$ROOTFS" world
|
||||
if [ ! -f "$ROOTFS/lib/apk/db/installed" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
apk --root "$ROOTFS" --arch aarch64 add --initdb --no-scripts $PKGS >/dev/null
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
apk --root "$ROOTFS" --arch aarch64 add --no-scripts $PKGS >/dev/null
|
||||
fi
|
||||
|
||||
"$REPO/scripts/prune-rootfs-packages.sh" "$ROOTFS" purge
|
||||
|
||||
echo "[4/8] Creating system accounts and default credentials..."
|
||||
PW_HASH="$(openssl passwd -6 -salt geminux "$PASSWORD")"
|
||||
python3 - "$ROOTFS" "$PW_HASH" <<'PYEOF'
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = sys.argv[1]
|
||||
pw_hash = sys.argv[2]
|
||||
|
||||
|
||||
def load(name):
|
||||
path = os.path.join(root, "etc", name)
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
with open(path, "r") as handle:
|
||||
return [line.rstrip("\n") for line in handle if line.strip()]
|
||||
|
||||
|
||||
def store(name, rows):
|
||||
path = os.path.join(root, "etc", name)
|
||||
with open(path, "w") as handle:
|
||||
handle.write("\n".join(rows) + "\n")
|
||||
|
||||
|
||||
passwd = load("passwd")
|
||||
group = load("group")
|
||||
shadow = load("shadow")
|
||||
|
||||
system_users = [
|
||||
"klogd:x:100:101:klogd:/dev/null:/sbin/nologin",
|
||||
"chrony:x:101:102:chrony:/dev/null:/sbin/nologin",
|
||||
"messagebus:x:102:103:messagebus:/dev/null:/sbin/nologin",
|
||||
"dnsmasq:x:103:104:dnsmasq:/dev/null:/sbin/nologin",
|
||||
"polkitd:x:105:110:polkitd:/var/empty:/sbin/nologin",
|
||||
"greetd:x:107:112:greetd:/var/lib/greetd:/sbin/nologin",
|
||||
"user:x:10000:10000::/home/user:/bin/ash",
|
||||
]
|
||||
for entry in system_users:
|
||||
name = entry.split(":")[0]
|
||||
if not any(row.startswith(name + ":") for row in passwd):
|
||||
passwd.append(entry)
|
||||
|
||||
system_groups = [
|
||||
"klogd:x:101:klogd",
|
||||
"chrony:x:102:chrony",
|
||||
"messagebus:x:103:messagebus",
|
||||
"dnsmasq:x:104:dnsmasq",
|
||||
"plugdev:x:106:user",
|
||||
"pipewire:x:107:user",
|
||||
"seat:x:108:user",
|
||||
"polkitd:x:110:polkitd",
|
||||
"greetd:x:112:greetd",
|
||||
"user:x:10000:",
|
||||
]
|
||||
for entry in system_groups:
|
||||
name = entry.split(":")[0]
|
||||
if not any(row.startswith(name + ":") for row in group):
|
||||
group.append(entry)
|
||||
|
||||
member_groups = (
|
||||
"wheel", "audio", "input", "netdev", "plugdev", "video", "seat",
|
||||
"dialout", "tty", "pipewire",
|
||||
)
|
||||
for index, row in enumerate(group):
|
||||
fields = row.split(":")
|
||||
if fields[0] not in member_groups:
|
||||
continue
|
||||
members = [item for item in fields[3].split(",") if item]
|
||||
if "user" not in members:
|
||||
members.append("user")
|
||||
fields[3] = ",".join(members)
|
||||
group[index] = ":".join(fields)
|
||||
|
||||
for entry in system_users:
|
||||
name = entry.split(":")[0]
|
||||
if name == "user":
|
||||
continue
|
||||
if not any(row.startswith(name + ":") for row in shadow):
|
||||
shadow.append(name + ":!:::::::")
|
||||
|
||||
if not any(row.startswith("user:") for row in shadow):
|
||||
shadow.append("user:" + pw_hash + ":::::::")
|
||||
for index, row in enumerate(shadow):
|
||||
if row.startswith("root:"):
|
||||
fields = row.split(":")
|
||||
if len(fields) > 1 and fields[1] == "":
|
||||
fields[1] = pw_hash
|
||||
shadow[index] = ":".join(fields)
|
||||
|
||||
store("passwd", passwd)
|
||||
store("group", group)
|
||||
store("shadow", shadow)
|
||||
PYEOF
|
||||
|
||||
mkdir -p "$ROOTFS/home/user" "$ROOTFS/etc/geminux"
|
||||
chown -R 10000:10000 "$ROOTFS/home/user"
|
||||
chown 0:42 "$ROOTFS/etc/shadow"
|
||||
chmod 640 "$ROOTFS/etc/shadow"
|
||||
chown 0:0 "$ROOTFS/etc/geminux"
|
||||
chmod 0755 "$ROOTFS/etc/geminux"
|
||||
|
||||
echo "[5/8] Writing base system configuration..."
|
||||
"$REPO/scripts/set-geminux-hostname.sh" "$ROOTFS" "$DEVICE"
|
||||
mkdir -p "$ROOTFS/etc"
|
||||
printf '%s\n' "LANG=en_US.UTF-8" "LC_ALL=en_US.UTF-8" > "$ROOTFS/etc/locale.conf"
|
||||
if [ -f "$ROOTFS/usr/share/zoneinfo/UTC" ]; then
|
||||
cp "$ROOTFS/usr/share/zoneinfo/UTC" "$ROOTFS/etc/localtime"
|
||||
fi
|
||||
touch "$ROOTFS/etc/apk/interactive"
|
||||
mkdir -p "$ROOTFS/run/openrc" "$ROOTFS/dev/pts" "$ROOTFS/dev/shm" "$ROOTFS/tmp" "$ROOTFS/var/tmp"
|
||||
touch "$ROOTFS/run/openrc/shutdowntime"
|
||||
: > "$ROOTFS/dev/null"
|
||||
chmod 666 "$ROOTFS/dev/null"
|
||||
if [ -e "$ROOTFS/sbin/losetup" ] && [ ! -e "$ROOTFS/usr/sbin/losetup" ]; then
|
||||
ln -sf /sbin/losetup "$ROOTFS/usr/sbin/losetup"
|
||||
fi
|
||||
if [ ! -s "$ROOTFS/etc/machine-id" ]; then
|
||||
tr -d '-' < /proc/sys/kernel/random/uuid > "$ROOTFS/etc/machine-id"
|
||||
printf '\n' >> "$ROOTFS/etc/machine-id"
|
||||
fi
|
||||
mkdir -p "$ROOTFS/etc/sudoers.d"
|
||||
cat > "$ROOTFS/etc/sudoers.d/wheel" <<EOF
|
||||
%wheel ALL=(ALL:ALL) ALL
|
||||
EOF
|
||||
chmod 440 "$ROOTFS/etc/sudoers.d/wheel"
|
||||
|
||||
echo "[6/8] Enabling OpenRC runlevels..."
|
||||
mkdir -p "$ROOTFS/etc/runlevels/sysinit" "$ROOTFS/etc/runlevels/boot" \
|
||||
"$ROOTFS/etc/runlevels/default" "$ROOTFS/etc/runlevels/shutdown"
|
||||
enable_service() {
|
||||
runlevel="$1"
|
||||
service="$2"
|
||||
if [ -e "$ROOTFS/etc/init.d/$service" ]; then
|
||||
ln -sf "/etc/init.d/$service" "$ROOTFS/etc/runlevels/$runlevel/$service"
|
||||
fi
|
||||
}
|
||||
for svc in devfs dmesg udev udev-trigger udev-settle; do
|
||||
enable_service sysinit "$svc"
|
||||
done
|
||||
for svc in bootmisc hostname loopback modules sysctl tmpfs zram-init; do
|
||||
enable_service boot "$svc"
|
||||
done
|
||||
for svc in cgroups chronyd dbus elogind local modemmanager networkmanager \
|
||||
sshd tinydm udev-postmount wpa_supplicant; do
|
||||
enable_service default "$svc"
|
||||
done
|
||||
for svc in killprocs mount-ro savecache; do
|
||||
enable_service shutdown "$svc"
|
||||
done
|
||||
rm -f "$ROOTFS/etc/runlevels/boot/hwclock"
|
||||
|
||||
echo "[7/8] Applying the Geminux overlay and prebuilt artifacts..."
|
||||
"$REPO/scripts/apply-geminux-overlay.sh" "$ROOTFS" "$DEVICE"
|
||||
|
||||
echo "[8/8] Finalizing rootfs ownership and bootstrap marker..."
|
||||
printf '%s:%s\n' "$BOOTSTRAP_VERSION" "$PKG_HASH" > "$ROOTFS/etc/geminux/rootfs-bootstrap.done"
|
||||
chown -R "$HOST_UID:$HOST_GID" "$ROOTFS"
|
||||
echo "Geminux rootfs bootstrap completed for $DEVICE."
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
# Autonomously create a complete aarch64 Geminux rootfs from the repository.
|
||||
# Safe to run repeatedly: an up-to-date rootfs is left untouched.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
PKGS_FILE="$BASE_DIR/scripts/rootfs-packages.txt"
|
||||
CONTAINER_SCRIPT="$BASE_DIR/scripts/bootstrap-rootfs-container.sh"
|
||||
BOOTSTRAP_VERSION="1"
|
||||
MARKER_REL="etc/geminux/rootfs-bootstrap.done"
|
||||
|
||||
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
||||
TARGET_DEVICE="gemini-x27"
|
||||
FORCE=0
|
||||
CHECK_ONLY=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--force|-f)
|
||||
FORCE=1
|
||||
;;
|
||||
--check|-c)
|
||||
CHECK_ONLY=1
|
||||
;;
|
||||
gemini-x27|gemini|geminux)
|
||||
TARGET_DEVICE="gemini-x27"
|
||||
;;
|
||||
*)
|
||||
if [ -z "${ROOTFS_DIR_SET:-}" ]; then
|
||||
ROOTFS_DIR="$arg"
|
||||
ROOTFS_DIR_SET=1
|
||||
else
|
||||
echo "Usage: $0 [rootfs-dir] [device] [--force|--check]" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f "$PKGS_FILE" ] || [ ! -f "$CONTAINER_SCRIPT" ]; then
|
||||
echo "Error: bootstrap inputs are missing from $BASE_DIR/scripts." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$ROOTFS_DIR"
|
||||
ROOTFS_HOST="$(realpath "$ROOTFS_DIR")"
|
||||
PKG_HASH="$(sha256sum "$PKGS_FILE" | awk '{print $1}')"
|
||||
EXPECTED="$BOOTSTRAP_VERSION:$PKG_HASH"
|
||||
MARKER="$ROOTFS_HOST/$MARKER_REL"
|
||||
|
||||
if [ "$FORCE" -eq 0 ] && [ -f "$MARKER" ] && [ "$(cat "$MARKER")" = "$EXPECTED" ]; then
|
||||
echo "[bootstrap] Rootfs is already complete: $ROOTFS_HOST"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$CHECK_ONLY" -eq 1 ]; then
|
||||
echo "[bootstrap] Rootfs needs bootstrapping: $ROOTFS_HOST"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Error: Docker is required to bootstrap the aarch64 rootfs." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[bootstrap] Building a complete aarch64 rootfs at $ROOTFS_HOST for $TARGET_DEVICE..."
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-e TARGET_DEVICE="$TARGET_DEVICE" \
|
||||
-e GEMINUX_USER_PASSWORD="${GEMINUX_USER_PASSWORD:-geminux}" \
|
||||
-e BOOTSTRAP_VERSION="$BOOTSTRAP_VERSION" \
|
||||
-e PKG_HASH="$PKG_HASH" \
|
||||
-v "$ROOTFS_HOST:/rootfs" \
|
||||
-v "$BASE_DIR:/geminux:ro" \
|
||||
alpine:3.24 sh -eu /geminux/scripts/bootstrap-rootfs-container.sh
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
#!/bin/sh
|
||||
# Cross-compile pure-X11, zero-Rust, zero-gdk-pixbuf dunst + notify-send/dunstify for aarch64.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
mkdir -p "$BASE_DIR/build-cache" "$BASE_DIR/prebuilt/dunst"
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-e FORCE_REBUILD="${FORCE_REBUILD:-0}" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://mirror.nura.eco/postmarketos/v26.06
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
||||
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/dunst /geminux/build-cache 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
echo "[1/5] Installing host aarch64 cross-compile toolchain..."
|
||||
apk add --no-cache \
|
||||
build-base \
|
||||
git \
|
||||
ca-certificates \
|
||||
gcc-aarch64 \
|
||||
binutils-aarch64 \
|
||||
pkgconf \
|
||||
glib-dev \
|
||||
perl \
|
||||
python3 >/dev/null
|
||||
|
||||
DUNST_CACHE="/geminux/build-cache/dunst-src"
|
||||
if [ ! -f "$DUNST_CACHE/Makefile" ]; then
|
||||
echo "[1b/5] Cloning dunst v1.12.2..."
|
||||
rm -rf "$DUNST_CACHE"
|
||||
git clone --depth 1 --branch v1.12.2 https://github.com/dunst-project/dunst.git "$DUNST_CACHE"
|
||||
fi
|
||||
|
||||
echo "[2/5] Preparing pure Alpine Edge aarch64 sysroot for X11-only zero-Rust dunst..."
|
||||
SYSROOT="/tmp/aarch64-sysroot"
|
||||
mkdir -p "$SYSROOT/etc/apk/keys"
|
||||
cat > "$SYSROOT/etc/apk/repositories" <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/alpine-devel@*.rsa.pub "$SYSROOT/etc/apk/keys/"
|
||||
apk --root "$SYSROOT" --initdb --arch aarch64 add --no-scripts \
|
||||
alpine-baselayout \
|
||||
musl-dev \
|
||||
glib-dev \
|
||||
pango-dev \
|
||||
cairo-dev \
|
||||
harfbuzz-dev \
|
||||
libpng-dev \
|
||||
libjpeg-turbo-dev \
|
||||
libx11-dev \
|
||||
libxrandr-dev \
|
||||
libxinerama-dev \
|
||||
libxext-dev \
|
||||
libxscrnsaver-dev \
|
||||
libxcb-dev \
|
||||
libxft-dev \
|
||||
expat-dev \
|
||||
zlib-dev \
|
||||
pcre2-dev \
|
||||
libffi-dev >/dev/null
|
||||
|
||||
echo "[3/5] Patching dunst to remove gdk-pixbuf and use pure-C libpng + libjpeg-turbo..."
|
||||
WORK="/tmp/dunst-build"
|
||||
rm -rf "$WORK"
|
||||
cp -a "$DUNST_CACHE" "$WORK"
|
||||
cp -f /geminux/src/dunst-notify/icon.h "$WORK/src/icon.h"
|
||||
cp -f /geminux/src/dunst-notify/icon.c "$WORK/src/icon.c"
|
||||
|
||||
python3 - "$WORK" <<'"'"'PYEOF'"'"'
|
||||
import os, sys
|
||||
work = sys.argv[1]
|
||||
|
||||
cfg = os.path.join(work, "config.mk")
|
||||
txt = open(cfg).read()
|
||||
assert "gdk-pixbuf-2.0" in txt
|
||||
txt = txt.replace("gdk-pixbuf-2.0 \\", "libpng \\")
|
||||
txt = txt.replace("pangocairo \\", "libjpeg \\\n pangocairo \\")
|
||||
open(cfg, "w").write(txt)
|
||||
|
||||
notif_p = os.path.join(work, "src", "notification.c")
|
||||
ntxt = open(notif_p).read()
|
||||
old1 = """ if (n->icon_path) {
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_file(n->icon_path,
|
||||
n->min_icon_size, n->max_icon_size,
|
||||
draw_get_scale());
|
||||
if (pixbuf) {
|
||||
n->icon = gdk_pixbuf_to_cairo_surface(pixbuf);
|
||||
g_object_unref(pixbuf);
|
||||
} else {
|
||||
LOG_W("Failed to load icon from path: '\''%s'\''", n->icon_path);
|
||||
}
|
||||
}"""
|
||||
new1 = """ if (n->icon_path) {
|
||||
n->icon = get_surface_from_file(n->icon_path,
|
||||
n->min_icon_size, n->max_icon_size,
|
||||
draw_get_scale());
|
||||
if (!n->icon) {
|
||||
LOG_W("Failed to load icon from path: '\''%s'\''", n->icon_path);
|
||||
}
|
||||
}"""
|
||||
old2 = """ GdkPixbuf *icon = icon_get_for_data(new_icon, &n->icon_id,
|
||||
draw_get_scale(), n->min_icon_size, n->max_icon_size);
|
||||
n->icon = gdk_pixbuf_to_cairo_surface(icon);
|
||||
if (icon)
|
||||
g_object_unref(icon);"""
|
||||
new2 = """ n->icon = icon_get_for_data(new_icon, &n->icon_id,
|
||||
draw_get_scale(), n->min_icon_size, n->max_icon_size);"""
|
||||
assert old1 in ntxt and old2 in ntxt
|
||||
ntxt = ntxt.replace(old1, new1).replace(old2, new2)
|
||||
open(notif_p, "w").write(ntxt)
|
||||
print("PATCHED dunst src OK")
|
||||
PYEOF
|
||||
|
||||
echo "[4/5] Cross-compiling X11-only dunst and notify-send/dunstify for aarch64..."
|
||||
export PKG_CONFIG_SYSROOT_DIR="$SYSROOT"
|
||||
export PKG_CONFIG_LIBDIR="$SYSROOT/usr/lib/pkgconfig:$SYSROOT/usr/share/pkgconfig"
|
||||
export PKG_CONFIG_PATH=""
|
||||
export CC="aarch64-alpine-linux-musl-gcc --sysroot=$SYSROOT"
|
||||
make -C "$WORK" -j"$(nproc)" \
|
||||
CC="$CC" \
|
||||
VERSION="1.12.2-geminux" \
|
||||
WAYLAND=0 X11=1 DUNSTIFY=0 COMPLETIONS=0 SYSTEMD=0 \
|
||||
PREFIX=/usr SYSCONFDIR=/etc \
|
||||
dunst
|
||||
|
||||
rm -rf /geminux/prebuilt/dunst
|
||||
mkdir -p /geminux/prebuilt/dunst/usr/bin \
|
||||
/geminux/prebuilt/dunst/etc/dunst \
|
||||
/geminux/prebuilt/dunst/usr/share/dbus-1/services
|
||||
cp "$WORK/dunst" /geminux/prebuilt/dunst/usr/bin/dunst
|
||||
cp "$WORK/dunstctl" /geminux/prebuilt/dunst/usr/bin/dunstctl
|
||||
chmod 755 /geminux/prebuilt/dunst/usr/bin/dunst /geminux/prebuilt/dunst/usr/bin/dunstctl
|
||||
|
||||
NOTIFY_CFLAGS="$(pkg-config --cflags gio-2.0 glib-2.0)"
|
||||
NOTIFY_LIBS="$(pkg-config --libs gio-2.0 glib-2.0)"
|
||||
$CC -O2 -std=gnu11 -Wall /geminux/src/dunst-notify/notify-send.c \
|
||||
$NOTIFY_CFLAGS $NOTIFY_LIBS \
|
||||
-o /geminux/prebuilt/dunst/usr/bin/notify-send
|
||||
ln -sfn notify-send /geminux/prebuilt/dunst/usr/bin/dunstify
|
||||
chmod 755 /geminux/prebuilt/dunst/usr/bin/notify-send
|
||||
|
||||
cat > /geminux/prebuilt/dunst/usr/share/dbus-1/services/org.knopwob.dunst.service <<EOF
|
||||
[D-BUS Service]
|
||||
Name=org.freedesktop.Notifications
|
||||
Exec=/usr/bin/dunst
|
||||
EOF
|
||||
|
||||
GEMINUX_XRESOURCES=/geminux/overlay/rootfs/etc/skel/.Xresources \
|
||||
GEMINUX_DUNSTRC=/geminux/prebuilt/dunst/etc/dunst/dunstrc \
|
||||
/geminux/overlay/rootfs/usr/bin/geminux-sync-dunst-theme --no-restart
|
||||
|
||||
echo "[5/5] Stripping dunst aarch64 ELFs..."
|
||||
aarch64-alpine-linux-musl-strip --strip-unneeded \
|
||||
/geminux/prebuilt/dunst/usr/bin/dunst \
|
||||
/geminux/prebuilt/dunst/usr/bin/notify-send
|
||||
|
||||
ls -lh /geminux/prebuilt/dunst/usr/bin/
|
||||
'
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#!/bin/sh
|
||||
# Cross-compile Geminux UI SDK (libgemui.so), 9 landscape HiDPI apps,
|
||||
# and 7 zero-poll C11 daemons (+ power-ctl & checkpw) for aarch64.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
mkdir -p "$BASE_DIR/prebuilt/geminux/usr/lib" \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/include" \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/bin" \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/sbin"
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://mirror.nura.eco/postmarketos/v26.06
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
||||
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/geminux 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
echo "[1/4] Installing host aarch64 cross-compile toolchain..."
|
||||
apk add --no-cache \
|
||||
build-base \
|
||||
gcc-aarch64 \
|
||||
binutils-aarch64 \
|
||||
pkgconf >/dev/null
|
||||
|
||||
echo "[2/4] Preparing pure Alpine Edge aarch64 sysroot for libgemui, apps & daemons..."
|
||||
SYSROOT="/tmp/aarch64-ui-sysroot"
|
||||
mkdir -p "$SYSROOT/etc/apk/keys"
|
||||
cat > "$SYSROOT/etc/apk/repositories" <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/alpine-devel@*.rsa.pub "$SYSROOT/etc/apk/keys/"
|
||||
apk --root "$SYSROOT" --initdb --arch aarch64 add --no-scripts \
|
||||
alpine-baselayout \
|
||||
musl-dev \
|
||||
linux-headers \
|
||||
libx11-dev \
|
||||
libxft-dev \
|
||||
libxext-dev \
|
||||
libxrandr-dev \
|
||||
cairo-dev \
|
||||
pango-dev \
|
||||
harfbuzz-dev \
|
||||
glib-dev \
|
||||
libjpeg-turbo-dev \
|
||||
libpng-dev \
|
||||
fontconfig-dev \
|
||||
freetype-dev \
|
||||
expat-dev \
|
||||
zlib-dev \
|
||||
fribidi-dev >/dev/null
|
||||
|
||||
export PKG_CONFIG_SYSROOT_DIR="$SYSROOT"
|
||||
export PKG_CONFIG_LIBDIR="$SYSROOT/usr/lib/pkgconfig:$SYSROOT/usr/share/pkgconfig"
|
||||
export PKG_CONFIG_PATH=""
|
||||
export CC="aarch64-alpine-linux-musl-gcc --sysroot=$SYSROOT"
|
||||
export PKG_CONFIG="pkg-config"
|
||||
|
||||
echo "[3/4] Compiling libgemui, 9 apps, and 7 daemons (+ helpers) for aarch64..."
|
||||
WORK="/tmp/build-ui"
|
||||
rm -rf "$WORK" /geminux/prebuilt/geminux
|
||||
mkdir -p "$WORK" \
|
||||
/geminux/prebuilt/geminux/usr/lib \
|
||||
/geminux/prebuilt/geminux/usr/include \
|
||||
/geminux/prebuilt/geminux/usr/bin \
|
||||
/geminux/prebuilt/geminux/usr/sbin
|
||||
|
||||
for comp in libgemui geminux-apps geminux-daemons; do
|
||||
cp -a "/geminux/src/$comp" "$WORK/$comp"
|
||||
done
|
||||
|
||||
make -C "$WORK/libgemui" CC="$CC" PKG_CONFIG=pkg-config -j"$(nproc)" clean all
|
||||
make -C "$WORK/libgemui" CC="$CC" PKG_CONFIG=pkg-config DESTDIR=/geminux/prebuilt/geminux PREFIX=/usr install
|
||||
|
||||
make -C "$WORK/geminux-apps" CC="$CC" PKG_CONFIG=pkg-config -j"$(nproc)" clean all
|
||||
make -C "$WORK/geminux-apps" CC="$CC" PKG_CONFIG=pkg-config DESTDIR=/geminux/prebuilt/geminux PREFIX=/usr install
|
||||
|
||||
make -C "$WORK/geminux-daemons" CC="$CC" PKG_CONFIG=pkg-config \
|
||||
KERNEL_INC=/geminux/prebuilt/kernel/include -j"$(nproc)" clean all
|
||||
make -C "$WORK/geminux-daemons" CC="$CC" PKG_CONFIG=pkg-config \
|
||||
KERNEL_INC=/geminux/prebuilt/kernel/include DESTDIR=/geminux/prebuilt/geminux PREFIX=/usr install
|
||||
|
||||
echo "[4/4] Stripping aarch64 binaries and shared library..."
|
||||
aarch64-alpine-linux-musl-strip --strip-unneeded \
|
||||
/geminux/prebuilt/geminux/usr/lib/libgemui.so \
|
||||
/geminux/prebuilt/geminux/usr/bin/* \
|
||||
/geminux/prebuilt/geminux/usr/sbin/*
|
||||
|
||||
ls -lh /geminux/prebuilt/geminux/usr/lib/ \
|
||||
/geminux/prebuilt/geminux/usr/bin/ \
|
||||
/geminux/prebuilt/geminux/usr/sbin/
|
||||
'
|
||||
Executable
+258
@@ -0,0 +1,258 @@
|
||||
#!/bin/sh
|
||||
# Cross-compile Linux 7.3.5 kernel, DTB, modules, normal/recovery initramfs,
|
||||
# and pack LK-compatible boot images for Planet Computers Gemini PDA (MT6797X).
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
||||
if [ -e "$ROOTFS_DIR" ]; then
|
||||
ROOTFS_DIR="$(realpath "$ROOTFS_DIR")"
|
||||
fi
|
||||
|
||||
REPACK_ONLY=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--repack-only)
|
||||
REPACK_ONLY=1
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [--repack-only]"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [--repack-only]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
mkdir -p "$BASE_DIR/build-cache" "$BASE_DIR/prebuilt/kernel/boot" \
|
||||
"$BASE_DIR/prebuilt/kernel/lib/modules" "$BASE_DIR/images"
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-e FORCE_REBUILD="${FORCE_REBUILD:-0}" \
|
||||
-e DEBUG_KERNEL="${DEBUG_KERNEL:-0}" \
|
||||
-e REPACK_ONLY="$REPACK_ONLY" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://mirror.nura.eco/postmarketos/v26.06
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
||||
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" \
|
||||
/geminux/build-cache /geminux/prebuilt/kernel /geminux/images 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
if [ "${REPACK_ONLY:-0}" = "1" ] && \
|
||||
[ -f /geminux/prebuilt/kernel/boot/Image.gz ] && \
|
||||
[ -f /geminux/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb ]; then
|
||||
echo "[1/2] Installing initramfs & bootimg tools in Docker (repack-only)..."
|
||||
apk add --no-cache cpio gzip coreutils mkbootimg-osm0sis >/dev/null
|
||||
else
|
||||
REPACK_ONLY=0
|
||||
echo "[1/6] Installing Linux 7.3.5 cross-compile & bootimg tools in Docker..."
|
||||
apk add --no-cache \
|
||||
build-base \
|
||||
bash \
|
||||
bc \
|
||||
bison \
|
||||
flex \
|
||||
perl \
|
||||
python3 \
|
||||
patch \
|
||||
xz \
|
||||
tar \
|
||||
zstd \
|
||||
cpio \
|
||||
gzip \
|
||||
coreutils \
|
||||
grep \
|
||||
gawk \
|
||||
sed \
|
||||
kmod \
|
||||
findutils \
|
||||
diffutils \
|
||||
elfutils-dev \
|
||||
openssl-dev \
|
||||
linux-headers \
|
||||
dtc \
|
||||
mkbootimg-osm0sis \
|
||||
gcc-aarch64 \
|
||||
g++-aarch64 \
|
||||
binutils-aarch64 >/dev/null
|
||||
|
||||
KVER="7.3.5"
|
||||
TARBALL="/geminux/build-cache/linux-${KVER}.tar.xz"
|
||||
EXPECTED_SHA="8f293f83d54f0b7b9be56863ebc5e4ea79d73e530b4ae55c572be97ef39f0990"
|
||||
KSRC="/geminux/build-cache/linux-${KVER}"
|
||||
KBUILD="/geminux/build-cache/kernel-build"
|
||||
STAMP="$KSRC/.geminux-patches-sha"
|
||||
|
||||
[ -f "$TARBALL" ] || { echo "Missing $TARBALL" >&2; exit 1; }
|
||||
echo "${EXPECTED_SHA} ${TARBALL}" | sha256sum -c -
|
||||
|
||||
SERIES_HASH="$(cat /geminux/patches/kernel/series /geminux/patches/kernel/*.patch | sha256sum | awk "{print \$1}")"
|
||||
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "$STAMP" ] || [ "$(cat "$STAMP" 2>/dev/null || true)" != "$SERIES_HASH" ]; then
|
||||
echo "[2/6] Extracting Linux ${KVER} and applying Geminux patch series..."
|
||||
rm -rf "$KSRC"
|
||||
tar -xf "$TARBALL" -C /geminux/build-cache
|
||||
while IFS= read -r p || [ -n "$p" ]; do
|
||||
case "$p" in
|
||||
""|\#*) continue ;;
|
||||
esac
|
||||
echo " Applying patches/kernel/$p"
|
||||
patch -d "$KSRC" -p1 -s < "/geminux/patches/kernel/$p"
|
||||
done < /geminux/patches/kernel/series
|
||||
printf "%s\n" "$SERIES_HASH" > "$STAMP"
|
||||
else
|
||||
echo "[2/6] Reusing patched Linux ${KVER} source tree..."
|
||||
fi
|
||||
|
||||
mkdir -p "$KBUILD"
|
||||
MAKE_FLAGS="ARCH=arm64 CROSS_COMPILE=aarch64-alpine-linux-musl- O=$KBUILD"
|
||||
|
||||
echo "[3/6] Generating merged kernel config..."
|
||||
make -C "$KSRC" $MAKE_FLAGS defconfig >/dev/null
|
||||
FRAGMENTS="/geminux/kernel/configs/geminux-mt6797x.config"
|
||||
if [ "${DEBUG_KERNEL:-0}" = "1" ]; then
|
||||
FRAGMENTS="$FRAGMENTS /geminux/kernel/configs/geminux-debug.fragment"
|
||||
fi
|
||||
"$KSRC/scripts/kconfig/merge_config.sh" -m -O "$KBUILD" \
|
||||
"$KBUILD/.config" $FRAGMENTS >/dev/null
|
||||
yes "" | make -C "$KSRC" $MAKE_FLAGS olddefconfig >/dev/null
|
||||
|
||||
echo "[4/6] Compiling Image.gz, DTBs, and modules (-j$(nproc))..."
|
||||
make -C "$KSRC" $MAKE_FLAGS -j"$(nproc)" Image.gz dtbs modules
|
||||
|
||||
echo "[5/6] Staging kernel, DTB, UAPI headers, and zstd-stripped modules..."
|
||||
rm -rf /geminux/prebuilt/kernel/boot /geminux/prebuilt/kernel/lib/modules
|
||||
mkdir -p /geminux/prebuilt/kernel/boot /geminux/prebuilt/kernel/lib/modules \
|
||||
/geminux/prebuilt/kernel/include/linux
|
||||
|
||||
cp "$KBUILD/arch/arm64/boot/Image.gz" /geminux/prebuilt/kernel/boot/Image.gz
|
||||
cp "$KBUILD/arch/arm64/boot/dts/mediatek/mt6797-gemini-pda-geminux.dtb" \
|
||||
/geminux/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb
|
||||
cp "$KBUILD/.config" /geminux/prebuilt/kernel/boot/config-${KVER}-geminux
|
||||
cp "$KSRC/include/uapi/linux/mt6797_ccci.h" \
|
||||
/geminux/prebuilt/kernel/include/linux/mt6797_ccci.h
|
||||
|
||||
DTB_SIZE="$(wc -c < /geminux/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb)"
|
||||
echo " DTB size: $DTB_SIZE bytes (limit 524288)"
|
||||
[ "$DTB_SIZE" -le 524288 ] || { echo "ERROR: DTB exceeds 512 KiB LK limit!" >&2; exit 1; }
|
||||
|
||||
make -C "$KSRC" $MAKE_FLAGS INSTALL_MOD_PATH=/geminux/prebuilt/kernel \
|
||||
INSTALL_MOD_STRIP=1 modules_install >/dev/null
|
||||
find /geminux/prebuilt/kernel/lib/modules -type l \( -name build -o -name source \) -delete
|
||||
fi
|
||||
|
||||
echo "[6/6] Building normal + recovery initramfs and packing LK boot images..."
|
||||
SYSROOT_INIT="/tmp/initramfs-apk"
|
||||
mkdir -p "$SYSROOT_INIT/etc/apk/keys"
|
||||
cp /etc/apk/repositories "$SYSROOT_INIT/etc/apk/repositories"
|
||||
cp /etc/apk/keys/*.rsa.pub "$SYSROOT_INIT/etc/apk/keys/"
|
||||
apk --root "$SYSROOT_INIT" --initdb --arch aarch64 add --no-scripts \
|
||||
busybox-static >/dev/null
|
||||
|
||||
build_cpio() {
|
||||
mode="$1"
|
||||
out_gz="$2"
|
||||
stage_dir="/tmp/initramfs-$mode"
|
||||
rm -rf "$stage_dir"
|
||||
mkdir -p "$stage_dir/bin" "$stage_dir/sbin" "$stage_dir/usr/bin" \
|
||||
"$stage_dir/usr/sbin" "$stage_dir/etc" "$stage_dir/proc" \
|
||||
"$stage_dir/sys" "$stage_dir/dev" "$stage_dir/run" \
|
||||
"$stage_dir/mnt/root"
|
||||
cp "$SYSROOT_INIT/bin/busybox.static" "$stage_dir/bin/busybox"
|
||||
chmod 755 "$stage_dir/bin/busybox"
|
||||
for cmd in sh ash mount umount switch_root mkdir mknod chmod chown \
|
||||
cat cp mv rm ln ls echo printf grep awk sed head tail \
|
||||
cut tr wc sort uniq find xargs hexdump dd sync sleep usleep \
|
||||
poweroff reboot ip ifconfig route basename dirname env touch; do
|
||||
ln -sf busybox "$stage_dir/bin/$cmd"
|
||||
done
|
||||
# Pull static/musl e2fsck + resize2fs if available from aarch64 rootfs/apk
|
||||
if [ "$mode" = "recovery" ]; then
|
||||
cp /geminux/src/initramfs/init-recovery "$stage_dir/init"
|
||||
else
|
||||
cp /geminux/src/initramfs/init "$stage_dir/init"
|
||||
fi
|
||||
chmod 755 "$stage_dir/init"
|
||||
(cd "$stage_dir" && find . -print0 | cpio --null -ov --format=newc --quiet | gzip -9 > "$out_gz")
|
||||
}
|
||||
|
||||
# Also add e2fsprogs (e2fsck, resize2fs) + shared libs for initramfs filesystem safety
|
||||
apk --root "$SYSROOT_INIT" --arch aarch64 add --no-scripts \
|
||||
musl e2fsprogs e2fsprogs-extra util-linux-misc >/dev/null
|
||||
|
||||
build_cpio_with_fs() {
|
||||
mode="$1"
|
||||
out_gz="$2"
|
||||
build_cpio "$mode" "$out_gz"
|
||||
stage_dir="/tmp/initramfs-$mode"
|
||||
mkdir -p "$stage_dir/lib" "$stage_dir/usr/lib" "$stage_dir/sbin"
|
||||
cp -a "$SYSROOT_INIT/lib/"ld-musl-*.so* "$stage_dir/lib/" 2>/dev/null || true
|
||||
cp -a "$SYSROOT_INIT/lib/lib"* "$stage_dir/lib/" 2>/dev/null || true
|
||||
cp -a "$SYSROOT_INIT/usr/lib/lib"* "$stage_dir/usr/lib/" 2>/dev/null || true
|
||||
for tool in e2fsck fsck.ext4 resize2fs blkid; do
|
||||
if [ -e "$SYSROOT_INIT/sbin/$tool" ]; then
|
||||
cp -a "$SYSROOT_INIT/sbin/$tool" "$stage_dir/sbin/"
|
||||
elif [ -e "$SYSROOT_INIT/usr/sbin/$tool" ]; then
|
||||
cp -a "$SYSROOT_INIT/usr/sbin/$tool" "$stage_dir/sbin/"
|
||||
fi
|
||||
done
|
||||
(cd "$stage_dir" && find . -print0 | cpio --null -ov --format=newc --quiet | gzip -9 > "$out_gz")
|
||||
}
|
||||
|
||||
build_cpio_with_fs normal /tmp/initramfs-normal.cpio.gz
|
||||
build_cpio_with_fs recovery /tmp/initramfs-recovery.cpio.gz
|
||||
|
||||
cat /geminux/prebuilt/kernel/boot/Image.gz \
|
||||
/geminux/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb \
|
||||
> /tmp/Image.gz-dtb
|
||||
|
||||
CMDLINE="bootopt=64S3,32N2,64N2 console=ttyS0,921600n8 console=tty1 maxcpus=8 nokaslr noautodetect loglevel=4 rdinit=/init panic=10 clk_ignore_unused fbcon=rotate:3 consoleblank=0 fbcon=font:TER16x32 rootwait"
|
||||
if [ "${DEBUG_KERNEL:-0}" = "1" ]; then
|
||||
CMDLINE="bootopt=64S3,32N2,64N2 console=ttyS0,921600n8 console=tty1 earlycon maxcpus=8 nokaslr noautodetect loglevel=7 rdinit=/init panic=10 fbcon=rotate:3 consoleblank=0 fbcon=font:TER16x32 clk_ignore_unused rootwait"
|
||||
fi
|
||||
|
||||
mkbootimg-osm0sis \
|
||||
--kernel /tmp/Image.gz-dtb \
|
||||
--ramdisk /tmp/initramfs-normal.cpio.gz \
|
||||
--cmdline "$CMDLINE" \
|
||||
--base 0x40000000 \
|
||||
--kernel_offset 0x00080000 \
|
||||
--ramdisk_offset 0x05000000 \
|
||||
--second_offset 0x00f00000 \
|
||||
--tags_offset 0x04000000 \
|
||||
--pagesize 2048 \
|
||||
--output /geminux/images/boot-geminux.img
|
||||
|
||||
mkbootimg-osm0sis \
|
||||
--kernel /tmp/Image.gz-dtb \
|
||||
--ramdisk /tmp/initramfs-recovery.cpio.gz \
|
||||
--cmdline "$CMDLINE" \
|
||||
--base 0x40000000 \
|
||||
--kernel_offset 0x00080000 \
|
||||
--ramdisk_offset 0x05000000 \
|
||||
--second_offset 0x00f00000 \
|
||||
--tags_offset 0x04000000 \
|
||||
--pagesize 2048 \
|
||||
--output /geminux/images/recovery-geminux.img
|
||||
|
||||
for img in /geminux/images/boot-geminux.img /geminux/images/recovery-geminux.img; do
|
||||
sz="$(wc -c < "$img")"
|
||||
echo " $(basename "$img"): $sz bytes (limit 16777216)"
|
||||
[ "$sz" -le 16777216 ] || { echo "ERROR: $img exceeds 16 MiB LK limit!" >&2; exit 1; }
|
||||
done
|
||||
|
||||
chown -R "$HOST_UID:$HOST_GID" \
|
||||
/geminux/build-cache /geminux/prebuilt/kernel /geminux/images 2>/dev/null || true
|
||||
'
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/bin/sh
|
||||
# Cross-compile Geminux suckless X11 stack (st with HarfBuzz ligatures,
|
||||
# dwm with Pango/HarfBuzz + systray + .Xresources + Gemini Mod4, dmenu + stest).
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
mkdir -p "$BASE_DIR/prebuilt/suckless/usr/bin" "$BASE_DIR/prebuilt/suckless/usr/share/terminfo"
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://mirror.nura.eco/postmarketos/v26.06
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
||||
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/suckless 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
echo "[1/4] Installing host aarch64 cross-compile toolchain..."
|
||||
apk add --no-cache \
|
||||
build-base \
|
||||
gcc-aarch64 \
|
||||
binutils-aarch64 \
|
||||
pkgconf \
|
||||
ncurses >/dev/null
|
||||
|
||||
echo "[2/4] Preparing pure Alpine Edge aarch64 sysroot for suckless desktop..."
|
||||
SYSROOT="/tmp/aarch64-sysroot"
|
||||
mkdir -p "$SYSROOT/etc/apk/keys"
|
||||
cat > "$SYSROOT/etc/apk/repositories" <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/alpine-devel@*.rsa.pub "$SYSROOT/etc/apk/keys/"
|
||||
apk --root "$SYSROOT" --initdb --arch aarch64 add --no-scripts \
|
||||
alpine-baselayout \
|
||||
musl-dev \
|
||||
libx11-dev \
|
||||
libxft-dev \
|
||||
libxinerama-dev \
|
||||
libxrender-dev \
|
||||
fontconfig-dev \
|
||||
freetype-dev \
|
||||
harfbuzz-dev \
|
||||
pango-dev \
|
||||
cairo-dev \
|
||||
glib-dev \
|
||||
expat-dev \
|
||||
zlib-dev \
|
||||
libpng-dev \
|
||||
fribidi-dev >/dev/null
|
||||
|
||||
export PKG_CONFIG_SYSROOT_DIR="$SYSROOT"
|
||||
export PKG_CONFIG_LIBDIR="$SYSROOT/usr/lib/pkgconfig:$SYSROOT/usr/share/pkgconfig"
|
||||
export PKG_CONFIG_PATH=""
|
||||
export CC="aarch64-alpine-linux-musl-gcc --sysroot=$SYSROOT"
|
||||
export PKG_CONFIG="pkg-config"
|
||||
|
||||
echo "[3/4] Compiling st, dwm, dmenu, and stest for aarch64..."
|
||||
rm -rf /geminux/prebuilt/suckless
|
||||
mkdir -p /geminux/prebuilt/suckless/usr/bin /geminux/prebuilt/suckless/usr/share/terminfo
|
||||
|
||||
for comp in st dwm dmenu; do
|
||||
work="/tmp/build-$comp"
|
||||
rm -rf "$work"
|
||||
cp -a "/geminux/src/$comp" "$work"
|
||||
cp -f "$work/config.def.h" "$work/config.h"
|
||||
make -C "$work" CC="$CC" PKG_CONFIG=pkg-config -j"$(nproc)" clean all
|
||||
make -C "$work" CC="$CC" PKG_CONFIG=pkg-config DESTDIR=/geminux/prebuilt/suckless PREFIX=/usr install
|
||||
done
|
||||
|
||||
echo "[4/4] Compiling st terminfo and stripping binaries..."
|
||||
tic -x -o /geminux/prebuilt/suckless/usr/share/terminfo /geminux/src/st/st.info
|
||||
aarch64-alpine-linux-musl-strip --strip-unneeded \
|
||||
/geminux/prebuilt/suckless/usr/bin/st \
|
||||
/geminux/prebuilt/suckless/usr/bin/dwm \
|
||||
/geminux/prebuilt/suckless/usr/bin/dmenu \
|
||||
/geminux/prebuilt/suckless/usr/bin/stest
|
||||
|
||||
ls -lh /geminux/prebuilt/suckless/usr/bin/
|
||||
'
|
||||
Executable
+265
@@ -0,0 +1,265 @@
|
||||
#!/bin/sh
|
||||
# Cross-compile XLibre (X11Libre/xserver) + xf86-input-libinput + xf86-video-fbdev
|
||||
# for Geminux aarch64 (MT6797X Cortex-A53/A72 + Mali-T880 Panfrost Glamor/DRI3/GLX)
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
||||
if [ -e "$ROOTFS_DIR" ]; then
|
||||
ROOTFS_DIR="$(realpath "$ROOTFS_DIR")"
|
||||
fi
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-e FORCE_REBUILD="${FORCE_REBUILD:-0}" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
-v "$ROOTFS_DIR:/target-rootfs" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://mirror.nura.eco/postmarketos/v26.06
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
||||
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" \
|
||||
/geminux/prebuilt/xlibre /geminux/build-cache \
|
||||
/target-rootfs/usr/lib/xorg /target-rootfs/usr/bin/Xorg /target-rootfs/usr/bin/X 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
echo "[1/5] Installing host aarch64 cross-compilation toolchain and meson/ninja..."
|
||||
apk add --no-cache \
|
||||
build-base \
|
||||
git \
|
||||
ca-certificates \
|
||||
patch \
|
||||
gcc-aarch64 \
|
||||
g++-aarch64 \
|
||||
binutils-aarch64 \
|
||||
meson \
|
||||
ninja \
|
||||
pkgconf \
|
||||
python3 >/dev/null
|
||||
|
||||
XLIBRE_SRC="/geminux/build-cache/xlibre-xserver"
|
||||
if [ ! -f "$XLIBRE_SRC/meson.build" ]; then
|
||||
echo "[1b/5] Cloning X11Libre/xserver..."
|
||||
rm -rf "$XLIBRE_SRC"
|
||||
git clone --depth 1 https://github.com/X11Libre/xserver.git "$XLIBRE_SRC"
|
||||
for p in /geminux/patches/xlibre/*.patch; do
|
||||
[ -f "$p" ] && patch -d "$XLIBRE_SRC" -p1 < "$p"
|
||||
done
|
||||
fi
|
||||
|
||||
XF86_LIBINPUT_SRC="/geminux/build-cache/xf86-input-libinput"
|
||||
if [ ! -f "$XF86_LIBINPUT_SRC/meson.build" ]; then
|
||||
echo "[1c/5] Cloning X11Libre/xf86-input-libinput..."
|
||||
rm -rf "$XF86_LIBINPUT_SRC"
|
||||
git clone --depth 1 https://github.com/X11Libre/xf86-input-libinput.git "$XF86_LIBINPUT_SRC"
|
||||
fi
|
||||
|
||||
XF86_FBDEV_SRC="/geminux/build-cache/xf86-video-fbdev"
|
||||
if [ ! -f "$XF86_FBDEV_SRC/src/fbdev.c" ]; then
|
||||
echo "[1d/5] Cloning X11Libre/xf86-video-fbdev..."
|
||||
rm -rf "$XF86_FBDEV_SRC"
|
||||
git clone --depth 1 https://github.com/X11Libre/xf86-video-fbdev.git "$XF86_FBDEV_SRC"
|
||||
fi
|
||||
|
||||
echo "[2/5] Preparing pure Alpine Edge aarch64 sysroot for XLibre + DDX drivers..."
|
||||
SYSROOT="/tmp/aarch64-sysroot"
|
||||
mkdir -p "$SYSROOT/etc/apk/keys"
|
||||
cat > "$SYSROOT/etc/apk/repositories" <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/alpine-devel@*.rsa.pub "$SYSROOT/etc/apk/keys/"
|
||||
apk --root "$SYSROOT" --initdb --arch aarch64 add --no-scripts \
|
||||
alpine-baselayout \
|
||||
musl-dev \
|
||||
linux-headers \
|
||||
xorgproto \
|
||||
xtrans \
|
||||
font-util-dev \
|
||||
pixman-dev \
|
||||
libx11-dev \
|
||||
libxext-dev \
|
||||
libxfont2-dev \
|
||||
libxkbfile-dev \
|
||||
libxshmfence-dev \
|
||||
libxdmcp-dev \
|
||||
libxau-dev \
|
||||
libxcvt-dev \
|
||||
libdrm-dev \
|
||||
libepoxy-dev \
|
||||
mesa-dev \
|
||||
eudev-dev \
|
||||
dbus-dev \
|
||||
libpciaccess-dev \
|
||||
openssl-dev \
|
||||
libinput-dev \
|
||||
mtdev-dev >/dev/null
|
||||
|
||||
OPT_CFLAGS="-O2 -march=armv8-a+crc+crypto -mtune=cortex-a53 -fno-plt"
|
||||
|
||||
cat > /tmp/aarch64-cross.ini <<EOF
|
||||
[binaries]
|
||||
c = '\''aarch64-alpine-linux-musl-gcc'\''
|
||||
cpp = '\''aarch64-alpine-linux-musl-g++'\''
|
||||
ar = '\''aarch64-alpine-linux-musl-ar'\''
|
||||
strip = '\''aarch64-alpine-linux-musl-strip'\''
|
||||
pkg-config = '\''pkgconf'\''
|
||||
|
||||
[built-in options]
|
||||
c_args = ['\''--sysroot=/tmp/aarch64-sysroot'\'', '\''-O2'\'', '\''-march=armv8-a+crc+crypto'\'', '\''-mtune=cortex-a53'\'', '\''-fno-plt'\'']
|
||||
c_link_args = ['\''--sysroot=/tmp/aarch64-sysroot'\'', '\''-Wl,-O1,--as-needed'\'']
|
||||
|
||||
[properties]
|
||||
sys_root = '\''/tmp/aarch64-sysroot'\''
|
||||
pkg_config_libdir = '\''/tmp/aarch64-sysroot/usr/lib/pkgconfig:/tmp/aarch64-sysroot/usr/share/pkgconfig'\''
|
||||
|
||||
[host_machine]
|
||||
system = '\''linux'\''
|
||||
cpu_family = '\''aarch64'\''
|
||||
cpu = '\''aarch64'\''
|
||||
endian = '\''little'\''
|
||||
EOF
|
||||
|
||||
# Detect ABI module directory from meson.build or default xlibre-25
|
||||
ABI_MOD_DIR="/usr/lib/xorg/modules/xlibre-25"
|
||||
if grep -q "xlibre-26" "$XLIBRE_SRC/meson.build" 2>/dev/null; then
|
||||
ABI_MOD_DIR="/usr/lib/xorg/modules/xlibre-26"
|
||||
fi
|
||||
|
||||
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f /geminux/prebuilt/xlibre/usr/bin/Xorg ]; then
|
||||
echo "[3/5] Configuring and compiling XLibre (X11Libre/xserver) for aarch64..."
|
||||
rm -rf /tmp/build-xlibre
|
||||
meson setup /tmp/build-xlibre "$XLIBRE_SRC" \
|
||||
--cross-file=/tmp/aarch64-cross.ini \
|
||||
--prefix=/usr \
|
||||
--libdir=lib \
|
||||
--libexecdir=libexec \
|
||||
--sysconfdir=/etc \
|
||||
--localstatedir=/var \
|
||||
--buildtype=release \
|
||||
-Dxorg=true \
|
||||
-Dxorg-sdk=true \
|
||||
-Dglamor=true \
|
||||
-Dglx=true \
|
||||
-Ddri1=false \
|
||||
-Ddri2=true \
|
||||
-Ddri3=true \
|
||||
-Ddrm=true \
|
||||
-Dgbm=true \
|
||||
-Dudev=true \
|
||||
-Dudev_kms=true \
|
||||
-Dsystemd_logind=true \
|
||||
-Dseatd_libseat=false \
|
||||
-Dsuid_wrapper=false \
|
||||
-Dpciaccess=true \
|
||||
-Dvgahw=false \
|
||||
-Dint10=false \
|
||||
-Ddga=false \
|
||||
-Dxv=true \
|
||||
-Dxvmc=false \
|
||||
-Dxephyr=false \
|
||||
-Dxnest=false \
|
||||
-Dxvfb=false \
|
||||
-Dxfake=false \
|
||||
-Dxfbdev=false \
|
||||
-Dxmodesetting=false \
|
||||
-Dxf86-input-inputtest=false \
|
||||
-Dxf86-input-null=false \
|
||||
-Dlegacy_nvidia_340x=false \
|
||||
-Dlegacy_nvidia_padding=false \
|
||||
-Ddocs=false \
|
||||
-Ddevel-docs=false \
|
||||
-Dtests=false \
|
||||
-Dlibunwind=false \
|
||||
-Dsha1=libcrypto \
|
||||
-Dinput_thread=true \
|
||||
-Ddefault_font_path=/usr/share/fonts/misc,/usr/share/fonts/TTF,/usr/share/fonts/OTF \
|
||||
-Dxkb_dir=/usr/share/X11/xkb \
|
||||
-Dxkb_output_dir=/tmp \
|
||||
-Dxkb_bin_dir=/usr/bin \
|
||||
-Dlog_dir=/tmp
|
||||
|
||||
ninja -C /tmp/build-xlibre -j"$(nproc)"
|
||||
rm -rf /geminux/prebuilt/xlibre
|
||||
mkdir -p /geminux/prebuilt/xlibre
|
||||
DESTDIR="/geminux/prebuilt/xlibre" ninja -C /tmp/build-xlibre install
|
||||
else
|
||||
echo "[3/5] Reusing compiled XLibre in /geminux/prebuilt/xlibre..."
|
||||
fi
|
||||
|
||||
if [ -d /geminux/prebuilt/xlibre/tmp/aarch64-sysroot/usr ]; then
|
||||
cp -a /geminux/prebuilt/xlibre/tmp/aarch64-sysroot/usr/. /geminux/prebuilt/xlibre/usr/
|
||||
rm -rf /geminux/prebuilt/xlibre/tmp
|
||||
fi
|
||||
|
||||
# Detect actual installed module ABI dir
|
||||
REAL_MOD_DIR="$(find /geminux/prebuilt/xlibre/usr/lib/xorg/modules -maxdepth 1 -mindepth 1 -type d -name "xlibre-*" | head -n 1)"
|
||||
if [ -n "$REAL_MOD_DIR" ]; then
|
||||
ABI_MOD_DIR="/usr/lib/xorg/modules/$(basename "$REAL_MOD_DIR")"
|
||||
fi
|
||||
|
||||
cp -a /geminux/prebuilt/xlibre/usr/. "$SYSROOT/usr/"
|
||||
|
||||
echo "[4/5] Compiling xf86-input-libinput and xf86-video-fbdev against XLibre SDK ($ABI_MOD_DIR)..."
|
||||
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "/geminux/prebuilt/xlibre$ABI_MOD_DIR/input/libinput_drv.so" ]; then
|
||||
rm -rf /tmp/build-libinput
|
||||
meson setup /tmp/build-libinput "$XF86_LIBINPUT_SRC" \
|
||||
--cross-file=/tmp/aarch64-cross.ini \
|
||||
--prefix=/usr \
|
||||
--libdir=lib \
|
||||
--sysconfdir=/etc \
|
||||
--buildtype=release \
|
||||
-Dxorg-module-dir="$ABI_MOD_DIR/input" \
|
||||
-Dsdkdir=/usr/include/xorg \
|
||||
-Dxorg-conf-dir=/usr/share/X11/xorg.conf.d
|
||||
ninja -C /tmp/build-libinput -j"$(nproc)"
|
||||
DESTDIR="/geminux/prebuilt/xlibre" ninja -C /tmp/build-libinput install
|
||||
fi
|
||||
|
||||
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so" ]; then
|
||||
mkdir -p "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers" /tmp/fbdev-inc
|
||||
cat > /tmp/fbdev-inc/config.h <<EOF
|
||||
#include "xorg-server.h"
|
||||
#define PACKAGE_VERSION_MAJOR 25
|
||||
#define PACKAGE_VERSION_MINOR 0
|
||||
#define PACKAGE_VERSION_PATCHLEVEL 0
|
||||
#define PACKAGE_VERSION_SUFFIX ""
|
||||
EOF
|
||||
aarch64-alpine-linux-musl-gcc \
|
||||
--sysroot="$SYSROOT" \
|
||||
$OPT_CFLAGS -shared -fPIC \
|
||||
-I/tmp/fbdev-inc \
|
||||
-I"$SYSROOT/usr/include/xorg" \
|
||||
-I"$XLIBRE_SRC/include" \
|
||||
-I"$SYSROOT/usr/include/pixman-1" \
|
||||
-I"$SYSROOT/usr/include/X11/dri" \
|
||||
-I"$SYSROOT/usr/include/libdrm" \
|
||||
"$XF86_FBDEV_SRC/src/fbdev.c" \
|
||||
-o "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so"
|
||||
fi
|
||||
|
||||
echo "[5/5] Stripping XLibre binaries and cleaning headers..."
|
||||
find /geminux/prebuilt/xlibre/usr/bin /geminux/prebuilt/xlibre/usr/lib -type f \( -name "Xorg" -o -name "gtf" -o -name "*.so" \) -exec aarch64-alpine-linux-musl-strip --strip-unneeded {} +
|
||||
rm -rf /geminux/prebuilt/xlibre/usr/include \
|
||||
/geminux/prebuilt/xlibre/usr/lib/pkgconfig \
|
||||
/geminux/prebuilt/xlibre/usr/share/aclocal \
|
||||
/geminux/prebuilt/xlibre/usr/share/man \
|
||||
/geminux/prebuilt/xlibre/usr/share/X11/xorg.conf.d/10-nvidia*.conf \
|
||||
/geminux/prebuilt/xlibre/etc/X11/xorg.conf.d/10-nvidia*
|
||||
ln -sfn Xorg /geminux/prebuilt/xlibre/usr/bin/X
|
||||
|
||||
if [ -d /target-rootfs/usr ]; then
|
||||
cp -a /geminux/prebuilt/xlibre/. /target-rootfs/
|
||||
fi
|
||||
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/xlibre /geminux/build-cache /target-rootfs/usr/lib/xorg /target-rootfs/usr/bin/Xorg /target-rootfs/usr/bin/X 2>/dev/null || true
|
||||
ls -lh /geminux/prebuilt/xlibre/usr/bin/Xorg "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/"*.so "/geminux/prebuilt/xlibre$ABI_MOD_DIR/input/"*.so
|
||||
'
|
||||
@@ -0,0 +1,91 @@
|
||||
arch
|
||||
ash
|
||||
base64
|
||||
bash
|
||||
bbconfig
|
||||
busybox
|
||||
cat
|
||||
chattr
|
||||
chgrp
|
||||
chmod
|
||||
chown
|
||||
conspy
|
||||
coreutils
|
||||
cp
|
||||
cttyhack
|
||||
date
|
||||
dd
|
||||
df
|
||||
dmesg
|
||||
dnsdomainname
|
||||
dumpkmap
|
||||
echo
|
||||
ed
|
||||
egrep
|
||||
false
|
||||
fatattr
|
||||
fdflush
|
||||
fgrep
|
||||
findmnt
|
||||
fsync
|
||||
getopt
|
||||
grep
|
||||
gunzip
|
||||
gzip
|
||||
hostname
|
||||
ionice
|
||||
iostat
|
||||
ipcalc
|
||||
kbd_mode
|
||||
kill
|
||||
kmod
|
||||
link
|
||||
ln
|
||||
login
|
||||
ls
|
||||
lsattr
|
||||
lsblk
|
||||
lsfd
|
||||
lzop
|
||||
mkdir
|
||||
mknod
|
||||
mktemp
|
||||
more
|
||||
mount
|
||||
mountpoint
|
||||
mpstat
|
||||
mv
|
||||
netstat
|
||||
nice
|
||||
pidof
|
||||
ping
|
||||
ping6
|
||||
pipe_progress
|
||||
printenv
|
||||
ps
|
||||
pwd
|
||||
rc-status
|
||||
rev
|
||||
rm
|
||||
rmdir
|
||||
run-parts
|
||||
sed
|
||||
setpriv
|
||||
setserial
|
||||
sh
|
||||
sleep
|
||||
stat
|
||||
stty
|
||||
su
|
||||
sync
|
||||
tar
|
||||
touch
|
||||
true
|
||||
udevadm
|
||||
umount
|
||||
uname
|
||||
usleep
|
||||
vmstat
|
||||
watch
|
||||
wdctl
|
||||
zcat
|
||||
@@ -0,0 +1,35 @@
|
||||
acpid
|
||||
adjtimex
|
||||
arp
|
||||
fbsplash
|
||||
getty
|
||||
halt
|
||||
ifconfig
|
||||
ifenslave
|
||||
inotifyd
|
||||
ipaddr
|
||||
iplink
|
||||
ipneigh
|
||||
iproute
|
||||
iprule
|
||||
iptunnel
|
||||
klogd
|
||||
loadkmap
|
||||
logread
|
||||
mdev
|
||||
nameif
|
||||
nologin
|
||||
poweroff
|
||||
raidautorun
|
||||
reboot
|
||||
route
|
||||
rfkill
|
||||
setconsole
|
||||
slattach
|
||||
sysctl
|
||||
syslogd
|
||||
tunctl
|
||||
udhcpc
|
||||
vconfig
|
||||
watchdog
|
||||
zcip
|
||||
@@ -0,0 +1,70 @@
|
||||
[[
|
||||
awk
|
||||
beep
|
||||
bunzip2
|
||||
bzcat
|
||||
bzip2
|
||||
chvt
|
||||
clear
|
||||
cmp
|
||||
cpio
|
||||
crontab
|
||||
cryptpw
|
||||
deallocvt
|
||||
diff
|
||||
dos2unix
|
||||
find
|
||||
free
|
||||
fuser
|
||||
groups
|
||||
hd
|
||||
killall
|
||||
last
|
||||
lsusb
|
||||
lzcat
|
||||
lzma
|
||||
lzopcat
|
||||
makemime
|
||||
microcom
|
||||
mkpasswd
|
||||
nc
|
||||
nmeter
|
||||
nslookup
|
||||
openvt
|
||||
pgrep
|
||||
pkill
|
||||
pmap
|
||||
pscan
|
||||
pstree
|
||||
pwdx
|
||||
reformime
|
||||
reset
|
||||
resize
|
||||
setkeycodes
|
||||
sha3sum
|
||||
showkey
|
||||
strings
|
||||
time
|
||||
top
|
||||
traceroute
|
||||
traceroute6
|
||||
tree
|
||||
ttysize
|
||||
udhcpc6
|
||||
unix2dos
|
||||
unlzma
|
||||
unlzop
|
||||
unxz
|
||||
unzip
|
||||
uptime
|
||||
uudecode
|
||||
uuencode
|
||||
vi
|
||||
vlock
|
||||
volname
|
||||
wget
|
||||
which
|
||||
whois
|
||||
xargs
|
||||
xxd
|
||||
xzcat
|
||||
@@ -0,0 +1,24 @@
|
||||
add-shell
|
||||
addgroup
|
||||
adduser
|
||||
arping
|
||||
brctl
|
||||
crond
|
||||
delgroup
|
||||
deluser
|
||||
ether-wake
|
||||
fbset
|
||||
killall5
|
||||
loadfont
|
||||
nanddump
|
||||
nandwrite
|
||||
nbd-client
|
||||
ntpd
|
||||
partprobe
|
||||
rdate
|
||||
rdev
|
||||
readahead
|
||||
remove-shell
|
||||
sendmail
|
||||
setfont
|
||||
setlogcons
|
||||
Executable
+263
@@ -0,0 +1,263 @@
|
||||
#!/bin/sh
|
||||
# Comprehensive Geminux verification suite (repo policy, zero-Rust ELF scan,
|
||||
# Alpine Edge upgrade simulation, aarch64 binaries, image integrity, unit tests).
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
||||
IMAGES_DIR="$BASE_DIR/images"
|
||||
|
||||
if [ ! -d "$ROOTFS_DIR/lib/apk/db" ]; then
|
||||
echo "FAIL: rootfs not bootstrapped at $ROOTFS_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[1/8] Checking APK repositories (pure Alpine Edge + @geminux, zero postmarketOS)..."
|
||||
grep -q '^@geminux /var/lib/geminux/apk-repo$' "$ROOTFS_DIR/etc/apk/repositories"
|
||||
grep -q 'alpine/edge/main' "$ROOTFS_DIR/etc/apk/repositories"
|
||||
grep -q 'alpine/edge/community' "$ROOTFS_DIR/etc/apk/repositories"
|
||||
grep -q 'alpine/edge/testing' "$ROOTFS_DIR/etc/apk/repositories"
|
||||
if grep -qi 'postmarketos' "$ROOTFS_DIR/etc/apk/repositories"; then
|
||||
echo "FAIL: unexpected postmarketos repository in target rootfs" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "OK"
|
||||
|
||||
echo "[2/8] Checking excluded Wayland/Rust/compiler/upstream packages..."
|
||||
for bad_pkg in sway wayfire weston phosh cage xwayland grim slurp wofi \
|
||||
sudo-rs postmarketos-base-sudo-rs rust cargo librsvg libglycin rav1e \
|
||||
rav1e-libs libdovi mesa-rusticl gdk-pixbuf adwaita-icon-theme imv-x11 \
|
||||
gst-libav gst-plugins-bad gst-plugins-good libnotify \
|
||||
linux-edge linux-lts xorg-server xf86-input-libinput xf86-video-fbdev \
|
||||
gcc g++ musl-dev make; do
|
||||
if grep -Fxq "P:$bad_pkg" "$ROOTFS_DIR/lib/apk/db/installed"; then
|
||||
echo "FAIL: forbidden package '$bad_pkg' is installed in rootfs" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "OK (zero forbidden packages)"
|
||||
|
||||
echo "[3/8] Running full binary ELF Rust scan across $ROOTFS_DIR..."
|
||||
python3 - "$ROOTFS_DIR" <<'PYEOF'
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
root = sys.argv[1]
|
||||
raw_markers = re.compile(
|
||||
rb"(core::panicking|rustc_version|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
|
||||
)
|
||||
sym_markers = re.compile(
|
||||
r"(rust_eh_personality|rust_begin_unwind|_ZN4core9panicking|_ZN3std9panicking|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
|
||||
)
|
||||
elfs = []
|
||||
hits = []
|
||||
for parent, _, names in os.walk(root):
|
||||
for name in names:
|
||||
p = os.path.join(parent, name)
|
||||
if os.path.islink(p) or not os.path.isfile(p):
|
||||
continue
|
||||
try:
|
||||
with open(p, "rb") as f:
|
||||
if f.read(4) != b"\x7fELF":
|
||||
continue
|
||||
f.seek(0)
|
||||
data = f.read()
|
||||
except OSError:
|
||||
continue
|
||||
elfs.append(p)
|
||||
m = raw_markers.search(data)
|
||||
if m:
|
||||
hits.append((os.path.relpath(p, root), m.group(0).decode("ascii", "replace")))
|
||||
|
||||
if elfs:
|
||||
batch_sz = 200
|
||||
for i in range(0, len(elfs), batch_sz):
|
||||
chunk = elfs[i:i + batch_sz]
|
||||
proc = subprocess.run(
|
||||
["readelf", "-d", "-Ws"] + chunk,
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
cur_file = chunk[0]
|
||||
for line in proc.stdout.splitlines():
|
||||
if line.startswith("File: "):
|
||||
cur_file = line[6:].strip()
|
||||
continue
|
||||
sm = sym_markers.search(line)
|
||||
if sm:
|
||||
hits.append((os.path.relpath(cur_file, root), sm.group(1)))
|
||||
|
||||
print(f"Scanned {len(elfs)} ELF binaries/libraries in rootfs -> {len(hits)} Rust marker hit(s)")
|
||||
if hits:
|
||||
for path, marker in hits[:20]:
|
||||
print(f"FAIL: Rust marker '{marker}' in {path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
PYEOF
|
||||
|
||||
echo "[4/8] Simulating Alpine Edge live 'apk upgrade' with locked @geminux packages..."
|
||||
ROOTFS_HOST="$(realpath "$ROOTFS_DIR")"
|
||||
docker run --rm --network=host \
|
||||
-v "$ROOTFS_HOST:/rootfs" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
mkdir -p /var/lib/geminux
|
||||
ln -sfn /rootfs/var/lib/geminux/apk-repo /var/lib/geminux/apk-repo
|
||||
cp -f /rootfs/etc/apk/keys/*.rsa.pub /etc/apk/keys/ 2>/dev/null || true
|
||||
|
||||
apk --root /rootfs --arch aarch64 update
|
||||
UPG_OUT="$(apk --root /rootfs --arch aarch64 upgrade --simulate 2>&1)"
|
||||
printf "%s\n" "$UPG_OUT"
|
||||
|
||||
for pkg in geminux-kernel-modules geminux-xlibre geminux-suckless \
|
||||
geminux-dunst geminux-ui geminux-config; do
|
||||
if ! grep -q "^${pkg}@geminux=" /rootfs/etc/apk/world; then
|
||||
echo "FAIL: ${pkg} is not exact-version pinned to @geminux in world" >&2
|
||||
exit 1
|
||||
fi
|
||||
if printf "%s\n" "$UPG_OUT" | grep -q -E "(Upgrading|Replacing|Deleting|Downgrading) ${pkg}\b"; then
|
||||
echo "FAIL: ${pkg} would be modified by upstream upgrade" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if printf "%s\n" "$UPG_OUT" | grep -q -E "(rust|cargo|librsvg|libglycin|gdk-pixbuf|rav1e|libdovi|xorg-server|linux-edge)"; then
|
||||
echo "FAIL: upgrade simulation tried to pull forbidden Rust or upstream override package" >&2
|
||||
exit 1
|
||||
fi
|
||||
'
|
||||
echo "OK"
|
||||
|
||||
echo "[5/8] Verifying overlay artifact sync..."
|
||||
"$BASE_DIR/scripts/sync-prebuilt-overlay.sh" --check
|
||||
|
||||
echo "[6/8] Verifying aarch64 ELF architecture on all Geminux custom binaries..."
|
||||
file \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/bin/Xorg" \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/libglamoregl.so" \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/extensions/libglx.so" \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/modesetting_drv.so" \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/fbdev_drv.so" \
|
||||
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/input/libinput_drv.so" \
|
||||
"$BASE_DIR/prebuilt/suckless/usr/bin/st" \
|
||||
"$BASE_DIR/prebuilt/suckless/usr/bin/dwm" \
|
||||
"$BASE_DIR/prebuilt/suckless/usr/bin/dmenu" \
|
||||
"$BASE_DIR/prebuilt/suckless/usr/bin/stest" \
|
||||
"$BASE_DIR/prebuilt/dunst/usr/bin/dunst" \
|
||||
"$BASE_DIR/prebuilt/dunst/usr/bin/notify-send" \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/lib/libgemui.so" \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/bin/"* \
|
||||
"$BASE_DIR/prebuilt/geminux/usr/sbin/"* | \
|
||||
awk '!/ARM aarch64/ { print "FAIL: not aarch64: " $0; bad=1 } END { exit bad }'
|
||||
echo "OK (all aarch64 ELFs verified)"
|
||||
|
||||
echo "[7/8] Verifying partition budgets, ext4 image e2fsck, and SHA256SUMS..."
|
||||
BOOT_SZ="$(stat -c %s "$IMAGES_DIR/boot-geminux.img")"
|
||||
REC_SZ="$(stat -c %s "$IMAGES_DIR/recovery-geminux.img")"
|
||||
DTB_SZ="$(stat -c %s "$BASE_DIR/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb")"
|
||||
[ "$BOOT_SZ" -le 16777216 ] || { echo "FAIL: boot-geminux.img > 16 MiB ($BOOT_SZ)" >&2; exit 1; }
|
||||
[ "$REC_SZ" -le 16777216 ] || { echo "FAIL: recovery-geminux.img > 16 MiB ($REC_SZ)" >&2; exit 1; }
|
||||
[ "$DTB_SZ" -le 524288 ] || { echo "FAIL: DTB > 512 KiB ($DTB_SZ)" >&2; exit 1; }
|
||||
|
||||
python3 - "$IMAGES_DIR/boot-geminux.img" "$IMAGES_DIR/recovery-geminux.img" \
|
||||
"$BASE_DIR/prebuilt/kernel/boot/config-7.3.5-geminux" "$ROOTFS_DIR" <<'PYEOF'
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
for path in sys.argv[1:3]:
|
||||
with open(path, "rb") as f:
|
||||
hdr = f.read(640)
|
||||
if hdr[:8] != b"ANDROID!":
|
||||
raise SystemExit(f"FAIL: invalid boot image magic in {path}")
|
||||
kernel_addr = struct.unpack("<I", hdr[12:16])[0]
|
||||
if kernel_addr != 0x40080000:
|
||||
raise SystemExit(
|
||||
f"FAIL: {path} kernel_addr={kernel_addr:#010x}, expected 0x40080000 for Gemini LK"
|
||||
)
|
||||
cmdline = hdr[64:576].split(b"\x00", 1)[0].decode("ascii", "replace")
|
||||
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
|
||||
if req not in cmdline.split():
|
||||
raise SystemExit(f"FAIL: {path} cmdline missing '{req}': {cmdline}")
|
||||
|
||||
with open(sys.argv[3], "r", encoding="utf-8") as f:
|
||||
kcfg = f.read()
|
||||
for line in kcfg.splitlines():
|
||||
if line.startswith("CONFIG_CMDLINE="):
|
||||
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
|
||||
if req not in line:
|
||||
raise SystemExit(f"FAIL: {sys.argv[3]} {line} missing '{req}'")
|
||||
break
|
||||
else:
|
||||
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_CMDLINE")
|
||||
|
||||
rootfs = sys.argv[4]
|
||||
for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
|
||||
"usr/lib/dri/simpledrm_dri.so", "etc/runlevels/boot/geminux-usb-gadget"):
|
||||
if not os.path.lexists(os.path.join(rootfs, req_rel)):
|
||||
raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}")
|
||||
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")):
|
||||
raise SystemExit("FAIL: hwdrivers must not be enabled in sysinit")
|
||||
xorg_mode = os.stat(os.path.join(rootfs, "usr/bin/Xorg")).st_mode & 0o7777
|
||||
if xorg_mode != 0o4755:
|
||||
raise SystemExit(f"FAIL: rootfs/usr/bin/Xorg mode is {oct(xorg_mode)}, expected 0o4755")
|
||||
|
||||
awk_path = os.path.join(rootfs, "usr", "bin", "awk")
|
||||
if not os.path.lexists(awk_path):
|
||||
raise SystemExit(f"FAIL: missing BusyBox applet {awk_path}")
|
||||
|
||||
bb_path = os.path.join(rootfs, "bin", "busybox")
|
||||
with open(bb_path, "rb") as f:
|
||||
bb_data = f.read()
|
||||
idx = bb_data.find(b"[\x00[[\x00")
|
||||
if idx < 0:
|
||||
raise SystemExit(f"FAIL: unable to locate applet table in {bb_path}")
|
||||
end = bb_data.find(b"\x00\x00", idx)
|
||||
names = [s.decode("ascii") for s in bb_data[idx:end].split(b"\x00") if s]
|
||||
missing = [
|
||||
n for n in names
|
||||
if not any(os.path.lexists(os.path.join(rootfs, d, n))
|
||||
for d in ("bin", "sbin", "usr/bin", "usr/sbin"))
|
||||
]
|
||||
if missing:
|
||||
raise SystemExit(f"FAIL: {len(missing)} missing BusyBox applet(s): {' '.join(missing)}")
|
||||
print(f"OK (kernel_addr=0x40080000, noautodetect, {len(names)} BusyBox applets linked)")
|
||||
PYEOF
|
||||
|
||||
docker run --rm -v "$IMAGES_DIR:/images:ro" -v "$BASE_DIR/prebuilt/kernel/boot:/kboot:ro" alpine:3.24 sh -eu -c '
|
||||
apk add --no-cache e2fsprogs e2fsprogs-extra dtc >/dev/null
|
||||
e2fsck -fn /images/geminux-rootfs.img
|
||||
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
|
||||
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not mode 04755" >&2; exit 1;
|
||||
}
|
||||
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*0\b" || {
|
||||
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not UID 0" >&2; exit 1;
|
||||
}
|
||||
debugfs -R "stat /usr/bin/doas" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
|
||||
echo "FAIL: geminux-rootfs.img /usr/bin/doas is not mode 04755" >&2; exit 1;
|
||||
}
|
||||
debugfs -R "stat /home/user" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*10000\b" || {
|
||||
echo "FAIL: geminux-rootfs.img /home/user is not UID 10000" >&2; exit 1;
|
||||
}
|
||||
DTS_OUT="$(dtc -I dtb -O dts /kboot/mt6797-gemini-pda-geminux.dtb 2>/dev/null)"
|
||||
printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory \{$" || { echo "FAIL: DTB missing /memory node" >&2; exit 1; }
|
||||
if printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory@40000000 \{$"; then
|
||||
echo "FAIL: DTB still contains root /memory@40000000" >&2
|
||||
exit 1
|
||||
fi
|
||||
if printf "%s\n" "$DTS_OUT" | grep -q "memory@7df00000"; then
|
||||
echo "FAIL: DTB contains static memory@7df00000 that triggers LK reserved_memory_conflict_check" >&2
|
||||
exit 1
|
||||
fi
|
||||
'
|
||||
(cd "$IMAGES_DIR" && sha256sum -c SHA256SUMS)
|
||||
|
||||
echo "[8/8] Running all 5 Python unit/verification suites..."
|
||||
python3 "$BASE_DIR/scripts/test-flash-mtk-gpt.py"
|
||||
python3 "$BASE_DIR/scripts/test-xkb-keymap.py"
|
||||
python3 "$BASE_DIR/scripts/test-theme-dunst-sync.py"
|
||||
python3 "$BASE_DIR/scripts/test-ccci-protocol.py"
|
||||
python3 "$BASE_DIR/scripts/test-power-policy.py"
|
||||
|
||||
echo "============================================================"
|
||||
echo "ALL GEMINUX CHECKS PASSED CLEANLY"
|
||||
echo "============================================================"
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Extract device-owned MT6797 Wi-Fi, Bluetooth, and SPM firmware blobs
|
||||
from a stock Gemini PDA system partition image or mounted directory.
|
||||
|
||||
Extracted files are placed in gitignored firmware-cache/mt6797/ so Geminux can
|
||||
bundle them locally on the device without redistributing non-free firmware.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
REQUIRED_BLOBS = (
|
||||
"ROMv3_patch_1_0_hdr.bin",
|
||||
"ROMv3_patch_1_1_hdr.bin",
|
||||
"WIFI_RAM_CODE_6797",
|
||||
"WMT_SOC.cfg",
|
||||
)
|
||||
|
||||
OPTIONAL_SPM_GLOB_PREFIX = "pcm_"
|
||||
|
||||
SEARCH_SUBDIRS = (
|
||||
"vendor/firmware",
|
||||
"system/vendor/firmware",
|
||||
"etc/firmware",
|
||||
"system/etc/firmware",
|
||||
)
|
||||
|
||||
SPARSE_MAGIC = b"\x3a\xff\x26\xed"
|
||||
|
||||
|
||||
def sha256_file(path):
|
||||
h = hashlib.sha256()
|
||||
with open(path, "rb") as f:
|
||||
while True:
|
||||
chunk = f.read(65536)
|
||||
if not chunk:
|
||||
break
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def is_sparse_image(path):
|
||||
with open(path, "rb") as f:
|
||||
return f.read(4) == SPARSE_MAGIC
|
||||
|
||||
|
||||
def debugfs_ls(image_path, internal_dir):
|
||||
cmd = ["debugfs", "-R", f"ls -p /{internal_dir}", image_path]
|
||||
res = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
||||
if res.returncode != 0:
|
||||
return []
|
||||
names = []
|
||||
for line in res.stdout.splitlines():
|
||||
# debugfs ls -p format: /inode/mode/uid/gid/name/size/
|
||||
parts = line.split("/")
|
||||
if len(parts) >= 6:
|
||||
name = parts[5]
|
||||
if name and name not in (".", ".."):
|
||||
names.append(name)
|
||||
return names
|
||||
|
||||
|
||||
def debugfs_dump(image_path, internal_path, dest_path):
|
||||
cmd = ["debugfs", "-R", f"dump /{internal_path} {dest_path}", image_path]
|
||||
res = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
||||
return res.returncode == 0 and os.path.isfile(dest_path) and os.path.getsize(dest_path) > 0
|
||||
|
||||
|
||||
def extract_from_ext4(image_path, out_dir):
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
found = {}
|
||||
|
||||
# Collect candidate files across known firmware directories inside system.img
|
||||
for subdir in SEARCH_SUBDIRS:
|
||||
entries = debugfs_ls(image_path, subdir)
|
||||
if not entries:
|
||||
continue
|
||||
for name in entries:
|
||||
is_req = name in REQUIRED_BLOBS
|
||||
is_spm = name.startswith(OPTIONAL_SPM_GLOB_PREFIX) and name.endswith(".bin")
|
||||
if not (is_req or is_spm):
|
||||
continue
|
||||
if name in found:
|
||||
continue
|
||||
dest = os.path.join(out_dir, name)
|
||||
if debugfs_dump(image_path, f"{subdir}/{name}", dest):
|
||||
found[name] = dest
|
||||
|
||||
return found
|
||||
|
||||
|
||||
def extract_from_dir(src_dir, out_dir):
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
found = {}
|
||||
candidates = [src_dir] + [os.path.join(src_dir, s) for s in SEARCH_SUBDIRS]
|
||||
for base in candidates:
|
||||
if not os.path.isdir(base):
|
||||
continue
|
||||
for name in os.listdir(base):
|
||||
is_req = name in REQUIRED_BLOBS
|
||||
is_spm = name.startswith(OPTIONAL_SPM_GLOB_PREFIX) and name.endswith(".bin")
|
||||
if not (is_req or is_spm):
|
||||
continue
|
||||
if name in found:
|
||||
continue
|
||||
src = os.path.join(base, name)
|
||||
if os.path.isfile(src):
|
||||
dest = os.path.join(out_dir, name)
|
||||
shutil.copy2(src, dest)
|
||||
found[name] = dest
|
||||
return found
|
||||
|
||||
|
||||
def write_manifest(out_dir, found):
|
||||
manifest = os.path.join(out_dir, "MANIFEST.sha256")
|
||||
with open(manifest, "w") as f:
|
||||
for name in sorted(found):
|
||||
digest = sha256_file(found[name])
|
||||
f.write(f"{digest} {name}\n")
|
||||
return manifest
|
||||
|
||||
|
||||
def extract_firmware(source_path, out_dir):
|
||||
if not os.path.exists(source_path):
|
||||
raise FileNotFoundError(f"Source path not found: {source_path}")
|
||||
|
||||
if os.path.isdir(source_path):
|
||||
found = extract_from_dir(source_path, out_dir)
|
||||
else:
|
||||
if shutil.which("debugfs") is None:
|
||||
raise RuntimeError("'debugfs' (e2fsprogs) is required to extract firmware from ext4 images")
|
||||
if is_sparse_image(source_path):
|
||||
if shutil.which("simg2img") is None:
|
||||
raise RuntimeError("'simg2img' (android-tools) is required for sparse system images")
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-fw-") as tmp:
|
||||
raw_img = os.path.join(tmp, "system.raw.img")
|
||||
subprocess.run(["simg2img", source_path, raw_img], check=True)
|
||||
found = extract_from_ext4(raw_img, out_dir)
|
||||
else:
|
||||
found = extract_from_ext4(source_path, out_dir)
|
||||
|
||||
missing = [b for b in REQUIRED_BLOBS if b not in found]
|
||||
if found:
|
||||
write_manifest(out_dir, found)
|
||||
return found, missing
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Extract MT6797 firmware blobs from stock Gemini system.img or directory.")
|
||||
parser.add_argument("source", help="Path to stock system.img (raw/sparse ext4) or extracted directory")
|
||||
parser.add_argument("-o", "--out-dir", default=os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
||||
"firmware-cache", "mt6797"),
|
||||
help="Destination directory (default: firmware-cache/mt6797)")
|
||||
parser.add_argument("--allow-partial", action="store_true",
|
||||
help="Exit 0 even if some required blobs were not found")
|
||||
args = parser.parse_args()
|
||||
|
||||
found, missing = extract_firmware(args.source, args.out_dir)
|
||||
print(f"[fw-extract] Extracted {len(found)} file(s) into {args.out_dir}:")
|
||||
for name in sorted(found):
|
||||
print(f" - {name} ({os.path.getsize(found[name])} bytes)")
|
||||
|
||||
if missing:
|
||||
print(f"[fw-extract] Warning: missing required blob(s): {', '.join(missing)}", file=sys.stderr)
|
||||
if not args.allow_partial:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+313
@@ -0,0 +1,313 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Surgical GPT parser and builder for full-disk Geminux on Gemini PDA (MT6797X).
|
||||
|
||||
Preserves MediaTek pre-OS/radio partitions (SYS1..SYS27 up to 0x0E000000) and
|
||||
end-of-disk flashinfo/sgpt intact while reclaiming all Android/userdata space
|
||||
after 0x0E000000 into a single full-disk 'linux' rootfs partition plus a 16 MiB
|
||||
'boot2' fallback kernel slot.
|
||||
"""
|
||||
|
||||
import struct
|
||||
import uuid
|
||||
import zlib
|
||||
|
||||
SECTOR_SIZE = 512
|
||||
GPT_HEADER_SIZE = 92
|
||||
GPT_ENTRY_SIZE = 128
|
||||
GPT_ENTRY_COUNT = 128
|
||||
GPT_ARRAY_SECTORS = (GPT_ENTRY_COUNT * GPT_ENTRY_SIZE) // SECTOR_SIZE # 32
|
||||
PROTECTED_END_BYTE = 0x0E000000
|
||||
PROTECTED_END_LBA = PROTECTED_END_BYTE // SECTOR_SIZE # 0x70000 (224 MiB)
|
||||
BOOT2_SIZE_BYTES = 0x1000000 # 16 MiB
|
||||
BOOT2_SECTORS = BOOT2_SIZE_BYTES // SECTOR_SIZE # 32768
|
||||
ALIGN_4M_SECTORS = (4 * 1024 * 1024) // SECTOR_SIZE # 8192 sectors
|
||||
|
||||
# Linux filesystem data GUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (mixed-endian)
|
||||
LINUX_FS_TYPE_GUID = uuid.UUID("0FC63DAF-8483-4772-8E79-3D69D8477DE4").bytes_le
|
||||
# Generic Android/MediaTek basic data type GUID
|
||||
BASIC_DATA_TYPE_GUID = uuid.UUID("EBD0A0A2-B9E5-4433-87C0-68B6B72699C7").bytes_le
|
||||
|
||||
REQUIRED_PRE_REGION_PARTITIONS = (
|
||||
"recovery",
|
||||
"proinfo",
|
||||
"nvram",
|
||||
"protect1",
|
||||
"protect2",
|
||||
"lk",
|
||||
"boot",
|
||||
"tee1",
|
||||
"md1img",
|
||||
)
|
||||
|
||||
|
||||
class GptEntry:
|
||||
"""Represents a single 128-byte GPT partition entry."""
|
||||
|
||||
def __init__(self, type_guid, unique_guid, first_lba, last_lba, flags, name):
|
||||
self.type_guid = type_guid
|
||||
self.unique_guid = unique_guid
|
||||
self.first_lba = first_lba
|
||||
self.last_lba = last_lba
|
||||
self.flags = flags
|
||||
self.name = name
|
||||
|
||||
@property
|
||||
def sectors(self):
|
||||
return self.last_lba - self.first_lba + 1
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, raw):
|
||||
type_guid, unique_guid, first_lba, last_lba, flags, raw_name = struct.unpack(
|
||||
"<16s16sQQQ72s", raw[:128]
|
||||
)
|
||||
name = raw_name.decode("utf-16-le", errors="replace").split("\x00", 1)[0]
|
||||
return cls(type_guid, unique_guid, first_lba, last_lba, flags, name)
|
||||
|
||||
def to_bytes(self):
|
||||
encoded = self.name.encode("utf-16-le")[:72]
|
||||
encoded = encoded.ljust(72, b"\x00")
|
||||
return struct.pack(
|
||||
"<16s16sQQQ72s",
|
||||
self.type_guid,
|
||||
self.unique_guid,
|
||||
self.first_lba,
|
||||
self.last_lba,
|
||||
self.flags,
|
||||
encoded,
|
||||
)
|
||||
|
||||
|
||||
class GptHeader:
|
||||
"""Represents a 512-byte GPT header block."""
|
||||
|
||||
def __init__(self, raw):
|
||||
if len(raw) < SECTOR_SIZE:
|
||||
raise ValueError("GPT header buffer shorter than 512 bytes")
|
||||
(
|
||||
self.signature,
|
||||
self.revision,
|
||||
self.header_size,
|
||||
self.header_crc32,
|
||||
self.reserved,
|
||||
self.current_lba,
|
||||
self.backup_lba,
|
||||
self.first_usable_lba,
|
||||
self.last_usable_lba,
|
||||
self.disk_guid,
|
||||
self.part_entry_start_lba,
|
||||
self.num_part_entries,
|
||||
self.part_entry_size,
|
||||
self.part_array_crc32,
|
||||
) = struct.unpack("<8sIIIIQQQQ16sQIII", raw[:92])
|
||||
if self.signature != b"EFI PART":
|
||||
raise ValueError(f"Invalid GPT signature: {self.signature!r}")
|
||||
|
||||
def pack_with_crcs(self, part_array_bytes):
|
||||
self.part_array_crc32 = zlib.crc32(part_array_bytes) & 0xFFFFFFFF
|
||||
zero_crc = struct.pack(
|
||||
"<8sIIIIQQQQ16sQIII",
|
||||
b"EFI PART",
|
||||
self.revision,
|
||||
self.header_size,
|
||||
0,
|
||||
0,
|
||||
self.current_lba,
|
||||
self.backup_lba,
|
||||
self.first_usable_lba,
|
||||
self.last_usable_lba,
|
||||
self.disk_guid,
|
||||
self.part_entry_start_lba,
|
||||
self.num_part_entries,
|
||||
self.part_entry_size,
|
||||
self.part_array_crc32,
|
||||
)
|
||||
self.header_crc32 = zlib.crc32(zero_crc[:self.header_size]) & 0xFFFFFFFF
|
||||
packed = struct.pack(
|
||||
"<8sIIIIQQQQ16sQIII",
|
||||
b"EFI PART",
|
||||
self.revision,
|
||||
self.header_size,
|
||||
self.header_crc32,
|
||||
0,
|
||||
self.current_lba,
|
||||
self.backup_lba,
|
||||
self.first_usable_lba,
|
||||
self.last_usable_lba,
|
||||
self.disk_guid,
|
||||
self.part_entry_start_lba,
|
||||
self.num_part_entries,
|
||||
self.part_entry_size,
|
||||
self.part_array_crc32,
|
||||
)
|
||||
return packed.ljust(SECTOR_SIZE, b"\x00")
|
||||
|
||||
|
||||
def parse_primary_gpt(pgpt_bytes):
|
||||
"""Parse LBA 0..33 (17 KiB) primary GPT image into MBR, header, and active entries."""
|
||||
if len(pgpt_bytes) < (2 + GPT_ARRAY_SECTORS) * SECTOR_SIZE:
|
||||
raise ValueError("Primary GPT buffer too small (need at least 34 sectors)")
|
||||
mbr = pgpt_bytes[:SECTOR_SIZE]
|
||||
header = GptHeader(pgpt_bytes[SECTOR_SIZE:2 * SECTOR_SIZE])
|
||||
entry_start = header.part_entry_start_lba * SECTOR_SIZE
|
||||
entries = []
|
||||
for idx in range(header.num_part_entries):
|
||||
off = entry_start + idx * header.part_entry_size
|
||||
raw = pgpt_bytes[off:off + header.part_entry_size]
|
||||
if len(raw) < 128:
|
||||
break
|
||||
if raw[:16] == b"\x00" * 16:
|
||||
continue
|
||||
entries.append(GptEntry.from_bytes(raw))
|
||||
return mbr, header, entries
|
||||
|
||||
|
||||
def verify_gpt_crcs(header, entries_bytes):
|
||||
"""Validate header CRC32 and partition array CRC32."""
|
||||
actual_arr_crc = zlib.crc32(entries_bytes) & 0xFFFFFFFF
|
||||
if actual_arr_crc != header.part_array_crc32:
|
||||
raise ValueError(
|
||||
f"Partition array CRC32 mismatch: expected {header.part_array_crc32:#x}, got {actual_arr_crc:#x}"
|
||||
)
|
||||
zero_crc = struct.pack(
|
||||
"<8sIIIIQQQQ16sQIII",
|
||||
header.signature,
|
||||
header.revision,
|
||||
header.header_size,
|
||||
0,
|
||||
0,
|
||||
header.current_lba,
|
||||
header.backup_lba,
|
||||
header.first_usable_lba,
|
||||
header.last_usable_lba,
|
||||
header.disk_guid,
|
||||
header.part_entry_start_lba,
|
||||
header.num_part_entries,
|
||||
header.part_entry_size,
|
||||
header.part_array_crc32,
|
||||
)
|
||||
actual_hdr_crc = zlib.crc32(zero_crc[:header.header_size]) & 0xFFFFFFFF
|
||||
if actual_hdr_crc != header.header_crc32:
|
||||
raise ValueError(
|
||||
f"GPT header CRC32 mismatch: expected {header.header_crc32:#x}, got {actual_hdr_crc:#x}"
|
||||
)
|
||||
|
||||
|
||||
def build_geminux_gpts(pgpt_bytes, total_sectors, force_layout=False):
|
||||
"""Build updated primary (LBA 0..33) and backup (33 sectors) GPTs for full-disk Geminux.
|
||||
|
||||
Returns (new_pgpt_bytes, new_sgpt_bytes, new_entries).
|
||||
"""
|
||||
mbr, hdr, entries = parse_primary_gpt(pgpt_bytes)
|
||||
entry_size = hdr.part_entry_size or GPT_ENTRY_SIZE
|
||||
num_entries = hdr.num_part_entries or GPT_ENTRY_COUNT
|
||||
|
||||
# Validate expected Gemini pre-OS/firmware partition set
|
||||
names_lower = {e.name.lower(): e for e in entries}
|
||||
if not force_layout:
|
||||
missing = [n for n in REQUIRED_PRE_REGION_PARTITIONS if n not in names_lower]
|
||||
if missing:
|
||||
raise ValueError(
|
||||
f"Unexpected device partition table (missing {', '.join(missing)}); "
|
||||
"refusing to repartition without --force-gpt"
|
||||
)
|
||||
|
||||
preserved = []
|
||||
flashinfo_entry = None
|
||||
for entry in entries:
|
||||
if entry.name.lower() == "flashinfo":
|
||||
flashinfo_entry = entry
|
||||
continue
|
||||
if entry.last_lba < PROTECTED_END_LBA:
|
||||
preserved.append(entry)
|
||||
elif entry.first_lba < PROTECTED_END_LBA:
|
||||
raise ValueError(
|
||||
f"Partition '{entry.name}' ({entry.first_lba}..{entry.last_lba}) crosses "
|
||||
f"0x0E000000 boundary ({PROTECTED_END_LBA})"
|
||||
)
|
||||
|
||||
if not force_layout:
|
||||
for req in REQUIRED_PRE_REGION_PARTITIONS:
|
||||
if names_lower[req].last_lba >= PROTECTED_END_LBA:
|
||||
raise ValueError(
|
||||
f"Protected partition '{req}' ends at LBA {names_lower[req].last_lba}, "
|
||||
"beyond 0x0E000000"
|
||||
)
|
||||
|
||||
last_usable = total_sectors - (GPT_ARRAY_SECTORS + 2)
|
||||
if hdr.last_usable_lba and hdr.last_usable_lba <= last_usable:
|
||||
last_usable = hdr.last_usable_lba
|
||||
|
||||
if flashinfo_entry is not None:
|
||||
tail_limit = flashinfo_entry.first_lba
|
||||
else:
|
||||
tail_limit = last_usable + 1
|
||||
|
||||
# Align boot2 end down to 4 MiB boundary
|
||||
boot2_end_excl = (tail_limit // ALIGN_4M_SECTORS) * ALIGN_4M_SECTORS
|
||||
boot2_start = boot2_end_excl - BOOT2_SECTORS
|
||||
if boot2_start <= PROTECTED_END_LBA:
|
||||
raise ValueError("Disk too small for full-disk linux + boot2 layout")
|
||||
|
||||
linux_start = PROTECTED_END_LBA
|
||||
linux_last = boot2_start - 1
|
||||
|
||||
existing_linux = names_lower.get("linux")
|
||||
existing_boot2 = names_lower.get("boot2")
|
||||
|
||||
linux_guid = existing_linux.unique_guid if existing_linux else uuid.uuid4().bytes_le
|
||||
boot2_guid = existing_boot2.unique_guid if existing_boot2 else uuid.uuid4().bytes_le
|
||||
|
||||
linux_entry = GptEntry(
|
||||
LINUX_FS_TYPE_GUID,
|
||||
linux_guid,
|
||||
linux_start,
|
||||
linux_last,
|
||||
0,
|
||||
"linux",
|
||||
)
|
||||
boot2_entry = GptEntry(
|
||||
BASIC_DATA_TYPE_GUID,
|
||||
boot2_guid,
|
||||
boot2_start,
|
||||
boot2_end_excl - 1,
|
||||
0,
|
||||
"boot2",
|
||||
)
|
||||
|
||||
new_entries = list(preserved) + [linux_entry, boot2_entry]
|
||||
if flashinfo_entry is not None:
|
||||
new_entries.append(flashinfo_entry)
|
||||
|
||||
if len(new_entries) > num_entries:
|
||||
raise ValueError(f"Too many partitions ({len(new_entries)} > {num_entries})")
|
||||
|
||||
part_array = bytearray(num_entries * entry_size)
|
||||
for idx, entry in enumerate(new_entries):
|
||||
part_array[idx * entry_size:(idx + 1) * entry_size] = entry.to_bytes()
|
||||
|
||||
# Primary GPT (LBA 0 MBR + LBA 1 Primary Header + LBA 2..33 Entries)
|
||||
pri_hdr = GptHeader(pgpt_bytes[SECTOR_SIZE:2 * SECTOR_SIZE])
|
||||
pri_hdr.current_lba = 1
|
||||
pri_hdr.backup_lba = total_sectors - 1
|
||||
pri_hdr.part_entry_start_lba = 2
|
||||
pri_hdr.first_usable_lba = hdr.first_usable_lba or 34
|
||||
pri_hdr.last_usable_lba = last_usable
|
||||
pri_hdr.num_part_entries = num_entries
|
||||
pri_hdr.part_entry_size = entry_size
|
||||
pri_hdr_bytes = pri_hdr.pack_with_crcs(bytes(part_array))
|
||||
|
||||
new_pgpt = bytes(mbr) + pri_hdr_bytes + bytes(part_array)
|
||||
|
||||
# Backup GPT (32 sectors Entries + 1 sector Backup Header at total_sectors - 1)
|
||||
bak_hdr = GptHeader(pgpt_bytes[SECTOR_SIZE:2 * SECTOR_SIZE])
|
||||
bak_hdr.current_lba = total_sectors - 1
|
||||
bak_hdr.backup_lba = 1
|
||||
bak_hdr.part_entry_start_lba = total_sectors - 1 - GPT_ARRAY_SECTORS
|
||||
bak_hdr.first_usable_lba = pri_hdr.first_usable_lba
|
||||
bak_hdr.last_usable_lba = last_usable
|
||||
bak_hdr.num_part_entries = num_entries
|
||||
bak_hdr.part_entry_size = entry_size
|
||||
bak_hdr_bytes = bak_hdr.pack_with_crcs(bytes(part_array))
|
||||
|
||||
new_sgpt = bytes(part_array) + bak_hdr_bytes
|
||||
return new_pgpt, new_sgpt, new_entries
|
||||
Executable
+272
@@ -0,0 +1,272 @@
|
||||
#!/bin/sh
|
||||
# Package Geminux custom binaries, kernel modules, XLibre, suckless desktop,
|
||||
# dunst, UI apps/daemons, and overlay configs into signed aarch64 APKs (@geminux).
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
KEYS_DIR="$BASE_DIR/keys"
|
||||
REPO_DIR="$BASE_DIR/prebuilt/apk-repo"
|
||||
PRIV_KEY="$KEYS_DIR/geminux-local.rsa"
|
||||
PUB_KEY="$KEYS_DIR/geminux-local.rsa.pub"
|
||||
|
||||
mkdir -p "$KEYS_DIR" "$REPO_DIR/aarch64"
|
||||
|
||||
if [ ! -f "$PRIV_KEY" ] || [ ! -f "$PUB_KEY" ]; then
|
||||
echo "[*] Generating RSA-4096 signing key pair for @geminux APK repository..."
|
||||
docker run --rm -v "$KEYS_DIR:/keys" alpine:3.24 sh -eu -c '
|
||||
apk add --no-cache openssl >/dev/null
|
||||
openssl genrsa -out /keys/geminux-local.rsa 4096 2>/dev/null
|
||||
openssl rsa -in /keys/geminux-local.rsa -pubout -out /keys/geminux-local.rsa.pub 2>/dev/null
|
||||
chmod 0600 /keys/geminux-local.rsa
|
||||
chmod 0644 /keys/geminux-local.rsa.pub
|
||||
'
|
||||
if command -v chown >/dev/null 2>&1; then
|
||||
chown "$(id -u):$(id -g)" "$PRIV_KEY" "$PUB_KEY" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
VER="$("$BASE_DIR/scripts/version.sh" --print)"
|
||||
CODENAME="$("$BASE_DIR/scripts/version.sh" --print-codename)"
|
||||
|
||||
exec docker run --rm --network=host \
|
||||
-e HOST_UID="$(id -u)" \
|
||||
-e HOST_GID="$(id -g)" \
|
||||
-e GEMINUX_VERSION="$VER" \
|
||||
-e GEMINUX_CODENAME="$CODENAME" \
|
||||
-v "$BASE_DIR:/geminux" \
|
||||
alpine:3.24 sh -eu -c '
|
||||
cleanup_perms() {
|
||||
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/apk-repo /geminux/keys/geminux-local.rsa* 2>/dev/null || true
|
||||
}
|
||||
trap cleanup_perms EXIT
|
||||
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
EOF
|
||||
cp /geminux/keys/alpine-devel@*.rsa.pub /etc/apk/keys/
|
||||
cp /geminux/keys/geminux-local.rsa.pub /etc/apk/keys/geminux-local.rsa.pub
|
||||
|
||||
apk add --no-cache openssl binutils python3 >/dev/null
|
||||
|
||||
OUT_DIR="/geminux/prebuilt/apk-repo/aarch64"
|
||||
rm -rf "$OUT_DIR"
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
WORK="/tmp/apk-build"
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
python3 - "$GEMINUX_VERSION" "$GEMINUX_CODENAME" "$OUT_DIR" "$WORK" <<'\''PYEOF'\''
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ver = sys.argv[1]
|
||||
codename = sys.argv[2]
|
||||
out_dir = sys.argv[3]
|
||||
work_dir = sys.argv[4]
|
||||
sign_key = "/geminux/keys/geminux-local.rsa"
|
||||
pkg_ver = f"{ver}-r0"
|
||||
|
||||
|
||||
def collect_needed_so(stage_dir):
|
||||
internal = set()
|
||||
elfs = []
|
||||
for root, _, names in os.walk(stage_dir):
|
||||
for name in names:
|
||||
p = os.path.join(root, name)
|
||||
if os.path.islink(p) or not os.path.isfile(p):
|
||||
continue
|
||||
if ".so" in name:
|
||||
internal.add(name)
|
||||
with open(p, "rb") as f:
|
||||
if f.read(4) == b"\x7fELF":
|
||||
elfs.append(p)
|
||||
|
||||
needed = set()
|
||||
for elf in elfs:
|
||||
proc = subprocess.run(["readelf", "-d", elf], capture_output=True, text=True, check=False)
|
||||
for line in proc.stdout.splitlines():
|
||||
m = re.search(r"\(NEEDED\)\s+Shared library:\s+\[([^\]]+)\]", line)
|
||||
if m:
|
||||
so = m.group(1)
|
||||
if so.startswith("ld-musl-") or so in internal:
|
||||
continue
|
||||
needed.add(f"so:{so}")
|
||||
return sorted(needed)
|
||||
|
||||
|
||||
def make_pkg(name, pver, desc, stage_dir, provides=None, depends=None, replaces=None):
|
||||
apk_path = os.path.join(out_dir, f"{name}-{pver}.apk")
|
||||
cmd = [
|
||||
"apk", "mkpkg",
|
||||
"--sign-key", sign_key,
|
||||
"--files", stage_dir,
|
||||
"--info", f"name:{name}",
|
||||
"--info", f"version:{pver}",
|
||||
"--info", "arch:aarch64",
|
||||
"--info", f"description:{desc}",
|
||||
"--info", "license:GPL-2.0-or-later AND MIT",
|
||||
"--info", "origin:geminux",
|
||||
]
|
||||
if provides:
|
||||
cmd += ["--info", f"provides:{'\'' '\''.join(provides)}"]
|
||||
if depends:
|
||||
cmd += ["--info", f"depends:{'\'' '\''.join(depends)}"]
|
||||
if replaces:
|
||||
cmd += ["--info", f"replaces:{'\'' '\''.join(replaces)}"]
|
||||
cmd += ["--output", apk_path]
|
||||
subprocess.run(cmd, check=True)
|
||||
print(f"[apk] Built {os.path.basename(apk_path)}")
|
||||
|
||||
|
||||
owned_files = set()
|
||||
|
||||
|
||||
def copy_tree_dedup(src, dst, dedup=False):
|
||||
if not os.path.isdir(src):
|
||||
return
|
||||
for root, dirs, files in os.walk(src, followlinks=False):
|
||||
rel_dir = os.path.relpath(root, src)
|
||||
dst_dir = dst if rel_dir == "." else os.path.join(dst, rel_dir)
|
||||
os.makedirs(dst_dir, exist_ok=True)
|
||||
for d in dirs:
|
||||
sp = os.path.join(root, d)
|
||||
dp = os.path.join(dst_dir, d)
|
||||
if os.path.islink(sp):
|
||||
rel = os.path.relpath(sp, src)
|
||||
if dedup and rel in owned_files:
|
||||
continue
|
||||
if os.path.lexists(dp):
|
||||
os.unlink(dp)
|
||||
os.symlink(os.readlink(sp), dp)
|
||||
owned_files.add(rel)
|
||||
for fn in files:
|
||||
sp = os.path.join(root, fn)
|
||||
dp = os.path.join(dst_dir, fn)
|
||||
rel = os.path.relpath(sp, src)
|
||||
if dedup and rel in owned_files:
|
||||
continue
|
||||
if os.path.islink(sp):
|
||||
if os.path.lexists(dp):
|
||||
os.unlink(dp)
|
||||
os.symlink(os.readlink(sp), dp)
|
||||
else:
|
||||
shutil.copy2(sp, dp)
|
||||
owned_files.add(rel)
|
||||
|
||||
|
||||
# 1. geminux-kernel-modules
|
||||
kstage = os.path.join(work_dir, "geminux-kernel-modules")
|
||||
copy_tree_dedup("/geminux/prebuilt/kernel/lib", os.path.join(kstage, "lib"))
|
||||
copy_tree_dedup("/geminux/prebuilt/kernel/boot", os.path.join(kstage, "boot"))
|
||||
make_pkg(
|
||||
"geminux-kernel-modules", "7.3.5-r0",
|
||||
"Geminux Linux 7.3.5-geminux kernel image, DTB, and MT6797X hardware modules",
|
||||
kstage,
|
||||
provides=["geminux-kernel=7.3.5-r0"],
|
||||
)
|
||||
|
||||
# 2. geminux-xlibre
|
||||
xstage = os.path.join(work_dir, "geminux-xlibre")
|
||||
copy_tree_dedup("/geminux/prebuilt/xlibre", xstage)
|
||||
xorg_bin = os.path.join(xstage, "usr", "bin", "Xorg")
|
||||
if os.path.isfile(xorg_bin):
|
||||
os.chmod(xorg_bin, 0o4755)
|
||||
# Keep xorg.conf.d Drop-ins owned solely by geminux-config to prevent file conflicts.
|
||||
xconf_dropin = os.path.join(xstage, "etc", "X11", "xorg.conf.d")
|
||||
if os.path.isdir(xconf_dropin):
|
||||
for fn in os.listdir(xconf_dropin):
|
||||
rel = os.path.join("etc", "X11", "xorg.conf.d", fn)
|
||||
ov_path = os.path.join("/geminux/overlay/rootfs", rel)
|
||||
if os.path.exists(ov_path):
|
||||
os.unlink(os.path.join(xconf_dropin, fn))
|
||||
owned_files.discard(rel)
|
||||
make_pkg(
|
||||
"geminux-xlibre", "25.2.0-r0",
|
||||
"XLibre Xorg 25.x server with Panfrost Glamor, libinput, and fbdev drivers",
|
||||
xstage,
|
||||
provides=["cmd:Xorg=25.2.0-r0", "cmd:X=25.2.0-r0", "cmd:gtf=25.2.0-r0", "geminux-xserver=25.2.0-r0"],
|
||||
depends=collect_needed_so(xstage),
|
||||
)
|
||||
|
||||
# 3. geminux-suckless
|
||||
sstage = os.path.join(work_dir, "geminux-suckless")
|
||||
copy_tree_dedup("/geminux/prebuilt/suckless", sstage)
|
||||
make_pkg(
|
||||
"geminux-suckless", pkg_ver,
|
||||
"Patched Geminux DWM (Pango/HarfBuzz, systray, .Xresources), st (ligatures), and dmenu",
|
||||
sstage,
|
||||
provides=[f"cmd:dwm={pkg_ver}", f"cmd:st={pkg_ver}", f"cmd:dmenu={pkg_ver}", f"cmd:stest={pkg_ver}"],
|
||||
depends=collect_needed_so(sstage),
|
||||
)
|
||||
|
||||
# 4. geminux-dunst
|
||||
dstage = os.path.join(work_dir, "geminux-dunst")
|
||||
copy_tree_dedup("/geminux/prebuilt/dunst", dstage)
|
||||
make_pkg(
|
||||
"geminux-dunst", "1.12.2-r0",
|
||||
"Pure X11 zero-gdk-pixbuf Dunst 1.12.2 notification daemon and GDBus notify-send",
|
||||
dstage,
|
||||
provides=["cmd:dunst=1.12.2-r0", "cmd:dunstctl=1.12.2-r0",
|
||||
"cmd:notify-send=1.12.2-r0", "cmd:dunstify=1.12.2-r0"],
|
||||
depends=collect_needed_so(dstage),
|
||||
)
|
||||
|
||||
# 5. geminux-ui
|
||||
ustage = os.path.join(work_dir, "geminux-ui")
|
||||
copy_tree_dedup("/geminux/prebuilt/geminux", ustage)
|
||||
make_pkg(
|
||||
"geminux-ui", pkg_ver,
|
||||
"Geminux libgemui.so toolkit, 9 landscape HiDPI apps, and 7 zero-poll C11 daemons",
|
||||
ustage,
|
||||
provides=["so:libgemui.so=0", f"cmd:geminux-power-ctl={pkg_ver}"],
|
||||
depends=collect_needed_so(ustage),
|
||||
)
|
||||
|
||||
# 6. geminux-config
|
||||
cstage = os.path.join(work_dir, "geminux-config")
|
||||
copy_tree_dedup("/geminux/overlay/rootfs", cstage, dedup=True)
|
||||
for rel in ("etc/os-release", "usr/lib/os-release", "etc/issue", "etc/motd"):
|
||||
p = os.path.join(cstage, rel)
|
||||
if os.path.isfile(p):
|
||||
with open(p, "r", encoding="utf-8") as f:
|
||||
txt = f.read()
|
||||
txt = txt.replace("@GEMINUX_VERSION@", ver).replace("@GEMINUX_CODENAME@", codename)
|
||||
with open(p, "w", encoding="utf-8") as f:
|
||||
f.write(txt)
|
||||
make_pkg(
|
||||
"geminux-config", pkg_ver,
|
||||
"Geminux system configs, OpenRC units, ALSA UCM2, XKB layout, 21 themes, and udev/power rules",
|
||||
cstage,
|
||||
depends=[
|
||||
f"geminux-kernel-modules=7.3.5-r0",
|
||||
f"geminux-xlibre=25.2.0-r0",
|
||||
f"geminux-suckless={pkg_ver}",
|
||||
f"geminux-dunst=1.12.2-r0",
|
||||
f"geminux-ui={pkg_ver}",
|
||||
],
|
||||
replaces=[
|
||||
"alpine-baselayout",
|
||||
"alpine-baselayout-data",
|
||||
"alpine-release",
|
||||
"bluez",
|
||||
"tinydm",
|
||||
"tinydm-openrc",
|
||||
"xinit",
|
||||
"zram-init-openrc",
|
||||
],
|
||||
)
|
||||
PYEOF
|
||||
|
||||
apk mkndx \
|
||||
--sign-key /geminux/keys/geminux-local.rsa \
|
||||
--description "Geminux local pinned hardware & desktop repository" \
|
||||
--output "$OUT_DIR/APKINDEX.tar.gz" \
|
||||
"$OUT_DIR"/*.apk
|
||||
ls -lh "$OUT_DIR"
|
||||
'
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
# Remove Wayland-only, Rust-based, and unwanted install_if packages from a target rootfs.
|
||||
# Usage: prune-rootfs-packages.sh <rootfs-dir> world|purge
|
||||
set -eu
|
||||
|
||||
ROOTFS="$1"
|
||||
PHASE="$2"
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
PRUNE_FILE="$BASE_DIR/scripts/rootfs-prune-packages.txt"
|
||||
INSTALLED_DB="$ROOTFS/lib/apk/db/installed"
|
||||
WORLD_FILE="$ROOTFS/etc/apk/world"
|
||||
|
||||
if [ ! -f "$PRUNE_FILE" ]; then
|
||||
echo "Error: missing $PRUNE_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PRUNE_PKGS="$(grep -v '^[[:space:]]*#' "$PRUNE_FILE" | grep -v '^[[:space:]]*$' | grep -v '^[!@]' | tr '\n' ' ')"
|
||||
WORLD_DENY="$(grep '^!' "$PRUNE_FILE" | tr '\n' ' ')"
|
||||
WORLD_DROP="$(grep '^@' "$PRUNE_FILE" | sed 's/^@//' | tr '\n' ' ')"
|
||||
DENY_NAMES=""
|
||||
for deny in $WORLD_DENY; do
|
||||
DENY_NAMES="$DENY_NAMES ${deny#!}"
|
||||
done
|
||||
|
||||
pin_world_constraints() {
|
||||
if [ -f "$WORLD_FILE" ]; then
|
||||
cp "$WORLD_FILE" "$WORLD_FILE.geminux-tmp"
|
||||
else
|
||||
: > "$WORLD_FILE.geminux-tmp"
|
||||
fi
|
||||
for pkg in $PRUNE_PKGS $DENY_NAMES; do
|
||||
grep -vxF "$pkg" "$WORLD_FILE.geminux-tmp" > "$WORLD_FILE.geminux-tmp2" || true
|
||||
mv "$WORLD_FILE.geminux-tmp2" "$WORLD_FILE.geminux-tmp"
|
||||
grep -vxF "!$pkg" "$WORLD_FILE.geminux-tmp" > "$WORLD_FILE.geminux-tmp2" || true
|
||||
mv "$WORLD_FILE.geminux-tmp2" "$WORLD_FILE.geminux-tmp"
|
||||
done
|
||||
for entry in $WORLD_DROP; do
|
||||
grep -vxF "$entry" "$WORLD_FILE.geminux-tmp" > "$WORLD_FILE.geminux-tmp2" || true
|
||||
mv "$WORLD_FILE.geminux-tmp2" "$WORLD_FILE.geminux-tmp"
|
||||
done
|
||||
for deny in $WORLD_DENY; do
|
||||
printf '%s\n' "$deny" >> "$WORLD_FILE.geminux-tmp"
|
||||
done
|
||||
mv "$WORLD_FILE.geminux-tmp" "$WORLD_FILE"
|
||||
}
|
||||
|
||||
case "$PHASE" in
|
||||
world)
|
||||
pin_world_constraints
|
||||
;;
|
||||
purge)
|
||||
if [ -f "$INSTALLED_DB" ]; then
|
||||
PRUNE_INSTALLED=""
|
||||
for pkg in $PRUNE_PKGS; do
|
||||
if grep -Fxq "P:$pkg" "$INSTALLED_DB"; then
|
||||
PRUNE_INSTALLED="$PRUNE_INSTALLED $pkg"
|
||||
fi
|
||||
done
|
||||
if [ -n "$PRUNE_INSTALLED" ]; then
|
||||
echo "[prune] Removing:$PRUNE_INSTALLED"
|
||||
# shellcheck disable=SC2086
|
||||
if ! apk --root "$ROOTFS" --arch aarch64 del --no-scripts $PRUNE_INSTALLED; then
|
||||
echo " -> Warning: some excluded packages could not be purged" >&2
|
||||
fi
|
||||
fi
|
||||
pin_world_constraints
|
||||
if ! apk --root "$ROOTFS" --arch aarch64 fix --no-scripts; then
|
||||
echo " -> Warning: apk fix could not enforce prune constraints" >&2
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 <rootfs-dir> world|purge" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,122 @@
|
||||
# Geminux aarch64 rootfs package set.
|
||||
# Single source of truth for scripts/bootstrap-rootfs.sh and rebuild-image.sh.
|
||||
# Pure X11 (XLibre + Panfrost), zero Wayland components, zero Rust, zero on-device compiler.
|
||||
alpine-base
|
||||
alsa-ucm-conf
|
||||
alsa-utils
|
||||
bash
|
||||
bc
|
||||
bluez
|
||||
bluez-btmgmt
|
||||
bluez-openrc
|
||||
brightnessctl
|
||||
cairo
|
||||
ca-certificates
|
||||
chrony
|
||||
chrony-openrc
|
||||
coreutils
|
||||
curl
|
||||
dbus
|
||||
dbus-libs
|
||||
dbus-openrc
|
||||
doas
|
||||
dosfstools
|
||||
e2fsprogs
|
||||
e2fsprogs-extra
|
||||
elogind
|
||||
eudev
|
||||
eudev-openrc
|
||||
evtest
|
||||
exfatprogs
|
||||
font-dejavu
|
||||
font-dejavu-sans-mono-nerd
|
||||
font-fira-code
|
||||
font-noto
|
||||
font-noto-cjk
|
||||
font-noto-emoji
|
||||
git
|
||||
glib
|
||||
gsettings-desktop-schemas
|
||||
gst-plugins-base
|
||||
gstreamer
|
||||
harfbuzz
|
||||
hicolor-icon-theme
|
||||
htop
|
||||
i2c-tools
|
||||
ip6tables
|
||||
iproute2
|
||||
iptables
|
||||
iw
|
||||
kmod
|
||||
lang
|
||||
less
|
||||
libcurl
|
||||
libdrm
|
||||
libepoxy
|
||||
libinput
|
||||
libjpeg-turbo
|
||||
libpng
|
||||
libva
|
||||
libva-utils
|
||||
libxcvt
|
||||
libxft
|
||||
libxinerama
|
||||
libxrandr
|
||||
libxscrnsaver
|
||||
libxtst
|
||||
mandoc
|
||||
mesa-dri-gallium
|
||||
mesa-egl
|
||||
mesa-gbm
|
||||
mesa-gl
|
||||
mesa-gles
|
||||
mesa-utils
|
||||
mobile-broadband-provider-info
|
||||
modemmanager
|
||||
modemmanager-openrc
|
||||
mtdev
|
||||
musl-locales
|
||||
nano
|
||||
networkmanager
|
||||
networkmanager-cli
|
||||
networkmanager-openrc
|
||||
networkmanager-wifi
|
||||
nsxiv
|
||||
openrc
|
||||
openssh
|
||||
openssh-server-pam
|
||||
pango
|
||||
pipewire
|
||||
pipewire-alsa
|
||||
pipewire-pulse
|
||||
pipewire-spa-bluez
|
||||
pixman
|
||||
polkit
|
||||
scrot
|
||||
setxkbmap
|
||||
sqlite-libs
|
||||
sudo
|
||||
tinydm
|
||||
tinydm-openrc
|
||||
tinydm-x11
|
||||
tzdata
|
||||
usbutils
|
||||
util-linux
|
||||
util-linux-misc
|
||||
v4l-utils
|
||||
wireplumber
|
||||
wpa_supplicant
|
||||
wpa_supplicant-openrc
|
||||
xauth
|
||||
xclip
|
||||
xdotool
|
||||
xhost
|
||||
xinit
|
||||
xkbcomp
|
||||
xkeyboard-config
|
||||
xrandr
|
||||
xrdb
|
||||
xset
|
||||
xsetroot
|
||||
zram-init
|
||||
zram-init-openrc
|
||||
@@ -0,0 +1,83 @@
|
||||
# Packages excluded from the final Geminux aarch64 image (Wayland, Rust, upstream overrides, compilers).
|
||||
grim
|
||||
imv-wayland
|
||||
libdecor
|
||||
slurp
|
||||
wofi
|
||||
xwayland
|
||||
sudo-rs
|
||||
postmarketos-base-sudo-rs
|
||||
gstreamer-ptp-helper
|
||||
libheif-rav1e
|
||||
rust
|
||||
cargo
|
||||
librsvg
|
||||
libglycin
|
||||
glycin-image-rs
|
||||
glycin-svg
|
||||
glycin-loaders
|
||||
rav1e
|
||||
rav1e-libs
|
||||
libdovi
|
||||
mesa-rusticl
|
||||
gdk-pixbuf
|
||||
adwaita-icon-theme
|
||||
imv-x11
|
||||
gst-libav
|
||||
gst-plugins-bad
|
||||
gst-plugins-good
|
||||
libnotify
|
||||
generate-kernel-cmdline
|
||||
linux-lts
|
||||
linux-edge
|
||||
linux-virt
|
||||
linux-rpi
|
||||
xorg-server
|
||||
xorg-server-common
|
||||
xf86-input-libinput
|
||||
xf86-video-fbdev
|
||||
gcc
|
||||
g++
|
||||
musl-dev
|
||||
make
|
||||
!imv-wayland
|
||||
!grim
|
||||
!slurp
|
||||
!wofi
|
||||
!libdecor
|
||||
!xwayland
|
||||
!gstreamer-ptp-helper
|
||||
!libheif-rav1e
|
||||
!postmarketos-base-sudo-rs
|
||||
!sudo-rs
|
||||
!rust
|
||||
!cargo
|
||||
!librsvg
|
||||
!libglycin
|
||||
!glycin-image-rs
|
||||
!glycin-svg
|
||||
!glycin-loaders
|
||||
!rav1e
|
||||
!rav1e-libs
|
||||
!libdovi
|
||||
!mesa-rusticl
|
||||
!gdk-pixbuf
|
||||
!adwaita-icon-theme
|
||||
!imv-x11
|
||||
!gst-libav
|
||||
!gst-plugins-bad
|
||||
!gst-plugins-good
|
||||
!libnotify
|
||||
!generate-kernel-cmdline
|
||||
!linux-lts
|
||||
!linux-edge
|
||||
!linux-virt
|
||||
!linux-rpi
|
||||
!xorg-server
|
||||
!xorg-server-common
|
||||
!xf86-input-libinput
|
||||
!xf86-video-fbdev
|
||||
!gcc
|
||||
!g++
|
||||
!musl-dev
|
||||
!make
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
# Install the target hostname, hosts file and OpenRC hostname link.
|
||||
set -eu
|
||||
|
||||
ROOTFS="${1:-}"
|
||||
DEVICE="${2:-gemini-x27}"
|
||||
|
||||
if [ -z "$ROOTFS" ] || [ ! -d "$ROOTFS" ]; then
|
||||
echo "Usage: $0 <rootfs-dir> [device]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$DEVICE" in
|
||||
gemini-x27|gemini|geminux)
|
||||
HOSTNAME_VAL="geminux"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unsupported device '$DEVICE' (expected gemini-x27)." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "$ROOTFS/etc" "$ROOTFS/etc/runlevels/boot"
|
||||
printf '%s\n' "$HOSTNAME_VAL" > "$ROOTFS/etc/hostname"
|
||||
cat > "$ROOTFS/etc/hosts" <<EOF
|
||||
127.0.0.1 $HOSTNAME_VAL localhost.localdomain localhost
|
||||
::1 $HOSTNAME_VAL localhost ipv6-localhost ipv6-loopback
|
||||
fe00::0 ipv6-localnet
|
||||
ff00::0 ipv6-mcastprefix
|
||||
ff02::1 ipv6-allnodes
|
||||
ff02::2 ipv6-allrouters
|
||||
ff02::3 ipv6-allhosts
|
||||
EOF
|
||||
if [ -e "$ROOTFS/etc/init.d/hostname" ]; then
|
||||
ln -sfn /etc/init.d/hostname "$ROOTFS/etc/runlevels/boot/hostname"
|
||||
fi
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
# Keep the tracked overlay/rootfs snapshot in sync with prebuilt/ artifacts.
|
||||
# prebuilt/ is the single source of truth; this script mirrors every artifact
|
||||
# that also exists in overlay/rootfs back into the overlay.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
CHECK_ONLY=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check|-c)
|
||||
CHECK_ONLY=1
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [--check]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
python3 - "$BASE_DIR" "$CHECK_ONLY" <<'PYEOF'
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
base = sys.argv[1]
|
||||
check_only = sys.argv[2] == "1"
|
||||
prebuilt_root = os.path.join(base, "prebuilt")
|
||||
overlay_root = os.path.join(base, "overlay", "rootfs")
|
||||
|
||||
|
||||
def digest(path):
|
||||
with open(path, "rb") as handle:
|
||||
return hashlib.sha256(handle.read()).hexdigest()
|
||||
|
||||
|
||||
def regular_files(root):
|
||||
result = []
|
||||
for parent, _, names in os.walk(root):
|
||||
for name in names:
|
||||
path = os.path.join(parent, name)
|
||||
if not os.path.islink(path) and os.path.isfile(path):
|
||||
result.append(path)
|
||||
return result
|
||||
|
||||
|
||||
def is_elf(path):
|
||||
try:
|
||||
with open(path, "rb") as handle:
|
||||
return handle.read(4) == b"\x7fELF"
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
by_name = {}
|
||||
for path in regular_files(prebuilt_root):
|
||||
by_name.setdefault(os.path.basename(path), []).append(path)
|
||||
|
||||
drift = []
|
||||
matched = 0
|
||||
for target in regular_files(overlay_root):
|
||||
rel = os.path.relpath(target, overlay_root)
|
||||
candidates = by_name.get(os.path.basename(target), [])
|
||||
source = None
|
||||
for candidate in candidates:
|
||||
stripped = os.path.relpath(candidate, prebuilt_root).split(os.sep, 1)[-1]
|
||||
if stripped == rel:
|
||||
source = candidate
|
||||
break
|
||||
if source is None and candidates:
|
||||
bin_dir = os.path.join(overlay_root, "usr", "bin") + os.sep
|
||||
local_bin_dir = os.path.join(overlay_root, "usr", "local", "bin") + os.sep
|
||||
for candidate in candidates:
|
||||
if is_elf(candidate) and not target.startswith(bin_dir) and \
|
||||
not target.startswith(local_bin_dir):
|
||||
continue
|
||||
source = candidate
|
||||
break
|
||||
if source is None:
|
||||
continue
|
||||
matched += 1
|
||||
if digest(source) == digest(target):
|
||||
continue
|
||||
drift.append((source, target))
|
||||
if not check_only:
|
||||
shutil.copy2(source, target)
|
||||
|
||||
if check_only:
|
||||
for source, target in drift:
|
||||
print("out of sync: " + os.path.relpath(target, base))
|
||||
print("artifact drift: %d of %d mirrored file(s)" % (len(drift), matched))
|
||||
sys.exit(1 if drift else 0)
|
||||
|
||||
print("synced %d artifact(s) into overlay/rootfs; %d already in sync" % (
|
||||
len(drift), matched - len(drift)))
|
||||
PYEOF
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify MT6797 CCCI UAPI header constants and 16-byte hardware framing logic."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
HDR_PATH = os.path.join(BASE_DIR, "prebuilt", "kernel", "include", "linux", "mt6797_ccci.h")
|
||||
PROTO_C = os.path.join(BASE_DIR, "src", "geminux-daemons", "geminux-ccci-proto.c")
|
||||
DAEMON_INC = os.path.join(BASE_DIR, "src", "geminux-daemons")
|
||||
KERNEL_INC = os.path.join(BASE_DIR, "prebuilt", "kernel", "include")
|
||||
|
||||
C_TEST = r"""
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include "geminux-ccci-proto.h"
|
||||
|
||||
int main(void) {
|
||||
assert(sizeof(struct mt6797_ccci_header) == 16);
|
||||
|
||||
geminux_ccci_sm_t sm;
|
||||
geminux_ccci_sm_init(&sm);
|
||||
assert(sm.state == MT6797_MD_STATE_GATED);
|
||||
|
||||
/* Little-endian wire encoding of HS1 on CONTROL_RX (channel 0) */
|
||||
uint8_t hs1_wire[16] = {
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x2a, 0x00, 0x00, 0x00,
|
||||
};
|
||||
struct mt6797_ccci_header rx, tx;
|
||||
bool need_reply = false;
|
||||
geminux_ccci_unpack_hdr(hs1_wire, &rx);
|
||||
assert(rx.channel == MT6797_CCCI_CH_CONTROL_RX);
|
||||
assert(rx.data1 == MT6797_CCCI_MSG_HS1);
|
||||
assert(rx.reserved == 42U);
|
||||
|
||||
assert(geminux_ccci_handle_ctrl(&sm, &rx, &tx, &need_reply));
|
||||
assert(need_reply);
|
||||
assert(sm.state == MT6797_MD_STATE_HS1);
|
||||
assert(tx.channel == MT6797_CCCI_CH_CONTROL_TX);
|
||||
assert(tx.data1 == MT6797_CCCI_MSG_HS1);
|
||||
assert(tx.reserved == 42U);
|
||||
|
||||
struct mt6797_ccci_header ready_rx;
|
||||
geminux_ccci_pack_hdr(&ready_rx, 0, MT6797_CCCI_MSG_NORMAL_BOOT_READY,
|
||||
MT6797_CCCI_CH_CONTROL_RX, 0);
|
||||
assert(geminux_ccci_handle_ctrl(&sm, &ready_rx, &tx, &need_reply));
|
||||
assert(!need_reply);
|
||||
assert(sm.state == MT6797_MD_STATE_READY);
|
||||
|
||||
struct mt6797_ccci_header ex_rx;
|
||||
geminux_ccci_pack_hdr(&ex_rx, 1, MT6797_CCCI_MSG_MD_EX,
|
||||
MT6797_CCCI_CH_CONTROL_RX, 0);
|
||||
assert(geminux_ccci_handle_ctrl(&sm, &ex_rx, &tx, &need_reply));
|
||||
assert(sm.state == MT6797_MD_STATE_EXCEPTION);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
with open(HDR_PATH, "r", encoding="utf-8") as handle:
|
||||
hdr = handle.read()
|
||||
|
||||
expected = {
|
||||
"MT6797_CCCI_CH_CONTROL_RX": r"\b0\b",
|
||||
"MT6797_CCCI_CH_CONTROL_TX": r"\b1\b",
|
||||
"MT6797_CCCI_CH_FS_RX": r"\b14\b",
|
||||
"MT6797_CCCI_CH_FS_TX": r"\b15\b",
|
||||
"MT6797_CCCI_CH_RPC_RX": r"\b32\b",
|
||||
"MT6797_CCCI_CH_RPC_TX": r"\b33\b",
|
||||
"MT6797_CCCI_CH_STATUS_RX": r"\b67\b",
|
||||
"MT6797_CCCI_CH_STATUS_TX": r"\b68\b",
|
||||
"MT6797_CCCI_MSG_HS1": r"0xFFFFFFFFU",
|
||||
"MT6797_CCCI_MSG_NORMAL_BOOT_READY": r"0xB0000002U",
|
||||
}
|
||||
for macro, pat in expected.items():
|
||||
if not re.search(rf"#define\s+{macro}\s+{pat}", hdr):
|
||||
raise AssertionError(f"Missing or mismatched macro {macro} in {HDR_PATH}")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-ccci-test-") as tmp:
|
||||
src = os.path.join(tmp, "test_ccci.c")
|
||||
bin_path = os.path.join(tmp, "test_ccci")
|
||||
with open(src, "w", encoding="utf-8") as handle:
|
||||
handle.write(C_TEST)
|
||||
|
||||
gcc = shutil.which("gcc")
|
||||
if gcc:
|
||||
subprocess.run(
|
||||
[gcc, "-std=c11", "-Wall", "-Wextra", "-Werror",
|
||||
"-I", DAEMON_INC, "-I", KERNEL_INC,
|
||||
src, PROTO_C, "-o", bin_path],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run([bin_path], check=True)
|
||||
else:
|
||||
subprocess.run(
|
||||
["docker", "run", "--rm", "-v", f"{BASE_DIR}:/geminux:ro",
|
||||
"-v", f"{tmp}:/work", "alpine:3.24", "sh", "-eu", "-c",
|
||||
"apk add --no-cache build-base linux-headers >/dev/null && "
|
||||
"gcc -std=c11 -Wall -Wextra -Werror -I/geminux/src/geminux-daemons "
|
||||
"-I/geminux/prebuilt/kernel/include /work/test_ccci.c "
|
||||
"/geminux/src/geminux-daemons/geminux-ccci-proto.c -o /work/test_ccci && "
|
||||
"/work/test_ccci"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
print("[PASS] MT6797 CCCI 16-byte framing, channel map, and handshake verified")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+460
@@ -0,0 +1,460 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline test suite for Geminux flash-mtk GPT builder, safety guards, and firmware extractor."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SCRIPTS_DIR = os.path.join(BASE_DIR, "scripts")
|
||||
FLASH_DEPS = os.path.join(BASE_DIR, ".flash-deps")
|
||||
if os.path.isdir(FLASH_DEPS):
|
||||
sys.path.insert(0, FLASH_DEPS)
|
||||
sys.path.insert(0, BASE_DIR)
|
||||
sys.path.insert(0, SCRIPTS_DIR)
|
||||
|
||||
from geminux_gpt import (
|
||||
BASIC_DATA_TYPE_GUID,
|
||||
GPT_ARRAY_SECTORS,
|
||||
GPT_ENTRY_COUNT,
|
||||
GPT_ENTRY_SIZE,
|
||||
LINUX_FS_TYPE_GUID,
|
||||
PROTECTED_END_LBA,
|
||||
SECTOR_SIZE,
|
||||
GptEntry,
|
||||
GptHeader,
|
||||
build_geminux_gpts,
|
||||
parse_primary_gpt,
|
||||
verify_gpt_crcs,
|
||||
)
|
||||
import importlib.util
|
||||
|
||||
def _load_mod(name, path):
|
||||
sp = importlib.util.spec_from_file_location(name, path)
|
||||
mod = importlib.util.module_from_spec(sp)
|
||||
sp.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
extract_firmware = _load_mod(
|
||||
"extract_vendor_fw", os.path.join(SCRIPTS_DIR, "extract-vendor-fw.py")
|
||||
).extract_firmware
|
||||
flash_mtk = _load_mod("flash_mtk", os.path.join(BASE_DIR, "flash-mtk.py"))
|
||||
|
||||
|
||||
def make_synthetic_gemini_pgpt(total_sectors):
|
||||
# Replicate Planet Computers Gemini x27 SYS1..SYS34 partitions
|
||||
parts_spec = [
|
||||
("recovery", 0x8000, 0x1000000),
|
||||
("para", 0x1008000, 0x80000),
|
||||
("expdb", 0x1088000, 0xa00000),
|
||||
("frp", 0x1a88000, 0x100000),
|
||||
("nvcfg", 0x1b88000, 0x800000),
|
||||
("nvdata", 0x2388000, 0x2000000),
|
||||
("metadata", 0x4388000, 0x2000000),
|
||||
("protect1", 0x6388000, 0x800000),
|
||||
("protect2", 0x6b88000, 0xc78000),
|
||||
("seccfg", 0x7800000, 0x800000),
|
||||
("oemkeystore", 0x8000000, 0x200000),
|
||||
("proinfo", 0x8200000, 0x300000),
|
||||
("md1img", 0x8500000, 0x1800000),
|
||||
("md1dsp", 0x9d00000, 0x400000),
|
||||
("md1arm7", 0xa100000, 0x300000),
|
||||
("md3img", 0xa400000, 0x500000),
|
||||
("scp1", 0xa900000, 0x100000),
|
||||
("scp2", 0xaa00000, 0x100000),
|
||||
("nvram", 0xab00000, 0x500000),
|
||||
("lk", 0xb000000, 0x80000),
|
||||
("lk2", 0xb080000, 0x80000),
|
||||
("boot", 0xb100000, 0x1000000),
|
||||
("logo", 0xc100000, 0x800000),
|
||||
("tee1", 0xc900000, 0x500000),
|
||||
("tee2", 0xce00000, 0x500000),
|
||||
("keystore", 0xd300000, 0xd00000),
|
||||
("system", 0xe000000, 0xa0000000),
|
||||
("cache", 0xae000000, 0x1b000000),
|
||||
("userdata", 0xc9000000, (total_sectors - 32768 - 64) * SECTOR_SIZE - 0xc9000000),
|
||||
]
|
||||
|
||||
entries = []
|
||||
for name, start_b, size_b in parts_spec:
|
||||
first_lba = start_b // SECTOR_SIZE
|
||||
last_lba = (start_b + size_b) // SECTOR_SIZE - 1
|
||||
entries.append(GptEntry(
|
||||
BASIC_DATA_TYPE_GUID,
|
||||
uuid.uuid4().bytes_le,
|
||||
first_lba,
|
||||
last_lba,
|
||||
0,
|
||||
name,
|
||||
))
|
||||
|
||||
flashinfo_sectors = 0x1000000 // SECTOR_SIZE
|
||||
flashinfo_first = total_sectors - 34 - flashinfo_sectors
|
||||
entries.append(GptEntry(
|
||||
BASIC_DATA_TYPE_GUID,
|
||||
uuid.uuid4().bytes_le,
|
||||
flashinfo_first,
|
||||
flashinfo_first + flashinfo_sectors - 1,
|
||||
0,
|
||||
"flashinfo",
|
||||
))
|
||||
|
||||
part_array = bytearray(GPT_ENTRY_COUNT * GPT_ENTRY_SIZE)
|
||||
for i, e in enumerate(entries):
|
||||
part_array[i * GPT_ENTRY_SIZE:(i + 1) * GPT_ENTRY_SIZE] = e.to_bytes()
|
||||
|
||||
raw_hdr = struct.pack(
|
||||
"<8sIIIIQQQQ16sQIII",
|
||||
b"EFI PART",
|
||||
0x00010000,
|
||||
92,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
total_sectors - 1,
|
||||
34,
|
||||
total_sectors - 34,
|
||||
uuid.uuid4().bytes_le,
|
||||
2,
|
||||
GPT_ENTRY_COUNT,
|
||||
GPT_ENTRY_SIZE,
|
||||
0,
|
||||
).ljust(SECTOR_SIZE, b"\x00")
|
||||
hdr = GptHeader(raw_hdr)
|
||||
hdr_bytes = hdr.pack_with_crcs(bytes(part_array))
|
||||
mbr = bytearray(SECTOR_SIZE)
|
||||
mbr[510:512] = b"\x55\xAA"
|
||||
return bytes(mbr) + hdr_bytes + bytes(part_array)
|
||||
|
||||
|
||||
def test_gpt_repartition():
|
||||
# ~64 GB eMMC sector count
|
||||
total_sectors = 122142720
|
||||
orig_pgpt = make_synthetic_gemini_pgpt(total_sectors)
|
||||
_, orig_hdr, orig_entries = parse_primary_gpt(orig_pgpt)
|
||||
|
||||
new_pgpt, new_sgpt, new_entries = build_geminux_gpts(orig_pgpt, total_sectors)
|
||||
assert len(new_pgpt) == 34 * SECTOR_SIZE
|
||||
assert len(new_sgpt) == 33 * SECTOR_SIZE
|
||||
|
||||
_, pri_hdr, parsed_entries = parse_primary_gpt(new_pgpt)
|
||||
verify_gpt_crcs(pri_hdr, new_pgpt[2 * SECTOR_SIZE:])
|
||||
|
||||
# Verify backup GPT CRCs as well
|
||||
bak_entries_bytes = new_sgpt[:GPT_ARRAY_SECTORS * SECTOR_SIZE]
|
||||
bak_hdr = GptHeader(new_sgpt[GPT_ARRAY_SECTORS * SECTOR_SIZE:])
|
||||
verify_gpt_crcs(bak_hdr, bak_entries_bytes)
|
||||
assert bak_hdr.current_lba == total_sectors - 1
|
||||
assert bak_hdr.backup_lba == 1
|
||||
assert bak_hdr.part_entry_start_lba == total_sectors - 1 - GPT_ARRAY_SECTORS
|
||||
|
||||
# Check every pre-0x0E000000 partition is preserved byte-for-byte
|
||||
orig_pre = [e for e in orig_entries if e.last_lba < PROTECTED_END_LBA]
|
||||
new_pre = [e for e in parsed_entries if e.last_lba < PROTECTED_END_LBA]
|
||||
assert len(orig_pre) == len(new_pre) == 26
|
||||
for a, b in zip(orig_pre, new_pre):
|
||||
assert a.to_bytes() == b.to_bytes(), f"Mismatch in preserved partition {a.name}"
|
||||
|
||||
names = [e.name for e in parsed_entries]
|
||||
assert "system" not in names
|
||||
assert "cache" not in names
|
||||
assert "userdata" not in names
|
||||
assert "linux" in names
|
||||
assert "boot2" in names
|
||||
assert "flashinfo" in names
|
||||
|
||||
linux_p = next(e for e in parsed_entries if e.name == "linux")
|
||||
boot2_p = next(e for e in parsed_entries if e.name == "boot2")
|
||||
flash_p = next(e for e in parsed_entries if e.name == "flashinfo")
|
||||
|
||||
assert linux_p.type_guid == LINUX_FS_TYPE_GUID
|
||||
assert linux_p.first_lba == PROTECTED_END_LBA
|
||||
assert linux_p.last_lba == boot2_p.first_lba - 1
|
||||
linux_gib = (linux_p.sectors * SECTOR_SIZE) / (1024 ** 3)
|
||||
assert linux_gib > 57.5, f"Expected >57.5 GiB linux partition, got {linux_gib:.2f}"
|
||||
assert boot2_p.sectors * SECTOR_SIZE == 0x1000000
|
||||
assert boot2_p.last_lba < flash_p.first_lba
|
||||
print(f"[PASS] GPT repartitioning verified (linux={linux_gib:.2f} GiB, 26 protected partitions intact)")
|
||||
|
||||
|
||||
def test_write_safety():
|
||||
for protected in ("preloader", "nvram", "proinfo", "protect1", "protect2", "lk", "tee1", "md1img"):
|
||||
blocked = False
|
||||
try:
|
||||
flash_mtk.enforce_write_safety(protected, allow_protected=False)
|
||||
except PermissionError:
|
||||
blocked = True
|
||||
assert blocked, f"Protected partition {protected} was NOT blocked!"
|
||||
flash_mtk.enforce_write_safety(protected, allow_protected=True)
|
||||
|
||||
for allowed in ("boot", "recovery", "boot2", "linux"):
|
||||
flash_mtk.enforce_write_safety(allowed, allow_protected=False)
|
||||
print("[PASS] Protected partition write-denylist verified")
|
||||
|
||||
|
||||
def test_firmware_extraction():
|
||||
if shutil.which("mke2fs") is None or shutil.which("debugfs") is None:
|
||||
print("[SKIP] mke2fs/debugfs not available on host for ext4 extraction test")
|
||||
return
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-fwtest-") as tmp:
|
||||
src_tree = os.path.join(tmp, "sysroot", "vendor", "firmware")
|
||||
os.makedirs(src_tree, exist_ok=True)
|
||||
expected = {
|
||||
"ROMv3_patch_1_0_hdr.bin": b"ROMV3_0" * 64,
|
||||
"ROMv3_patch_1_1_hdr.bin": b"ROMV3_1" * 64,
|
||||
"WIFI_RAM_CODE_6797": b"WIFI_FW" * 128,
|
||||
"WMT_SOC.cfg": b"coex=1\n",
|
||||
"pcm_suspend.bin": b"PCM_SUSPEND" * 16,
|
||||
}
|
||||
for name, data in expected.items():
|
||||
with open(os.path.join(src_tree, name), "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
sys_img = os.path.join(tmp, "system.img")
|
||||
subprocess.run(
|
||||
["mke2fs", "-t", "ext4", "-F", "-q", "-d", os.path.join(tmp, "sysroot"), sys_img, "4M"],
|
||||
check=True,
|
||||
)
|
||||
out_dir = os.path.join(tmp, "fw-out")
|
||||
found, missing = extract_firmware(sys_img, out_dir)
|
||||
assert not missing, f"Missing firmware blobs: {missing}"
|
||||
assert set(found.keys()) == set(expected.keys())
|
||||
for name, data in expected.items():
|
||||
with open(os.path.join(out_dir, name), "rb") as f:
|
||||
assert f.read() == data
|
||||
assert os.path.isfile(os.path.join(out_dir, "MANIFEST.sha256"))
|
||||
print("[PASS] Stock system.img firmware extraction verified")
|
||||
|
||||
|
||||
def test_mtkclient_gpt_settings():
|
||||
from types import SimpleNamespace
|
||||
|
||||
vendor_mtk = os.path.join(BASE_DIR, "vendor", "mtkclient")
|
||||
if vendor_mtk not in sys.path:
|
||||
sys.path.insert(0, vendor_mtk)
|
||||
from mtkclient.Library.partition import Partition
|
||||
|
||||
cfg = flash_mtk.create_mtk_config()
|
||||
assert cfg.gpt_settings is not None, "create_mtk_config() left cfg.gpt_settings as None"
|
||||
assert cfg.gpt_settings.gpt_num_part_entries == 0
|
||||
|
||||
total_sectors = 122142720
|
||||
pgpt = make_synthetic_gemini_pgpt(total_sectors)
|
||||
# Ensure protective MBR has EFI partition entry matching hardware GPT
|
||||
pgpt_arr = bytearray(pgpt)
|
||||
pgpt_arr[0x1BE:0x1CE] = struct.pack("<B3sB3sII", 0x00, b"\x00\x02\x00", 0xEE, b"\xff\xff\xff", 1, total_sectors - 1)
|
||||
pgpt = bytes(pgpt_arr)
|
||||
|
||||
def fake_readflash(addr, length, filename="", parttype="user", display=False):
|
||||
chunk = pgpt[addr:addr + length]
|
||||
return chunk.ljust(length, b"\x00")
|
||||
|
||||
daconfig = SimpleNamespace(storage=SimpleNamespace(flashsize=total_sectors * SECTOR_SIZE), pagesize=SECTOR_SIZE)
|
||||
daloader = SimpleNamespace(daconfig=daconfig, readflash=fake_readflash)
|
||||
fake_mtk = SimpleNamespace(config=cfg, daloader=daloader)
|
||||
part = Partition(fake_mtk, fake_readflash, lambda: (b"", None))
|
||||
_, guid_gpt = part.get_gpt(cfg.gpt_settings, "user")
|
||||
assert guid_gpt is not None, "Partition.get_gpt failed with GptSettings(0, 0, 0)"
|
||||
names = [e.name for e in guid_gpt.partentries]
|
||||
assert "proinfo" in names and "nvram" in names and "linux" not in names, f"Unexpected entries: {names}"
|
||||
print(f"[PASS] mtkclient GptSettings regression verified ({len(names)} partitions parsed)")
|
||||
|
||||
|
||||
def test_finish_da_session():
|
||||
from types import SimpleNamespace
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-da-exit-") as tmp:
|
||||
state_file = os.path.join(tmp, ".state")
|
||||
calls = []
|
||||
|
||||
class FakeDaloader:
|
||||
def shutdown(self, bootmode=0):
|
||||
calls.append(("shutdown", bootmode))
|
||||
|
||||
class FakePort:
|
||||
def close(self):
|
||||
calls.append(("close",))
|
||||
|
||||
fake_mtk = SimpleNamespace(
|
||||
config=SimpleNamespace(hwparam_path=tmp),
|
||||
daloader=FakeDaloader(),
|
||||
port=FakePort(),
|
||||
)
|
||||
|
||||
with open(state_file, "w") as f:
|
||||
f.write("cached")
|
||||
flash_mtk.finish_da_session(fake_mtk, reboot=True)
|
||||
assert not os.path.exists(state_file), ".state file was not cleaned on DA reboot"
|
||||
assert calls == [("shutdown", 1), ("close",)], f"Unexpected calls: {calls}"
|
||||
|
||||
calls.clear()
|
||||
flash_mtk.finish_da_session(fake_mtk, reboot=False)
|
||||
assert calls == [("shutdown", 0), ("close",)], f"Unexpected calls: {calls}"
|
||||
print("[PASS] DA shutdown/reboot session cleanup verified")
|
||||
|
||||
|
||||
def test_fast_preloader_handshake():
|
||||
from types import SimpleNamespace
|
||||
from mtkclient.Library.Port import Port
|
||||
|
||||
def run_case(initial_packets, coalesced_dup=False):
|
||||
rx_packets = list(initial_packets)
|
||||
tx_seen = []
|
||||
|
||||
class FakeEndpoint:
|
||||
def __init__(self, is_in):
|
||||
self.is_in = is_in
|
||||
self.wMaxPacketSize = 512
|
||||
|
||||
def write(self, data, timeout=200):
|
||||
tx_seen.append(bytes(data))
|
||||
if data == b"\xa0":
|
||||
if coalesced_dup:
|
||||
rx_packets.append(b"READY\x5f\x5f")
|
||||
else:
|
||||
rx_packets.append(b"\x5f")
|
||||
elif data == b"\x0a":
|
||||
rx_packets.append(b"\xf5")
|
||||
elif data == b"\x50":
|
||||
rx_packets.append(b"\xaf")
|
||||
elif data == b"\x05":
|
||||
rx_packets.append(b"\xfa")
|
||||
return len(data)
|
||||
|
||||
def read(self, size, timeout=100):
|
||||
if not rx_packets:
|
||||
return b""
|
||||
pkt = rx_packets[0]
|
||||
if size < len(pkt):
|
||||
raise OSError("LIBUSB_ERROR_OVERFLOW")
|
||||
rx_packets.pop(0)
|
||||
return pkt
|
||||
|
||||
fake_cdc = SimpleNamespace(
|
||||
pid=0x2000,
|
||||
EP_OUT=FakeEndpoint(False),
|
||||
EP_IN=FakeEndpoint(True),
|
||||
set_line_coding=lambda *a, **kw: None,
|
||||
setcontrollinestate=lambda *a, **kw: None,
|
||||
)
|
||||
fake_port = Port.__new__(Port)
|
||||
fake_port.cdc = fake_cdc
|
||||
fake_port.info = lambda *a, **kw: None
|
||||
fake_port.debug = lambda *a, **kw: None
|
||||
fake_port.warning = lambda *a, **kw: None
|
||||
fake_port.error = lambda *a, **kw: None
|
||||
|
||||
assert fake_port.run_handshake(retries=25) is True, (
|
||||
f"Preloader handshake failed (initial={initial_packets}, tx={tx_seen})"
|
||||
)
|
||||
assert tx_seen[-4:] == [b"\xa0", b"\x0a", b"\x50", b"\x05"], (
|
||||
f"Unexpected handshake TX sequence: {tx_seen}"
|
||||
)
|
||||
|
||||
run_case([b"READY\r\n"])
|
||||
run_case([b"READY"], coalesced_dup=True)
|
||||
|
||||
parsed = flash_mtk.build_arg_parser().parse_args(["--wait-timeout", "450"])
|
||||
assert parsed.wait_timeout == 450
|
||||
cfg = flash_mtk.create_mtk_config(wait_timeout=450)
|
||||
assert cfg.wait_timeout == 450
|
||||
print("[PASS] Fast BROM/Preloader handshake (maxinsize, no overflow, READY-tolerant) verified")
|
||||
|
||||
|
||||
def test_xflash_shutdown_wire_packet():
|
||||
from types import SimpleNamespace
|
||||
|
||||
vendor_mtk = os.path.join(BASE_DIR, "vendor", "mtkclient")
|
||||
if vendor_mtk not in sys.path:
|
||||
sys.path.insert(0, vendor_mtk)
|
||||
import mtkclient.Library.Connection.usblib as usblib
|
||||
import mtkclient.Library.DA.xflash.xflash_lib as xflash_lib
|
||||
from mtkclient.Library.DA.xflash.xflash_param import Cmd
|
||||
|
||||
orig_sleep = xflash_lib.time.sleep
|
||||
sleep_calls = []
|
||||
try:
|
||||
xflash_lib.time.sleep = lambda sec: sleep_calls.append(sec)
|
||||
|
||||
for bootmode, expected in (
|
||||
(1, (1, 100, 0, 1, 0, 1, 0)),
|
||||
(0, (0, 0, 0, 0, 0, 1, 0)),
|
||||
):
|
||||
sent = []
|
||||
close_calls = []
|
||||
sleep_calls.clear()
|
||||
da = xflash_lib.DAXFlash.__new__(xflash_lib.DAXFlash)
|
||||
da.cmd = Cmd()
|
||||
da.eh = SimpleNamespace(status=hex)
|
||||
da.error = lambda *a, **kw: None
|
||||
da.xsend = lambda data, *a, **kw: (sent.append(data), True)[1]
|
||||
da.status = lambda: 0
|
||||
da.mtk = SimpleNamespace(
|
||||
port=SimpleNamespace(close=lambda reset=False: close_calls.append(reset))
|
||||
)
|
||||
|
||||
assert da.shutdown(async_mode=0, dl_bit=0, bootmode=bootmode) is True
|
||||
assert len(sent) == 2 and sent[0] == Cmd.SHUTDOWN, f"Unexpected commands: {sent}"
|
||||
assert len(sent[1]) == 28, f"Expected 28-byte shutdown_ctrl, got {len(sent[1])} bytes"
|
||||
unpacked = struct.unpack("<IIIIIII", sent[1])
|
||||
assert unpacked == expected, f"bootmode={bootmode}: got {unpacked}, expected {expected}"
|
||||
assert close_calls == [False], f"Unexpected port.close(reset=...) calls: {close_calls}"
|
||||
assert sleep_calls == [0.35], f"Expected 0.35s disconnect wait, got {sleep_calls}"
|
||||
|
||||
class FakeDev:
|
||||
def __init__(self):
|
||||
self._ctx = SimpleNamespace(dispose=lambda dev: None)
|
||||
|
||||
def reset(self):
|
||||
raise OSError(2, "Entity not found")
|
||||
|
||||
info_msgs = []
|
||||
debug_msgs = []
|
||||
usblib.time.sleep = lambda sec: None
|
||||
uc = usblib.UsbClass.__new__(usblib.UsbClass)
|
||||
uc.rxleft = bytearray()
|
||||
uc.connected = True
|
||||
uc.interface = 0
|
||||
uc.device = FakeDev()
|
||||
uc.info = lambda msg: info_msgs.append(msg)
|
||||
uc.debug = lambda msg: debug_msgs.append(msg)
|
||||
uc.close(reset=True)
|
||||
assert info_msgs == [], f"Unexpected info log on expected ENOENT disconnect: {info_msgs}"
|
||||
assert len(debug_msgs) == 1 and "Entity not found" in debug_msgs[0], debug_msgs
|
||||
assert uc.connected is False
|
||||
finally:
|
||||
xflash_lib.time.sleep = orig_sleep
|
||||
print("[PASS] XFlash 28-byte shutdown wire packet and ENOENT suppression verified")
|
||||
|
||||
|
||||
def test_cli_help():
|
||||
res = subprocess.run(
|
||||
[os.path.join(BASE_DIR, "flash-mtk.sh"), "--help"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
assert res.returncode == 0, res.stderr
|
||||
assert "--only-backup" in res.stdout and "--flash-full" in res.stdout
|
||||
assert "--reboot" in res.stdout and "--poweroff" in res.stdout and "--no-reboot" in res.stdout
|
||||
assert "--wait-timeout" in res.stdout
|
||||
print("[PASS] flash-mtk.sh --help verified")
|
||||
|
||||
|
||||
def main():
|
||||
test_gpt_repartition()
|
||||
test_write_safety()
|
||||
test_firmware_extraction()
|
||||
test_mtkclient_gpt_settings()
|
||||
test_finish_da_session()
|
||||
test_fast_preloader_handshake()
|
||||
test_xflash_shutdown_wire_packet()
|
||||
test_cli_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify zero-poll daemon design and Geminux power/lid-suspend policy logic."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DAEMON_DIR = os.path.join(BASE_DIR, "src", "geminux-daemons")
|
||||
POLICY_C = os.path.join(DAEMON_DIR, "geminux-power-policy.c")
|
||||
|
||||
DAEMON_FILES = {
|
||||
"geminux-powerd.c": "epoll_wait",
|
||||
"geminux-statusd.c": "epoll_wait",
|
||||
"geminux-ccci-daemon.c": "epoll_wait",
|
||||
"geminux-modem-ctl.c": "epoll_wait",
|
||||
"geminux-bt-obex.c": "g_main_loop_run",
|
||||
"geminux-leds.c": "epoll_wait",
|
||||
}
|
||||
|
||||
C_TEST = r"""
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "geminux-power-policy.h"
|
||||
|
||||
int main(void) {
|
||||
geminux_power_policy_t pol;
|
||||
geminux_policy_init(&pol);
|
||||
assert(pol.profile == POWER_PROFILE_BALANCED);
|
||||
assert(pol.lid_suspend_enabled);
|
||||
assert(!geminux_should_suspend_on_lid(&pol));
|
||||
|
||||
/* Closing lid on battery should trigger S3 suspend */
|
||||
pol.lid_closed = true;
|
||||
assert(geminux_should_suspend_on_lid(&pol));
|
||||
|
||||
/* Active voice call inhibitor blocks lid suspend */
|
||||
assert(geminux_policy_add_inhibit(&pol, "call"));
|
||||
assert(!geminux_should_suspend_on_lid(&pol));
|
||||
assert(geminux_policy_del_inhibit(&pol, "call"));
|
||||
assert(geminux_should_suspend_on_lid(&pol));
|
||||
|
||||
/* Connected external HDMI display blocks lid suspend */
|
||||
pol.hdmi_connected = true;
|
||||
assert(!geminux_should_suspend_on_lid(&pol));
|
||||
pol.hdmi_connected = false;
|
||||
assert(geminux_should_suspend_on_lid(&pol));
|
||||
|
||||
/* Profile parameters: eco disables A72 big cluster, balanced/perf enable A72 */
|
||||
geminux_profile_params_t eco = geminux_policy_params(POWER_PROFILE_ECO, false);
|
||||
assert(strcmp(eco.governor, "schedutil") == 0);
|
||||
assert(!eco.a72_online);
|
||||
assert(eco.suspend_timeout_s > 0);
|
||||
|
||||
geminux_profile_params_t bal = geminux_policy_params(POWER_PROFILE_BALANCED, false);
|
||||
assert(strcmp(bal.governor, "schedutil") == 0);
|
||||
assert(bal.a72_online);
|
||||
|
||||
geminux_profile_params_t perf = geminux_policy_params(POWER_PROFILE_PERFORMANCE, true);
|
||||
assert(strcmp(perf.governor, "schedutil") == 0);
|
||||
assert(perf.a72_online);
|
||||
assert(perf.suspend_timeout_s == 0);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
for fname, required_loop in DAEMON_FILES.items():
|
||||
path = os.path.join(DAEMON_DIR, fname)
|
||||
with open(path, "r", encoding="utf-8") as handle:
|
||||
src = handle.read()
|
||||
for bad in (r"\bsleep\s*\(", r"\busleep\s*\(", r"\bnanosleep\s*\("):
|
||||
if re.search(bad, src):
|
||||
raise AssertionError(f"Busy-wait sleep call ({bad}) detected in {fname}")
|
||||
if required_loop not in src:
|
||||
raise AssertionError(f"Expected event loop primitive {required_loop} missing in {fname}")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-power-test-") as tmp:
|
||||
src = os.path.join(tmp, "test_power.c")
|
||||
bin_path = os.path.join(tmp, "test_power")
|
||||
with open(src, "w", encoding="utf-8") as handle:
|
||||
handle.write(C_TEST)
|
||||
|
||||
gcc = shutil.which("gcc")
|
||||
if gcc:
|
||||
subprocess.run(
|
||||
[gcc, "-std=c11", "-Wall", "-Wextra", "-Werror",
|
||||
"-I", DAEMON_DIR, src, POLICY_C, "-o", bin_path],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run([bin_path], check=True)
|
||||
else:
|
||||
subprocess.run(
|
||||
["docker", "run", "--rm", "-v", f"{BASE_DIR}:/geminux:ro",
|
||||
"-v", f"{tmp}:/work", "alpine:3.24", "sh", "-eu", "-c",
|
||||
"apk add --no-cache build-base >/dev/null && "
|
||||
"gcc -std=c11 -Wall -Wextra -Werror -I/geminux/src/geminux-daemons "
|
||||
"/work/test_power.c /geminux/src/geminux-daemons/geminux-power-policy.c "
|
||||
"-o /work/test_power && /work/test_power"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
print("[PASS] Zero-poll daemon loops and power/lid policy verified")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify all Geminux .xth themes and dunst theme synchronization."""
|
||||
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
THEMES_DIR = os.path.join(BASE_DIR, "overlay", "rootfs", "etc", "skel", ".xthemes")
|
||||
SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-dunst-theme")
|
||||
|
||||
REQUIRED_KEYS = (
|
||||
"theme.name", "theme.fontFace", "theme.iconFontFace", "theme.baseFontSize",
|
||||
"theme.bgMain", "theme.bgBar", "theme.bgHeader", "theme.bgOverlay",
|
||||
"theme.fgMain", "theme.fgBright", "theme.fgMuted", "theme.selBg", "theme.selFg",
|
||||
"theme.accent", "theme.border", "theme.danger", "theme.dangerBg",
|
||||
"dmenu.font", "dmenu.background", "dmenu.foreground", "dmenu.selbackground", "dmenu.selforeground",
|
||||
"dwm.font", "dwm.normbgcolor", "dwm.normfgcolor", "dwm.selbgcolor", "dwm.selfgcolor",
|
||||
"st.font", "st.background", "st.foreground", "st.cursorColor", "Xft.dpi",
|
||||
)
|
||||
|
||||
HEX_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
|
||||
|
||||
|
||||
def parse_xres(path):
|
||||
vals = {}
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("!") or line.startswith("#") or ":" not in line:
|
||||
continue
|
||||
k, v = line.split(":", 1)
|
||||
vals[k.strip()] = v.strip()
|
||||
return vals
|
||||
|
||||
|
||||
def main():
|
||||
themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth")))
|
||||
assert len(themes) >= 20, f"Expected >= 20 themes, found {len(themes)}"
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp:
|
||||
for th in themes:
|
||||
vals = parse_xres(th)
|
||||
for req in REQUIRED_KEYS:
|
||||
assert req in vals and vals[req], f"Missing {req} in {os.path.basename(th)}"
|
||||
assert "Fira Code" in vals["theme.fontFace"], f"Expected Fira Code in {os.path.basename(th)}"
|
||||
assert "Fira Code" in vals["st.font"], f"Expected Fira Code in st.font of {os.path.basename(th)}"
|
||||
assert "Fira Code" in vals["dmenu.font"], f"Expected Fira Code in dmenu.font of {os.path.basename(th)}"
|
||||
assert "Fira Code" in vals["dwm.font"], f"Expected Fira Code in dwm.font of {os.path.basename(th)}"
|
||||
for color_key in ("theme.bgMain", "theme.fgMain", "theme.accent", "theme.danger"):
|
||||
assert HEX_RE.match(vals[color_key]), f"Invalid hex color {color_key}={vals[color_key]} in {th}"
|
||||
|
||||
dunstrc = os.path.join(tmp, f"{os.path.basename(th)}.dunstrc")
|
||||
env = dict(os.environ, GEMINUX_XRESOURCES=th, GEMINUX_DUNSTRC=dunstrc)
|
||||
subprocess.run([SYNC_SCRIPT, "--no-restart"], env=env, check=True)
|
||||
with open(dunstrc) as df:
|
||||
txt = df.read()
|
||||
assert vals["theme.accent"] in txt
|
||||
assert vals["theme.bgMain"] in txt
|
||||
assert vals["theme.dangerBg"] in txt
|
||||
assert "font = Fira Code " in txt
|
||||
assert "width = 560" in txt
|
||||
|
||||
print(f"[PASS] Verified {len(themes)} .xth themes and dunst synchronization")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile and verify Geminux Gemini PDA US XKB keymap using xkbcomp inside Docker."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
XKB_OVERLAY = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "share", "X11", "xkb")
|
||||
|
||||
|
||||
def main():
|
||||
script = r"""
|
||||
set -eu
|
||||
cat > /etc/apk/repositories <<EOF
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
EOF
|
||||
apk add --no-cache xkbcomp setxkbmap xkeyboard-config >/dev/null
|
||||
cp -a /geminux-xkb/. /usr/share/X11/xkb/
|
||||
cat > /tmp/gemini.xkb <<'XKB'
|
||||
xkb_keymap {
|
||||
xkb_keycodes { include "evdev+aliases(qwerty)" };
|
||||
xkb_types { include "complete+geminux" };
|
||||
xkb_compat { include "complete" };
|
||||
xkb_symbols { include "pc+planet_vndr/geminux(us)+inet(evdev)" };
|
||||
xkb_geometry { include "pc(pc105)" };
|
||||
};
|
||||
XKB
|
||||
xkbcomp -w 3 -I/usr/share/X11/xkb /tmp/gemini.xkb /tmp/gemini.xkm
|
||||
xkbcomp /tmp/gemini.xkm /tmp/gemini_dump.xkb
|
||||
cat /tmp/gemini_dump.xkb
|
||||
"""
|
||||
res = subprocess.run(
|
||||
["docker", "run", "--rm", "--network=host", "-v", f"{XKB_OVERLAY}:/geminux-xkb:ro",
|
||||
"alpine:3.24", "sh", "-eu", "-c", script],
|
||||
capture_output=True, text=True, check=False
|
||||
)
|
||||
if res.returncode != 0:
|
||||
print(res.stdout)
|
||||
print(res.stderr, file=sys.stderr)
|
||||
return res.returncode
|
||||
|
||||
dump = res.stdout
|
||||
checks = [
|
||||
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
|
||||
"asciitilde", "EuroSign", "Super_L", "ISO_Level3_Shift", "Mod4", "Mod5",
|
||||
"GEMINUX_LALT", "GEMINUX_FN",
|
||||
]
|
||||
for token in checks:
|
||||
assert token in dump, f"Expected '{token}' in compiled XKB dump"
|
||||
# Verify digit AE01 order: [ 1, exclam, F1, asciitilde ]
|
||||
assert "[ 1, exclam, F1, asciitilde ]" in dump or \
|
||||
"1, exclam, F1, asciitilde" in " ".join(dump.split()), \
|
||||
"AE01 digit/F1/tilde mapping mismatch"
|
||||
print("[PASS] XKB compilation & Fn+Alt=Mod4 / Fn+1..0=F1..F10 / Shift+Fn+1..0 symbols verified")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
# Compute and apply the Geminux Linux release version and codename.
|
||||
set -eu
|
||||
|
||||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
VERSION="${GEMINUX_VERSION:-0.1.0}"
|
||||
CODENAME="${GEMINUX_CODENAME:-helio}"
|
||||
|
||||
if [ "${1:-}" = "--print" ] || [ "${1:-}" = "-p" ]; then
|
||||
printf '%s\n' "$VERSION"
|
||||
exit 0
|
||||
fi
|
||||
if [ "${1:-}" = "--print-codename" ] || [ "${1:-}" = "-c" ]; then
|
||||
printf '%s\n' "$CODENAME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TARGET_ROOTFS="${1:-${ROOTFS_DIR:-$BASE_DIR/rootfs}}"
|
||||
|
||||
apply_template() {
|
||||
src_tpl="$1"
|
||||
dst_file="$2"
|
||||
if [ -f "$src_tpl" ]; then
|
||||
mkdir -p "$(dirname "$dst_file")"
|
||||
sed -e "s/@GEMINUX_VERSION@/$VERSION/g" \
|
||||
-e "s/@GEMINUX_CODENAME@/$CODENAME/g" \
|
||||
"$src_tpl" > "$dst_file"
|
||||
elif [ -f "$dst_file" ]; then
|
||||
sed -i -E \
|
||||
-e "s/@GEMINUX_VERSION@/$VERSION/g" \
|
||||
-e "s/@GEMINUX_CODENAME@/$CODENAME/g" \
|
||||
"$dst_file"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -d "$TARGET_ROOTFS" ]; then
|
||||
for rel in etc/os-release usr/lib/os-release etc/issue etc/motd; do
|
||||
apply_template "$BASE_DIR/overlay/rootfs/$rel" "$TARGET_ROOTFS/$rel"
|
||||
done
|
||||
echo "Applied Geminux version $VERSION ($CODENAME) to $TARGET_ROOTFS"
|
||||
else
|
||||
printf '%s\n' "$VERSION"
|
||||
fi
|
||||
Reference in new issue
Block a user