Difference between revisions of "Xen on ARM and Yocto"

From Xen
 
(One intermediate revision by the same user not shown)
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 \
 
/scratch/repos/poky/meta-xilinx/meta-xilinx-standalone \
 
"
 
INHERIT += "externalsrc"
 
EXTERNALSRC_pn-xen = "/scratch/repos/xen"
 
EXTERNALSRC_BUILD_pn-xen = "/scratch/repos/xen"
 
   
  +
The '''conf/local.conf''' file contains instructions for the variables that it sets. You should review and make sure to set:
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):
 
   
  +
DL_DIR -- set this to a local download directory for retrieved tarballs or other source code files
MACHINE ??= "zcu102-zynqmp"
 
  +
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"
 
DISTRO = "poky"
 
IMAGE_FSTYPES += "cpio.gz"
 
IMAGE_FSTYPES += "cpio.gz"
  +
QEMU_TARGETS = "i386 aarch64"
DISTRO_FEATURES_append=" xen"
 
  +
DISTRO_FEATURES += " virtualization xen"
IMAGE_INSTALL_append = " busybox dropbear xen-base zlib-dev"
 
  +
BUILD_REPRODUCIBLE_BINARIES = "1"
ASSUME_PROVIDED += "iasl-native"
 
PACKAGECONFIG_remove_pn-xen += " sdl"
 
   
  +
This configuration will enable OpenEmbedded's support for reproducible builds. It also reduces the number of emulation platforms for QEMU to significantly reduce build time.
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:
 
  +
If you would like to build QEMU to provide PV backends, such as disk and 9pfs, then you need to add:
   
IMAGE_INSTALL_append += " qemu"
 
 
PACKAGECONFIG_pn-qemu += " virtfs xen fdt"
 
PACKAGECONFIG_pn-qemu += " virtfs xen fdt"
  +
  +
Sdl is enabled by default in the Xen build of QEMU but it is not actually necessary and can be disabled with:
  +
 
PACKAGECONFIG_remove_pn-qemu += " sdl"
 
PACKAGECONFIG_remove_pn-qemu += " sdl"
QEMU_TARGETS = "i386 aarch64"
 
   
  +
== Building ==
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:
 
   
  +
$ bitbake xen-image-minimal
BBMULTICONFIG ?= "pmu"
 
do_image[mcdepends] = "multiconfig::pmu:pmu-firmware:do_deploy"
 
   
  +
When the build is completed, the output image file will be in build/tmp/deploy/images.
and the following to conf/multiconfig/pmu.conf:
 
   
  +
== Targetting hardware platforms ==
MACHINE="zynqmp-pmu"
 
DISTRO="xilinx-standalone"
 
TMPDIR="${TOPDIR}/pmutmp"
 
   
  +
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''
Finally lunch the build!
 
   
  +
eg. For the Raspberry Pi 4:
bitbake core-image-minimal
 
   
  +
In your poky directory, add the BSP layer:
The output will be under build/tmp/deploy/images.
 
  +
  +
$ 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"
   
   

Latest revision as of 20:39, 15 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"
QEMU_TARGETS = "i386 aarch64"
DISTRO_FEATURES += " virtualization xen"
BUILD_REPRODUCIBLE_BINARIES = "1"

This configuration will enable OpenEmbedded's support for reproducible builds. It also reduces the number of emulation platforms for QEMU to significantly reduce build time.

If you would like to build QEMU to provide PV backends, such as disk and 9pfs, then you need to add:

PACKAGECONFIG_pn-qemu += " virtfs xen fdt"

Sdl is enabled by default in the Xen build of QEMU but it is not actually necessary and can be disabled with:

PACKAGECONFIG_remove_pn-qemu += " sdl"

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"