2023-02-08 23:16:39 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-04-05 00:35:49 +02:00
|
|
|
cleanup(){
|
|
|
|
test -n "$rootfs" && test -f $rootfs && rm $rootfs
|
|
|
|
}
|
|
|
|
trap 'exit 1' INT HUP QUIT TERM ALRM USR1
|
|
|
|
trap 'cleanup' EXIT
|
|
|
|
|
2023-02-08 23:16:39 +01:00
|
|
|
usage(){
|
2023-04-05 00:35:49 +02:00
|
|
|
echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg [initramfs]"
|
2023-02-08 23:16:39 +01:00
|
|
|
echo -e "\nWithout --background, use C-p c (not C-a c) to switch to the monitor"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-09-24 22:03:26 +02:00
|
|
|
|
2023-09-20 23:53:59 +02:00
|
|
|
arch="mips"
|
|
|
|
if test "$1" = "--arch" ; then
|
|
|
|
arch=$2
|
|
|
|
shift;shift
|
|
|
|
fi
|
|
|
|
|
2022-09-24 22:03:26 +02:00
|
|
|
if test "$1" = "--background" ; then
|
2023-02-08 23:16:39 +01:00
|
|
|
statedir=$2
|
|
|
|
if test -z "$statedir" || ! test -d $statedir ; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
pid="${statedir}/pid"
|
|
|
|
socket="${statedir}/console"
|
|
|
|
monitor="${statedir}/monitor"
|
2022-09-26 11:47:29 +02:00
|
|
|
echo "running in background, socket is $socket, pid $pid"
|
2023-02-08 23:16:39 +01:00
|
|
|
flags="--daemonize --pidfile $pid -serial unix:$socket,server,nowait -monitor unix:$monitor,server,nowait"
|
2022-09-24 22:03:26 +02:00
|
|
|
shift;shift
|
|
|
|
else
|
|
|
|
flags="-serial mon:stdio"
|
|
|
|
fi
|
|
|
|
|
2023-02-08 23:16:39 +01:00
|
|
|
test -n "$2" || usage
|
|
|
|
|
2023-05-07 00:01:56 +02:00
|
|
|
lan=${LAN-"socket,mcast=230.0.0.1:1235,localaddr=127.0.0.1"}
|
|
|
|
|
2023-09-20 19:33:08 +02:00
|
|
|
rootfs=$(mktemp run-liminix-vm-fs-XXXXXX)
|
2023-04-15 18:22:35 +02:00
|
|
|
dd if=/dev/zero of=$rootfs bs=1M count=16 conv=sync
|
|
|
|
dd if=$2 of=$rootfs bs=65536 conv=sync,nocreat,notrunc
|
2023-04-05 00:35:49 +02:00
|
|
|
|
|
|
|
if test -n "$3"; then
|
|
|
|
initramfs="-initrd $3"
|
|
|
|
fi
|
|
|
|
|
2023-09-20 23:53:59 +02:00
|
|
|
case "$arch" in
|
|
|
|
mips)
|
|
|
|
QEMU="qemu-system-mips -M malta"
|
|
|
|
;;
|
|
|
|
aarch64)
|
|
|
|
QEMU="qemu-system-aarch64 -M virt -semihosting -cpu cortex-a72"
|
|
|
|
;;
|
|
|
|
esac
|
2023-02-08 23:16:39 +01:00
|
|
|
|
2023-11-05 20:13:51 +01:00
|
|
|
phram="mtdparts=phram0:16M(rootfs) phram.phram=phram0,${PHRAM_ADDRESS},16Mi,65536 root=/dev/mtdblock0";
|
|
|
|
|
2023-09-20 23:53:59 +02:00
|
|
|
set -x
|
|
|
|
$QEMU \
|
2023-11-05 20:13:51 +01:00
|
|
|
-m 272 \
|
2022-09-24 22:03:26 +02:00
|
|
|
-echr 16 \
|
2023-11-05 20:13:51 +01:00
|
|
|
-append "$CMDLINE liminix $phram" \
|
|
|
|
-device loader,file=$rootfs,addr=$PHRAM_ADDRESS \
|
2023-04-05 00:35:49 +02:00
|
|
|
${initramfs} \
|
2023-02-05 18:37:31 +01:00
|
|
|
-netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \
|
2023-05-07 00:01:56 +02:00
|
|
|
-device virtio-net,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \
|
|
|
|
-netdev ${lan},id=lan \
|
|
|
|
-device virtio-net,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \
|
2023-02-08 23:16:39 +01:00
|
|
|
-kernel $1 -display none $flags ${QEMU_OPTIONS}
|