Building Xen Hypervisor through Yocto Flow

Table of Contents

Building the Xen Image

Below are the steps to build the Xen Image using Yocto:

Install the repo

Repo is a tool that enables the management of many git repositories given a single manifest file. The repo will fetch the git repositories specified in the manifest and, by doing so, sets up a Yocto Project build environment for you.

# Download the Repo script.
curl -k > repo
# Generally, curl is install at /usr/bin/curl. If it is installed at custom location please point it to correct location.
# Make it executable.
chmod a+x repo

# If it is correctly installed, you should see a Usage message when invoked with the help flag.
repo --help
# If system complaints about repo not found. Please run with './repo --help' 

Fetch all sources

# initialize the repo.
repo init -u git:// -b <release-version>

# repo sync to get all sources
repo sync

Example of release-version: rel-v2020.2, rel-v2020.1 and rel-v2019.2 etc.

In case you get the following error

ayankuma@xcbayankuma40x:/scratch$ repo sync
  File "/scratch/.repo/repo/", line 79
SyntaxError: invalid syntax

You need to add python3 before 'repo'. The command will then be as follows :-

# initialize the repo.
python3 repo init -u git:// -b <release-version>

# repo sync to get all sources
python3 repo sync

Change the memory settings on your machine

This is because of a known issue with Yocto builds. For details, and

sudo sysctl -w vm.overcommit_memory=0
sudo sysctl -w vm.overcommit_ratio=50

Source environment

# source the environment to build using bitbake.
source setupsdk

Add option to generate rootfs image with Yocto build

This option will generate the rootfs in cpio.gz format which will be used in creating boot-scripts step. Rootfs built will contain the useful Xen tools like xl.

# Edit conf/local.conf and Add the below line
IMAGE_FSTYPES += "cpio.gz"

Build using bitbake

Next, we will build the xen-image-minimal image. This will produce Xen, Linux kernel for Xen and rootfs. If only Xen needs to be build, it can done using MACHINE=vck190-versal bitbake xen.
 $ MACHINE=vck190-versal bitbake xen-image-minimal
# Please use appropriate yocto machine name to build for a target hardware. Examples:

This step can take a lot of time depending upon host machine processing power. It will also required significant disk space, please see Yocto for more details.

Creating boot scripts

To create boot scripts, we use Imagebuilder which generates a U-Boot script that loads all the necessary binaries and automatically adds the required entries to device tree at boot time. In order to use it, we will need to write a config file first.

First, cd to <current directory>/tmp/deploy/images/$(machine_name). Example: build/tmp/deploy/images/vck190-versal.

Next, create a file named "config" with the contents as illustrated below and save the file.




Save the config file. 

Now uboot-script-gen can be used to generate boot.scr:

bash uboot-script-gen -c config -d . -t tftp

Running Xen on QEMU

Boot the qemu using below command:

MACHINE=vck190-versal runqemu xen-image-minimal
# Please change the machine name appropriatly.
Once you get to the u-boot prompt use the below commands to TFTP boot Xen.
tftpb 0xC00000 boot_xen.scr; source 0xC00000

This should start the QEMU boot.

After you enter the above command, the QEMU boot sequence loads the Xen images and boots Linux. At the prompt login, enter root as the username and root as the password.

To quit the emulation, press CTRL+A followed by X.