Difference between revisions of "Xen on ARM and Yocto"

From Xen
(Updated the page for the Yocto Dunfell LTS branch and targetting QEMU and the Raspberry Pi 4 board)
Line 1: Line 1:
Follow these instructions to cross-compile a minimal Dom0 initramfs, with all the Xen tools, for ARM64 platforms. The build runs on x86 machines, while the target is ARM64. In this example, we are targeting Xilinx Zynq MPSoCs.
+
Follow these instructions to cross-compile a hypervisor and minimal Dom0 filesystem image containing the Xen tools for the ARM64 QEMU emulator. The instructions are similar for other ARM64 platforms.
   
  +
== Obtaining the source code ==
Firstly clone the poky, we are using the ''warrior'' release:
 
   
  +
We will use the Yocto stable release, "Dunfell":
$ git clone -b warrior http://git.yoctoproject.org/git/poky
 
  +
  +
$ git clone -b dunfell http://git.yoctoproject.org/git/poky
 
$ cd poky
 
$ cd poky
  +
$ git clone -b dunfell http://git.openembedded.org/meta-openembeddded
  +
$ git clone -b dunfell http://git.yoctoproject.org/git/meta-virtualization
   
  +
== Preparing the build tree ==
Download and install the relevant meta repositories:
 
   
  +
Initialize your shell to be ready to build - this will generate basic configuration files when you do this the first time:
$ git clone -b warrior http://git.openembedded.org/meta-openembedded
 
$ git clone -b warrior https://git.yoctoproject.org/git/meta-virtualization
 
   
  +
$ source ./oe-init-build-env
The following is specific to Xilinx:
 
   
  +
Edit '''conf/bblayers.conf''', to add the source code layers needed. /scratch/repos/poky is the directory where you cloned the poky source code to - you will need to adjust the example paths here to match your directory layout:
git clone -b warrior https://github.com/Xilinx/meta-xilinx.git
 
 
Manually edit conf/bblayers.conf, add the following, where /scratch/repos/poky is the directory where you cloned poky previously:
 
 
BBLAYERS ?= " \
 
BBLAYERS ?= " \
 
/scratch/repos/poky/meta \
 
/scratch/repos/poky/meta \
Line 25: Line 26:
 
/scratch/repos/poky/meta-openembedded/meta-networking \
 
/scratch/repos/poky/meta-openembedded/meta-networking \
 
/scratch/repos/poky/meta-virtualization \
 
/scratch/repos/poky/meta-virtualization \
  +
"
/scratch/repos/poky/meta-xilinx/meta-xilinx-bsp \
 
  +
/scratch/repos/poky/meta-xilinx/meta-xilinx-contrib \
 
  +
The '''conf/local.conf''' file contains instructions for the variables that it sets. You should review and make sure to set:
/scratch/repos/poky/meta-xilinx/meta-xilinx-standalone \
 
  +
"
 
  +
DL_DIR -- set this to a local download directory for retrieved tarballs or other source code files
INHERIT += "externalsrc"
 
  +
SSTATE_DIR -- set to a local directory for build cache files to speed up subsequent builds
EXTERNALSRC_pn-xen = "/scratch/repos/xen"
 
  +
PACKAGE_CLASSES -- package_ipk can be a good choice for package format
EXTERNALSRC_BUILD_pn-xen = "/scratch/repos/xen"
 
   
Edit conf/local.conf, add the following or making sure they match if already present (MACHINE is the target platform, here we are using ''zcu102-zynqmp'' as reference):
+
Then add the following to the same file, or make sure that the values here match if the variables are already present in the file:
   
MACHINE ??= "zcu102-zynqmp"
+
MACHINE = "qemuarm64"
 
DISTRO = "poky"
 
DISTRO = "poky"
 
IMAGE_FSTYPES += "cpio.gz"
 
IMAGE_FSTYPES += "cpio.gz"
  +
DISTRO_FEATURES += " virtualization xen"
DISTRO_FEATURES_append=" xen"
 
  +
BUILD_REPRODUCIBLE_BINARIES = "1"
IMAGE_INSTALL_append = " busybox dropbear xen-base zlib-dev"
 
ASSUME_PROVIDED += "iasl-native"
 
PACKAGECONFIG_remove_pn-xen += " sdl"
 
   
  +
This configuration will enable OpenEmbedded's support for reproducible builds.
Sdl is enabled by default in the Xen build but it is not actually necessary.
 
If you would like to build QEMU to provide PV backends, such as disk and 9pfs, then you need to add to conf/local.conf:
 
   
  +
== Building ==
IMAGE_INSTALL_append += " qemu"
 
PACKAGECONFIG_pn-qemu += " virtfs xen fdt"
 
PACKAGECONFIG_remove_pn-qemu += " sdl"
 
QEMU_TARGETS = "i386 aarch64"
 
   
  +
$ bitbake xen-image-minimal
Note that we only care about the i386 QEMU target because that is the one that comes with the Xen PV backends, but the aarch64 target is required to make the build succeed.
 
If you are using meta-xilinx and building for ''zcu102-zynqmp'', then you also need the following in conf/local.conf:
 
   
  +
When the build is completed, the output image file will be in build/tmp/deploy/images.
BBMULTICONFIG ?= "pmu"
 
do_image[mcdepends] = "multiconfig::pmu:pmu-firmware:do_deploy"
 
   
  +
