From f0678f1e5b244603ee6e86c2ac5feed60220da6b Mon Sep 17 00:00:00 2001 From: cloudwithax Date: Tue, 17 Feb 2026 17:31:42 -0500 Subject: [PATCH] feat: replace Alpine mkinitfs with minimal ALARM-compatible initrd Co-Authored-By: Claude Opus 4.6 --- scripts/mkinitrd.sh | 54 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/scripts/mkinitrd.sh b/scripts/mkinitrd.sh index 28006b3..741df8c 100755 --- a/scripts/mkinitrd.sh +++ b/scripts/mkinitrd.sh @@ -1,7 +1,51 @@ #!/bin/bash +# Create a minimal initramfs for the stock H700 kernel. +# The stock kernel has most drivers built-in, so we just need +# a minimal init that mounts rootfs and exec's /sbin/init. +set -e -podman run --arch=arm64 --security-opt=label=disable \ - -v "${2:-./artifacts}:/artifacts" \ - -v ./mkinitfs.conf:/tmp/mkinitfs.conf:ro \ - --rm "docker.io/library/alpine:${1:-latest}" \ - sh -c "apk update && apk add mkinitfs apk-tools && mkinitfs -c /tmp/mkinitfs.conf -n -o /artifacts/initramfs" +outdir="${1:-./artifacts}" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' 0 + +mkdir -p "$tmp"/{bin,dev,proc,sys,newroot} + +# Use busybox from host or build a static one +# For now, create a minimal shell init script +cat > "$tmp/init" << 'INITEOF' +#!/bin/busybox sh +/bin/busybox mount -t proc none /proc +/bin/busybox mount -t sysfs none /sys +/bin/busybox mount -t devtmpfs none /dev + +# Find the root partition (partition 5 = rootfs) +root="" +for dev in /dev/mmcblk0p5 /dev/mmcblk0p4; do + if [ -b "$dev" ]; then + root="$dev" + break + fi +done + +if [ -z "$root" ]; then + echo "Cannot find root partition!" + /bin/busybox sh +fi + +/bin/busybox mount -t ext4 "$root" /newroot +exec /bin/busybox switch_root /newroot /sbin/init +INITEOF +chmod +x "$tmp/init" + +# Get a static busybox for aarch64 +if [ ! -f "$outdir/busybox" ]; then + podman run --arch=aarch64 --security-opt=label=disable \ + -v "$(realpath "$outdir"):/out" \ + --rm "docker.io/library/alpine:latest" \ + sh -c "apk add busybox-static && cp /bin/busybox.static /out/busybox" +fi +cp "$outdir/busybox" "$tmp/bin/busybox" +chmod +x "$tmp/bin/busybox" + +# Create initramfs +(cd "$tmp" && find . | cpio -o -H newc 2>/dev/null | gzip > "$outdir/initramfs")