Xen on ARM and Yocto: Difference between revisions

From Xen
Jump to navigationJump to search
No edit summary
m (remove an extra "d")
 
(8 intermediate revisions by 2 users 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-openembedded
$ 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 http://github.com/cazfi/meta-games.git
$ 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

meta-games is needed for sdl but freeciv causes issues with warrior. Let's remove it:

$ rm -rf meta-games/recipes-games/freeciv/

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 29: Line 25:
/scratch/repos/poky/meta-openembedded/meta-python \
/scratch/repos/poky/meta-openembedded/meta-python \
/scratch/repos/poky/meta-openembedded/meta-networking \
/scratch/repos/poky/meta-openembedded/meta-networking \
/scratch/repos/poky/meta-games \
/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 libsdl-net libsdl-mixer"
BUILD_REPRODUCIBLE_BINARIES = "1"
ASSUME_PROVIDED += "iasl-native"


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.
IMAGE_INSTALL_append = " dropbear"
INITRAMFS_IMAGE = "core-image-minimal"
INITRAMFS_IMAGE_BUNDLE = "1"


If you would like to build QEMU to provide PV backends, such as disk and 9pfs, then you need to add:
You also need to add the following if you are using meta-xilinx:


PACKAGECONFIG_pn-qemu += " virtfs xen fdt"
BBMULTICONFIG ?= "pmu"
do_image[mcdepends] = "multiconfig::pmu:pmu-firmware:do_deploy"


Sdl is enabled by default in the Xen build of QEMU but it is not actually necessary and can be disabled with:
and also add to conf/multiconfig/pmu.conf:


PACKAGECONFIG_remove_pn-qemu += " sdl"
MACHINE="zynqmp-pmu"
DISTRO="xilinx-standalone"
TMPDIR="${TOPDIR}/pmutmp"


== Building ==


$ bitbake xen-image-minimal
Finally lunch the build!


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


== Targetting hardware platforms ==
The output will be under build/tmp/deploy/images.

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"





Latest revision as of 20:39, 16 April 2024

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-openembedded
$ 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"