How to install and use KVM within AGL on a mixed-critical Renesas R-Car M3
Virtual Open Systems originates AGL EG-VIRT
Virtual Open Systems is actively contributing in the Automotive Grade Linux (AGL) community to enable open source virtualization functionalities. The company has originated within AGL a specific Virtualization Expert Group (EG-VIRT), it is leading the community code contributions and bi-weekly telco meetings.
At the Automotive Linux Summit 2017 (ALS-2017), Virtual Open Systems has demonstrated the integration with AGL of its VOSYSmonitor mixed-criticality virtualization product, it has shared with the community a specific EG-VIRT presentation and a published article Virtualization: The Smart-Connected Vehicle Enabler.
One of the first code contributions of Virtual Open Systems for AGL virtualization has been to enable KVM hypervisor on the Renesas R-Car M3 with a shared patch Enable Linux-based hypervisor execution in AGL, which has been merged in the upstream codebase of the AGL meta-rcar-gen3 yocto layer.
This guide shows how to run KVM virtual machines (VMs) on AGL based on this shared patch, in accordance with the architecture overview in the following figure.
Figure 1 - Architecture overview
In section 1, the AGL distribution for R-Car M3 will be downloaded and compiled; in section 2, a static QEMU binary will be created together with the guest kernel/rootfs (Section 3). Finally, in section 4 a new Ubuntu guest will be executed in AGL.
This guide does not require graphics, all the commands and the VM can be run from command line through a terminal or serial/SSH connection.
1. Build AGL with Virtual Open Systems KVM patch
The KVM support for Renesas R-Car M3 is integrated in the open source AGL distribution. Therefore, a standard AGL build for the R-Car M3 can be used for the purpose of this guide.
The AGL community provides step by step instructions to build a new image for Renesas R-Car M3 and R-Car H3. It has to be paid attention to download the AGL "Master Branch" in the download AGL source code and to target m3ulcb machine type in the section "Build for R Car Starter Kit gen3", as it is done in the following example:
$ repo init -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo
$ repo sync
$ source meta-agl/scripts/aglsetup.sh -m m3ulcb -b build agl-devel agl-demo agl-netboot agl-appfw-smack agl-localdev
$ bitbake agl-demo-platform
That would download and build from scratch the latest AGL sources; depending on the hardware configuration and on the connection speed after some time, the kernel binaries and the root file system will be available in the build/tmp/deploy/images/m3ulcb folder of the working directory.
Once done, follow the Automotive Grade Linux guide at the section Booting AGL Image on R-Car Starter Kit Gen3 boards using a microSD card to complete the installation of the binaries in the M3 microSD card.
At this point, everything is ready to start the build of the required software dependencies. For the purpose of the build operation, in the next sections we will use Docker to compile QEMU and the virtual machine kernel/rootfs. Therefore before proceeding further, make sure to have Docker available in the system; then create a new container with the following command:
$ docker run -e CROSS_COMPILE=aarch64-linux-gnu- \
-it -d --name agl-kvm-guide -v $PWD:/home \
ubuntu:17.10 /bin/bash
The container is now ready, so we can proceed to the next section.
2. Statically build QEMU for aarch64
The KVM hypervisor needs the userspace QEMU emulator to create machine models abstractions for the guests. QEMU and its dependencies are not automatically installed in the AGL distribution. For this reason, in this section we will compile a static image of QEMU.
To do this, we will use Docker and a script prepared by Virtual Open Systems. Download it in the working directory and run the following command to launch its execution in the container created in the previous section:
$ docker exec -it agl-kvm-guide /home/VOSYS_qemu_static_cross_compile.sh
At the end of the execution, the qemu-system-aarch64 binary file will be placed in the current folder. Copy this file in a USB pen-drive, since it will be needed later in the R-Car M3.
Attention!
Check the produced binary: To verify that the compiled QEMU binary has been correctly built, it is possible to use the file tool. Executing file qemu-system-aarch64 should result in: qemu-system-arm: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=1b55b8b85f77cc7a9a685c9b0fbeac71921edaa5, not stripped
At this point everything is almost ready to execute virtual machines in the R-Car M3. In the next section the guest kernel and rootfs will be prepared.
3. Preparation of the guest kernel and rootfs
In order to boot a functional KVM VM, a kernel and a rootfs image will be created. In particular, this guide builds an Ubuntu Xenial virtual machine to be run on top of AGL through KVM.
Login or register to access full information