Xen: porting Android Cuttlefish on Xen Virtual Machine

Introduction

This page gives details for how to build Android Cuttlefish running on Xen virtual machine. To give complete info, this page also gives detailed steps for building U-boot, Linux kernel, etc.

Since we don’t port Android Cuttlefish host program on Xen Dom0, we need to run Android Cuttlefish virtual machine on Arm64 Ubuntu or Debian to help us to generate Android images (initrd image, system image, SD card image, etc) and these images finally can be used when launching Xen virtual machine.

Building U-boot

  1. Download U-boot repository

$ mkdir android-u-boot && cd android-u-boot $ repo init -u https://android.googlesource.com/kernel/manifest -b u-boot-mainline $ repo sync -j32 -d
  1. Cherry pick patches for building Xen target
    The additional commits below seem to be already merged into u-boot repository:

$ cd u-boot $ git fetch https://android.googlesource.com/platform/external/u-boot refs/changes/82/2651382/1 && git cherry-pick FETCH_HEAD $ git fetch https://android.googlesource.com/platform/external/u-boot refs/changes/83/2651383/1 && git cherry-pick FETCH_HEAD $ git fetch https://android.googlesource.com/platform/external/u-boot refs/changes/84/2651384/1 && git cherry-pick FETCH_HEAD $ git fetch https://android.googlesource.com/platform/external/u-boot refs/changes/85/2651385/1 && git cherry-pick FETCH_HEAD
  1. Build U-boot binary

$ cd ../ # Change to the folder android-u-boot $ tools/bazel run //u-boot:xen_aarch64_dist --sandbox_debug --verbose_failures --compilation_mode dbg --save_temps

Finally, the U-boot binary location is out/u-boot/dist/u-boot.bin. This binary will be used by Xen virtual machine for booting system.

Building Linux kernel

  1. Download Linux kernel repository

  1. Apply patches for Android common kernel

  1. Build Linux kernel and modules

Building Android Cuttlefish target

  1. Download AOSP

  1. Cherry out Cuttlefish branch for support Xen virtual machine:
    In the instruction step below the branch xen_aosp_maintenance_20231108 should be rebased on top of main or master branch rather than being checked-out (at the time of writing this note, 20th of December 2023).

  1. Enable gatekeeper and keymint services in compatibility matrix

Then apply below change with command patch -p1 < enable_gatekeeper_keymint_services.patch:

  1. We have built Android kernel which is described in the previous section, now we need to copy kernel image and modules into AOSP:

  1. Build Android Cuttlefish images

Finally, we can get files aosp_cf_arm64_auto-img-eng.XXX.zip and cvd-host_package.tar.gz under the folder out/dist/. The first file is a tar file which includes Android images and the second file is Cuttlefish virtual machine related utilities.

Generate Android Cuttlefish images for virtual machine

After we copied files aosp_cf_arm64_auto-img-eng.leoy.zip and cvd-host_package.tar.gz on the Arm64 machine, the machine should have installed Ubunt or Debian system so it can run Android Cuttlefish virtual machine on it.

Before launch Cuttlefish virtual machine, there have some dependencies need to be installed on the system. Please refer the page Launch Cuttlefish for details.

Then run below commands for launching Android Cuttlefish virtual machines, and at the end, the Cuttlefish images are located in the folder andriod-cf/cuttlefish/instances/cvd-1/.

Â