Abstract
This documentation describes how to use the primitive commands for generating Android images and running Android on virtual platform. In the end, we can see how to directly run Android Automotive OS on Xen virtual machine with QEMU command.
What’s Cuttlefish flow?
Cuttlefish allows user to use command line interface (CLI) to launch Android images on Cuttlefish virtual platform, it provides the command launch_cvd
for this purpose.
The prerequisites for using the launch_cvd
is Cuttlefish package. The package contains binaries and utilites. We can download the Cuttlefish package for Arm64 via http://ci.android.com/, then search the branch aosp-main-throttled
and select the device target aosp_cf_arm64_only_phone-trunk_staging-userdebug
.
After downloading and uncompress the Cuttlefish package, combining with Android images, we can execute the launch_cvd
command to boot up Android on Cuttlefish:
$ HOME=$PWD ./bin/launch_cvd
The launch_cvd
command rus two commands assemble_cvd
and run_cvd
in its child processes. If both commands work as expected, the Android can launch successfully on Cuttlefish machine. The assemble_cvd
command generates root file system images with qcow2 overlay format, then the run_cvd
command invokes the virtual machine manager (either Crosvm or QEMU) to boot the generated images on virtual machine. The diagram below shows the Cuttlefish flow.
Using assemble_cvd
Let’s we assume we work on TRS and want to run Android Automotive OS on Xen virtual machine, in this case, it’s likely we cannot directly use launch_cvd
command for launching Xen virtual machine. Then we need to use assumble_cvd
command to help us to generate file system images, and we can execute QEMU command to launch Xen virtual machine. This is why we need to understand how to use assumble_cvd
command.
If directly run assumble_cvd
command, you will receive an error log and the program exits abnormaly:
leoy@leoy-yangtze:~/Dev2/aosp_cuttlefish_test/cf$ HOME=$PWD ./bin/assemble_cvd 12-22 15:53:35.219 665720 665720 E assemble_cvd: assemble_cvd.cc:571 assemble_cvd failed: 12-22 15:53:35.219 665720 665720 E assemble_cvd: assemble_cvd.cc:571 | device/google/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc:484 12-22 15:53:35.219 665720 665720 E assemble_cvd: assemble_cvd.cc:571 | Result<int> cuttlefish::AssembleCvdMain(int, char **) 12-22 15:53:35.219 665720 665720 E assemble_cvd: assemble_cvd.cc:571 v CF_EXPECT(tty == 0) 12-22 15:53:35.219 665720 665720 E assemble_cvd: assemble_cvd.cc:571 stdin was a tty, expected to be passed the output of a previous stage. Did you mean to run launch_cvd? Aborted
The log reminds user to invoke launch_cvd
instead of the assemble_cvd
command. But this doesn’t mean we really cannot run assemble_cvd
command directly. Alternatively, we can save what’s the command and arguments into a shell script (we named it as test.sh
):
HOME=$PWD ./bin/assemble_cvd --group_id=cvd_1 --report_anonymous_usage_stats=y --vm_manager=qemu_cli --webrtc_device_id=cvd_1-1 --gpu_mode=drm_virgl
Then we can use the to launch the shell script with below command. This command can help use to close stdin and direct the stdout to the pipe :
true | sh test.sh 2>&1 | cat
Using run_cvd
Same as the assemble_cvd
command, it prevents to directly run the run_cvd
command. If we want to directly execute it, we can use the command:
$ true | HOME=$PWD ./bin/run_cvd 2>&1 | cat
run_cvd
manages backend programs internally for emulating virtual devices (e.g. for WiFi, secure devices, etc), after the configurations for the emulation, it launches VMM (QEMU or Crosvm) to kick off virtual machine instance.