Skip to content

Add run-emulator.sh for one-command QEMU launch#337

Closed
KonTy wants to merge 1 commit into
AsteroidOS:2.0from
KonTy:emulator-launch-script
Closed

Add run-emulator.sh for one-command QEMU launch#337
KonTy wants to merge 1 commit into
AsteroidOS:2.0from
KonTy:emulator-launch-script

Conversation

@KonTy
Copy link
Copy Markdown

@KonTy KonTy commented Apr 14, 2026

Adds a script that builds the emulator image if needed and launches it with the right QEMU flags so it boots straight into the AsteroidOS watch UI.

It detects the best available display backend (GTK or SDL with virgl), enables KVM when possible, and forwards SSH to localhost:2222.

The key thing it does is use virtio-vga-gl as the sole GPU instead of the default setup which creates two display devices and ends up showing a text login instead of the UI.

Usage: ./run-emulator.sh

Related PRs:

Comment thread run-emulator.sh Outdated
Comment thread run-emulator.sh Outdated
Comment thread run-emulator.sh Outdated
Comment thread run-emulator.sh Outdated
Comment thread run-emulator.sh
Comment thread run-emulator.sh
GPU_DEVICE=""

if echo "${DISPLAY_BACKENDS}" | grep -q '^gtk$'; then
DISPLAY_OPT="-display gtk,gl=on,show-cursor=on"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does that all overlap with the changes you introduced in https://github.com/AsteroidOS/meta-smartwatch/pull/299/changes ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emulator.conf sets QB_GRAPHICS and QB_OPT_APPEND which are used by Yocto's runqemu script. This run-emulator.sh is a standalone launcher that doesn't source the OE environment, so it needs the same GPU/display flags directly. Added a comment explaining this -- the flags intentionally mirror emulator.conf so behavior is the same either way.

Comment thread run-emulator.sh Outdated

if [ ! -f "${OE_INIT}" ]; then
error "OE init script not found at ${OE_INIT}"
error "Run prepare-build.sh emulator first to fetch sources."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not run prepare-build.sh instead of OE_INIT ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -- build_image() now runs prepare-build.sh emulator first, which handles fetching sources and setting up build/conf. Then sources oe-init-build-env and runs bitbake.

Comment thread run-emulator.sh Outdated
LAUNCH_ONLY=false

case "${1:-}" in
--build) FORCE_BUILD=true ;;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those flags would be a lot more explicit if they were named --force-build and --launch-only.

Otherwise I'd expect ./run-emulator.sh --build --launch to build and launch

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -- renamed to --force-build and --launch-only.

@KonTy
Copy link
Copy Markdown
Author

KonTy commented Apr 14, 2026

@FlorentRevest thanks a lot for good comments and questions, Yes I did use a lot of examples, and copied things, sorry I'm just learning things so thank you for pointing things out. I will go through them today when I come back from work.

Builds the emulator image if needed and launches it with the right
QEMU flags so it boots straight into the AsteroidOS watch UI. Detects
the best available display backend (GTK or SDL with virgl), enables
KVM when possible, and forwards SSH to localhost:2222.

Usage: ./run-emulator.sh
@KonTy KonTy force-pushed the emulator-launch-script branch from 5e05702 to c7158da Compare April 15, 2026 04:49
@KonTy
Copy link
Copy Markdown
Author

KonTy commented Apr 15, 2026

Addressed all review comments and force-pushed:

  • Removed telnet port 23 forward (nothing starts telnetd)
  • -cpu host when KVM is on, -cpu IvyBridge as fallback
  • Cleaned kernel cmdline to just root=/dev/vda rw ip=dhcp (removed mem=512M, oprofile, rcu, tsc, swiotlb)
  • Error message now suggests bitbake qemu-helper-native instead of distro packages
  • Added comment explaining qemu-system-i386 is correct (image is core2-32)
  • Added comment explaining GPU flags mirror emulator.conf QB_GRAPHICS
  • build_image() now runs prepare-build.sh emulator first
  • Renamed --build/--launch to --force-build/--launch-only
  • Removed debug QMP socket

Tested: emulator boots, SSH works on port 2222.

@FlorentRevest
Copy link
Copy Markdown
Member

I'm a bit surprises the emulated image is i386. @casept iirc you looked into this last, do you remember why that's the case ?

@FlorentRevest
Copy link
Copy Markdown
Member

@KonTy could you explain better why you think this script is necessary and yocto's "runqemu" script isn't enough ?

@casept
Copy link
Copy Markdown
Contributor

casept commented Apr 15, 2026

I'm a bit surprises the emulated image is i386. @casept iirc you looked into this last, do you remember why that's the case ?

I think there's no good reason, just historical I guess. I left it as found, but it'd probably be trivial to make it 64-bit.

@FlorentRevest
Copy link
Copy Markdown
Member

Okay let's keep the x86_64 conversion for later but I think we probably want to do that

@KonTy
Copy link
Copy Markdown
Author

KonTy commented Apr 18, 2026

@KonTy could you explain better why you think this script is necessary and yocto's "runqemu" script isn't enough ?

@FlorentRevest runqemu lacks SSH port forwarding in slirp mode and doesn't handle post-boot KMS patching. If we really want to make QEMU iamges useful for developement this is really needed. I can see if I can refactor the scrpt to delegate QEMU flags to runqemu where possible, ŭt the rapper is still needed for networking and KMS.

@KonTy KonTy closed this Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants