Up Squared PREEMPT_RT

Compiling an RT Kernel for the Up Squared

3 minutes read

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.

Up Squared

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.

Ubilinux

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 4.9.45.

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:

make upboard_defconfig

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.

xdg-open .config

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 linux-upboard directory.

$ 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:

Edit /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.

Conclusion

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.

Your
Machine Koder

Spread the love

Comments 21

    1. Post
      Author
    1. Post
      Author

      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.

  1. 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.

    1. Post
      Author
  2. 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.

    1. Post
      Author
  3. 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?

    1. Post
      Author

      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).

  4. 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?

  5. Dear,

    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

    1. Post
      Author

      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.

      Machine Koder

      1. Can you send me your deb packages for me? I followed your steps and got these packages:

        linux-firmware-image-4.9.45-rt37-upboard+_4.9.45-rt37-upboard+-1_amd64.deb
        linux-headers-4.9.45-rt37-upboard+_4.9.45-rt37-upboard+-1_amd64.deb
        linux-image-4.9.45-rt37-upboard+_4.9.45-rt37-upboard+-1_amd64.deb
        linux-libc-dev_4.9.45-rt37-upboard+-1_amd64.deb

        But I can not login to system. It seems stucked, and I can not solve it.

        Thank you.

        1. Post
          Author

          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.

  6. 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).

    1. Post
      Author

      Hi Jakub,

      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.

      Alex

  7. 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.

    1. Post
      Author

      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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.