mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 18:38:01 +00:00
af0144e51b
We need to download a base image anyway, so we might as well make that a full prebuilt of our VM image. This makes the initial startup of ./tools/aarch64vm significantly faster. It also makes it easier to add the prebuilt into a Docker dev container later. Also move the VM data into the cargo target dir so we do not dirty the src dir. A Makefile for building and uploading the prebuilt has been added. This change also moved the testvm code from ./tools/testvm into ./tools/impl so the python code can be shared with future scripts (relative imports from other folders are tricky in Python). BUG=b:199951064 TEST=./tools/aarch64vm ssh Change-Id: I3fb57bfb8f7330b765e9be5ded821615ecddd841 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3221704 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dennis Kempin <denniskempin@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
81 lines
2.4 KiB
Makefile
81 lines
2.4 KiB
Makefile
# Copyright 2021 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
#
|
|
# Builds the base image for test VMs used by ./tools/x86vm and
|
|
# ./tools/aarch64vm.
|
|
#
|
|
# To build and upload a new base image, uprev the version in the `version` file
|
|
# and run:
|
|
#
|
|
# make ARCH=x86_64 upload
|
|
# make ARCH=aarch64 upload
|
|
#
|
|
# You need write access to the crosvm-testvm storage bucket which is part of the
|
|
# crosvm-packages cloud project.
|
|
#
|
|
# Note: The locally built image is stored in the same place that testvm.py
|
|
# expects. So the image can be tested directly:
|
|
#
|
|
# make -C tools/impl/testvm ARCH=x86_64
|
|
# ./tools/x86vm run
|
|
|
|
CARGO_TARGET=$(shell cargo metadata --no-deps --format-version 1 | \
|
|
jq -r ".target_directory")
|
|
TARGET=$(CARGO_TARGET)/crosvm_tools/$(ARCH)
|
|
$(shell mkdir -p $(TARGET))
|
|
|
|
ifeq ($(ARCH), x86_64)
|
|
DEBIAN_ARCH=amd64
|
|
QEMU_CMD=qemu-system-x86_64 \
|
|
-cpu Broadwell \
|
|
-enable-kvm
|
|
else ifeq ($(ARCH), aarch64)
|
|
DEBIAN_ARCH=arm64
|
|
QEMU_CMD=qemu-system-aarch64 \
|
|
-cpu cortex-a57 \
|
|
-M virt \
|
|
-bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd
|
|
else
|
|
$(error Only x86_64 or aarch64 are supported)
|
|
endif
|
|
|
|
GS_PREFIX=gs://crosvm-testvm
|
|
DEBIAN_URL=https://cloud.debian.org/images/cloud/bullseye/latest
|
|
|
|
BASE_IMG_NAME=base-$(ARCH)-$(shell cat version).qcow2
|
|
GS_URL=$(GS_PREFIX)/$(BASE_IMG_NAME)
|
|
LOCAL_IMAGE=$(TARGET)/$(BASE_IMG_NAME)
|
|
|
|
all: $(LOCAL_IMAGE)
|
|
|
|
clean:
|
|
rm -rf $(TARGET)
|
|
|
|
# Upload images to cloud storage. Do not overwrite existing images, uprev
|
|
# `image_version` instead.
|
|
upload: $(LOCAL_IMAGE)
|
|
gsutil cp -n $(LOCAL_IMAGE) $(GS_URL)
|
|
|
|
# Download debian bullseye as base image for the testvm.
|
|
$(TARGET)/debian.qcow2:
|
|
wget $(DEBIAN_URL)/debian-11-generic-$(DEBIAN_ARCH).qcow2 -O $@
|
|
|
|
# The cloud init file contains instructions for how to set up the VM when it's
|
|
# first booted.
|
|
$(TARGET)/clould_init.img: cloud_init.yaml
|
|
cloud-localds -v $@ $<
|
|
|
|
# Boot image to run through clould-init process.
|
|
# cloud-init will shut down the VM after initialization. Compress the image
|
|
# afterwards for distribution.
|
|
$(LOCAL_IMAGE): $(TARGET)/clould_init.img $(TARGET)/debian.qcow2
|
|
cp -f $(TARGET)/debian.qcow2 $@
|
|
$(QEMU_CMD) \
|
|
-m 4G -smp 8 \
|
|
-display none \
|
|
-serial stdio \
|
|
-hda $@ \
|
|
-drive file=$(TARGET)/clould_init.img,format=raw,index=1,media=disk
|
|
qemu-img convert -O qcow2 -c $@ $@-compressed
|
|
mv -f $@-compressed $@
|