Building the Xen Hypervisor with PetaLinux 2016.3


Before starting you need to create a PetaLinux project. It is assumed that a default PetaLinux reference design is used unchanged in these instructions.

Boot Xen and dom0 on QEMU or Hardware

To run Xen you can either use the prebulit version shipped with PetaLinux or build it yourself using PetaLinx. See the section below for steps about buildling Xen yourself.

Configurng and building XEN from source using PetaLinux (Optional)

The default PetaLinux configuration has all the necessary options set by default. The XEN tools and XEN hypervisor will be built by default. So simply run:
$ petalinux-build

You have to manually copy the xen-qemu.dtb from the pre-built directory:
$ cp pre-built/linux/images/xen-qemu.dtb images/linux/

Run Xen dom0 on QEMU:

To use the Xen you built yourself run:
$ petalinux-boot --qemu --u-boot

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"

Run Xen dom0 on HW:

To use the Xen you built yourself run:
$ petalinux-boot --jtag --u-boot

To use the prebuilt Xen run:
$ petalinux-boot --jtag --prebuilt 2

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, use xen-qemu.dtb otherwise use xen.dtb. Example:
$ tftpb 4000000 xen.dtb
$ tftpb 0x80000 Image
$ tftpb 6000000 xen.ub
$ bootm 6000000 - 4000000
Below is an example of what you will see.
U-Boot-PetaLinux> tftpb 4000000 xen.dtb
Using ethernet@ff0e0000 device
TFTP from server 10.10.70.101; our IP address is 10.10.70.1
Filename 'xen.dtb'.
Load address: 0x4000000
Loading: ##
         970.7 KiB/s
done
Bytes transferred = 28852 (70b4 hex)
U-Boot-PetaLinux> tftpb 0x80000 Image
Using ethernet@ff0e0000 device
TFTP from server 10.10.70.101; our IP address is 10.10.70.1
Filename 'Image'.
Load address: 0x80000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ######################
         6.9 MiB/s
done
Bytes transferred = 37524480 (23c9400 hex)
U-Boot-PetaLinux> tftpb 6000000 xen.ub
Using ethernet@ff0e0000 device
TFTP from server 10.10.70.101; our IP address is 10.10.70.1
Filename 'xen.ub'.
Load address: 0x6000000
Loading: ######################################################
         7.6 MiB/s
done
Bytes transferred = 788064 (c0660 hex)
U-Boot-PetaLinux> bootm 6000000 - 4000000
## Booting kernel from Legacy Image at 06000000 ...
   Image Name:
   Image Type:   AArch64 Linux Kernel Image (uncompressed)
   Data Size:    788000 Bytes = 769.5 KiB
   Load Address: 05000000
   Entry Point:  05000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 04000000
   Booting using the fdt blob at 0x4000000
   Loading Kernel Image ... OK
   Loading Device Tree to 0000000007ff5000, end 0000000007fff0b3 ... OK
 
Starting kernel ...
 
 
 
Starting QEMU as disk backend for dom0
/etc/rc5.d/S70xencommons: line 102: /usr/bin/qemu-system-i386: No such file or directory
Warning unable to detect baudrate, use 115200!
Running dynamic getty on hvc0/115200
 
PetaLinux 2016.3 Xilinx-ZCU102-DA7-ES2-2016_3 /dev/hvc0
Xilinx-ZCU102-DA7-ES2-2016_3 login:

Starting additional guests (Tested on QEMU with the 2016.3 ZCU102 BSP)


PetaLinux has no pre-built or automatic support for starting additional guests.
We'll go through the manual steps needed to do so.

First, we'll enable SSH. This is done by configuring the rootfs.
$ petalinux-config -c rootfs

We navigate to Filesystem Packages->console/network->dropbear and enable all of the options there.
Once enabled exit petalinux-config and ensure that the new selection is saved. Then rebuild PetaLinux
$ petalinux-build

If running on QEMU, we'll need to setup a port mapping for port 22 (SSH) in our VM.
In this example, we forward the hosts port 2222 to the VM's port 22.
$ petalinux-boot --qemu --u-boot --qemu-args "-net nic -net nic -net nic -net nic -net user,tftp=images/linux,hostfwd=tcp:127.0.0.1:2222-22"

