1# Copyright 2021 The ChromiumOS Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4# 5# Builds the base image for test VMs used by ./tools/x86vm and 6# ./tools/aarch64vm. 7# 8# To build and upload a new base image, uprev the version in the `version` file 9# and run: 10# 11# make ARCH=x86_64 upload 12# make ARCH=aarch64 upload 13# 14# You need write access to the crosvm-testvm storage bucket which is part of the 15# crosvm-packages cloud project. 16# 17# Note: The locally built image is stored in the same place that testvm.py 18# expects. So the image can be tested directly: 19# 20# make -C tools/impl/testvm ARCH=x86_64 21# ./tools/x86vm run 22 23# Follow same logic to store artifacts as tools/impl/testvm.py 24TMPDIR?=/tmp 25CROSVM_CACHE_DIR?=$(TMPDIR) 26TARGET=$(CROSVM_CACHE_DIR)/crosvm_tools/$(ARCH) 27$(shell mkdir -p $(TARGET)) 28 29ifeq ($(ARCH), x86_64) 30 DEBIAN_ARCH=amd64 31 QEMU_CMD=qemu-system-x86_64 \ 32 -cpu host \ 33 -enable-kvm 34else ifeq ($(ARCH), aarch64) 35 DEBIAN_ARCH=arm64 36 QEMU_CMD=qemu-system-aarch64 \ 37 -cpu cortex-a57 \ 38 -M virt \ 39 -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd 40else 41 $(error Only x86_64 or aarch64 are supported) 42endif 43 44GS_PREFIX=gs://crosvm/testvm 45DEBIAN_URL=https://cloud.debian.org/images/cloud/trixie/daily/latest/ 46 47BASE_IMG_NAME=base-$(ARCH)-$(shell cat version).qcow2 48GS_URL=$(GS_PREFIX)/$(BASE_IMG_NAME) 49LOCAL_IMAGE=$(TARGET)/$(BASE_IMG_NAME) 50 51all: $(LOCAL_IMAGE) 52 53clean: 54 rm -rf $(TARGET) 55 56# Upload images to cloud storage. Do not overwrite existing images, uprev 57# `image_version` instead. 58upload: $(LOCAL_IMAGE) 59 gsutil cp -n $(LOCAL_IMAGE) $(GS_URL) 60 61# Download debian bullseye as base image for the testvm. 62$(TARGET)/debian.qcow2: 63 wget $(DEBIAN_URL)/debian-13-generic-$(DEBIAN_ARCH)-daily.qcow2 -O $@.tmp 64 qemu-img resize $@.tmp 8G 65 mv $@.tmp $@ 66 67# The cloud init file contains instructions for how to set up the VM when it's 68# first booted. 69$(TARGET)/clould_init.img: cloud_init.yaml 70 cloud-localds -v $@ $< 71 72# Boot image to run through clould-init process. 73# cloud-init will shut down the VM after initialization. Compress the image 74# afterwards for distribution. 75$(LOCAL_IMAGE): $(TARGET)/clould_init.img $(TARGET)/debian.qcow2 76 cp -f $(TARGET)/debian.qcow2 $@ 77 $(QEMU_CMD) \ 78 -m 4G -smp 8 \ 79 -display none \ 80 -serial stdio \ 81 -drive file=$@,format=qcow2,index=0,media=disk \ 82 -drive file=$(TARGET)/clould_init.img,format=raw,index=1,media=disk 83 qemu-img convert -O qcow2 -c $@ $@-compressed 84 mv -f $@-compressed $@ 85