Makefile 2.4 KB

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