Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tools/vamos
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kernel|system|firmware|gpt|all>"; 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 <prepare|bash|run|kill>"; exit 1 ;;
esac ;;
profile)
shift
exec "$DIR/tools/profile/rootfs.sh" "$@" ;;
Expand All @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tools/vm/bash.sh
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions tools/vm/kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euox pipefail

sudo killall -9 qemu-system-aarch64 || true
54 changes: 54 additions & 0 deletions tools/vm/prepare.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tools/vm/run.sh
Original file line number Diff line number Diff line change
@@ -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
Loading