Skip to end of banner
Go to start of banner

Xen: porting Android Cuttlefish on Xen Virtual Machine

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

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

$ 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

$ mkdir android-kernel && cd android-kernel
$ repo init -u https://android.googlesource.com/kernel/manifest -b common-android-mainline
$ repo sync -j32 -d
  1. Apply patches for Android common kernel

# Download the two patches:
#  0001-ANDROID-GKI-Support-Arm64-Android-on-Xen-virtual-mac.patch
#  0002-Configs-disable-UBSAN.patch                               
$ cd common
$ git am 0001-ANDROID-GKI-Support-Arm64-Android-on-Xen-virtual-mac.patch
$ git am 0002-Configs-disable-UBSAN.patch
  1. Build Linux kernel and modules

$ cd ../  # Change to the folder android-kernel

# Build kernel and modules with 16KiB page size
$ tools/bazel run //common-modules/virtual-device:virtual_device_aarch64_16k_dist --sandbox_debug --verbose_failures
$ tools/bazel run //common:kernel_aarch64_16k_dist --sandbox_debug --verbose_failures

# Build kernel and modules with default page size (4KiB)
$ tools/bazel run //common-modules/virtual-device:virtual_device_aarch64_dist --sandbox_debug --verbose_failures
$ tools/bazel run //common:kernel_aarch64_dist --sandbox_debug --verbose_failures

Building Android Cuttlefish target

  1. Download AOSP

$ mkdir aosp_master
$ cd aosp_master
$ repo init -u https://android.googlesource.com/platform/manifest -b master
$ repo sync -j8
  1. Cherry out Cuttlefish branch for support Xen virtual machine:

$ cd device/google/cuttlefish
$ git remote add aosp_xen https://gitlab.com/Linaro/blueprints/automotive/xen-aosp/cuttlefish.git
$ git fetch aosp_xen
$ git checkout -b xen_aosp_maintenance_20231108 aosp_xen/xen_aosp_maintenance_20231108 
  1. Enable gatekeeper and keymint services in compatibility matrix

$ cd hardware/interfaces/

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

diff --git a/compatibility_matrices/compatibility_matrix.9.xml b/compatibility_matrices/compatibility_matrix.9.xml
index e23f2aec1..c1d5ad5ea 100644
--- a/compatibility_matrices/compatibility_matrix.9.xml
+++ b/compatibility_matrices/compatibility_matrix.9.xml
@@ -253,6 +253,14 @@
             <instance>default</instance>
         </interface>
     </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.gatekeeper</name>
+        <version>1.0</version>
+        <interface>
+            <name>IGatekeeper</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
     <hal format="aidl" optional="true">
         <name>android.hardware.gatekeeper</name>
         <version>1</version>
@@ -394,6 +402,23 @@
             <instance>default</instance>
         </interface>
     </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.keymaster</name>
+        <version>3.0</version>
+        <version>4.0-1</version>
+        <interface>
+            <name>IKeymasterDevice</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.keymaster</name>
+        <version>4.0-1</version>
+        <interface>
+            <name>IKeymasterDevice</name>
+            <instance>strongbox</instance>
+        </interface>
+    </hal>
     <hal format="aidl" optional="true">
         <name>android.hardware.security.keymint</name>
         <version>1-3</version>
  1. We have built Android kernel which is described in the previous section, now we need to copy kernel image and modules into AOSP:

$ cd /path/to/android-kernel
$ export AOSP_DIR="/path/to/android-master"
$ rm -rf $AOSP_DIR/kernel/prebuilts/common-modules/virtual-device/mainline/arm64/*
$ rm -rf $AOSP_DIR/kernel/prebuilts/mainline/arm64/*
$ mkdir $AOSP_DIR/kernel/prebuilts/common-modules/virtual-device/mainline/arm64/16k
$ mkdir $AOSP_DIR/kernel/prebuilts/mainline/arm64/16k
$ cp -r out/virtual_device_aarch64_16k/dist/* $AOSP_DIR/kernel/prebuilts/common-modules/virtual-device/mainline/arm64/16k/
$ cp -r out/kernel_aarch64_16k/dist/* $AOSP_DIR/kernel/prebuilts/mainline/arm64/16k/
$ cp -r out/virtual_device_aarch64/dist/* $AOSP_DIR/kernel/prebuilts/common-modules/virtual-device/mainline/arm64/
$ cp -r out/kernel_aarch64/dist/* $AOSP_DIR/kernel/prebuilts/mainline/arm64/
$ mv $AOSP_DIR/kernel/prebuilts/mainline/arm64/Image $AOSP_DIR/kernel/prebuilts/mainline/arm64/kernel-mainline
$ mv $AOSP_DIR/kernel/prebuilts/mainline/arm64/16k/Image $AOSP_DIR/kernel/prebuilts/mainline/arm64/16k/kernel-mainline
  1. Build Android Cuttlefish images

$ cd /path/to/android-master

# Setup building environment
$ . build/envsetup.sh

# Older AOSP code base might need to lunch the target
# 'aosp_cf_arm64_auto-userdebug'. This target is obsolete
# on the AOSP master branch and you should use the target
# 'aosp_cf_arm64_auto-trunk_staging-userdebug' if you are
# working on a new enough AOSP master branch.

$ lunch aosp_cf_arm64_auto-trunk_staging-userdebug

# Build AOSP with mainline kernel
$ make TARGET_KERNEL_USE=mainline -j16

# Generate the release images
$ make TARGET_KERNEL_USE=mainline dist -j16

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/.

$ mkdir android-cf
$ cd android-cf
$ unzip /path/to/aosp_cf_arm64_auto-img-eng.leoy.zip
$ tar zxvf /path/to/cvd-host_package.tar.gz
$ HOME=$PWD ./bin/launch_cvd --vm_manager=qemu_cli --daemon -console=true

  • No labels