From e203271e1d17082c489211bcca656dae9bd7e378 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Sun, 12 Oct 2025 15:00:28 -0700 Subject: [PATCH] boot improvements and acceleration --- hack/autofix.sh | 12 ++---------- hack/boot.sh | 39 ++++++++++++++++++++++++++++++--------- hack/common.sh | 13 ++++++++++++- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/hack/autofix.sh b/hack/autofix.sh index 649d1d3..9222969 100755 --- a/hack/autofix.sh +++ b/hack/autofix.sh @@ -3,15 +3,7 @@ set -e cd "$(dirname "${0}")/.." || exit 1 -NATIVE_ARCH="$(uname -m)" -[ "${NATIVE_ARCH}" = "arm64" ] && NATIVE_ARCH="aarch64" -[ "${NATIVE_ARCH}" = "amd64" ] && NATIVE_ARCH="x86_64" - -if [ "$(uname)" != "Linux" ]; then - cargo clippy --workspace --fix --allow-dirty --allow-staged \ - --target "${NATIVE_ARCH}-unknown-uefi" -else - cargo clippy --workspace --fix --allow-dirty --allow-staged -fi +. "hack/common.sh" +cargo clippy --workspace --fix --allow-dirty --allow-staged --target "${HOST_ARCH}-unknown-uefi" ./hack/format.sh diff --git a/hack/boot.sh b/hack/boot.sh index 3494d9a..b31ad6e 100755 --- a/hack/boot.sh +++ b/hack/boot.sh @@ -5,31 +5,52 @@ cd "$(dirname "${0}")/.." || exit 1 . "hack/common.sh" -./hack/build.sh "${TARGET_ARCH}" "${RUST_PROFILE}" +if [ "${SKIP_BUILD}" != "1" ]; then + ./hack/build.sh "${TARGET_ARCH}" "${RUST_PROFILE}" +fi clear set -- - if [ "${TARGET_ARCH}" = "x86_64" ]; then set -- "${@}" qemu-system-x86_64 -M q35 elif [ "${TARGET_ARCH}" = "aarch64" ]; then set -- "${@}" qemu-system-aarch64 -M virt -cpu cortex-a57 fi +if [ -n "${QEMU_ACCEL}" ]; then + set -- "${@}" "-accel" "kvm" +fi + +if [ "${QEMU_GDB}" = "1" ]; then + set -- "${@}" "-s" +fi + +if [ "${QEMU_GDB_WAIT}" = "1" ]; then + set -- "${@}" "-S" +fi + set -- "${@}" -smp 2 -m 4096 if [ "${NO_GRAPHICAL_BOOT}" = "1" ]; then set -- "${@}" -nographic else - set -- "${@}" \ - -device virtio-serial-pci,id=vs0 \ - -chardev stdio,id=stdio0 \ - -device virtconsole,chardev=stdio0,id=console0 + if [ "${QEMU_LEGACY_SERIAL}" = "1" ]; then + set -- "${@}" -serial stdio + else + set -- "${@}" \ + -device virtio-serial-pci,id=vs0 \ + -chardev stdio,id=stdio0 \ + -device virtconsole,chardev=stdio0,id=console0 + fi - set -- "${@}" \ - -vga none \ - -device "virtio-gpu,edid=on,xres=1024,yres=768" + if [ "${QEMU_LEGACY_VGA}" = "1" ]; then + set -- "${@}" -vga std + else + set -- "${@}" \ + -vga none \ + -device "virtio-gpu,edid=on,xres=1024,yres=768" + fi fi rm -f "${FINAL_DIR}/ovmf-boot.fd" diff --git a/hack/common.sh b/hack/common.sh index a966ce2..0a165e4 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -6,8 +6,13 @@ DOCKER_PREFIX="ghcr.io/edera-dev/sprout" DEFAULT_RUST_PROFILE="release" DEFAULT_DOCKER_TAG="latest" +HOST_ARCH="$(uname -m)" + +[ "${HOST_ARCH}" = "arm64" ] && HOST_ARCH="aarch64" +[ "${HOST_ARCH}" = "amd64" ] && HOST_ARCH="x86_64" + [ -z "${TARGET_ARCH}" ] && TARGET_ARCH="${1}" -{ [ -z "${TARGET_ARCH}" ] || [ "${TARGET_ARCH}" = "native" ]; } && TARGET_ARCH="$(uname -m)" +{ [ -z "${TARGET_ARCH}" ] || [ "${TARGET_ARCH}" = "native" ]; } && TARGET_ARCH="${HOST_ARCH}" [ -z "${RUST_PROFILE}" ] && RUST_PROFILE="${2}" [ -z "${RUST_PROFILE}" ] && RUST_PROFILE="${DEFAULT_RUST_PROFILE}" @@ -29,3 +34,9 @@ RUST_TARGET="${TARGET_ARCH}-unknown-uefi" [ -z "${DOCKER_TAG}" ] && DOCKER_TAG="${DEFAULT_DOCKER_TAG}" DOCKER_TARGET="linux/${TARGET_ARCH}" FINAL_DIR="target/final/${TARGET_ARCH}" + +if [ -z "${QEMU_ACCEL}" ] && [ "${TARGET_ARCH}" = "${HOST_ARCH}" ] && + [ -f "/proc/cpuinfo" ] && + grep -E '^flags.*:.+ vmx .*' /proc/cpuinfo >/dev/null; then + QEMU_ACCEL="kvm" +fi