Continuing on with my getting started series for the Kria KR260 Robotics Starter kit, I'm covering how to create an embedded Linux image for it using PetaLinux with the appropriate hooks enabled for FPGA accelerated applications to be developed for it later on using Vitis.
As I explained in my Vitis 2022.1 on Ubuntu 22.04 installation project post, KRS does not support PetaLinux for the KR260, it only supports the cross compilation of an Ubuntu 22.04 image as the root filesystem. So I have switched back to the gcc-multilib
GNU C compiler on my host machine to be able to compile PetaLinux root filesystems. Therefore any PetaLinux projects I will be doing for the KR260 will not involve KRS, and will just be accelerated applications and/or regular Linux applications.
The BSPs for the Kria KR260 and KV260 require the Update1 to be applied to PetaLinux, otherwise the project will not build correctly (if at all). Start be sourcing the PetaLinux tools in the host machine environment.
~$ source /tools/Xilinx/PetaLinux/2022.1/settings.sh
And upgrade the PetaLinux eSDK with Update1:
~$ petalinux-upgrade -u http://petalinux.xilinx.com/sswreleases/rel-v2022/sdkupdate/2022.1_update1/ -p "aarch64" --wget-args "--wait 1 -nH --cut-dirs=4"
Change directories into the desired location to create the PetaLinux project in. I personally like to create my PetaLinux projects in the top level directory of the corresponding Vivado project I'm pulling the hardware design in from. Once in the desired directory location, create a PetaLinux project using the Kria KR260 BSP (download here), and change directories into it.
~$ cd ./Kria_KR260/
~/Kria_KR260$ petalinux-create --type project -s ../Downloads/xilinx-kr260-starterkit-v2022.1-05140151.bsp --name linux_os
~/Kria_KR260$ cd ./linux_os/
Then import the hardware platform exported from Vivado that has the hooks for an accelerated design:
~/Kria_KR260/linux_os$ petalinux-config --get-hw-description ../
In the system configuration editor, start by enabling FPGA manager (which I'm not totally sure why the FPGA manager isn't enabled by default in the BSP since the KR260 definitely needs it for the device tree overlay functionality).
Then set the root filesystem type to INITRD with the INITRAMFS/INITRD Image name set as petalinux-initramfs-image, and disable TFTP boot if you don't plan to use it.
FPGA Manager --> Fpga Manager[*]
Image Packaging Configuration --> Root Filesystem Type --> INITRD[*]
Image Packaging Configuration --> INITRAMFS/INITRD Image name --> petalinux-initramfs-image
Image Packaging Configuration --> Copy final images to tftpboot[]
Changing the image name to petalinux-initramfs-image (default is petalinux-image-minimal) is super important or the ramdisk image to mount the root filesystem in the early steps of the boot process will not be generated which will cause the root filesystem to not be persistent between power cycles on the KR260.
Exit the system configuration editor, opting to save the changes.
Then attempt to build the project for the first time.
~/Kria_KR260/linux_os$ petaliunx-build
Package Dependency Fix on Host (If Needed)If you get any errors when attempting to build the PetaLinux project in relation to dpkg-architecture
not being found such as the following (which you probably will if you have ROS 2 Humble installed):
| using tcl headers from -I/usr/include/tcl8.6 -I/usr/include/tcl8.6/generic
| checking for tcl.h... yes
| using /usr/lib/tclConfig.sh
| /usr/lib/tclConfig.sh: line 2: dpkg-architecture: command not found
| /usr/lib//tcl8.6/tclConfig.sh: line 2: dpkg-architecture: command not found
Start by cleaning the project:
~/Kria_KR260/linux_os$ petaliunx-build -x mrproper
Then remove the libtcl8.6
package and reinstall with the following other dependencies:
~$ sudo apt-get remove libtcl8.6
~$ sudo apt-get update
~$ sudo apt-get install blt libopencv-contrib-dev libopencv-dev libopencv-viz-dev libopencv-viz4.5d libtcl8.6
Open a new terminal window, source the PetaLinux tools again and build the PetaLinux project:
~$ source /tools/Xilinx/PetaLinux/2022.1/settings.sh
~$ cd ./Kria_KR260/linux_os/
~/Kria_KR260/linux_os$ petaliunx-build
This first build took a little over two hours for me; this PetaLinux project for the KR260 is very large, and with all of the required libraries it's just a lot right now. I'm sure there will be an improvement in some future iterations.
Which I why I recommend running that first build before customizing the root filesystem and/or kernel at all to add any packages. The subsequent build after that first one do execute within a few minutes since it's just adding on the extra packages.
Customize & Add XRT SupportIf there are any kernel packages you would like to add, launch the kernel configuration editor and select accordingly:
~/Kria_KR260/linux_os$ petalinux-config -c kernel
There aren't any extra things I'm adding to the KR260 kernel outside of what the BSP enables by default so I skipped straight to the root filesystem configuration editor to add support for acceleration and XRT:
~/Kria_KR260/linux_os$ petalinux-config -c rootfs
To add the XRT support and the general packages accelerated applications will need in the root filesystem, enable the following packages if they aren't already by the KR260 BSP:
Filesystem Packages --> console --> utils --> git --> [*] git
Filesystem Packages --> base --> dnf --> [*] dnf
Filesystem Packages --> x11 --> base --> libdrm --> [*] libdrm
Filesystem Packages --> x11 --> base --> libdrm --> [*] libdrm-tests
Filesystem Packages --> x11 --> base --> libdrm --> [*] libdrm-kms
Filesystem Packages --> libs --> xrt --> [*] xrt
Filesystem Packages --> libs --> xrt --> [*] xrt-dev
Filesystem Packages --> libs --> zocl --> [*] zocl
Filesystem Packages --> libs --> opencl-headers --> [*] opencl-headers
Filesystem Packages --> libs --> opencl-clhpp --> [*] opencl-clhpp-dev
Petaliunx Package Groups --> packagegroup-petalinux --> [*] packagegroup-petalinux
Petaliunx Package Groups --> packagegroup-petalinux-gstreamer --> [*] packagegroup-petalinux-gstreamer
Petaliunx Package Groups --> packagegroup-petalinux-opencv --> [*] packagegroup-petalinux-gstreamer
Petaliunx Package Groups --> packagegroup-petalinux-v4lutils --> [*] packagegroup-petalinux-gstreamer
Petaliunx Package Groups --> packagegroup-petalinux-x11 --> [*] packagegroup-petalinux-gstreamer
Rebuild the project after adding the packages to the root filesystem (and kernel if you choose):
~/Kria_KR260/linux_os$ petaliunx-build
Build Sysroot (SDK) for ProjectAfter the project has been built, build the SDK for the project to get a sysroot to use with Vitis to compile any custom accelerated applications later on:
~/Kria_KR260/linux_os$ petaliunx-build --sdk
Once the project has been built, package the boot binary for the custom image:
~/Kria_KR260/linux_os$ petalinux-package --boot --u-boot --force
Then package the WIC image for the SD card:
~/Kria_KR260/linux_os$ petalinux-package --wic --images-dir images/linux/ --bootfiles "ramdisk.cpio.gz.u-boot,boot.scr,Image,system.dtb,system-zynqmp-sck-kr-g-revB.dtb" --disk-name "sda"
Note that since the KR260 has the SD card connected to the Zynq FPGA via the USB controller on the KR260 carrier board, that's why we need to specify the disk name as sda.
Flash SD CardYou can manually load the wic onto the SD card from the command line, but I go the lazy route and use balenaEtcher:
Since the KR260's initial release, some critical updates have been made to the boot firmware that lives on its QSPI flash (the biggest update to note is for the Ethernet drivers). There are several ways to update this firmware, but the easiest method I've found is to simply flash an SD card with the pre-built Ubuntu 22.04 Desktop image from Canonical, boot the KR260 with it connected to my router via Ethernet (see instructions here), then transfer the new BOOT.BIN file to it from my host machine using scp.
Note: Be sure to use one of the right-hand side Ethernet ports (Gem 0 and Gem 1) since the left two (Gem 2 and Gem 3) are connected through the programmable logic:
Start by downloading the latest BOOT.BIN from the Kria wiki here. At the time of writing, that is the BOOT_xilinx-k26-starterkit-v2022.1-07250622_update2.BIN version.
Once the KR260 has been booted up with the Ubuntu image and a custom user password has been set, run a command like ifconfig
to see what IP has been assigned to it on the LAN:
ubuntu@kria:~$ ifconfig
Using the IP address assigned and user password created on the KR260's Ubuntu image, run the scp
command from the host machine to transfer the downloaded BOOT.BIN to the KR260:
~$ scp ./Kria_KR260/docs/BOOT_xilinx-k26-starterkit-v2022.1-07250622_update2.BIN ubuntu@192.168.x.xxx:/home/ubuntu
Then use the xmutil
boot firmware update tool on the KR260 to flash the new BOOT.BIN onto the QSPI:
ubuntu@kria:~$ sudo xmutil bootfw_update -i BOOT_xilinx-k26-starterkit-v2022.1-07250622_update2.BIN
Once successfully updated, power down the KR260:
ubuntu@kria:~$ sudo shutdown -h now
Boot KR260Swap out the Ubuntu SD card in the KR260 for the custom PetaLinux SD card and boot the KR260. And just like with the first boot of the Ubuntu image, create a custom user password when prompted:
The next step with the KR260 is switching over to the Vitis IDE for developing an accelerated application which I will post soon!
Comments