#!/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 outdir="${1:-./artifacts}" mkdir -p "$outdir" 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")