...
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
First let's enable Xen to be built by default.
Code Block |
---|
|
$ petalinux-config -c rootfs |
Now let's enable Xen:
Code Block |
---|
|
Petalinux Package Groups ---> packagegroup-petalinux-xen ---> [*] packagegroup-petalinux-xen |
Now we need to change the rootFS to be an INITRD
Code Block |
---|
|
$ petalinux-config |
And change
Code Block |
---|
|
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 configuration that expects 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 to boot DomU.
We also want to edit the device tree to build in the extra Xen related configs.
Edit this file
Code Block |
---|
|
project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi |
and add this line: /include/ "xen.dtsi".
It should look like this for harware:
Code Block |
---|
|
/include/ "system-conf.dtsi"
/include/ "xen.dtsi"
/ { }; |
or like this for QEMU:
Code Block |
---|
|
/include/ "system-conf.dtsi"
/include/ "xen.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:
Code Block |
---|
|
project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend |
and add this line to it: file://xen.dtsi.
The file should look like this:
Code Block |
---|
|
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += "file://system-user.dtsi"
SRC_URI += "file://xen.dtsi"
|
Then run petaliux-build:
Code Block |
---|
|
$ petalinux-build |
TFTP Booting Xen and Dom0
Run Xen dom0 on QEMU:
To use the prebuilt Xen run:
Code Block |
---|
|
$ 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:
Code Block |
---|
|
$ petalinux-boot --qemu --u-boot |
Run Xen dom0 on HW:
To use the prebuilt Xen on hardware:
Code Block |
---|
|
$ petalinux-boot --jtag --prebuilt 2 |
To use the Xen you built yourself run:
Code Block |
---|
|
$ petalinux-boot --jtag --u-boot |
You should eventually see something similar to this, when you do press any key to stop the autoboot.
Code Block |
---|
|
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):
Code Block |
---|
|
$ setenv serverip 10.0.2.2 |
Now to download and boot Xen, if running on QEMU, use xen-qemu.dtb otherwise use xen.dtb. Example:
TFTPing Xen using ImageBuilder
ImageBuilder is a set of Open Source community scripts to automatically configure a Xen system with Dom0 and multiple Dom0-less VMs for booting. ImageBuilder can generate a U-Boot script that loads all of the binaries automatically and boot the full system quickly. ImageBuilder is available here. The main script is scripts/uboot-script-gen and its usage is described in details on the Xen Project wikipage.
uboot-script-gen takes raw binaries as input (not uboot binaries). Petalinux pre-build images provide u-boot binaries for Xen and the Dom0 rootfs. First, they need to be converted into raw binaries:
Code Block |
---|
|
dd if=xen.ub of=xen bs=64 skip=1
dd if=xen-rootfs.cpio.gz.u-boot of=xen-rootfs.cpio.gz bs=64 skip=1 |
Then, they can be used in a config file as follows for uboot-script-gen:
Code Block |
---|
|
MEMORY_START="0x0"
MEMORY_END="0x80000000"
DEVICE_TREE="xen.dtb"
XEN="xen"
DOM0_KERNEL="xen-Image"
DOM0_RAMDISK="xen-rootfs.cpio.gz"
NUM_DOMUS=0
UBOOT_SOURCE="boot.source"
UBOOT_SCRIPT="boot.scr" |
Now uboot-script-gen can be used to generate boot.scr:
Code Block |
---|
|
$ bash ./scripts/uboot-script-gen -c config -d . -t tftp |
Boot the system with the following uboot command (assuming the tftp serverip is 10.0.2.2, which is typically the value for QEMU):
Code Block |
---|
|
$u-boot> setenv serverip 10.0.2.2
u-boot> tftpb 0xC00000 boot.scr; source 0xC00000 |
TFTPing Xen from pre-built images manually
Code Block |
---|
|
$ tftpb 1280000 xen-qemu.dtb; tftpb 0x80000 xen-Image; tftpb 1400000 xen.ub; tftpb 9000000 xen-rootfs.cpio.gz.u-boot; bootm 1400000 9000000 1280000 |
Booting with larger binaries and Workaround for ZCU104
Any time you update binaries and they potentially increase in size, please make sure that they don't overlap. For instance, if the kernel Image is loaded at 0x80000 and the dtb at 0x1280000, it means that the maximum size of the kernel is 12MB. More than that and the loading addresses need to be updated to avoid overlaps. Moreover, both address and size of the kernel Image are also specified under the /chosen node in the dtb file.
The ZCU104 BSP comes with a larger Dom0 rootfs (xen-rootfs.cpio.gz.u-boot file). U-boot has issues booting the rootfs as a u-boot image, it needs to be loaded as a raw binary instead. Thus, the following workaround is required for ZCU104.
Convert the xen-rootfs back to a normal binary:
Code Block |
---|
|
$ dd if=xen-rootfs.cpio.gz.u-boot of=xen-rootfs.cpio.gz. bs=64 skip=1 |
Add the following node under /chosen in device tree xen-qemu.dts (you can convert a device tree binary to source and back using dtc):
...