/
Building the Xen Hypervisor with PetaLinux 2017.1

Building the Xen Hypervisor with PetaLinux 2017.1

The guide below shows you how to build Xen, boot Xen and then run some example configurations on ZU+. The steps below use PetaLinux and assume you have some knowledge of using PetaLinux.

Table of Contents

Introduction

Before starting you need to create a PetaLinux project. It is assumed that a default PetaLinux reference design is used unchanged in these instructions.
The default PetaLinux configuration has images ready to do boot Xen, these are the pre-built images. You can use those or you can manually edit receipes and build Xen yourself. The pre-built images can be found in this directory (inside a PetaLinux project) pre-built/linux/images/ and prefixed with "xen-". You can either use the pre-builts or follow the next section to configure and build Xen yourself. If you are using the pre-builts you can skip to the booting Xen section for your release version.

Configuring and building XEN from source using PetaLinux 2017.1

First let's enable Xen to be built by default.
$ petalinux-config -c rootfs
Now let's enable Xen:
Filesystem Packages ---> misc ---> packagegroup-petalinux-xen ---> [*] packagegroup-petalinux-xen
Now we need to change the rootFS to be an INITRD
$ petalinux-config
And change
Image Packaging Configuration  --->  Root filesystem type (INITRAMFS)  ---> (X) INITRD
NOTE: This means that any images built will NOT have the rootFS in the Image that is built by PetaLinux. This means you will need to edit any scripts or configs that expect the rootFS to be included. This includes the Xen configs mentioned later.
You can still use the prebuilt Image file which does still include the rootFS.
We also want to edit the device tree to build in the extra Xen related configs.
Edit this file
project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
and add this line: /include/ "xen-overlay.dtsi".
It should look like this for harware:
/include/ "system-conf.dtsi"
/include/ "xen-overlay.dtsi"
/ {
};
or like this for QEMU:
/include/ "system-conf.dtsi"
/include/ "xen-overlay.dtsi"
/ {
    cpus {
        cpu@1 {
            device_type = "none";
        };
        cpu@2 {
            device_type = "none";
        };
        cpu@3 {
            device_type = "none";
        };
    };
};
NOTE: There is a bug on QEMU where the CPUs running in SMP sometimes cause hangs. To avoid this we only tell Xen about a single CPU.


Also edit this file:
project-spec/meta-user/recipes-bsp/device-tree/device-tree-generation_%.bbappend
and add this line to it: file://xen-overlay.dtsi.
The file should look like this:
SRC_URI_append ="\
    file://system-user.dtsi \
    file://xen-overlay.dtsi \
"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
Then run petaliux-build:
$ petalinux-build

TFTP Booting Xen and Dom0 2017.1

Run Xen dom0 on QEMU:

To use the prebuilt Xen run:
$ petalinux-boot --qemu --prebuilt 2 --qemu-args "-net nic -net nic -net nic -net nic -net user,tftp=pre-built/linux/images"
To use the Xen you built yourself run:
$ petalinux-boot --qemu --u-boot

Run Xen dom0 on HW:

To use the prebuilt Xen on hardware:
$ petalinux-boot --jtag --prebuilt 2
To use the Xen you built yourself run:
$ petalinux-boot --jtag --u-boot

You should eventually see something similar to this, when you do press any key to stop the autoboot.
Hit any key to stop autoboot:

If u-boot wasn't able to get an IP address from the DHCP server you may need to manually set the serverip (it's typically 10.0.2.2 for QEMU):
$ setenv serverip 10.0.2.2

Now to download and boot Xen, if running on QEMU,