...
Code Block |
---|
|
$ mmc dev $sdbootdev &&&& mmcinfo; load mmc $sdbootdev:$partid 0xC00000 boot.scr; source 0xC00000 |
Graphical Desktop in Dom0
ZU+ only.
To get a graphic desktop, e.g. matchbox, working in dom0, it is necessary to add two SMIDs to device tree: the SMID 0xce3 for zynqmp-display@fd4a0000 and SMID 0xce4 for dma@fd4c0000. The attached DTB comes with the necessary modifications.
Starting simple additional guests
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.
Code Block |
---|
|
$ petalinux-boot --qemu --u-boot --qemu-args "-net nic -net nic -net nic -net nic -net user,tftp=pre-built/linux/xen,hostfwd=tcp:127.0.0.1:2222-10.0.2.15:22" |
Once you hit the u-boot prompt, follow the steps in the earlier section on how to run Xen dom0.
When dom0 has finished booting, we'll need to copy a guest Image into dom0's filesystem.
We'll use the base prebuilt 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:
To target QEMU run the following on the host:
Code Block |
---|
|
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P 2222 pre-built/linux/xen/xen-Image root@localhost:/boot/Image |
If running on hardware run the following on the host:
Code Block |
---|
|
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pre-built/linux/xen/xen-Image root@<board-ip>:/boot/Image |
If you would prefer to load DomU's kernel to the guest via SD card, you can follow the instructions in the "Starting Linux guests with Pass-through networking" section.
The xen-image-minimal rootFS includes some prepared configurations that you can use. These are located in '/etc/xen/'
To start a simple guest
run the following from the dom0 promptcode, one needs to copy the xen-rootfs.cpio.gz to /boot by running the following command on the host
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
# xl create -c example-simple.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+].Once at the dom0 prompt you can list the guests from dom0:To get back to the guests console: Code Block |
---|
|
# xl console guest0 |
You can create further guests by for example running: Code Block |
---|
|
# 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 scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P 2222 pre-built/linux/xen/xen-rootfs.cpio.gz root@localhost:/boot/ |
On the QEMU, edit /etc/xen/example-simple.cfg. So that it contains the following :-
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
name = "guest0"
kernel = "/boot/Image"
ramdisk = "/boot/xen-rootfs.cpio.gz"
extra = "console=hvc0 rdinit=/sbin/init root=/dev/ram0"
memory = 1024
vcpus = 2 |
run the following from the dom0 prompt Code Block |
---|
|
# xl create -c example-simple.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+].Once at the dom0 prompt you can list the guests from dom0:To get back to the guests console: Code Block |
---|
|
# xl console guest0 |
You can create further guests by for example running: Code Block |
---|
|
# xl create example-simple.cfg name=\"guest1\"
# xl create example-simple.cfg name=\"guest2\"
root@plnx_aarch64:/etc/xen# xl list
Name 0 512 1 ID r----- Mem VCPUs 79.8State Time(s)
Domain-0 0 512 1 r----- 79.8
guest0 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:
Code Block |
---|
|
# xl destroy guest0 |
CPU Pinning
The following will only work on QEMU with multi-core enabled or on real HW.
When running multiple guests with multiple Virtual CPUs, Xen will schedule the various vCPUs onto real physical CPUs.
The rules and considerations taken in scheduling decisions depend on the chosen scheduler and the configuration.
To avoid having multiple vCPUs share a single pCPU, it is possible to pin a vCPU onto a pCPU and to give it exclusive access.
To create a simple guest with one Virtual CPU pinned to Physical CPU #3, you can do the following:
Code Block |
---|
|
xl create example-simple.cfg 'name="g0"' 'vcpus="1"' 'cpus="3"' |
Another way to pin virtual CPUs on to Physical CPUs is to create dedicated cpu-pools.
This has the advantage of isolating the scheduling instances.
By default a single cpu-pool named Pool-0 exists. It contains all the physical cpus.
We'll now create our pool named rt using the credit2 scheduler.
Code Block |
---|
|
xl cpupool-create 'name="rt"' 'sched="credit"'
xl cpupool-cpu-remove Pool-0 3
xl cpupool-cpu-add rt 3 |
Now we are ready to create a guest with a single vcpu pinned to physical CPU #3.
Code Block |
---|
|
xl create /etc/xen/example-simple.cfg 'vcpus="1"' 'pool="rt"' 'cpus="3"' 'name="g0"' |
Starting Linux guests with Para-Virtual networking (PV network)
...
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.
Code Block |
---|
|
$ petalinux-boot --qemu --u-boot --qemu-args "-net nic -net nic -net nic -net nic -net user,tftp=pre-built/linux/xen,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 and have copied a domU image (see earlier steps) 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:
Code Block |
---|
|
# killall -9 udhcpc |
List and remove existing addresses from eth0:
Code Block |
---|
|
# ip addr show dev eth0 |
In our example the address is 10.0.2.15/24:
Code Block |
---|
|
# ip addr del 10.0.2.15/24 dev eth0 |
Then, create the bridge and start DHCP on it for dom0:
Code Block |
---|
|
# brctl addbr xenbr0
# brctl addif xenbr0 eth0
# /sbin/udhcpc -i xenbr0 -b |
You should see something like the following:
Code Block |
---|
|
udhcpc (v1.24.1) started
[ 165.460858] xenbr0: port 1(eth0) entered blocking state
[ 165.461819] 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 |
Similar to before we will use the pre-defined examples in '/etc/xen/'
The start DomU
Code Block |
---|
|
# xl create -c example-pvnet.cfg |
You should see a new linux instance boot up.
Now we'll ssh into the domU from the host running Para-Virtual networking:
Code Block |
---|
|
$ ssh -p 2322 root@localhost |
Starting Linux guests with Pass-through networking
It is possible to directly assign the network peripheral to a domU on both ZU+ and Versal. The following example is for ZU+.
Turn xen.dtb into xen.dts:
Code Block |
---|
|
dtc -I dtb -O dts xen.dtb > xen.dts |
The, edit xen.dts by adding xen,passthrough; under the node of the device to assign, in this case ethernet@ff0e0000:
Code Block |
---|
|
ethernet@ff0e0000 {
compatible = "cdns,zynqmp-gem";
status = "enabled";
interrupt-parent = <0x2>;
interrupts = <0x0 0x3f 0x4 0x0 0x3f 0x4>;
reg = <0x0 0xff0e0000 0x0 0x1000>;
clock-names = "pclk", "hclk", "tx_clk";
#address-cells = <0x1>;
#size-cells = <0x0>;
#stream-id-cells = <0x1>;
iommus = <0x6 0x77>;
power-domains = <0x10>;
clocks = <0xd 0xd 0xd>;
phy-mode = "rgmii-id";
xlnx,ptp-enet-clock = <0x0>;
local-mac-address = [00 0a 35 00 02 90];
phy-handle = <0x11>;
linux,phandle = <0x22>;
phandle = <0x22>;
xen,passthrough;
phy@c {
reg = <0xc>;
ti,rx-internal-delay = <0x8>;
ti,tx-internal-delay = <0xa>;
ti,fifo-depth = <0x1>;
linux,phandle = <0x11>;
phandle = <0x11>;
};
}; |
Convert xen.dts back into xen.dtb:
Code Block |
---|
|
dtc -I dts -O dtb xen.dts > xen.dtb.dtb into xen.dts:
Code Block |
---|
|
dtc -I dtb -O dts xen.dtb > xen.dts |
The, edit xen.dts by adding xen,passthrough; under the node of the device to assign, in this case ethernet@ff0e0000:
Code Block |
---|
|
ethernet@ff0e0000 {
compatible = "cdns,zynqmp-gem";
status = "enabled";
interrupt-parent = <0x2>;
interrupts = <0x0 0x3f 0x4 0x0 0x3f 0x4>;
reg = <0x0 0xff0e0000 0x0 0x1000>;
clock-names = "pclk", "hclk", "tx_clk";
#address-cells = <0x1>;
#size-cells = <0x0>;
#stream-id-cells = <0x1>;
iommus = <0x6 0x77>;
power-domains = <0x10>;
clocks = <0xd 0xd 0xd>;
phy-mode = "rgmii-id";
xlnx,ptp-enet-clock = <0x0>;
local-mac-address = [00 0a 35 00 02 90];
phy-handle = <0x11>;
linux,phandle = <0x22>;
phandle = <0x22>;
xen,passthrough;
phy@c {
reg = <0xc>;
ti,rx-internal-delay = <0x8>;
ti,tx-internal-delay = <0xa>;
ti,fifo-depth = <0x1>;
linux,phandle = <0x11>;
phandle = <0x11>;
};
}; |
Convert xen.dts back into xen.dtb:
Code Block |
---|
|
dtc -I dts -O dtb xen.dts > xen.dtb |
Use this xen-rootfs-custom.cpio.gz for dom0 as it has /boot/xen-Image and /boot/xen-rootfs.cpio.gz
The following is the config file to be used with imagebuilder/scripts/uboot-script-gen
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
MEMORY_START="0x0"
MEMORY_END="0x80000000"
DEVICE_TREE="xen.dtb"
XEN="xen"
DOM0_KERNEL="xen-Image"
DOM0_RAMDISK="xen-rootfs-custom.cpio.gz"
NUM_DOMUS=0
UBOOT_SOURCE="boot.source"
UBOOT_SCRIPT="boot.scr" |
When dom0 boots up, one can confirm that ethernet is not up.
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
root@xilinx-zcu102-2021_2:/etc/xen# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
|
Edit /etc/xen/example-passnet.cfg to make it as follows
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
name = "guest0"
kernel = "/boot/xen-Image"
ramdisk = "/boot/xen-rootfs.cpio.gz"
extra = "console=hvc0 rdinit=/sbin/init root=/dev/ram0 init=/bin/sh"
memory = 1024
vcpus = 2
dtdev = [ "/amba/ethernet@ff0e0000" ]
device_tree = "/etc/xen/passthrough-example-part.dtb"
irqs = [ 95 ]
iomem = [ "0xff0e0,1" ] |
Then, boot the guest0
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
xl create -c example-passnet.cfg |
And confirm that guest0 can access ethernet
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
root@xilinx-zcu102-2021_2:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0A:35:00:22:01
inet addr:10.0.2.16 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::20a:35ff:fe00:2201/64 Scope:Link
inet6 addr: fec0::20a:35ff:fe00:2201/64 Scope:Site
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9 errors:0 dropped:0 overruns:0 frame:0
TX packets:134 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1824 (1.7 KiB) TX bytes:36092 (35.2 KiB)
Interrupt:13
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) |
Starting a Guest with a Passthrough SD Card
...
For MMC assignment to a dom0less guest, use the attached partial device tree binary:
passthrough-example-part-dom0less.dtb
To use it, just add it to your ImageBuilder config as follows:
...
...
passthrough-example-part-dom0less.dtb
To use it, the following are the contents of the ImageBuilder config:
Code Block |
---|
|
MEMORY_START="0x0"
MEMORY_END="0x80000000"
DEVICE_TREE="xen.dtb"
XEN="xen"
DOM0_KERNEL="xen-Image"
DOM0_RAMDISK="xen-rootfs-custom.cpio.gz"
DOMU_KERNEL[0]="xen-Image"
DOMU_RAMDISK[0]="initrdxen-rootfs-custom.cpio.gz"
DOMU_PASSTHROUGH_DTB[0]="passthrough-example-part-dom0less.dtb"
NUM_DOMUS=1
UBOOT_SOURCE="boot-dom0less.source"
UBOOT_SCRIPT="boot-dom0less.scr" |
Regenerate the boot.scr and boot.source scripts as usual with ImageBuilder’s uboot-script-gen.
...