# Xen Kria SOM Starter Kits Support [Xen](https://xenproject.org/) is a free and open-source hypervisor, providing services that allow multiple computer operating systems to execute on the same computer hardware concurrently. The 2023.2 Kria Starter Kit Petalinux BSP as well as Yocto contains support for Xen. AMD specific details about XEN hypervisor can be found on this [Wiki page](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842530/XEN+Hypervisor). This page documents how to generate Xen artifacts (based on Kria Starter Kit embedded Linux) for Kria and provides an example on how to boot Ubuntu as a guest OS (that is, a DOMU) on a Xen DOM0. This particular combination requires about 4 GB of memory, which K26 has. Therefore, this can be done on either the KV260 or KR260. The K24 only has 2 GB of memory, so Xen is not supported. ## Prerequisites 1. Experience and equipments booting a regular Kria Starter Kit embedded Linux on Kria SOM Starter Kit (follow [Getting Started with PetaLinux on the KV260](https://www.xilinx.com/products/som/kria/kv260-vision-starter-kit/kv260-getting-started/setting-up-the-sd-card-image.html), but use a .wic image from the 2023.2 BSP for your Starter Kit on a minimum 16 GB SD card) 2. A Linux Desktop to create and program partitions 3. Yocto (preferred) or PetaLinux tool ## Generating Xen Artifacts Xen artifacts can be generated by native Yocto tool flow or found in the PetaLinux BSP. You can choose to use one of the tools to create Xen artifacts. ### Generating Xen Artifacts in the Native Yocto Tool Flow First, set up a Yocto project on a host with Yocto support using the instructions [here](https://xilinx.github.io/kria-apps-docs/yocto/build/html/docs/yocto_kria_support.html), stop after the ```source setupsdk``` step. Then, to enable Xen, append the following to the end of ```build/conf/local.conf```: for 2024.1 and older, append the following: ```bash BOOTMODE = "xen" IMAGE_INSTALL:append = "packagegroup-petalinux-xen" ENABLE_XEN_DTSI = "1" ENABLE_XEN_QEMU_DTSI = "1" ENABLE_XEN_UBOOT_SCR = "1" XEN_SERIAL_CONSOLES = "serial1" ``` from 24.2 and onward package group name was changed, append the following instead: ```bash BOOTMODE = "xen" IMAGE_INSTALL:append = "packagegroup-xen" ENABLE_XEN_DTSI = "1" ENABLE_XEN_QEMU_DTSI = "1" ENABLE_XEN_UBOOT_SCR = "1" XEN_SERIAL_CONSOLES = "serial1" ``` Then, build the image the usual way: To generate Xen support for KV260, use k26-smk-kv as the ``````: ```bash MACHINE=k26-smk-kv-sdt bitbake kria-image-full-cmdline # or in older tools: MACHINE=k26-smk-kv bitbake kria-image-full-cmdline ``` To generate Xen support for KR260, use k26-smk-kr as the ``````: ```bash MACHINE=k26-smk-kr-sdt bitbake kria-image-full-cmdline # or in older tools: MACHINE=k26-smk-kr bitbake kria-image-full-cmdline ``` There is no Xen support for the combined MACHINE name ```k26-smk```. In the Yocto project, the Yocto generated .wic that contains Xen support is found in ```/build/tmp/deploy/images//kria-image-full-cmdline-*.wic```.
Expand for Xen Artifact generation in the PetaLinux tool flow ### Xen Artifacts in PetaLinux Tool Flow Use the Yocto flow because the flow is verified and steps are simpler in the [Prepare the SD Card](#prepare-the-sd-card) stage. If you must use PetaLinux, download a 2023.2 version or later [Kria SOM Starter Kit BSP](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/1641152513/Kria+K26+SOM#PetaLinux-Board-Support-Packages). Extract the PetaLinux project: ```bash petalinux-create -t project -s xilinx---.bsp cd xilinx-- ``` The .wic image required is in ```pre-built/linux/images/petalinux-sdimage.wic.xz```, and the Xen artifacts required are found in ```pre-built/linux/xen```.
## Prepare the SD Card Flash the embedded Linux .wic image from either [Yocto](#generating-xen-artifacts-in-the-native-yocto-tool-flow) or [PetaLinux flow](#xen-artifacts-in-the-petalinux-tool-flow) to an SD card using Balena Etcher. This sets up the SD card to contain two partitions: partition 1 with boot images (accessible by Windows and Linux) and partition 2 with the Kria Starter Kit embedded Linux rootfs (not accessible by Windows) that is also used for XEN DOM0. A third partition is created to house the DOMU rootfs. ### Partition 1 If you are using a Yocto generated .wic image, partition 1 already contain Xen artifacts because the .wic is generated with Xen support.
Expand for Partition 1 setup for the PetaLinux Flow only PetaLinux tool flow only: Open the SD card on a host computer (can be Windows or Linux), go to partition 1, remove the boot images on that partition, and copy all the Xen artifacts in ```pre-built/linux/xen``` into partition 1.

Next, copy over the Ubuntu image that you want to boot as DOMU. Download the [iot-limerick-kria-classic-desktop-2204-x07-20230302-63-system-boot.tar.gz](https://people.canonical.com/~platform/images/xilinx/kria-ubuntu-22.04/iot-limerick-kria-classic-desktop-2204-x07-20230302-63-system-boot.tar.gz?_ga=2.93916574.2043050383.1684286640-1062417632.1681766747) file from the [Kria Ubuntu download site](https://ubuntu.com/download/amd-xilinx), uncompress it, and copy the ```image.fit``` file into partition 1 for DOMU later. This file is not being used in Xen booting but is place in partition 1 as a way to transfer the file onto target. ### Partition 2 Partition 2 was programmed with a Kria Starter Kit embedded Linux rootfs from setting the SD card image with the Kria Starter Kit embedded Linux .wic image. This can be reused for Xen. ### Partition 3 This step needs to be done on a Linux host. Download the Ubuntu rootfs for DomU. Download the Ubuntu image from [Kria Ubuntu download site](https://ubuntu.com/download/amd-xilinx). For this example, the [iot-limerick-kria-classic-desktop-2204-x07-20230302-63-rootfs.ext4.xz](https://people.canonical.com/~platform/images/xilinx/kria-ubuntu-22.04/iot-limerick-kria-classic-desktop-2204-x07-20230302-63-rootfs.ext4.xz?_ga=2.22151480.2043050383.1684286640-1062417632.1681766747) file is used. Unzip the downloaded rootfs file to .ext4 using the following: ```bash xz -d iot-limerick-kria-classic-desktop-2204-x07-20230302-63-rootfs.ext4.xz ``` Plug the SD card into a Linux host machine. In this example, it is assumed that the SD card is found in ```/dev/sda```, but you can find it in different file path depending on your machine. Observe the two partitions with ```sudo fdisk -l /dev/sda```; it should look similar to the following with two partitions: ```bash Device Boot Start End Sectors Size Id Type /dev/sda1 * 8 4194311 4194304 2G c W95 FAT32 (LBA) /dev/sda2 4194312 12582919 8388608 4G 83 Linux ``` Enter the ```sudo fdisk /dev/sda``` command, and enter ```n``` to create a new partition. You are prompted about the partition type, enter ```p```, next for the Partition number, hit **Enter** or enter the number ```3```. Finally, for First and Last Sector, hit **Enter** to automatically create a partition with all remaining storage on the SD card. Now, it should look similar to the following: ```bash Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): 3 First sector (12582920-31116287, default 12584960): Last sector, +sectors or +size{K,M,G,T,P} (12584960-31116287, default 31116287): Created a new partition 3 of type 'Linux' and of size 8.9 GiB. ``` Next, enter ```w``` to write the partition table and exit. Next, format the newly created partition to support ext4 rootfs. Use following command to format it to a .ext4 format: ```bash sudo mkfs.ext4 -L root /dev/sda3 ``` ```/dev/sda3``` is the path for new partition that is used for rootfs for DOMU. Run `sudo fdisk -l` again to verify all the partitions. It should look similar to the following with three partitions: ```text Device Boot Start End Sectors Size Id Type /dev/sda1 * 8 4194311 4194304 2G c W95 FAT32 (LBA) /dev/sda2 4194312 12582919 8388608 4G 83 Linux /dev/sda3 12584960 31116287 18531328 8.9G 83 Linux ``` Finally, copy the Ubuntu rootfs you downloaded and extracted earlier to partition ```/dev/sda3```: ```bash sudo dd if=iot-limerick-kria-classic-desktop-2204-x07-20230302-63-rootfs.ext4 of=/dev/sda3 ``` >**TIP:** If dd gives produces the "No space left on device" error but the file is smaller than the space allocated, do the following: ```bash sudo rm /dev/sda3 sudo fdisk /dev/sda # enter "D" and then "3" to delete partition 3 #then remove the SD card and reinsert and go back to the beginning of this section to start from creating partition 3 again. ``` Now partition 3 is also ready. ## Boot Xen On Target Plug the SD card into the Starter Kit and turn on the power. If you used Yocto to generate the Xen artifact, Xen is automatically booted; you can move to the next section.
Boot XEN with PetaLinux tool flow If you use PetaLinux to generate Xen artifacts, you automatically get to the U-Boot command prompt. Enter this to load `xen_boot_sd.scr` to 0xc00000 and source the script to boot Xen: For KV260, SD card is on mmc, so use the following commands to boot: ```bash load mmc 1:1 0xc00000 xen_boot_sd.scr #KV260 only! source 0xc00000 ``` For KR260, the SD card is on a USB, so use the following commands to boot: ``` bash load usb 0 0xc00000 xen_boot_sd.scr #KR260 only! source 0xc00000 ``` This boots the Kria Starter Kit embedded Linux XEN (DOM0).
### Boot Ubuntu as DOMU First, change to root: ```bash sudo -s ``` In ```/boot```, you should find the ```image.fit``` file that was put there in step 1. The location and file name can vary depending on the release and tool used. You can search for it using ```find / -iname "image.fit"```. Extract the Ubuntu kernel image: ```bash dumpimage -T flat_dt -p 0 /boot/image.fit -o /home//ubuntu_Image ``` Next, check how much memory is dom0 consuming and the available memory using ```xl info```. In this example, there should be a little more than 1.9G left to use for DOMU. Therefore, you can allocate 1900 MB for DOMU in the next step. Create a ```guest0.cfg``` file with the following content: If running Xen on KV260: ```bash name = "guest0" kernel = "/home//ubuntu_Image" # Ubuntu Kernel extracted disk = ['/dev/mmcblk1p3,,xvda'] # Ubuntu Rootfs in partition 3 extra = "console=hvc0 root=/dev/xvda" memory = 1900 # This can be increased if there is more free memory. vcpus = 2 ``` If running Xen on KR260: ```bash name = "guest0" kernel = "/home//ubuntu_Image" # Ubuntu Kernel extracted disk = ['/dev/sda3,,xvda'] # Ubuntu Rootfs in partition 3 extra = "console=hvc0 root=/dev/xvda" memory = 1900 # This can be increased if there is more free memory. vcpus = 2 ``` Next, check if `/dev/mmcblk1p3` or `/dev/sda3` is mounted automatically by dom0 using ```df -h```. If its mounted, unmount it so that DOMU can use it: ```bash umount /dev/mmcblk1p3 # KV260 only umount /dev/sda3 # KR260 only ``` Start guest0/DOMU using: ```bash xl create -c guest0.cfg ``` This boots to ```root@ubuntu```. To get out of DOMU, press ```ctrl-]```. After getting out of DOMU, in XEN DOM0 prompt, rnter ```xl list``` to see a list of operating systems running similar to the following: ``` bash xilinx-kv260-starterkit-20231:/home/petalinux# xl list Name ID Mem VCPUs State Time(s) Domain-0 0 2048 1 r----- 17916.8 guest0 1 1899 2 r----- 28894.7 ``` To access the guest0 DOMU again, do ```xl console ``` To kill the guest0 DOMU, identify the from the prints, and then to kill the session, execute ```xl destroy ```. Another DOMU session can be started without having to reboot Xen. ## Kria Starter Kit Embedded Linux as DOMU To run Kria Starter Kit embedded Linux instead of Ubuntu as DOMU, the steps are similar to that of Ubuntu OS as DOMU, except for the kernel image and rootfs artifacts for the perspective OS and the config file. There only two artifacts required in this example. In the image folder, copy the ```Image``` file and ```rootfs.cpio.gz``` file into boot partition 1. For partition 3, skip the dd command and leave the partition empty. Once booted up and in root, copy the two artifacts to partition 3. To find out where the partitions are mapped to, use the ```df -h``` command: ``` k26-smk-kv:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/root 1.5G 955M 408M 71% / devtmpfs 563M 4.0K 563M 1% /dev tmpfs 693M 0 693M 0% /dev/shm tmpfs 277M 11M 267M 4% /run tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup tmpfs 693M 4.0K 693M 1% /tmp tmpfs 693M 136K 692M 1% /var/volatile /dev/mmcblk1p1 511M 147M 365M 29% /boot /dev/mmcblk1p3 113G 5.2G 103G 5% /run/media/writable-mmcblk1p3 tmpfs 139M 0 139M 0% /run/user/1000 ``` In the example output above (for KV260), the boot partition (mmcblk1p1) is mapped to ```/boot```, and the third partition (mmcblk1p3) is mounted to ```/run/media/writable-mmcblk1p3```. In this case, copy this command: ```text cp /boot/Image /run/media/writable-mmcblk1p3 cp /boot/rootfs.cpio.gz /run/media/writable-mmcblk1p3 ``` Use the following as `guest0.cfg` (adjusting kernel and ramdisk path accordingly): ```text name = "guest0" kernel = "/run/media/writable-mmcblk1p3/Image" ramdisk = "/run/media/writable-mmcblk1p3/rootfs.cpio.gz" extra ="console=hvc0 init=/bin/sh root=/dev/ram0" memory = 1801 vcpus = 1 ``` ## Known Limitations 1. With the current Xem hypervisor configuration, DOMU does not have access to peripherals. Peripheral access is mapped to dom0. Therefore, Ethernet is not accessible for DOMU. Upon DOMU initialization (tested with Kria Starter Kit embedded Linux 2023.2 XEN + Ubuntu 22.04 x07 image) you see cloud init errors. 2. XEN on Kria currently do not save its state across reboot. For example, the files in rootfs or password do not persist over power cycles or reboots. 3. on XEN - xlnx_platformstats number of CPU information is not accurate - this is because domains only see vCPUs, not pCPUs. It also doesnt have information on the CPU frequency as Xen do not expose it vit the device tree.

Copyright © 2023–2025 Advanced Micro Devices, Inc.

Terms and Conditions