summaryrefslogtreecommitdiffstats
path: root/configs/platform-x86_64/run
diff options
context:
space:
mode:
Diffstat (limited to 'configs/platform-x86_64/run')
-rwxr-xr-xconfigs/platform-x86_64/run144
1 files changed, 144 insertions, 0 deletions
diff --git a/configs/platform-x86_64/run b/configs/platform-x86_64/run
new file mode 100755
index 0000000..ad9fdcc
--- /dev/null
+++ b/configs/platform-x86_64/run
@@ -0,0 +1,144 @@
+#!/bin/bash
+
+platformconfig=$(dirname $0)/platformconfig
+#
+#
+# we need information about the platform
+#
+if [ ! -e "$platformconfig" ]; then
+ echo "error: ${platformconfig} does not exist"
+ exit 1
+fi
+
+source $platformconfig
+
+if [ -n "${PTXCONF_PLATFORM}" ]; then
+ PTXDIST_PLATFORMDIR="./platform-${PTXCONF_PLATFORM}"
+else
+ PTXDIST_PLATFORMDIR="."
+fi
+
+if [ ! -e "${PTXDIST_PLATFORMDIR}/images/linuximage" ]; then
+ echo "error: run 'ptxdist go' first"
+ exit 1
+fi
+
+# the emulator to run
+QEMU_EXEC="${PTXDIST_PLATFORMDIR}/sysroot-host/bin/qemu-system-x86_64"
+
+if [ ! -e "${QEMU_EXEC}" ]; then
+ echo "error: enable and install 'host-qemu' first"
+ exit 1
+fi
+
+# the port a 'telned' would connect to (in the emulated sysem)
+TELNET_INTERNAL_PORT=23
+# port QEMU opens at the host side to give access to the ${TELNET_INTERNAL_PORT}
+TELNET_EXTERNAL_PORT=4444
+
+# dito for ssh
+SSH_INTERNAL_PORT=22
+SSH_EXTERNAL_PORT=4445
+
+# check if vde is available for networking
+if [ -z "${VDE_SOCKET}" ]; then
+ for dir in $(ls -d /var/run/vde2/*.ctl 2>/dev/null); do
+ if [ -r "${dir}" ]; then
+ VDE_SOCKET="${dir}"
+ fi
+ done
+fi
+if [ -n "${VDE_SOCKET}" ]; then
+ # make sure qemu supports vde networking
+ if ${QEMU_EXEC} --help | grep -q -- '-net.*vde'; then
+ QEMU_NET=( -netdev vde,id=net1,sock=${VDE_SOCKET} )
+ fi
+fi
+
+# fall back to user network if necessary
+if [ -z "${QEMU_NET}" ]; then
+ QEMU_NET=(-netdev user,id=net1,hostfwd=tcp:127.0.0.1:${TELNET_EXTERNAL_PORT}-:${TELNET_INTERNAL_PORT},hostfwd=tcp:127.0.0.1:${SSH_EXTERNAL_PORT}-:${SSH_INTERNAL_PORT} )
+fi
+
+BASE_CMDLINE="console=ttyS0,115200 loglevel=5 systemd.show_status=auto"
+
+if [ -d "${PTXDIST_PLATFORMDIR}/root/.virtfs_metadata" ]; then
+ security_model="mapped-file"
+else
+ security_model="none"
+fi
+
+# Machine to emulate
+QEMU_ARGS=( -L ${PTXDIST_PLATFORMDIR}/sysroot-host/share/qemu/ -machine pc-q35-2.12 -smp 2 -cpu host -accel kvm -m 1G -s )
+# disable graphics output
+QEMU_ARGS[${#QEMU_ARGS[@]}]="-nographic"
+# Exit qemu on reboot
+QEMU_ARGS[${#QEMU_ARGS[@]}]="-no-reboot"
+# Configure networking
+QEMU_ARGS=( "${QEMU_ARGS[@]}" -net nic,netdev=net1 "${QEMU_NET[@]}" )
+# Set base time to test NTP and time handling
+QEMU_ARGS=( "${QEMU_ARGS[@]}" -rtc base=2000-01-01 )
+
+QEMU_LINUX_ARGS=( -kernel ${PTXDIST_PLATFORMDIR}/images/linuximage )
+
+check_hd() {
+ if [ ! -e "${PTXDIST_PLATFORMDIR}/images/root.ext2" ]; then
+ echo "error: root.ext2 is missing. Run 'ptxdist images' first"
+ exit 1
+ fi
+}
+
+run_qemu_hda() {
+ check_hd
+ exec ${QEMU_EXEC} \
+ "${QEMU_ARGS[@]}" \
+ -drive file=${PTXDIST_PLATFORMDIR}/images/root.ext2,if=virtio,format=raw \
+ "${QEMU_EXTRA_ARGS[@]}" \
+ "${QEMU_LINUX_ARGS[@]}" \
+ -append "root=/dev/vda console=ttyS0,115200 rw ${BASE_CMDLINE}"
+}
+
+#
+# This needs:
+# CONFIG_NET_9P_VIRTIO=y
+# CONFIG_9P_FS=y
+#
+run_qemu_9p() {
+ exec ${QEMU_EXEC} \
+ "${QEMU_ARGS[@]}" \
+ -fsdev local,id=rootfs,path=${PTXDIST_PLATFORMDIR}/root,security_model="${security_model}" \
+ -device virtio-9p-pci,fsdev=rootfs,mount_tag=/dev/root \
+ "${QEMU_EXTRA_ARGS[@]}" \
+ "${QEMU_LINUX_ARGS[@]}" \
+ -append "root=/dev/root rw rootfstype=9p rootflags=trans=virtio ${BASE_CMDLINE}"
+}
+
+# 9p net port
+P9_ROOTFS_PORT=99999
+
+run_qemu_9pnet() {
+ ROOTPATH=$(realpath ${PTXDIST_PLATFORMDIR}/root)
+ # the emulator to run
+ DIOD_EXEC="/sbin/diod"
+
+ if [ ! -e "${DIOD_EXEC}" ]; then
+ echo "error: apt-get install 'diod' first"
+ exit 1
+ fi
+
+ ${DIOD_EXEC} -f -n -S -l 127.0.0.1:${P9_ROOTFS_PORT} -e ${ROOTPATH} &
+ # this is an ugly workaround so diod will be closed after qemu has stopped
+ DIOD_PID=$(echo $!)
+ (tail --pid $$ -f /dev/null; kill ${DIOD_PID}) &
+
+ exec ${QEMU_EXEC} \
+ "${QEMU_ARGS[@]}" \
+ "${QEMU_EXTRA_ARGS[@]}" \
+ "${QEMU_LINUX_ARGS[@]}" \
+ -append "ip=dhcp root=10.0.2.2 rw rootfstype=9p rootflags=trans=tcp,version=9p2000.L,aname=${ROOTPATH},port=${P9_ROOTFS_PORT} ${BASE_CMDLINE} ${EXTRA_CMDLINE}"
+}
+
+target="${1:-9p}"
+
+#set -x
+run_qemu_${target}