Once you hit the u-boot prompt, follow the steps in the earlier section on how to run Xen dom0.
When dom0 is done starting, we'll need to copy a guest Image into dom0's filesystem.
We'll simply reuse the PetaLinux Image as our domU guest.

If running on QEMU, we use scp's -P option to connect to our hosts port 2222 where QEMU will forward the connection to the guests port 22:
scp -P 2222 images/linux/Image root@localhost:/boot/
If running on HW:
scp images/linux/Image root@<board-ip>:/boot/

Now we need an xl configuration file that describes the VM. We'll create it in /etc/xen/example1.cfg. Here's a small example of the contents of such a file:
name = "guest0"
kernel = "/boot/Image"
extra = "console=hvc0 rdinit=/sbin/init"
memory = 256
vcpus = 2

Next step is to start the VM. This is done from a dom0 prompt:
xl create -c /etc/xen/example1.cfg

You'll see another instance of Linux booting up.
At any time you can leave the console of the guest and get back to dom0 by pressing ctrl+].
You can list the guests from dom0:
xl list

To get back to the guests console:
xl console guest0

You can create further guests by for example running:
xl create example-simple.cfg name=\"guest1\"
xl create example-simple.cfg name=\"guest2\"
root@plnx_aarch64:/etc/xen# xl list
Name                                        ID   Mem VCPUs  State Time(s)
Domain-0                                     0   512     1     r-----      79.8
Domain-0                                     0   512     1     r-----      79.8
guest0                                       1   256     2     ------      93.7
guest1                                       2   256     2     ------      26.6
guest2                                       3   256     2     ------       1.8

To destroy a guest:
xl destroy guest0

Starting Linux guests with Para-Virtual networking


In this section we'll describe how to run Linux guests that use para-virtual network connections with dom0 and external networks.
First, we need to reconfigure the PetaLinux kernel.
petalinux-config -c kernel

Enable Device Drivers, Network devices, Xen backend network device. Save and exit.
Now, we'll reconfigure the rootfs.
petalinux-config -c rootfs

Enable dropbear as described in the previous section nr 2.
We also need to enable the bridge-utils. These are found under Filesystem Packages, net, bridge-utils.

This time we will run QEMU slightly different. We'll create two port mappings. One for dom0's SSH port and another for the Para-Virtual domU.
The default IP addresses assigned by QEMUs builtin DHCP server start from 10.0.2.15 and count upwards.
Dom0 will be assigned 10.0.2.15, the next guest 10.0.2.16 and so on.
So here's the command line that maps host port 2222 to dom0 port 22 and 2322 to domUs port 22.
petalinux-boot --qemu --u-boot --qemu-args "-net nic -net nic -net nic -net nic -net user,tftp=./images/linux/,hostfwd=tcp:127.0.0.1:2222-10.0.2.15:22,hostfwd=tcp:127.0.0.1:2322-10.0.2.16:22"

Now, follow the instructions from section 1 on how to boot Xen dom0.
Once you are at the dom0 prompt, we'll need to setup the networking.
In this example, we will configure the guests to directly join the external network by means of a bridge.

First of all, we need to de-configure the default setup.
Kill the dhcp client for eth0:
killall -9 udhcpc

List and remove existing addresses from eth0:
ip addr show dev eth0
In our example the address is 10.0.2.15/24:
ip addr del 10.0.2.15/24 dev eth0

Then, create the bridge and start DHCP on it for dom0:
brctl addbr xenbr0
brctl addif xenbr0 eth0
/sbin/udhcpc -i xenbr0 -b

You should see something like the following:
udhcpc (v1.23.2) started
[ 146.546689] xenbr0: port 1(eth0) entered forwarding state
[ 146.550165] xenbr0: port 1(eth0) entered forwarding state
Sending discover...
Sending select for 10.0.2.15...
Lease of 10.0.2.15 obtained, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 10.0.2.3

Now we need an xl config file describing the VM. The contents are very similar to the example in section 2, we only add one line.
In this example we create /etc/xen/example-pvnet.cfg in dom0's filesystem:
name = "guest0"
kernel = "/boot/Image"
extra = "console=hvc0 rdinit=/sbin/init"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]

Now we are good to go:
xl create -c /etc/xen/example-pvnet.cfg

You should see a new linux instance boot up.
Now we'll ssh into the domU running Para-Virtual networking:
ssh -p 2322 root@localhost

© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy