• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23CARGO_TARGET=$(shell cargo metadata --no-deps --format-version 1 | \
24	jq -r ".target_directory")
25TARGET=/tmp/crosvm_tools/$(ARCH)
26$(shell mkdir -p $(TARGET))
27
28ifeq ($(ARCH), x86_64)
29  DEBIAN_ARCH=amd64
30  QEMU_CMD=qemu-system-x86_64 \
31		-cpu host \
32		-enable-kvm
33else ifeq ($(ARCH), aarch64)
34  DEBIAN_ARCH=arm64
35  QEMU_CMD=qemu-system-aarch64 \
36		-cpu cortex-a57 \
37		-M virt \
38		-bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd
39else
40  $(error Only x86_64 or aarch64 are supported)
41endif
42
43GS_PREFIX=gs://crosvm/testvm
44DEBIAN_URL=https://cloud.debian.org/images/cloud/bookworm/daily/20220912-1136/
45
46BASE_IMG_NAME=base-$(ARCH)-$(shell cat version).qcow2
47GS_URL=$(GS_PREFIX)/$(BASE_IMG_NAME)
48LOCAL_IMAGE=$(TARGET)/$(BASE_IMG_NAME)
49
50all: $(LOCAL_IMAGE)
51
52clean:
53	rm -rf $(TARGET)
54
55# Upload images to cloud storage. Do not overwrite existing images, uprev
56# `image_version` instead.
57upload: $(LOCAL_IMAGE)
58	gsutil cp -n $(LOCAL_IMAGE) $(GS_URL)
59
60# Download debian bullseye as base image for the testvm.
61$(TARGET)/debian.qcow2:
62	wget $(DEBIAN_URL)/debian-12-generic-$(DEBIAN_ARCH)-daily-20220912-1136.qcow2 -O $@
63	qemu-img resize $@ 4G
64
65# The cloud init file contains instructions for how to set up the VM when it's
66# first booted.
67$(TARGET)/clould_init.img: cloud_init.yaml
68	cloud-localds -v $@ $<
69
70# Boot image to run through clould-init process.
71# cloud-init will shut down the VM after initialization. Compress the image
72# afterwards for distribution.
73$(LOCAL_IMAGE): $(TARGET)/clould_init.img $(TARGET)/debian.qcow2
74	cp -f $(TARGET)/debian.qcow2 $@
75	$(QEMU_CMD) \
76		-m 4G -smp 8 \
77		-display none \
78		-serial stdio \
79		-drive file=$@,format=qcow2,index=0,media=disk \
80		-drive file=$(TARGET)/clould_init.img,format=raw,index=1,media=disk
81	qemu-img convert -O qcow2 -c $@ $@-compressed
82	mv -f $@-compressed $@
83