In this blog post, you will learn how to compile a PREEMPT_RT kernel for the Up Squared (Up2) board.
DISCLAIMER: This article was posted end of 2018. Things have changed since then and I decided against using the Up Squared for my project because I couldn't get the RT latency to a reasonable level with this hardware. Please don't take this article as a step by step guide, but use it as a guide.
The Up2 is an x86 Intel Apollo Lake-based mini-computer. Features such a quad-core CPU, dual Ethernet, a PCI-Express mini port and a Raspberry Pi compatible pin header make this board very attractive for high-end RT-Linux applications.
I was looking for a reasonably priced computer which can run ROS and Machinekit decently and still has leftover resources to render a fancy Qt/QML GUI and is relatively future-proof in terms of image recognition and machine learning.
Besides being an interesting x86 platform, there a new AI vision kit being sold as an extension for the Up2, which can become handing when implementing object and image recognition with ROS.
Someone from the community also proved that it is possible to run an external GPU via the Mini PCI-Express port.
All in all, Up2 seems like an excellent platform for robotics applications with ROS.
The Up2 comes with a Linux distribution called Ubilinux. Ubilinux is a Debian based distribution supported by Emutex. It comes with everything pre-installed to use the Raspberry Pi compatible pin headers of the Up2, this includes a kernel driver.
I decided against using the Ubilinux distribution since the modifications made by Emutex aren't transparent and I prefer to be in control of what my Linux distribution has installed or not.
The installation of a vanilla Debian Stretch works fine on the Up2. The only shortcoming I noticed, was that the GPIO access requires the Up2 kernel driver.
Therefore I decided to compile the Up2 kernel with the PREEMPT_RT patch myself.
Up2 PREEMPT_RT Kernel
Now we come to the quintessence of this article, compiling and installing the PREEMPT_RT kernel for the Up2.
I started with the Up Board kernel build guide and adapted it for Debian Stretch and the PREEMPT_RT patch and modifications to the kernel configuration.
First of all, install the build dependencies.
sudo apt-get update sudo apt-get install -y git build-essential kernel-package libncurses5-dev libssl-dev
Then continue by cloning the Ubilinux Kernel repository.
cd mkdir repos cd repos git clone --depth=1 https://github.com/emutex/ubilinux-kernel.git -b upboard-4.9 linux-upboard
Next, download and apply the PREEMPT_RT kernel patches. To find out the kernel version of your kernel source tree run
make kernelversion. In my case it was
Based on this version number, you need to look for a matching PREEMPT_RT patch in the kernel archives.
cd linux-upboard wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.9/older/patch-4.9.47-rt37.patch.xz unxz -cd patch-4.9.47-rt37.patch.xz | patch -p1
Then you can create the default kernel configuration:
The kernel now needs to be configured to use the RT scheduler. Either use the kernel menuconfig wizard using
make menuconfig or use your preferred text editor to edit the
.config file directly.
You need to set following kernel configuration parameters:
HIGH_RES_TIMERS=y CONFIG_PREEMPT_RT_FULL=y CONFIG_HZ_1000=y CONFIG_HZ=1000 CONFIG_OF=n
I encourage you also to disable the CPU idle state and to set the default CPU frequency governor to performance.
CONFIG_CPU_IDLE=n CONFIG_INTEL_IDLE=n CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
Next, you need to compile the Linux kernel.
make -j`nproc` && make -j`nproc` bindeb-pkg
Before the compilation starts, you might be asked to set additional configuration parameters. It should be safe to use the defaults, but note that debugging features might be enabled which could cause additional latencies.
After the compilition is complete (which can take several hours), you will find a few debian packages in the parent directory of the
$ ls linux-4.9.45-rt57-upboard-rt+_4.9.45-rt57-upboard-rt+-3_amd64.changes linux-firmware-image-4.9.45-rt57-upboard-rt+_4.9.45-rt57-upboard-rt+-3_amd64.deb linux-headers-4.9.45-rt57-upboard-rt+_4.9.45-rt57-upboard-rt+-3_amd64.deb linux-image-4.9.45-rt57-upboard-rt+_4.9.45-rt57-upboard-rt+-3_amd64.deb linux-libc-dev_4.9.45-rt57-upboard-rt+-3_amd64.deb linux-upboard
Install the new kernel package with:
sudo dpkg -i linux-*.deb
Restart your system and you should be running a PREEMPT_RT kernel.
$ uname -a Linux upsquared 4.9.45-rt57-upboard-rt+ #3 SMP PREEMPT RT Fri Sep 14 19:27:04 CEST 2018 x86_64 GNU/Linux
Tuning RT parameters
Unfortunately installing an RT kernel is not enough. For many applications, you still need to tweak the kernel parameters and other properties in order to get the required RT performance.
I won't cover how to do that in this post. However, I can encourage you to take a look at the "Improving the Real-Time Properties" guide.
A quick hint at this point. To modify the kernel boot arguments use the following:
/etc/default/grub and append your kernel options to the
GRUB_CMDLINE_LINUX_DEFAULT line an then automatically re-generate the grub.cfg file with:
grub-mkconfig -o /boot/grub/grub.cfg
Don't try to modify the grub config by hand.
In this article, you learned how to compile a PREEMPT_RT kernel for the Up Squared board. The guide also may be helpful for other compiling kernels for other boards as well.
If you have enjoyed reading this article, please subsribe to stay up to date with my newest blog posts.
Can Up board use this same way as Up squared board to install preempt rt kernel?
I have not tested it, but the kernel for the Up Squared and the Up Board should be the same.
Does the 40-pins GPIO works after running this real-time kernel?
Yes. Since we patched the Up2 kernel with the PREEMPT_RT patch it is possible to use the GPIOs. However, the GPIO pins themselves have a high latency, so they may not be suitable for your application.
Any advice to integrate an I2C device with the Up Squared board? It's an NFC reader that works perfectly on a Raspberry Pi 3 but I can not get it working on the Up Squared board.
Thanks in advance.
Since the RPi GPIO port is "emulated" via an external FPGA chip over SPI, the behavior could be different. Since I'm not an expert on the Up Squared hardware and GPIO drivers, I think you should ask this question in the [Up Forum](https://forum.up-community.org/categories/up-squared). There is also some info about I2C on the Up Squared [here](https://wiki.up-community.org/Pinout_UP2#I2C_ports).
Thank you so much for your answer. I already knew the up-Community as a source of initial information and asked this question but I didn't get any answer. My problem (after analizing kernel messages) is: "i2c_dw_handle_tx_abort: lost arbitration". From your expert point of view, do you have any idea or way I could work to solve him? (My device is a compatible RPi NFC Card reader configured in I2c mode with a BIOS setup based in 100Khz standard mode & PCI. I also test ACPI mode but it didn't work either).
Thanks in advance.
I found this thread [here](https://forum.up-community.org/discussion/2058/i2c-arbitration-error-help) which might relate to your problem. Have you tried decreasing the I2C bus baudrate?
I'm looking into the Pentium version of this board as I need a decent CPU with a current build I'm working on. The FPGA would be great if it were usable. I'm a big fan of Mesa but a built in FPGA would make for a very small footprint. From a discussion about this on the LinuxCNC forums, it seems that MK's HM2 VHDL should work with the Altera FPGA but I'm told that it is too small to run HM2. Any thoughts on whether it is possible to re-configure the FPGA for LCNC/MK and if there is any use for it?
In short, it's not possible since the manufacturer does neither provide the toolchain nor support for changing the firmware.
Moreover, the Up2 has terrible RT performance compared to other barebone PCs such as the Gigabyte Brix, I'm not sure why, but it's likely that culprit is some hardware device.
So I can only recommend you to use MESA cards and something like a Gigabyte Brix for your setup (same as I used for the robot).
Thanks for this detailed post. I followed more or less exactly as described. I'm trying to figure out why my lowlatency kernel will fail to boot on the up^2. I'm getting a failure to mount root partition I guess, and it cycles through "Running /cscripts/local-block . . . mdadm: CREATE group disk not found" until it times out and drops into initramfs. My stock upsquared kernel is booting just fine. Any thoughts on what is amiss?
I was following all the instructions with the same version of kernel and patch. It was successfully compiled, but when trying to boot, I get the following error:
mmc0: mmc_select_hs200 failed, error -84
mmc0: error -84 whilst initializing MMC card
I though I didn't enable appropriate driver in the kernel config, but it seems to be OK (MMC drivers are compiled as loadable modules, I also tried to compile them inside the kernel).
I checked 'dmesg' output for the working kernel (4.15.0-37), there is an entry "mmc0: new HS400 MMC card at address 0001".
Did you experience any issues like that? How did you solve it?
Best regards, Marcin
Thank you. You have helped me a lot.
I am working on make a robot arm with upboard as the controller board.
You are welcome.
We did not end up using the Up Squared for our robot project due to some latency issues. However, the "secret" of getting good RT performance is using cgroups. So if you are looking into RT control, I recommend you to check out CPU isolation, partrt, and cgroups.
Can you send me your deb packages for me? I followed your steps and got these packages:
But I can not login to system. It seems stucked, and I can not solve it.
Unfortunately, I already returned my Up Squared to the person who gave it to me for testing, so I can't help you with the packages.
However, if the system seems stuck, try to login via the tty terminal over one of the serial ports.
Also thank you for your RT suggestions. I will try it.
Hello Machine Koder,
In your code you are patching the kernel with -rt37 version of the patch, and your final files have -rt57 version, is this just a typo or have you encountered any problems with rt37? Ive compiled the kernel accoding to your article (with rt37) but it was very unstable (system was freezing after running almost any apllication).
Very likely I used the rt57 kernel if it has the extension. However, please note that I discarded the Up Squared because I could not achieve a good (small) RT latency. I did not experience any freezing, however.
H, I am sorry but this blog post or tutorial or whatever it is ..is garbage. No one is able to achieve your results. You are unable to write any numbers (latencies, testing method, ...) from your work on UP2 board. You is unable to respond any technical question other than *nothing* with hates to the UP board. For them.. for me with UP board with need for RT kernel this post is no more than lost of time.
Can You or anyone write down working combination of distribution, version, kernel patch version and configuration that works?
If not, please write at begin of this post warning "this not work" or something.
Thank you for the feedback. If you read through the post you will see the kernel version this was tested with. As stated in previous posts, I don't have the Up Squared anymore, so I can't update the info.
I still believe this post might be helpful for people who want to compile an RT kernel for the Up Squared, even if you can't follow it step by step.
Still, I think your suggestion of adding a disclaimer to the post is valid, especially since it doesn't state when it was posted.