== Targetting hardware platforms ==
and the following to conf/multiconfig/pmu.conf:
 
   
  +
If you are targetting a specific ARM hardware platform, you will likely need to add the "BSP layer", which contains the MACHINE definition for the hardware, and any closely related software such as bootloader configuration. The MACHINE variable needs to be set to match the hardware definition. You may also add additional layers containing related support software, if any.
MACHINE="zynqmp-pmu"
 
DISTRO="xilinx-standalone"
 
TMPDIR="${TOPDIR}/pmutmp"
 
   
  +
''TODO: instructions in this section are still pending validation for Dunfell''
   
  +
eg. For the Raspberry Pi 4:
Finally lunch the build!
 
   
  +
In your poky directory, add the BSP layer:
bitbake core-image-minimal
 
   
  +
$ git clone -b dunfell https://git.yoctoproject.org/git/meta-raspberrypi
The output will be under build/tmp/deploy/images.
 
  +
  +
In '''local.conf''', set:
  +
MACHINE = "raspberrypi4-64"
  +
  +
In '''bblayers.conf''', add:
  +
BBLAYERS_append = " /scratch/repos/poky/meta-raspberrypi"
  +
  +
and then perform your build as before.
  +
  +
== Building with a local copy of the Xen source code ==
  +
  +
''TODO: instructions in this section are still pending validation for Dunfell''
  +
  +
If you are building a local copy of a Xen source tree, you can add to '''local.conf''':
  +
INHERIT_pn-xen += "externalsrc"
  +
INHERIT_pn-xen-tools += "externalsrc"
  +
EXTERNALSRC_pn-xen = "/scratch/repos/xen"
  +
EXTERNALSRC_pn-xen-tools = "/scratch/repos/xen"
  +
EXTERNALSRC_BUILD_pn-xen = "/scratch/repos/xen"
  +
EXTERNALSRC_BUILD_pn-xen-tools = "/scratch/repos/xen"
   
   

Revision as of 20:44, 14 December 2020

Follow these instructions to cross-compile a hypervisor and minimal Dom0 filesystem image containing the Xen tools for the ARM64 QEMU emulator. The instructions are similar for other ARM64 platforms.

Obtaining the source code

We will use the Yocto stable release, "Dunfell":

$ git clone -b dunfell http://git.yoctoproject.org/git/poky
$ cd poky
$ git clone -b dunfell http://git.openembedded.org/meta-openembeddded
$ git clone -b dunfell http://git.yoctoproject.org/git/meta-virtualization

Preparing the build tree

Initialize your shell to be ready to build - this will generate basic configuration files when you do this the first time:

 $ source ./oe-init-build-env

Edit conf/bblayers.conf, to add the source code layers needed. /scratch/repos/poky is the directory where you cloned the poky source code to - you will need to adjust the example paths here to match your directory layout:

BBLAYERS ?= " \
/scratch/repos/poky/meta \
/scratch/repos/poky/meta-poky \
/scratch/repos/poky/meta-yocto-bsp \
/scratch/repos/poky/meta-openembedded/meta-oe \
/scratch/repos/poky/meta-openembedded/meta-filesystems \
/scratch/repos/poky/meta-openembedded/meta-python \
/scratch/repos/poky/meta-openembedded/meta-networking \
/scratch/repos/poky/meta-virtualization \
 "

The conf/local.conf file contains instructions for the variables that it sets. You should review and make sure to set:

DL_DIR           -- set this to a local download directory for retrieved tarballs or other source code files
SSTATE_DIR       -- set to a local directory for build cache files to speed up subsequent builds
PACKAGE_CLASSES  -- package_ipk can be a good choice for package format

Then add the following to the same file, or make sure that the values here match if the variables are already present in the file:

MACHINE = "qemuarm64"
DISTRO = "poky"
IMAGE_FSTYPES += "cpio.gz"
DISTRO_FEATURES += " virtualization xen"
BUILD_REPRODUCIBLE_BINARIES = "1"

This configuration will enable OpenEmbedded's support for reproducible builds.

Building

$ bitbake xen-image-minimal

When the build is completed, the output image file will be in build/tmp/deploy/images.

Targetting hardware platforms

If you are targetting a specific ARM hardware platform, you will likely need to add the "BSP layer", which contains the MACHINE definition for the hardware, and any closely related software such as bootloader configuration. The MACHINE variable needs to be set to match the hardware definition. You may also add additional layers containing related support software, if any.

TODO: instructions in this section are still pending validation for Dunfell

eg. For the Raspberry Pi 4:

In your poky directory, add the BSP layer:

$ git clone -b dunfell https://git.yoctoproject.org/git/meta-raspberrypi

In local.conf, set:

MACHINE = "raspberrypi4-64"

In bblayers.conf, add:

BBLAYERS_append = " /scratch/repos/poky/meta-raspberrypi"

and then perform your build as before.

Building with a local copy of the Xen source code

TODO: instructions in this section are still pending validation for Dunfell

If you are building a local copy of a Xen source tree, you can add to local.conf:

INHERIT_pn-xen += "externalsrc"
INHERIT_pn-xen-tools += "externalsrc"
EXTERNALSRC_pn-xen = "/scratch/repos/xen"
EXTERNALSRC_pn-xen-tools = "/scratch/repos/xen"
EXTERNALSRC_BUILD_pn-xen = "/scratch/repos/xen"
EXTERNALSRC_BUILD_pn-xen-tools = "/scratch/repos/xen"