From 416beb5198c424e1702f86a2bdfee8068b9d573f Mon Sep 17 00:00:00 2001 From: Jeff Peters Date: Sat, 28 Mar 2026 18:10:14 -0700 Subject: [PATCH] Adding qemu vm scripts to boot the kernel locally --- README.md | 4 ++++ tools/vamos | 12 ++++++++++ tools/vm/bash.sh | 8 +++++++ tools/vm/kill.sh | 4 ++++ tools/vm/prepare.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++ tools/vm/run.sh | 24 ++++++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100755 tools/vm/bash.sh create mode 100755 tools/vm/kill.sh create mode 100755 tools/vm/prepare.sh create mode 100755 tools/vm/run.sh diff --git a/README.md b/README.md index 7752f48a..c7a31691 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ a new operating system for comma 3X and comma four ./vamos setup # init submodules and udev rules ./vamos build kernel # build boot.img ./vamos build system # build system.img +./vamos vm prepare # init qemu package +./vamos vm bash # run bash in kernel and system +./vamos vm run # run full system and kernel +./vamos vm kill # kill qemu as system has no promt ./vamos flash kernel # flash boot.img via EDL ./vamos flash system # flash system.img via EDL ./vamos flash all # flash both diff --git a/tools/vamos b/tools/vamos index 86446841..ecdce731 100755 --- a/tools/vamos +++ b/tools/vamos @@ -40,6 +40,14 @@ case "${1:-}" in all) "$DIR/tools/flash/gpt.sh" && "$DIR/tools/flash/firmware.sh" && "$DIR/tools/flash/kernel.sh" && "$DIR/tools/flash/system.sh" ;; *) echo "Usage: vamos flash "; exit 1 ;; esac ;; + vm) + case "${2:-}" in + prepare) exec "$DIR/tools/vm/prepare.sh" ;; + bash) exec "$DIR/tools/vm/bash.sh" ;; + run) exec "$DIR/tools/vm/run.sh" ;; + kill) exec "$DIR/tools/vm/kill.sh" ;; + *) echo "Usage: vamos vm "; exit 1 ;; + esac ;; profile) shift exec "$DIR/tools/profile/rootfs.sh" "$@" ;; @@ -49,6 +57,10 @@ case "${1:-}" in echo " setup Initialize submodules and udev rules" echo " build kernel Build the kernel (output/boot.img)" echo " build system Build the system image (output/system.img)" + echo " vm prepare Prepare the VM environment using QEMU" + echo " vm bash Run a bash shell in the VM" + echo " vm run Run the VM with the built kernel and system" + echo " vm kill Kill the VM" echo " flash kernel Flash boot.img to device via EDL (--legacy for legacy kernel)" echo " flash system Flash system.img to device via EDL" echo " flash firmware Flash firmware partitions to device via EDL" diff --git a/tools/vm/bash.sh b/tools/vm/bash.sh new file mode 100755 index 00000000..494202a7 --- /dev/null +++ b/tools/vm/bash.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null && pwd)" +cd "$DIR" + +BUILD_DIR="$DIR/build" +tools/vm/run.sh "init=/bin/bash" diff --git a/tools/vm/kill.sh b/tools/vm/kill.sh new file mode 100755 index 00000000..ec3edec0 --- /dev/null +++ b/tools/vm/kill.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euox pipefail + +sudo killall -9 qemu-system-aarch64 || true diff --git a/tools/vm/prepare.sh b/tools/vm/prepare.sh new file mode 100755 index 00000000..0ab1e90c --- /dev/null +++ b/tools/vm/prepare.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null && pwd)" +cd "$DIR" + +BUILD_DIR="$DIR/build" + +# Arch Linux +if [ -f /usr/bin/pacman ]; then + sudo pacman -S --needed \ + docker \ + jq \ + docker-buildx \ + bc \ + qemu-full \ + android-tools + + if ! systemctl is-active --quiet docker.service; then + sudo systemctl start docker.service + fi + +fi + +# Ubuntu/Debian +if [ -f /usr/bin/apt ]; then + sudo apt-get install \ + jq \ + git-lfs \ + docker.io \ + docker-buildx \ + qemu-system \ + android-sdk-libsparse-utils \ + bc \ + -y + + if ! systemctl is-active --quiet docker.service; then + sudo systemctl start docker.service + fi +fi + +if ! groups "$USER" | grep -q "\bdocker\b"; then + echo "Adding $USER to docker group..." + sudo groupadd docker || true + sudo usermod -aG docker "$USER" + echo "Please log out and log back in for docker group changes to take effect." +fi + +if [ ${BUILD_DIR}/system.img -nt ${BUILD_DIR}/system_raw.img ]; then + echo "Converting system.img to raw format..." + simg2img ${BUILD_DIR}/system.img ${BUILD_DIR}/system_raw.img +else + echo "system_raw.img is up to date." +fi diff --git a/tools/vm/run.sh b/tools/vm/run.sh new file mode 100755 index 00000000..5899a0e8 --- /dev/null +++ b/tools/vm/run.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null && pwd)" +cd "$DIR" + +if [ ! -f "$DIR/build/system_raw.img" ]; then + echo "system_raw.img not found, running prepare step..." + "$DIR/tools/vm/prepare.sh" +fi + +BUILD_DIR="$DIR/build" +EXTRA_CMDLINE="${1:-}" +set -x +qemu-system-aarch64 \ + -machine virt \ + -cpu cortex-a57 \ + -smp 8 \ + -m 4G \ + -kernel ./kernel/linux/out/arch/arm64/boot/Image \ + -drive file=${BUILD_DIR}/system_raw.img,if=virtio,format=raw \ + -no-reboot \ + -append "root=/dev/vda console=ttyAMA0 loglevel=7 earlycon=pl011,0x9000000 panic=-1 ${EXTRA_CMDLINE}" \ + -nographic