2022-07-30 05:28:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2022-09-12 08:46:31 +00:00
|
|
|
: ${TMPDIR:=$XDG_RUNTIME_DIR}
|
|
|
|
: ${TMPDIR:=/tmp}
|
|
|
|
|
2022-08-29 07:59:56 +00:00
|
|
|
if [ "$1" == "-k" ]; then
|
|
|
|
kernel="$(realpath "$2")"
|
|
|
|
shift 2
|
|
|
|
fi
|
|
|
|
|
2022-07-30 05:28:29 +00:00
|
|
|
if [ ! -d "$1" ]; then
|
|
|
|
echo "Usage:"
|
|
|
|
echo " $0 <kernel build root> [kernel commandline] [initramfs]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
kernel_base="$(realpath "$1")"
|
|
|
|
args="$2"
|
|
|
|
initramfs=""
|
2022-08-30 12:42:16 +00:00
|
|
|
shift 2
|
|
|
|
|
2022-10-15 12:27:11 +00:00
|
|
|
if [ "$1" == "--" ]; then
|
|
|
|
shift
|
|
|
|
elif [ -n "$1" ]; then
|
2022-08-30 12:42:16 +00:00
|
|
|
initramfs="$(realpath "$1")"
|
|
|
|
shift
|
2022-07-30 05:28:29 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-29 07:59:56 +00:00
|
|
|
if [ -z "$kernel" ]; then
|
|
|
|
kernel="$kernel_base"/arch/arm64/boot/Image.gz
|
|
|
|
fi
|
|
|
|
|
2022-08-17 17:05:49 +00:00
|
|
|
base="$(dirname "$0")"
|
2022-07-30 05:28:29 +00:00
|
|
|
|
|
|
|
echo "Creating m1n1+kernel image"
|
2022-09-12 08:46:31 +00:00
|
|
|
cp "$base"/../../build/m1n1.bin "$TMPDIR/m1n1-linux.bin"
|
2022-08-29 07:59:56 +00:00
|
|
|
if [ -n "$args" ]; then
|
2022-09-12 08:46:31 +00:00
|
|
|
echo "chosen.bootargs=$args" >>"$TMPDIR/m1n1-linux.bin"
|
2022-07-30 05:28:29 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-12 08:46:31 +00:00
|
|
|
cat "$kernel_base"/arch/arm64/boot/dts/apple/*.dtb >>"$TMPDIR/m1n1-linux.bin"
|
2022-08-29 07:59:56 +00:00
|
|
|
if [[ "$kernel" == *.gz ]]; then
|
2022-09-12 08:46:31 +00:00
|
|
|
cat "$kernel" >>"$TMPDIR/m1n1-linux.bin"
|
2022-08-29 07:59:56 +00:00
|
|
|
else
|
2022-09-12 08:46:31 +00:00
|
|
|
gzip -c <"$kernel" >>"$TMPDIR/m1n1-linux.bin"
|
2022-08-29 07:59:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$initramfs" ]; then
|
2022-12-04 14:35:10 +00:00
|
|
|
initramfs_size=$(stat --printf='%s' "$initramfs")
|
2023-10-11 17:47:07 +00:00
|
|
|
python3 - << EOF >>"$TMPDIR/m1n1-linux.bin"
|
2022-12-04 14:35:10 +00:00
|
|
|
import os, sys
|
|
|
|
|
|
|
|
magic = b'm1n1_initramfs'
|
|
|
|
size = int(${initramfs_size}).to_bytes(4, byteorder='little')
|
|
|
|
os.write(sys.stdout.fileno(), magic + size)
|
|
|
|
EOF
|
2022-09-12 08:46:31 +00:00
|
|
|
cat "$initramfs" >>"$TMPDIR/m1n1-linux.bin"
|
2022-07-30 06:59:21 +00:00
|
|
|
fi
|
2022-08-29 07:59:56 +00:00
|
|
|
|
2022-07-30 05:28:29 +00:00
|
|
|
echo "Chainloading to updated m1n1..."
|
2023-10-11 17:47:07 +00:00
|
|
|
python3 "$base"/chainload.py -r "$base"/../../build/m1n1.bin
|
2022-07-30 05:28:29 +00:00
|
|
|
echo "Starting guest..."
|
2023-10-11 17:47:07 +00:00
|
|
|
exec python3 "$base"/run_guest.py \
|
2022-09-12 08:46:31 +00:00
|
|
|
-c "load_system_map('$kernel_base/System.map')" "$@" \
|
|
|
|
-r "$TMPDIR/m1n1-linux.bin"
|